Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AArch64][GlobalISel] Cannot legalize G_ICMP for i192 #64394

Open
nitinjohnraj opened this issue Aug 3, 2023 · 2 comments
Open

[AArch64][GlobalISel] Cannot legalize G_ICMP for i192 #64394

nitinjohnraj opened this issue Aug 3, 2023 · 2 comments

Comments

@nitinjohnraj
Copy link
Contributor

The following code snippet crashes the legalizer, since G_ICMP cannot be legalized for s192. The legalizer first widens s192 to s256, after which it fails to legalize the code. Other instructions (like G_ADD) do get legalized for s192.

[nraj@host llvm-project]$ cat test.mir
---
name:            cmp_sgt_i192
body:             |
  bb.0.entry:
    ; CHECK-LABEL: name: cmp_sgt_i64
    ; CHECK: %xhi:_(s64) = COPY $x10
    ; CHECK-NEXT: %xlo:_(s64) = COPY $x11
    ; CHECK-NEXT: %yhi:_(s64) = COPY $x12
    ; CHECK-NEXT: %ylo:_(s64) = COPY $x13
    ; CHECK-NEXT: [[ICMP:%[0-9]+]]:_(s64) = G_ICMP intpred(sgt), %xlo(s64), %ylo
    ; CHECK-NEXT: [[ICMP1:%[0-9]+]]:_(s64) = G_ICMP intpred(eq), %xlo(s64), %ylo
    ; CHECK-NEXT: [[ICMP2:%[0-9]+]]:_(s64) = G_ICMP intpred(ugt), %xhi(s64), %yhi
    ; CHECK-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 1
    ; CHECK-NEXT: [[AND:%[0-9]+]]:_(s64) = G_AND [[ICMP1]], [[C]]
    ; CHECK-NEXT: [[SELECT:%[0-9]+]]:_(s64) = G_SELECT [[AND]](s64), [[ICMP2]], [[ICMP]]
    ; CHECK-NEXT: $x10 = COPY [[SELECT]](s64)
    ; CHECK-NEXT: PseudoRET implicit $x10
    %x:_(s192) = G_IMPLICIT_DEF
    %y:_(s192) = G_IMPLICIT_DEF
    %z:_(s1) = G_ICMP intpred(sgt), %x, %y
    %z0:_(s64) = G_ANYEXT %z
    $x0 = COPY %z0(s64)
    RET_ReallyLR implicit $x0

...
[nraj@sw06 llvm-project]$ /scratch/nraj/gisel/build/x64_riscv_release/bin/llc -mtriple=aarch64 -run-pass=legalizer test.mir -o - --debug
... (Some lines skipped)
=== New Iteration ===
Legalizing: %z:_(s1) = G_ICMP intpred(sgt), %x:_(s192), %y:_
Applying legalizer ruleset to: 132, Tys={s1, s192, }, Opcode=132, MMOs={}
.. no match
.. match
.. .. WidenScalar, 1, s256
.. Widen scalar
.. .. Changing MI: %z:_(s1) = G_ICMP intpred(sgt), %x:_(s192), %y:_
CSEInfo::Recording new MI G_SEXT
CSEInfo::Recording new MI G_SEXT
.. .. Changed MI: %z:_(s1) = G_ICMP intpred(sgt), %4:_(s256), %5:_
.. .. New MI: %4:_(s256) = G_SEXT %x:_(s192)
.. .. New MI: %5:_(s256) = G_SEXT %y:_(s192)
.. No debug info was present
Legalizing: %z:_(s1) = G_ICMP intpred(sgt), %4:_(s256), %5:_
Applying legalizer ruleset to: 132, Tys={s1, s256, }, Opcode=132, MMOs={}
.. no match
.. no match
.. no match
.. match
.. .. NarrowScalar, 1, s64
.. Narrow scalar
LLVM ERROR: unable to legalize instruction: %z:_(s1) = G_ICMP intpred(sgt), %4:_(s256), %5:_ (in function: cmp_sgt_i192)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /scratch/nraj/gisel/build/x64_riscv_release/bin/llc -mtriple=aarch64 -run-pass=legalizer test.mir -o - --debug
1.      Running pass 'Function Pass Manager' on module 'test.mir'.
2.      Running pass 'Legalizer' on function '@cmp_sgt_i192'
 #0 0x0000000001a881a7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/nraj/gisel/build/x64_riscv_release/bin/llc+0x1a881a7)
 #1 0x0000000001a85ece llvm::sys::RunSignalHandlers() (/scratch/nraj/gisel/build/x64_riscv_release/bin/llc+0x1a85ece)
 #2 0x0000000001a889bf SignalHandler(int) Signals.cpp:0:0
 #3 0x00007fda7b5b1cf0 __restore_rt (/lib64/libpthread.so.0+0x12cf0)
 #4 0x00007fda7a025aff raise (/lib64/libc.so.6+0x4eaff)
 #5 0x00007fda79ff8ea5 abort (/lib64/libc.so.6+0x21ea5)
 #6 0x0000000001a05e63 llvm::report_fatal_error(llvm::Twine const&, bool) (/scratch/nraj/gisel/build/x64_riscv_release/bin/llc+0x1a05e63)
 #7 0x0000000001ce2e94 (/scratch/nraj/gisel/build/x64_riscv_release/bin/llc+0x1ce2e94)
 #8 0x0000000001ce3222 llvm::reportGISelFailure(llvm::MachineFunction&, llvm::TargetPassConfig const&, llvm::MachineOptimizationRemarkEmitter&, char const*, llvm::StringRef, llvm::MachineInstr const&) (/scratch/nraj/gisel/build/x64_riscv_release/bin/llc
+0x1ce3222)
 #9 0x0000000001c7eb9f llvm::Legalizer::runOnMachineFunction(llvm::MachineFunction&) (/scratch/nraj/gisel/build/x64_riscv_release/bin/llc+0x1c7eb9f)
#10 0x0000000000ee6e5c llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/scratch/nraj/gisel/build/x64_riscv_release/bin/llc+0xee6e5c)
#11 0x00000000013f62b3 llvm::FPPassManager::runOnFunction(llvm::Function&) (/scratch/nraj/gisel/build/x64_riscv_release/bin/llc+0x13f62b3)
#12 0x00000000013fdf31 llvm::FPPassManager::runOnModule(llvm::Module&) (/scratch/nraj/gisel/build/x64_riscv_release/bin/llc+0x13fdf31)
#13 0x00000000013f6ab6 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/scratch/nraj/gisel/build/x64_riscv_release/bin/llc+0x13f6ab6)
#14 0x00000000006a7a78 compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#15 0x00000000006a554d main (/scratch/nraj/gisel/build/x64_riscv_release/bin/llc+0x6a554d)
#16 0x00007fda7a011d85 __libc_start_main (/lib64/libc.so.6+0x3ad85)
#17 0x00000000006a1eee _start (/scratch/nraj/gisel/build/x64_riscv_release/bin/llc+0x6a1eee)
Aborted
@llvmbot
Copy link
Collaborator

llvmbot commented Aug 3, 2023

@llvm/issue-subscribers-backend-aarch64

@nitinjohnraj
Copy link
Contributor Author

The failure occurs due to an existing TODO in LegalizerHelper.

nitinjohnraj added a commit that referenced this issue Aug 7, 2023
Test legalization for (i7, i8, i16, i32, i48, i64) on rv32 and for (i8, i15, i16, i32, i64, i72, i128). Legalization fails for i96 on rv32 and i192 on rv64. Note that [i192 fails for AArch64](#64394).

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D157023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants