llvm.org GIT mirror llvm / 14e545d
Fix PR 4626, a crash in branch folding after OptimizeBlock produced a CFG it wasn't prepared for. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78351 91177308-0d34-0410-b5e6-96231b3b80d8 Dale Johannesen 10 years ago
2 changed file(s) with 108 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
892892 while (!MBB->pred_empty()) {
893893 MachineBasicBlock *Pred = *(MBB->pred_end()-1);
894894 Pred->ReplaceUsesOfBlockWith(MBB, FallThrough);
895 }
896
895 // If this resulted in a predecessor with true and false edges
896 // both going to the fallthrough block, clean up;
897 // BranchFolding doesn't like this.
898 MachineBasicBlock::succ_iterator SI = Pred->succ_begin();
899 bool found = false;
900 while (SI != Pred->succ_end()) {
901 if (*SI == FallThrough) {
902 if (!found) {
903 found = true;
904 ++SI;
905 } else {
906 SI = Pred->removeSuccessor(SI);
907 }
908 } else {
909 ++SI;
910 }
911 }
912 }
897913 // If MBB was the target of a jump table, update jump tables to go to the
898914 // fallthrough instead.
899915 MBB->getParent()->getJumpTableInfo()->
0 ; RUN: llvm-as < %s | llc -O3
1 ; PR4626
2 ; ModuleID = ''
3 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
4 target triple = "i386-pc-linux-gnu"
5 @g_3 = common global i8 0, align 1 ; [#uses=2]
6
7 define signext i8 @safe_mul_func_int16_t_s_s(i32 %_si1, i8 signext %_si2) nounwind readnone {
8 entry:
9 %tobool = icmp eq i32 %_si1, 0 ; [#uses=1]
10 %cmp = icmp sgt i8 %_si2, 0 ; [#uses=2]
11 %or.cond = or i1 %cmp, %tobool ; [#uses=1]
12 br i1 %or.cond, label %lor.rhs, label %land.lhs.true3
13
14 land.lhs.true3: ; preds = %entry
15 %conv5 = sext i8 %_si2 to i32 ; [#uses=1]
16 %cmp7 = icmp slt i32 %conv5, %_si1 ; [#uses=1]
17 br i1 %cmp7, label %cond.end, label %lor.rhs
18
19 lor.rhs: ; preds = %land.lhs.true3, %entry
20 %cmp10.not = icmp slt i32 %_si1, 1 ; [#uses=1]
21 %or.cond23 = and i1 %cmp, %cmp10.not ; [#uses=1]
22 br i1 %or.cond23, label %lor.end, label %cond.false
23
24 lor.end: ; preds = %lor.rhs
25 %tobool19 = icmp ne i8 %_si2, 0 ; [#uses=2]
26 %lor.ext = zext i1 %tobool19 to i32 ; [#uses=1]
27 br i1 %tobool19, label %cond.end, label %cond.false
28
29 cond.false: ; preds = %lor.end, %lor.rhs
30 %conv21 = sext i8 %_si2 to i32 ; [#uses=1]
31 br label %cond.end
32
33 cond.end: ; preds = %cond.false, %lor.end, %land.lhs.true3
34 %cond = phi i32 [ %conv21, %cond.false ], [ 1, %land.lhs.true3 ], [ %lor.ext, %lor.end ] ; [#uses=1]
35 %conv22 = trunc i32 %cond to i8 ; [#uses=1]
36 ret i8 %conv22
37 }
38
39 define i32 @func_34(i8 signext %p_35) nounwind readonly {
40 entry:
41 %tobool = icmp eq i8 %p_35, 0 ; [#uses=1]
42 br i1 %tobool, label %lor.lhs.false, label %if.then
43
44 lor.lhs.false: ; preds = %entry
45 %tmp1 = load i8* @g_3 ; [#uses=1]
46 %tobool3 = icmp eq i8 %tmp1, 0 ; [#uses=1]
47 br i1 %tobool3, label %return, label %if.then
48
49 if.then: ; preds = %lor.lhs.false, %entry
50 %tmp4 = load i8* @g_3 ; [#uses=1]
51 %conv5 = sext i8 %tmp4 to i32 ; [#uses=1]
52 ret i32 %conv5
53
54 return: ; preds = %lor.lhs.false
55 ret i32 0
56 }
57
58 define void @foo(i32 %p_5) noreturn nounwind {
59 entry:
60 %cmp = icmp sgt i32 %p_5, 0 ; [#uses=2]
61 %call = tail call i32 @safe() nounwind ; [#uses=1]
62 %conv1 = trunc i32 %call to i8 ; [#uses=3]
63 %tobool.i = xor i1 %cmp, true ; [#uses=3]
64 %cmp.i = icmp sgt i8 %conv1, 0 ; [#uses=3]
65 %or.cond.i = or i1 %cmp.i, %tobool.i ; [#uses=1]
66 br i1 %or.cond.i, label %lor.rhs.i, label %land.lhs.true3.i
67
68 land.lhs.true3.i: ; preds = %entry
69 %xor = zext i1 %cmp to i32 ; [#uses=1]
70 %conv5.i = sext i8 %conv1 to i32 ; [#uses=1]
71 %cmp7.i = icmp slt i32 %conv5.i, %xor ; [#uses=1]
72 %cmp7.i.not = xor i1 %cmp7.i, true ; [#uses=1]
73 %or.cond23.i = and i1 %cmp.i, %tobool.i ; [#uses=1]
74 %or.cond = and i1 %cmp7.i.not, %or.cond23.i ; [#uses=1]
75 br i1 %or.cond, label %lor.end.i, label %for.inc
76
77 lor.rhs.i: ; preds = %entry
78 %or.cond23.i.old = and i1 %cmp.i, %tobool.i ; [#uses=1]
79 br i1 %or.cond23.i.old, label %lor.end.i, label %for.inc
80
81 lor.end.i: ; preds = %lor.rhs.i, %land.lhs.true3.i
82 %tobool19.i = icmp eq i8 %conv1, 0 ; [#uses=0]
83 br label %for.inc
84
85 for.inc: ; preds = %for.inc, %lor.end.i, %lor.rhs.i, %land.lhs.true3.i
86 br label %for.inc
87 }
88
89 declare i32 @safe()