llvm.org GIT mirror llvm / 3a7f010
[LoopSimplify] Preserve LCSSA when removing edges from unreachable blocks. This fixes PR30454. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287379 91177308-0d34-0410-b5e6-96231b3b80d8 Michael Zolotukhin 2 years ago
4 changed file(s) with 38 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
311311
312312 /// Insert an unreachable instruction before the specified
313313 /// instruction, making it and the rest of the code in the block dead.
314 unsigned changeToUnreachable(Instruction *I, bool UseLLVMTrap);
314 unsigned changeToUnreachable(Instruction *I, bool UseLLVMTrap,
315 bool PreserveLCSSA = false);
315316
316317 /// Convert the CallInst to InvokeInst with the specified unwind edge basic
317318 /// block. This also splits the basic block where CI is located, because
13681368 return NumDeadInst;
13691369 }
13701370
1371 unsigned llvm::changeToUnreachable(Instruction *I, bool UseLLVMTrap) {
1371 unsigned llvm::changeToUnreachable(Instruction *I, bool UseLLVMTrap,
1372 bool PreserveLCSSA) {
13721373 BasicBlock *BB = I->getParent();
13731374 // Loop over all of the successors, removing BB's entry from any PHI
13741375 // nodes.
13751376 for (BasicBlock *Successor : successors(BB))
1376 Successor->removePredecessor(BB);
1377 Successor->removePredecessor(BB, PreserveLCSSA);
13771378
13781379 // Insert a call to llvm.trap right before this. This turns the undefined
13791380 // behavior into a hard fail instead of falling through into random code.
529529
530530 // Zap the dead pred's terminator and replace it with unreachable.
531531 TerminatorInst *TI = P->getTerminator();
532 changeToUnreachable(TI, /*UseLLVMTrap=*/false);
532 changeToUnreachable(TI, /*UseLLVMTrap=*/false, PreserveLCSSA);
533533 Changed = true;
534534 }
535535 }
0 ; RUN: opt < %s -lcssa -licm -S | FileCheck %s
1 ; PR30454
2 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
3 target triple = "x86_64-unknown-linux-gnu"
4
5 declare i8 @bar()
6
7 ; Test that we preserve LCSSA form when removing edges from unreachable blocks.
8 ; CHECK-LABEL: @foo
9 define void @foo() {
10 entry:
11 br label %for.cond
12
13 for.cond:
14 %x = phi i8 [ undef, %entry ], [ %y, %for.latch ]
15 br i1 undef, label %for.latch, label %exit
16
17 ; CHECK: unreachable.bb:
18 ; CHECK-NEXT: unreachable
19 unreachable.bb:
20 br i1 undef, label %exit, label %for.latch
21
22 for.latch:
23 %y = call i8 @bar()
24 br label %for.cond
25
26 ; CHECK: exit:
27 ; CHECK-NEXT: %x.lcssa = phi i8 [ %x, %for.cond ]
28 exit:
29 %z = zext i8 %x to i32
30 ret void
31 }