[Mlir-commits] [clang] [lldb] [llvm] [mlir] [APInt] Fix APInt constructions where value does not fit bitwidth (NFCI) (PR #80309)

Yingwei Zheng llvmlistbot at llvm.org
Sun Sep 22 20:40:34 PDT 2024


dtcxzyw wrote:

https://github.com/llvm/llvm-project/blob/62f737f7409b5d2b33c746158c62f14e5bb78aed/llvm/lib/Transforms/Utils/SimplifyCFG.cpp#L6516
We should allow truncations here.

```
; bin/opt -passes='simplifycfg<switch-to-lookup>' reduced.ll -S
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define i1 @_ZN5image5color9ColorType9has_alpha17h81054606b63d0c15E(i8 %0) {
  switch i8 %0, label %3 [
    i8 9, label %2
    i8 1, label %2
    i8 7, label %2
    i8 3, label %2
    i8 5, label %2
  ]

2:                                                ; preds = %1, %1, %1, %1, %1
  br label %3

3:                                                ; preds = %2, %1
  %.0 = phi i1 [ true, %2 ], [ false, %1 ]
  ret i1 %.0
}
```
```
opt: /home/dtcxzyw/WorkSpace/Projects/compilers/llvm-project/llvm/include/llvm/ADT/APInt.h:121: 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: bin/opt -passes=simplifycfg<switch-to-lookup> reduced.ll -S
1.      Running pass "function(simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;no-switch-range-to-icmp;switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>)" on module "reduced.ll"
2.      Running pass "simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;no-switch-range-to-icmp;switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>" on function "_ZN5image5color9ColorType9has_alpha17h81054606b63d0c15E"
 #0 0x0000717e69813f12 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.20.0git+0x213f12)
 #1 0x0000717e69810ddf llvm::sys::RunSignalHandlers() (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.20.0git+0x210ddf)
 #2 0x0000717e69810f25 SignalHandler(int) Signals.cpp:0:0
 #3 0x0000717e69242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x0000717e692969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x0000717e692969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x0000717e692969fc pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x0000717e69242476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x0000717e692287f3 abort ./stdlib/abort.c:81:7
 #9 0x0000717e6922871b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x0000717e69239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x0000717e62d2afef llvm::APInt::APInt(unsigned int, unsigned long, bool, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMTransformUtils.so.20.0git+0x12afef)
#12 0x0000717e62e97856 (anonymous namespace)::SwitchLookupTable::SwitchLookupTable(llvm::Module&, unsigned long, llvm::ConstantInt*, llvm::SmallVectorImpl<std::pair<llvm::ConstantInt*, llvm::Constant*>> const&, llvm::Constant*, llvm::DataLayout const&, llvm::StringRef const&) SimplifyCFG.cpp:0:0
#13 0x0000717e62eb4a96 switchToLookupTable(llvm::SwitchInst*, llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter>&, llvm::DomTreeUpdater*, llvm::DataLayout const&, llvm::TargetTransformInfo const&) SimplifyCFG.cpp:0:0
#14 0x0000717e62ebfedd (anonymous namespace)::SimplifyCFGOpt::simplifySwitch(llvm::SwitchInst*, llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter>&) SimplifyCFG.cpp:0:0
#15 0x0000717e62ec557b llvm::simplifyCFG(llvm::BasicBlock*, llvm::TargetTransformInfo const&, llvm::DomTreeUpdater*, llvm::SimplifyCFGOptions const&, llvm::ArrayRef<llvm::WeakVH>) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMTransformUtils.so.20.0git+0x2c557b)
#16 0x0000717e635bb663 iterativelySimplifyCFG(llvm::Function&, llvm::TargetTransformInfo const&, llvm::DomTreeUpdater*, llvm::SimplifyCFGOptions const&) SimplifyCFGPass.cpp:0:0
#17 0x0000717e635bc6d4 simplifyFunctionCFGImpl(llvm::Function&, llvm::TargetTransformInfo const&, llvm::DominatorTree*, llvm::SimplifyCFGOptions const&) SimplifyCFGPass.cpp:0:0
#18 0x0000717e635bcf05 simplifyFunctionCFG(llvm::Function&, llvm::TargetTransformInfo const&, llvm::DominatorTree*, llvm::SimplifyCFGOptions const&) SimplifyCFGPass.cpp:0:0
#19 0x0000717e635bd068 llvm::SimplifyCFGPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMScalarOpts.so.20.0git+0x3bd068)
#20 0x0000717e64ed4675 llvm::detail::PassModel<llvm::Function, llvm::SimplifyCFGPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMPasses.so.20.0git+0xd4675)
#21 0x0000717e6215576d llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x35576d)
#22 0x0000717e684d8695 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.20.0git+0xd8695)
#23 0x0000717e621538a6 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x3538a6)
#24 0x0000717e684d9055 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.20.0git+0xd9055)
#25 0x0000717e6215442a llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x35442a)
#26 0x0000717e69b161c1 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.20.0git+0x2d1c1)
#27 0x0000717e69b21944 optMain (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.20.0git+0x38944)
#28 0x0000717e69229d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#29 0x0000717e69229e40 call_init ./csu/../csu/libc-start.c:128:20
#30 0x0000717e69229e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#31 0x00006204288e7095 _start (bin/opt+0x1095)
Aborted (core dumped)
```


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


More information about the Mlir-commits mailing list