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

[WASM] v1i8 / v1i16 crashes backend with invalid Bitcast when targeting bleeding-edge #59625

Closed
HazyFish opened this issue Dec 20, 2022 · 5 comments
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] llvm:codegen

Comments

@HazyFish
Copy link
Contributor

HazyFish commented Dec 20, 2022

Description

When targeting WASM bleeding-edge, the following code crashes backend with assertion VT.getSizeInBits() == Operand.getValueSizeInBits() && "Cannot BITCAST between types of different sizes!" failed during WebAssembly Instruction Selection.

The code can successfully compile when targeting WASM without specifying -mcpu=bleeding-edge.

The problem exists for v1i8 / v1i16, but it does not exist for v1i32 / v1i64.

Minimal Reproduction

https://godbolt.org/z/T44czsqWr

Code

define <1 x i16> @f(<1 x i16> %0) {
BB:
  %B2 = srem <1 x i16> %0, %0
  br label %BB1

BB1:                                             ; preds = %BB
  %B = urem <1 x i16> %B2, <i16 3>
  ret <1 x i16> %B
}

Stack Trace

llc: /home/henry/aflplusplus-isel/llvm-project-latest/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:5530: llvm::SDValue llvm::SelectionDAG::getNode(unsigned int, const llvm::SDLoc &, llvm::EVT, llvm::SDValue, const llvm::SDNodeFlags): Assertion `VT.getSizeInBits() == Operand.getValueSizeInBits() && "Cannot BITCAST between types of different sizes!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: ./llvm-project-latest/build-debug/bin/llc -mtriple=wasm64 -mcpu=bleeding-edge ./crash-reports/dagisel-wasm64/bleeding-edge/1.ll
1.	Running pass 'Function Pass Manager' on module './crash-reports/dagisel-wasm64/bleeding-edge/1.ll'.
2.	Running pass 'WebAssembly Instruction Selection' on function '@f'
 #0 0x00007f9e979c0f2a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/henry/aflplusplus-isel/llvm-project-latest/llvm/lib/Support/Unix/Signals.inc:567:11
 #1 0x00007f9e979c10db PrintStackTraceSignalHandler(void*) /home/henry/aflplusplus-isel/llvm-project-latest/llvm/lib/Support/Unix/Signals.inc:641:1
 #2 0x00007f9e979bf756 llvm::sys::RunSignalHandlers() /home/henry/aflplusplus-isel/llvm-project-latest/llvm/lib/Support/Signals.cpp:104:5
 #3 0x00007f9e979c1805 SignalHandler(int) /home/henry/aflplusplus-isel/llvm-project-latest/llvm/lib/Support/Unix/Signals.inc:412:1
 #4 0x00007f9e96155980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
 #5 0x00007f9e95451e87 raise /build/glibc-CVJwZb/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #6 0x00007f9e954537f1 abort /build/glibc-CVJwZb/glibc-2.27/stdlib/abort.c:81:0
 #7 0x00007f9e954433fa __assert_fail_base /build/glibc-CVJwZb/glibc-2.27/assert/assert.c:89:0
 #8 0x00007f9e95443472 (/lib/x86_64-linux-gnu/libc.so.6+0x30472)
 #9 0x00007f9e981528d0 llvm::SelectionDAG::getNode(unsigned int, llvm::SDLoc const&, llvm::EVT, llvm::SDValue, llvm::SDNodeFlags) /home/henry/aflplusplus-isel/llvm-project-latest/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:0:5
#10 0x00007f9e981371fd llvm::SelectionDAG::getNode(unsigned int, llvm::SDLoc const&, llvm::EVT, llvm::SDValue) /home/henry/aflplusplus-isel/llvm-project-latest/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:5149:10
#11 0x00007f9e9813e28a llvm::SelectionDAG::getBitcast(llvm::EVT, llvm::SDValue) /home/henry/aflplusplus-isel/llvm-project-latest/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:2229:10
#12 0x00007f9e97e40ab6 (anonymous namespace)::DAGCombiner::visitEXTRACT_SUBVECTOR(llvm::SDNode*) /home/henry/aflplusplus-isel/llvm-project-latest/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:22304:22
#13 0x00007f9e97df1045 (anonymous namespace)::DAGCombiner::visit(llvm::SDNode*) /home/henry/aflplusplus-isel/llvm-project-latest/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1792:40
#14 0x00007f9e97df0108 (anonymous namespace)::DAGCombiner::combine(llvm::SDNode*) /home/henry/aflplusplus-isel/llvm-project-latest/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1828:10
#15 0x00007f9e97def716 (anonymous namespace)::DAGCombiner::Run(llvm::CombineLevel) /home/henry/aflplusplus-isel/llvm-project-latest/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1626:18
#16 0x00007f9e97deefff llvm::SelectionDAG::Combine(llvm::CombineLevel, llvm::AAResults*, llvm::CodeGenOpt::Level) /home/henry/aflplusplus-isel/llvm-project-latest/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:25586:3
#17 0x00007f9e981c000f llvm::SelectionDAGISel::CodeGenAndEmitDAG() /home/henry/aflplusplus-isel/llvm-project-latest/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:785:3
#18 0x00007f9e981bfbbd llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, true>, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, true>, bool&) /home/henry/aflplusplus-isel/llvm-project-latest/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:701:1
#19 0x00007f9e981bf64d llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) /home/henry/aflplusplus-isel/llvm-project-latest/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1641:11
#20 0x00007f9e981bcb27 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) /home/henry/aflplusplus-isel/llvm-project-latest/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:480:3
#21 0x00007f9ea4be15aa (anonymous namespace)::WebAssemblyDAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) /home/henry/aflplusplus-isel/llvm-project-latest/llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp:61:5
#22 0x00007f9e9b1d51d5 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /home/henry/aflplusplus-isel/llvm-project-latest/llvm/lib/CodeGen/MachineFunctionPass.cpp:91:8
#23 0x00007f9e9a31d676 llvm::FPPassManager::runOnFunction(llvm::Function&) /home/henry/aflplusplus-isel/llvm-project-latest/llvm/lib/IR/LegacyPassManager.cpp:1430:23
#24 0x00007f9e9a3224a2 llvm::FPPassManager::runOnModule(llvm::Module&) /home/henry/aflplusplus-isel/llvm-project-latest/llvm/lib/IR/LegacyPassManager.cpp:1476:16
#25 0x00007f9e9a31df49 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /home/henry/aflplusplus-isel/llvm-project-latest/llvm/lib/IR/LegacyPassManager.cpp:1545:23
#26 0x00007f9e9a31dabd llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/henry/aflplusplus-isel/llvm-project-latest/llvm/lib/IR/LegacyPassManager.cpp:535:16
#27 0x00007f9e9a322781 llvm::legacy::PassManager::run(llvm::Module&) /home/henry/aflplusplus-isel/llvm-project-latest/llvm/lib/IR/LegacyPassManager.cpp:1672:3
#28 0x0000000000419b16 compileModule(char**, llvm::LLVMContext&) /home/henry/aflplusplus-isel/llvm-project-latest/llvm/tools/llc/llc.cpp:737:41
#29 0x0000000000417eaa main /home/henry/aflplusplus-isel/llvm-project-latest/llvm/tools/llc/llc.cpp:418:13
#30 0x00007f9e95434c87 __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:344:0
#31 0x00000000004176aa _start (./llvm-project-latest/build-debug/bin/llc+0x4176aa)

Cause

In the following code from method DAGCombiner::visitEXTRACT_SUBVECTOR:

In Line 22301, Src is t3: i32 = Constant<0>.
In Line 22303, Src becomes t4: v8i16 = BUILD_VECTOR Constant:i32<0>, Constant:i32<0>, Constant:i32<0>, Constant:i32<0>, Constant:i32<0>, Constant:i32<0>, Constant:i32<0>, Constant:i32<0>.
In Line 22304, DAG.getBitcast is called with 2 types of different size (v1i16 and v8i16), causing the assertion error.

if (NumElems == 1) {
SDValue Src = V->getOperand(IdxVal);
if (EltVT != Src.getValueType())
Src = DAG.getNode(ISD::TRUNCATE, SDLoc(N), InVT, Src);
return DAG.getBitcast(NVT, Src);
}

When not specifying bleeding-edge, the DAGCombiner::visitEXTRACT_SUBVECTOR method is not called.

@HazyFish
Copy link
Contributor Author

cc @DataCorrupted

@EugeneZelenko EugeneZelenko added backend:WebAssembly crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Dec 20, 2022
@llvmbot
Copy link
Collaborator

llvmbot commented Dec 20, 2022

@llvm/issue-subscribers-backend-webassembly

@dschuff
Copy link
Member

dschuff commented Dec 21, 2022

Just enabling SIMD by itself (i.e. specifying -mattr=+simd128) is also enough to reproduce. It also reproduces for wasm32

@junparser
Copy link
Contributor

try to fix this in https://reviews.llvm.org/D145757

@junparser
Copy link
Contributor

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] llvm:codegen
Projects
None yet
Development

No branches or pull requests

5 participants