[llvm] [SDAG] Don't allow implicit trunc in getConstant() (PR #117558)

Nathan Chancellor via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 26 15:03:42 PST 2024


nathanchance wrote:

Hi @nikic, I am seeing an assertion failure when building the Linux kernel for 32-bit powerpc after this change.

```c
char *get_next_block_mtfSymbol;
char get_next_block_mtfSymbol_0;
void get_next_block() {
  get_next_block_mtfSymbol_0 = get_next_block_mtfSymbol[-1];
}
```

```llvm
target datalayout = "E-m:e-p:32:32-Fn32-i64:64-n32"
target triple = "powerpc-unknown-linux-gnu"

define void @get_next_block() {
entry:
  %0 = load i8, ptr inttoptr (i32 -1 to ptr), align 1
  store i8 %0, ptr null, align 1
  ret void
}
```

```
$ clang --target=powerpc-linux-gnu -c -o /dev/null decompress_bunzip2.i
clang: llvm/include/llvm/ADT/APInt.h:128: llvm::APInt::APInt(unsigned int, uint64_t, bool, bool): Assertion `llvm::isUIntN(BitWidth, val) && "Value is not an N-bit unsigned value"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: clang --target=powerpc-linux-gnu -c -o /dev/null decompress_bunzip2.i
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module 'decompress_bunzip2.i'.
4.      Running pass 'PowerPC DAG->DAG Pattern Instruction Selection' on function '@get_next_block'
...

$ llc reduced.ll
llc: llvm/include/llvm/ADT/APInt.h:128: llvm::APInt::APInt(unsigned int, uint64_t, bool, bool): Assertion `llvm::isUIntN(BitWidth, val) && "Value is not an N-bit unsigned value"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: llc reduced.ll
1.      Running pass 'Function Pass Manager' on module 'reduced.ll'.
2.      Running pass 'PowerPC DAG->DAG Pattern Instruction Selection' on function '@get_next_block'
 #0 0x000055a661ef0828 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/mnt/nvme/tmp/cvise.kJkUnw63jz/install/llvm-bad/bin/llc+0x3391828)
 #1 0x000055a661eee2de llvm::sys::RunSignalHandlers() (/mnt/nvme/tmp/cvise.kJkUnw63jz/install/llvm-bad/bin/llc+0x338f2de)
 #2 0x000055a661ef0ed8 SignalHandler(int) Signals.cpp:0:0
 #3 0x00007fd107ddf1d0 (/usr/lib/libc.so.6+0x3d1d0)
 #4 0x00007fd107e383f4 (/usr/lib/libc.so.6+0x963f4)
 #5 0x00007fd107ddf120 raise (/usr/lib/libc.so.6+0x3d120)
 #6 0x00007fd107dc64c3 abort (/usr/lib/libc.so.6+0x244c3)
 #7 0x00007fd107dc63df (/usr/lib/libc.so.6+0x243df)
 #8 0x00007fd107dd7177 (/usr/lib/libc.so.6+0x35177)
 #9 0x000055a661c82ac8 (/mnt/nvme/tmp/cvise.kJkUnw63jz/install/llvm-bad/bin/llc+0x3123ac8)
#10 0x000055a660595953 llvm::PPCTargetLowering::SelectOptimalAddrMode(llvm::SDNode const*, llvm::SDValue, llvm::SDValue&, llvm::SDValue&, llvm::SelectionDAG&, llvm::MaybeAlign) const PPCISelLowering.cpp:0:0
#11 0x000055a6605ab2b5 (anonymous namespace)::PPCDAGToDAGISel::CheckComplexPattern(llvm::SDNode*, llvm::SDNode*, llvm::SDValue, unsigned int, llvm::SmallVectorImpl<std::pair<llvm::SDValue, llvm::SDNode*>>&) PPCISelDAGToDAG.cpp:0:0
#12 0x000055a661cf0b42 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) (/mnt/nvme/tmp/cvise.kJkUnw63jz/install/llvm-bad/bin/llc+0x3191b42)
#13 0x000055a6605a71db (anonymous namespace)::PPCDAGToDAGISel::Select(llvm::SDNode*) PPCISelDAGToDAG.cpp:0:0
#14 0x000055a661ce96cf llvm::SelectionDAGISel::DoInstructionSelection() (/mnt/nvme/tmp/cvise.kJkUnw63jz/install/llvm-bad/bin/llc+0x318a6cf)
#15 0x000055a661ce8658 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/mnt/nvme/tmp/cvise.kJkUnw63jz/install/llvm-bad/bin/llc+0x3189658)
#16 0x000055a661ce660f llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/mnt/nvme/tmp/cvise.kJkUnw63jz/install/llvm-bad/bin/llc+0x318760f)
#17 0x000055a661ce3450 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/mnt/nvme/tmp/cvise.kJkUnw63jz/install/llvm-bad/bin/llc+0x3184450)
#18 0x000055a66059fa2e (anonymous namespace)::PPCDAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) PPCISelDAGToDAG.cpp:0:0
#19 0x000055a661ce0d36 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/mnt/nvme/tmp/cvise.kJkUnw63jz/install/llvm-bad/bin/llc+0x3181d36)
#20 0x000055a660f62507 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/mnt/nvme/tmp/cvise.kJkUnw63jz/install/llvm-bad/bin/llc+0x2403507)
#21 0x000055a6614a75aa llvm::FPPassManager::runOnFunction(llvm::Function&) (/mnt/nvme/tmp/cvise.kJkUnw63jz/install/llvm-bad/bin/llc+0x29485aa)
#22 0x000055a6614afa42 llvm::FPPassManager::runOnModule(llvm::Module&) (/mnt/nvme/tmp/cvise.kJkUnw63jz/install/llvm-bad/bin/llc+0x2950a42)
#23 0x000055a6614a8076 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/mnt/nvme/tmp/cvise.kJkUnw63jz/install/llvm-bad/bin/llc+0x2949076)
#24 0x000055a6604d441e compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#25 0x000055a6604d1d1d main (/mnt/nvme/tmp/cvise.kJkUnw63jz/install/llvm-bad/bin/llc+0x1972d1d)
#26 0x00007fd107dc7e08 (/usr/lib/libc.so.6+0x25e08)
#27 0x00007fd107dc7ecc __libc_start_main (/usr/lib/libc.so.6+0x25ecc)
#28 0x000055a6604cdbe5 _start (/mnt/nvme/tmp/cvise.kJkUnw63jz/install/llvm-bad/bin/llc+0x196ebe5)
```

https://github.com/llvm/llvm-project/pull/117558


More information about the llvm-commits mailing list