HomePhabricator

[ValueTracking] Let isGuaranteedNotToBeUndefOrPoison look into branch…

Authored by aqjune on Feb 28 2020, 10:45 PM.

Description

[ValueTracking] Let isGuaranteedNotToBeUndefOrPoison look into branch conditions of dominating blocks' terminators

Summary:

  br i1 c, BB1, BB2:
BB1:
  use1(c)
BB2:
  use2(c)

In BB1 and BB2, c is never undef or poison because otherwise the branch would have triggered UB.

Checked with Alive2

Reviewers: xbolva00, spatel, lebedev.ri, reames, jdoerfert, nlopes, sanjoy

Reviewed By: reames

Subscribers: jdoerfert, hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D75401

Event Timeline

Hi! I had to revert this patch because following test results in SIGSEGV and passes with the patch reverted (you can find it at llvm/test/Transforms/LoopRotate/freeze-crash.ll):

; RUN: opt -loop-rotate -disable-output %s

define void @foo(i32* %arg) {
bb:
  %tmp = load i32, i32* %arg, align 4
  br label %bb1

bb1:                                              ; preds = %bb7, %bb
  %tmp2 = phi i32 [ %tmp, %bb ], [ 1, %bb7 ]
  %tmp3 = sub i32 0, %tmp2
  %tmp4 = icmp ult i32 0, %tmp3
  %tmp5 = freeze i1 %tmp4
  br i1 %tmp5, label %bb7, label %bb6

bb6:                                              ; preds = %bb1
  ret void

bb7:                                              ; preds = %bb1
  %tmp8 = getelementptr inbounds i8, i8* undef, i64 8
  br label %bb1
}

Here's the stack dump:

Stack dump:
0.  Program arguments: ~/build/buildDA/bin/opt -loop-rotate -o /dev/null ~/llvm-project/llvm/test/Transforms/LoopRotate/freeze-crash.ll 
1.  Running pass 'Function Pass Manager' on module '~/llvm-project/llvm/test/Transforms/LoopRotate/freeze-crash.ll'.
2.  Running pass 'Loop Pass Manager' on function '@foo'
3.  Running pass 'Rotate Loops' on basic block '%bb1'
 #0 0x0000000002e6ddc4 llvm::sys::PrintStackTrace(llvm::raw_ostream&) ~/llvm-project/llvm/lib/Support/Unix/Signals.inc:564:0
 #1 0x0000000002e6de57 PrintStackTraceSignalHandler(void*) ~/llvm-project/llvm/lib/Support/Unix/Signals.inc:625:0
 #2 0x0000000002e6bee8 llvm::sys::RunSignalHandlers() ~/llvm-project/llvm/lib/Support/Signals.cpp:68:0
 #3 0x0000000002e6d803 SignalHandler(int) ~/llvm-project/llvm/lib/Support/Unix/Signals.inc:406:0
 #4 0x00007fa1a42455d0 __restore_rt (/lib64/libpthread.so.0+0xf5d0)
 #5 0x00000000023f7e10 llvm::DomTreeNodeBase<llvm::BasicBlock>::getIDom() const ~/llvm-project/llvm/include/llvm/Support/GenericDomTree.h:82:0
 #6 0x0000000001d2485f llvm::isGuaranteedNotToBeUndefOrPoison(llvm::Value const*, llvm::Instruction const*, llvm::DominatorTree const*) ~/llvm-project/llvm/lib/Analysis/ValueTracking.cpp:4571:0
 #7 0x0000000001ada12c SimplifyFreezeInst(llvm::Value*, llvm::SimplifyQuery const&) ~/llvm-project/llvm/lib/Analysis/InstructionSimplify.cpp:5365:0
 #8 0x0000000001ada160 llvm::SimplifyFreezeInst(llvm::Value*, llvm::SimplifyQuery const&) ~/llvm-project/llvm/lib/Analysis/InstructionSimplify.cpp:5374:0
 #9 0x0000000001adae07 llvm::SimplifyInstruction(llvm::Instruction*, llvm::SimplifyQuery const&, llvm::OptimizationRemarkEmitter*) ~/llvm-project/llvm/lib/Analysis/InstructionSimplify.cpp:5519:0
#10 0x0000000002f0c4ed (anonymous namespace)::LoopRotate::rotateLoop(llvm::Loop*, bool) ~/llvm-project/llvm/lib/Transforms/Utils/LoopRotationUtils.cpp:421:0
#11 0x0000000002f0d6c5 (anonymous namespace)::LoopRotate::processLoop(llvm::Loop*) ~/llvm-project/llvm/lib/Transforms/Utils/LoopRotationUtils.cpp:717:0
#12 0x0000000002f0d830 llvm::LoopRotation(llvm::Loop*, llvm::LoopInfo*, llvm::TargetTransformInfo const*, llvm::AssumptionCache*, llvm::DominatorTree*, llvm::ScalarEvolution*, llvm::MemorySSAUpdater*, llvm::SimplifyQuery const&, bool, unsigned int, bool) ~/llvm-project/llvm/lib/Transforms/Utils/LoopRotationUtils.cpp:745:0
#13 0x0000000002b880e3 (anonymous namespace)::LoopRotateLegacyPass::runOnLoop(llvm::Loop*, llvm::LPPassManager&) ~/llvm-project/llvm/lib/Transforms/Scalar/LoopRotation.cpp:110:0
#14 0x0000000001b6a5b0 llvm::LPPassManager::runOnFunction(llvm::Function&) ~/llvm-project/llvm/lib/Analysis/LoopPass.cpp:194:0
#15 0x00000000024908a7 llvm::FPPassManager::runOnFunction(llvm::Function&) ~/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1482:0
#16 0x0000000002490af6 llvm::FPPassManager::runOnModule(llvm::Module&) ~/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1518:0
#17 0x0000000002490ee7 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) ~/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1583:0
#18 0x000000000249162b llvm::legacy::PassManagerImpl::run(llvm::Module&) ~/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1695:0
#19 0x0000000002491823 llvm::legacy::PassManager::run(llvm::Module&) ~/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1727:0
#20 0x000000000155db0a main ~/llvm-project/llvm/tools/opt/opt.cpp:940:0
#21 0x00007fa1a2d8e495 __libc_start_main (/lib64/libc.so.6+0x22495)
#22 0x000000000152e3d9 _start (~/build/buildDA/bin/opt+0x152e3d9)