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

[RISCV] Assertion `LHS.getValueType() == VT && RHS.getValueType() == VT && "Cannot use select on differing types"' failed. #90652

Closed
dtcxzyw opened this issue Apr 30, 2024 · 1 comment · Fixed by #90659
Assignees
Labels
backend:RISC-V crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@dtcxzyw
Copy link
Member

dtcxzyw commented Apr 30, 2024

Reduced test case: https://godbolt.org/z/ToPME8sW1

define i1 @test(i64 %x, i1 %cond1, i1 %cond2) {
entry:
  %sadd = call { i64, i1 } @llvm.sadd.with.overflow.i64(i64 %x, i64 1)
  %ov = extractvalue { i64, i1 } %sadd, 1
  %or = or i1 %cond2, %ov
  %sel = select i1 %cond1, i1 %cond2, i1 %or
  ret i1 %sel
}
llc: /root/llvm-project/llvm/include/llvm/CodeGen/SelectionDAG.h:1239: llvm::SDValue llvm::SelectionDAG::getSelect(const llvm::SDLoc&, llvm::EVT, llvm::SDValue, llvm::SDValue, llvm::SDValue): Assertion `LHS.getValueType() == VT && RHS.getValueType() == VT && "Cannot use select on differing types"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/llc -o /app/output.s -x86-asm-syntax=intel -mtriple=riscv64 <source>
1.	Running pass 'Function Pass Manager' on module '<source>'.
2.	Running pass 'RISC-V DAG->DAG Pattern Instruction Selection' on function '@test'
 #0 0x000000000395b768 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x395b768)
 #1 0x0000000003958ebc SignalHandler(int) Signals.cpp:0:0
 #2 0x000079ecb9e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x000079ecb9e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x000079ecb9e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x000079ecb9e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x000079ecb9e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #7 0x000079ecb9e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #8 0x0000000000bd692f llvm::SelectionDAG::getSelect(llvm::SDLoc const&, llvm::EVT, llvm::SDValue, llvm::SDValue, llvm::SDValue) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0xbd692f)
 #9 0x0000000001ab4ab6 tryFoldSelectIntoOp(llvm::SDNode*, llvm::SelectionDAG&, llvm::SDValue, llvm::SDValue, bool) RISCVISelLowering.cpp:0:0
#10 0x0000000001b125a6 llvm::RISCVTargetLowering::PerformDAGCombine(llvm::SDNode*, llvm::TargetLowering::DAGCombinerInfo&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x1b125a6)
#11 0x00000000035cdb7d (anonymous namespace)::DAGCombiner::combine(llvm::SDNode*) DAGCombiner.cpp:0:0
#12 0x00000000035cf48c (anonymous namespace)::DAGCombiner::Run(llvm::CombineLevel) DAGCombiner.cpp:0:0
#13 0x00000000035d1a6a llvm::SelectionDAG::Combine(llvm::CombineLevel, llvm::AAResults*, llvm::CodeGenOptLevel) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x35d1a6a)
#14 0x00000000037273d2 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x37273d2)
#15 0x000000000372af15 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x372af15)
#16 0x000000000372c987 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (.part.0) SelectionDAGISel.cpp:0:0
#17 0x0000000002976b71 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#18 0x0000000002f36633 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2f36633)
#19 0x0000000002f36871 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2f36871)
#20 0x0000000002f370d5 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2f370d5)
#21 0x000000000082aa5c compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#22 0x0000000000728f26 main (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x728f26)
#23 0x000079ecb9e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#24 0x000079ecb9e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#25 0x000000000082157e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x82157e)
Program terminated with signal: SIGSEGV
Compiler returned: 139
@dtcxzyw dtcxzyw added backend:RISC-V crash Prefer [crash-on-valid] or [crash-on-invalid] labels Apr 30, 2024
@dtcxzyw dtcxzyw self-assigned this Apr 30, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 30, 2024

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

Author: Yingwei Zheng (dtcxzyw)

Reduced test case: https://godbolt.org/z/ToPME8sW1 ``` define i1 @test(i64 %x, i1 %cond1, i1 %cond2) { entry: %sadd = call { i64, i1 } @llvm.sadd.with.overflow.i64(i64 %x, i64 1) %ov = extractvalue { i64, i1 } %sadd, 1 %or = or i1 %cond2, %ov %sel = select i1 %cond1, i1 %cond2, i1 %or ret i1 %sel } ``` ``` llc: /root/llvm-project/llvm/include/llvm/CodeGen/SelectionDAG.h:1239: llvm::SDValue llvm::SelectionDAG::getSelect(const llvm::SDLoc&, llvm::EVT, llvm::SDValue, llvm::SDValue, llvm::SDValue): Assertion `LHS.getValueType() == VT && RHS.getValueType() == VT && "Cannot use select on differing types"' failed. PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/llc -o /app/output.s -x86-asm-syntax=intel -mtriple=riscv64 <source> 1. Running pass 'Function Pass Manager' on module '<source>'. 2. Running pass 'RISC-V DAG->DAG Pattern Instruction Selection' on function '@test' #0 0x000000000395b768 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x395b768) #1 0x0000000003958ebc SignalHandler(int) Signals.cpp:0:0 #2 0x000079ecb9e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #3 0x000079ecb9e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc) #4 0x000079ecb9e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476) #5 0x000079ecb9e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3) #6 0x000079ecb9e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b) #7 0x000079ecb9e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96) #8 0x0000000000bd692f llvm::SelectionDAG::getSelect(llvm::SDLoc const&, llvm::EVT, llvm::SDValue, llvm::SDValue, llvm::SDValue) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0xbd692f) #9 0x0000000001ab4ab6 tryFoldSelectIntoOp(llvm::SDNode*, llvm::SelectionDAG&, llvm::SDValue, llvm::SDValue, bool) RISCVISelLowering.cpp:0:0 #10 0x0000000001b125a6 llvm::RISCVTargetLowering::PerformDAGCombine(llvm::SDNode*, llvm::TargetLowering::DAGCombinerInfo&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x1b125a6) #11 0x00000000035cdb7d (anonymous namespace)::DAGCombiner::combine(llvm::SDNode*) DAGCombiner.cpp:0:0 #12 0x00000000035cf48c (anonymous namespace)::DAGCombiner::Run(llvm::CombineLevel) DAGCombiner.cpp:0:0 #13 0x00000000035d1a6a llvm::SelectionDAG::Combine(llvm::CombineLevel, llvm::AAResults*, llvm::CodeGenOptLevel) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x35d1a6a) #14 0x00000000037273d2 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x37273d2) #15 0x000000000372af15 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x372af15) #16 0x000000000372c987 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (.part.0) SelectionDAGISel.cpp:0:0 #17 0x0000000002976b71 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0 #18 0x0000000002f36633 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2f36633) #19 0x0000000002f36871 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2f36871) #20 0x0000000002f370d5 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2f370d5) #21 0x000000000082aa5c compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0 #22 0x0000000000728f26 main (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x728f26) #23 0x000079ecb9e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90) #24 0x000079ecb9e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40) #25 0x000000000082157e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x82157e) Program terminated with signal: SIGSEGV Compiler returned: 139 ```

dtcxzyw added a commit that referenced this issue Apr 30, 2024
```
SelectionDAG has 17 nodes:
  t0: ch,glue = EntryToken
    t6: i64,ch = CopyFromReg t0, Register:i64 %2
  t8: i1 = truncate t6
          t4: i64,ch = CopyFromReg t0, Register:i64 %1
        t7: i1 = truncate t4
            t2: i64,ch = CopyFromReg t0, Register:i64 %0
          t10: i64,i1 = saddo t2, Constant:i64<1>
        t11: i1 = or t8, t10:1
      t12: i1 = select t7, t8, t11
    t13: i64 = any_extend t12
  t15: ch,glue = CopyToReg t0, Register:i64 $x10, t13
  t16: ch = RISCVISD::RET_GLUE t15, Register:i64 $x10, t15:1
```

`OtherOpVT` should be i1, but `OtherOp->getValueType(0)` returns `i64`,
which ignores `ResNo` in `SDValue`.

Fix #90652.
llvmbot pushed a commit to llvmbot/llvm-project that referenced this issue Apr 30, 2024
```
SelectionDAG has 17 nodes:
  t0: ch,glue = EntryToken
    t6: i64,ch = CopyFromReg t0, Register:i64 %2
  t8: i1 = truncate t6
          t4: i64,ch = CopyFromReg t0, Register:i64 %1
        t7: i1 = truncate t4
            t2: i64,ch = CopyFromReg t0, Register:i64 %0
          t10: i64,i1 = saddo t2, Constant:i64<1>
        t11: i1 = or t8, t10:1
      t12: i1 = select t7, t8, t11
    t13: i64 = any_extend t12
  t15: ch,glue = CopyToReg t0, Register:i64 $x10, t13
  t16: ch = RISCVISD::RET_GLUE t15, Register:i64 $x10, t15:1
```

`OtherOpVT` should be i1, but `OtherOp->getValueType(0)` returns `i64`,
which ignores `ResNo` in `SDValue`.

Fix llvm#90652.

(cherry picked from commit 2647bd7)
tstellar pushed a commit to llvmbot/llvm-project that referenced this issue May 1, 2024
```
SelectionDAG has 17 nodes:
  t0: ch,glue = EntryToken
    t6: i64,ch = CopyFromReg t0, Register:i64 %2
  t8: i1 = truncate t6
          t4: i64,ch = CopyFromReg t0, Register:i64 %1
        t7: i1 = truncate t4
            t2: i64,ch = CopyFromReg t0, Register:i64 %0
          t10: i64,i1 = saddo t2, Constant:i64<1>
        t11: i1 = or t8, t10:1
      t12: i1 = select t7, t8, t11
    t13: i64 = any_extend t12
  t15: ch,glue = CopyToReg t0, Register:i64 $x10, t13
  t16: ch = RISCVISD::RET_GLUE t15, Register:i64 $x10, t15:1
```

`OtherOpVT` should be i1, but `OtherOp->getValueType(0)` returns `i64`,
which ignores `ResNo` in `SDValue`.

Fix llvm#90652.

(cherry picked from commit 2647bd7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:RISC-V crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants