Skip to content

[RISC-V] Cannot select: t32: i32 = RISCVISD::CZERO_EQZ t25, t4 with xventanacondops #100855

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

Closed
patrick-rivos opened this issue Jul 27, 2024 · 4 comments · Fixed by #100891
Closed

Comments

@patrick-rivos
Copy link
Contributor

patrick-rivos commented Jul 27, 2024

C Testcase:

long long a;
void b();
void c() { b(!0 > a); }

./clang -march=rv32ixventanacondops red.c

Godbolt: https://godbolt.org/z/1e4zodoc3

Testcase:

target datalayout = "e-m:e-p:32:32-i64:64-n32-S128"
target triple = "riscv32-unknown-linux-gnu"

define void @c(i64 %0) #0 {
entry:
  %cmp = icmp sgt i64 1, %0
  %conv = zext i1 %cmp to i32
  store i32 %conv, ptr null, align 4
  ret void
}

attributes #0 = { "target-features"="+32bit,+relax,+xventanacondops,-a,-b,-c,-d,-e,-experimental-smmpm,-experimental-smnpm,-experimental-ssnpm,-experimental-sspm,-experimental-ssqosid,-experimental-supm,-experimental-zacas,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-f,-h,-m,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smepmp,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-v,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xwchc,-za128rs,-za64rs,-zaamo,-zabha,-zalrsc,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zicsr,-zifencei,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-zmmul,-ztso,-zvbb,-zvbc,-zve32f,-zve32x,-zve64d,-zve64f,-zve64x,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl128b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl32b,-zvl4096b,-zvl512b,-zvl64b,-zvl65536b,-zvl8192b" }

Command/backtrace:

> /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc reduced.ll
LLVM ERROR: Cannot select: t32: i32 = RISCVISD::CZERO_EQZ t25, t4
  t25: i32 = setcc t4, Constant:i32<0>, setlt:ch
    t4: i32,ch = CopyFromReg t0, Register:i32 %1
      t3: i32 = Register %1
    t10: i32 = Constant<0>
  t4: i32,ch = CopyFromReg t0, Register:i32 %1
    t3: i32 = Register %1
In function: c
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc reduced.ll
1.      Running pass 'Function Pass Manager' on module 'reduced.ll'.
2.      Running pass 'RISC-V DAG->DAG Pattern Instruction Selection' on function '@c'
 #0 0x00005edc1f7775f0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1dcf5f0)
 #1 0x00005edc1f774a0f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1dcca0f)
 #2 0x00005edc1f774b65 SignalHandler(int) Signals.cpp:0:0
 #3 0x0000788fe3c42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x0000788fe3c969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x0000788fe3c969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x0000788fe3c969fc pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x0000788fe3c42476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x0000788fe3c287f3 abort ./stdlib/abort.c:81:7
 #9 0x00005edc1decdc5c llvm::UniqueStringSaver::save(llvm::StringRef) (.cold) StringSaver.cpp:0:0
#10 0x00005edc1f5013bb llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1b593bb)
#11 0x00005edc1f507519 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1b5f519)
#12 0x00005edc1e0b893f llvm::RISCVDAGToDAGISel::Select(llvm::SDNode*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x71093f)
#13 0x00005edc1f4fda84 llvm::SelectionDAGISel::DoInstructionSelection() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1b55a84)
#14 0x00005edc1f50d090 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1b65090)
#15 0x00005edc1f5105f6 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1b685f6)
#16 0x00005edc1f511f2f llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1b69f2f)
#17 0x00005edc1f502af9 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1b5aaf9)
#18 0x00005edc1e68ee97 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#19 0x00005edc1ecad616 llvm::FPPassManager::runOnFunction(llvm::Function&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1305616)
#20 0x00005edc1ecad869 llvm::FPPassManager::runOnModule(llvm::Module&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1305869)
#21 0x00005edc1ecae1c5 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x13061c5)
#22 0x00005edc1df90b06 compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#23 0x00005edc1ded5aee main (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x52daee)
#24 0x0000788fe3c29d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#25 0x0000788fe3c29e40 call_init ./csu/../csu/libc-start.c:128:20
#26 0x0000788fe3c29e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#27 0x00005edc1df873d5 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x5df3d5)
zsh: IOT instruction (core dumped)  /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc

Godbolt: https://godbolt.org/z/9Te3fv1f7

Found via fuzzer.

@llvmbot
Copy link
Member

llvmbot commented Jul 27, 2024

@llvm/issue-subscribers-backend-risc-v

Author: Patrick O'Neill (patrick-rivos)

C Testcase: ```c long long a; void b(); void c() { b(!0 > a); } ``` `./clang -march=rv32ixventanacondops red.c`

Godbolt: https://godbolt.org/z/1e4zodoc3

Testcase:

target datalayout = "e-m:e-p:32:32-i64:64-n32-S128"
target triple = "riscv32-unknown-linux-gnu"

define void @<!-- -->c(i64 %0) #<!-- -->0 {
entry:
  %cmp = icmp sgt i64 1, %0
  %conv = zext i1 %cmp to i32
  store i32 %conv, ptr null, align 4
  ret void
}

attributes #<!-- -->0 = { "target-features"="+32bit,+relax,+xventanacondops,-a,-b,-c,-d,-e,-experimental-smmpm,-experimental-smnpm,-experimental-ssnpm,-experimental-sspm,-experimental-ssqosid,-experimental-supm,-experimental-zacas,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-f,-h,-m,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smepmp,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-v,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xwchc,-za128rs,-za64rs,-zaamo,-zabha,-zalrsc,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zicsr,-zifencei,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-zmmul,-ztso,-zvbb,-zvbc,-zve32f,-zve32x,-zve64d,-zve64f,-zve64x,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl128b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl32b,-zvl4096b,-zvl512b,-zvl64b,-zvl65536b,-zvl8192b" }

Command/backtrace:

&gt; /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc reduced.ll
LLVM ERROR: Cannot select: t32: i32 = RISCVISD::CZERO_EQZ t25, t4
  t25: i32 = setcc t4, Constant:i32&lt;0&gt;, setlt:ch
    t4: i32,ch = CopyFromReg t0, Register:i32 %1
      t3: i32 = Register %1
    t10: i32 = Constant&lt;0&gt;
  t4: i32,ch = CopyFromReg t0, Register:i32 %1
    t3: i32 = Register %1
In function: c
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc reduced.ll
1.      Running pass 'Function Pass Manager' on module 'reduced.ll'.
2.      Running pass 'RISC-V DAG-&gt;DAG Pattern Instruction Selection' on function '@<!-- -->c'
 #<!-- -->0 0x00005edc1f7775f0 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1dcf5f0)
 #<!-- -->1 0x00005edc1f774a0f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1dcca0f)
 #<!-- -->2 0x00005edc1f774b65 SignalHandler(int) Signals.cpp:0:0
 #<!-- -->3 0x0000788fe3c42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #<!-- -->4 0x0000788fe3c969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #<!-- -->5 0x0000788fe3c969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #<!-- -->6 0x0000788fe3c969fc pthread_kill ./nptl/pthread_kill.c:89:10
 #<!-- -->7 0x0000788fe3c42476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #<!-- -->8 0x0000788fe3c287f3 abort ./stdlib/abort.c:81:7
 #<!-- -->9 0x00005edc1decdc5c llvm::UniqueStringSaver::save(llvm::StringRef) (.cold) StringSaver.cpp:0:0
#<!-- -->10 0x00005edc1f5013bb llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1b593bb)
#<!-- -->11 0x00005edc1f507519 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1b5f519)
#<!-- -->12 0x00005edc1e0b893f llvm::RISCVDAGToDAGISel::Select(llvm::SDNode*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x71093f)
#<!-- -->13 0x00005edc1f4fda84 llvm::SelectionDAGISel::DoInstructionSelection() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1b55a84)
#<!-- -->14 0x00005edc1f50d090 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1b65090)
#<!-- -->15 0x00005edc1f5105f6 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&amp;) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1b685f6)
#<!-- -->16 0x00005edc1f511f2f llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&amp;) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1b69f2f)
#<!-- -->17 0x00005edc1f502af9 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&amp;) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1b5aaf9)
#<!-- -->18 0x00005edc1e68ee97 llvm::MachineFunctionPass::runOnFunction(llvm::Function&amp;) (.part.0) MachineFunctionPass.cpp:0:0
#<!-- -->19 0x00005edc1ecad616 llvm::FPPassManager::runOnFunction(llvm::Function&amp;) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1305616)
#<!-- -->20 0x00005edc1ecad869 llvm::FPPassManager::runOnModule(llvm::Module&amp;) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1305869)
#<!-- -->21 0x00005edc1ecae1c5 llvm::legacy::PassManagerImpl::run(llvm::Module&amp;) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x13061c5)
#<!-- -->22 0x00005edc1df90b06 compileModule(char**, llvm::LLVMContext&amp;) llc.cpp:0:0
#<!-- -->23 0x00005edc1ded5aee main (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x52daee)
#<!-- -->24 0x0000788fe3c29d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#<!-- -->25 0x0000788fe3c29e40 call_init ./csu/../csu/libc-start.c:128:20
#<!-- -->26 0x0000788fe3c29e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#<!-- -->27 0x00005edc1df873d5 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x5df3d5)
zsh: IOT instruction (core dumped)  /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc

Godbolt: https://godbolt.org/z/9Te3fv1f7

Found via fuzzer.

@dtcxzyw dtcxzyw added the invalid Resolved as invalid, i.e. not a bug label Jul 27, 2024
@dtcxzyw
Copy link
Member

dtcxzyw commented Jul 27, 2024

We don't support XVentanaCondOps on RV32.

@dtcxzyw dtcxzyw closed this as not planned Won't fix, can't repro, duplicate, stale Jul 27, 2024
@patrick-rivos
Copy link
Contributor Author

patrick-rivos commented Jul 27, 2024

If it's unsupported then -march=rv32i_xventanacondops should probably throw an error in the frontend rather than triggering an assert in the backend.

@topperc
Copy link
Collaborator

topperc commented Jul 27, 2024

Can we just support it in the backend for RV32? The spec says that it would be straightforward.

All current cores by Ventana Micro implement RV64 and are designed as 64-bit only, the
RV32-column is marked "n/a". The instructions in the XVentanaCondOps extension are
defined to operate on XLEN and would thus be directly applicable to RV32.

I'm fine with adding an error in the frontend too, but why make the backend more fragile than needed?

@topperc topperc reopened this Jul 27, 2024
topperc added a commit to topperc/llvm-project that referenced this issue Jul 27, 2024
Ventana doesn't have RV32 cores so they really supported for RV32,
but there's nothing specifically 64-bit about the instructions.

My goal here is to fix cannot select errors if XVentanaCondOps is
enabled on RV32. Alternatively, we could quality the lowering code
to also check IsRV64 so that we don't create RISCVISD::CZERO* nodes.
Fixing the isel patterns seemed simpler.

Fixes llvm#100855.
@EugeneZelenko EugeneZelenko removed the invalid Resolved as invalid, i.e. not a bug label Jul 27, 2024
topperc added a commit that referenced this issue Jul 28, 2024
Ventana doesn't have RV32 cores so the instructions aren't really
supported for RV32, but there's nothing specifically 64-bit about them.

My goal here is to fix cannot select errors if XVentanaCondOps is
enabled on RV32. Alternatively, we could quality the lowering code to
also check IsRV64 so that we don't create RISCVISD::CZERO* nodes. Fixing
the isel patterns seemed simpler.

Fixes #100855.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants