LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 48369 - opt crash with "-mem2reg -deadargelim -simplifycfg -inline -sroa -early-cse-memssa -jump-threading -instcombine" at "Combine redundant instructions"
Summary: opt crash with "-mem2reg -deadargelim -simplifycfg -inline -sroa -early-cse-m...
Status: RESOLVED FIXED
Alias: None
Product: new-bugs
Classification: Unclassified
Component: new bugs (show other bugs)
Version: trunk
Hardware: PC Linux
: P enhancement
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-12-03 05:11 PST by suochenyao
Modified: 2020-12-06 08:39 PST (History)
3 users (show)

See Also:
Fixed By Commit(s): 94f6d365e4


Attachments
bc file (3.25 KB, application/octet-stream)
2020-12-03 05:11 PST, suochenyao
Details

Note You need to log in before you can comment on or make changes to this bug.
Description suochenyao 2020-12-03 05:11:11 PST
Created attachment 24230 [details]
bc file

*******************************************************************************
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:
0.      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
1.      Running pass 'CallGraph Pass Manager' on module 'a.bc'.
2.      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
Comment 1 Sanjay Patel 2020-12-04 13:28:58 PST
Reduced:
define void @PR48369(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();
Comment 2 Sanjay Patel 2020-12-06 08:39:11 PST
https://reviews.llvm.org/rG94f6d365e4be