llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[IndVars] Simple IR test crashes with "PHI node has multiple entries for the same basic block with different incoming values!"

Open nrinskaya opened this issue 3 years ago • 2 comments

This bug was found by Azul FuzzGen IR test generator.

https://godbolt.org/z/1vd3zYzen

Run opt with -passes=indvars:

; ModuleID = 'bugpoint-reduced-simplified.bc'
source_filename = "gen_05726"
target triple = "x86_64-unknown-linux-gnu"

define void @function_0() {
entry_1:
  br label %bb_2

bb_2:                                             ; preds = %bb_3, %bb_2, %entry_1
  %ptr_i1_13.0 = phi i1 [ undef, %entry_1 ], [ %ptr_i1_13.0, %bb_2 ], [ %ptr_i1_13.1, %bb_3 ]
  %val_i1_52 = icmp sle i64 undef, 2546175499358690212
  %val_i8_56 = zext i1 %val_i1_52 to i8
  br i1 undef, label %bb_2, label %bb_3

bb_3:                                             ; preds = %bb_4, %bb_3, %bb_2
  %ptr_i1_13.1 = phi i1 [ %ptr_i1_13.0, %bb_2 ], [ %ptr_i1_13.1, %bb_3 ], [ %val_i1_52, %bb_4 ]
  %val_i1_62 = trunc i8 %val_i8_56 to i1
  switch i16 undef, label %bb_2 [
    i16 -1, label %bb_4
    i16 1, label %bb_4
    i16 4, label %bb_3
  ]

bb_4:                                             ; preds = %bb_3, %bb_3
  %val_i1_77 = icmp ult i1 %val_i1_62, undef
  br label %bb_3
}

Stacktrace:

PHI node has multiple entries for the same basic block with different incoming values!
  %val_i1_62.lcssa1 = phi i1 [ %val_i1_52.lcssa2, %bb_3 ], [ %val_i1_52.lcssa3, %bb_3 ]
label %bb_3
  %val_i1_52.lcssa3 = phi i1 [ %val_i1_52, %bb_2 ]
  %val_i1_52.lcssa2 = phi i1 [ %val_i1_52, %bb_2 ]
LLVM ERROR: Broken module found, compilation aborted!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=indvars <source>
 #0 0x000055d1630a9c24 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x000055d1630a7394 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f7b955573c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x143c0)
 #3 0x00007f7b9502403b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4303b)
 #4 0x00007f7b95003859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x000055d16043148a llvm::SuffixTree::insertLeaf(llvm::SuffixTreeNode&, unsigned int, unsigned int) (.cold) SuffixTree.cpp:0:0
 #6 0x000055d162fe5c8e (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x371ec8e)
 #7 0x000055d1627fd933 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2f36933)
 #8 0x000055d16050c6e6 llvm::detail::PassModel<llvm::Module, llvm::VerifierPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xc456e6)
 #9 0x000055d1627bcb2f llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2ef5b2f)
#10 0x000055d160517848 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::StringRef>, llvm::ArrayRef<llvm::PassPlugin>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xc50848)
#11 0x000055d16043d07a main (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xb7607a)
#12 0x00007f7b950050b3 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b3)
#13 0x000055d16050a1fe _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xc431fe)
Compiler returned: 139

nrinskaya avatar Aug 08 '22 09:08 nrinskaya

it's fine with opt 14.0.0, https://godbolt.org/z/4ob7vWfKb

vfdff avatar Aug 11 '22 04:08 vfdff

candidate MR: https://reviews.llvm.org/D131745 @fhahn, would please help me to review it?

vfdff avatar Aug 12 '22 02:08 vfdff

I put up a patch that should help to avoid constructing invalid PHIs in the first place: https://reviews.llvm.org/D132704

fhahn avatar Aug 25 '22 21:08 fhahn