llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.11k stars 12.01k forks source link

opt crash with "-mem2reg -deadargelim -simplifycfg -inline -sroa -early-cse-memssa -jump-threading -instcombine" at "Combine redundant instructions" #47713

Closed llvmbot closed 3 years ago

llvmbot commented 3 years ago
Bugzilla Link 48369
Resolution FIXED
Resolved on Dec 06, 2020 08:39
Version trunk
OS Linux
Attachments bc file
Reporter LLVM Bugzilla Contributor
CC @rotateright
Fixed by commit(s) 94f6d365e4

Extended Description


OS and Platform: CentOS Linux release 7.8.2003 (Core), x86_64 GNU/Linux


Program: $ cat a.c short a=0; int b=0, d=0, f=0; long c=0; char e=0; int main() { int g = 3; for (; a;) { int h = 0; for (;; d) { c = (h <= 0) << 8; h = b; for (; g;) ; for (; f;) for (; e;) ; } } return 0; }


clang version: $ clang --version clang version 12.0.0 (/home/suocy/src/llvm-dev/llvm-project/llvm/tools/clang e52a91e156d7ab26989fef526434b02514428c91) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /home/suocy/bin/llvm-dev/bin


Command Lines: $ clang -O3 -mllvm -disable-llvm-optzns -c -emit-llvm a.c -o a.bc a.c:9:13: warning: expression result unused [-Wunused-value] for (;; d) { ^ 1 warning generated. $ opt -mem2reg -deadargelim -simplifycfg -inline -sroa -early-cse-memssa -jump-threading -instcombine a.bc -o a.opt.bc PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace. Stack dump:

  1. Program arguments: /home/suocy/bin/llvm-dev/bin/opt -mem2reg -deadargelim -simplifycfg -inline -sroa -early-cse-memssa -jump-threading -instcombine a.bc -o a.opt.bc
  2. Running pass 'CallGraph Pass Manager' on module 'a.bc'.
  3. Running pass 'Combine redundant instructions' on function '@main'

    ​0 0x0000000002a8136c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/suocy/bin/llvm-dev/bin/opt+0x2a8136c)

    ​1 0x0000000002a7f1e4 llvm::sys::RunSignalHandlers() (/home/suocy/bin/llvm-dev/bin/opt+0x2a7f1e4)

    ​2 0x0000000002a7f343 SignalHandler(int) (/home/suocy/bin/llvm-dev/bin/opt+0x2a7f343)

    ​3 0x00007fec2e9b4630 __restore_rt (/lib64/libpthread.so.0+0xf630)

    ​4 0x0000000002584f5e llvm::InstCombinerImpl::visitSelectInst(llvm::SelectInst&) (/home/suocy/bin/llvm-dev/bin/opt+0x2584f5e)

    ​5 0x00000000024f310a llvm::InstCombinerImpl::run() (/home/suocy/bin/llvm-dev/bin/opt+0x24f310a)

    ​6 0x00000000024f4d29 combineInstructionsOverFunction(llvm::Function&, llvm::InstCombineWorklist&, llvm::AAResults, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo, llvm::ProfileSummaryInfo, unsigned int, llvm::LoopInfo) (/home/suocy/bin/llvm-dev/bin/opt+0x24f4d29)

    ​7 0x00000000024f698a llvm::InstructionCombiningPass::runOnFunction(llvm::Function&) (/home/suocy/bin/llvm-dev/bin/opt+0x24f698a)

    ​8 0x00000000022bf598 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/suocy/bin/llvm-dev/bin/opt+0x22bf598)

    ​9 0x0000000001a304f4 (anonymous namespace)::CGPassManager::runOnModule(llvm::Module&) (/home/suocy/bin/llvm-dev/bin/opt+0x1a304f4)

    ​10 0x00000000022bee43 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/suocy/bin/llvm-dev/bin/opt+0x22bee43)

    ​11 0x000000000072c61b main (/home/suocy/bin/llvm-dev/bin/opt+0x72c61b)

    ​12 0x00007fec2d58e555 __libc_start_main (/lib64/libc.so.6+0x22555)

    ​13 0x00000000007ddac5 _start (/home/suocy/bin/llvm-dev/bin/opt+0x7ddac5)

    Segmentation fault

rotateright commented 3 years ago

https://reviews.llvm.org/rG94f6d365e4be

rotateright commented 3 years ago

Reduced: define void @​#48369 (i32 %a, i32* %p) { entry: %phi.cmp = icmp sgt i32 %a, 0 br label %bb1

bb1: %cmp = phi i1 [ %phi.cmp, %deadbb ], [ true, %entry ] %shl = select i1 %cmp, i32 256, i32 0 store i32 %shl, i32* %p br label %inf_loop

inf_loop: br label %inf_loop

deadbb: br label %bb1

end: ret void }


Crashes with "opt -instcombine": Assertion failed: (Ptr != End && "dereferencing end() iterator"), function operator->, file /llvm-project/llvm/include/llvm/ADT/DenseMap.h, line 1241.

// Find the block's immediate dominator that ends with a conditional branch // that matches select's condition (maybe inverted). auto *IDomNode = DT[BB]->getIDom();