blob: e492f2c18726a8360dbdd22a79f999aa6bca1f42 [file] [log] [blame]
Andrew Trick23ef0d62012-01-14 03:17:23 +00001; RUN: llc < %s -O3 -march=x86-64 -mcpu=core2 | FileCheck %s
2
3declare i1 @check() nounwind
4declare i1 @foo(i8*, i8*, i8*) nounwind
5
6; Check that redundant phi elimination ran
7; CHECK: @test
8; CHECK: %while.body.i
9; CHECK: movs
10; CHECK-NOT: movs
11; CHECK: %for.end.i
12define i32 @test(i8* %base) nounwind uwtable ssp {
13entry:
14 br label %while.body.lr.ph.i
15
16while.body.lr.ph.i: ; preds = %cond.true.i
17 br label %while.body.i
18
19while.body.i: ; preds = %cond.true29.i, %while.body.lr.ph.i
20 %indvars.iv7.i = phi i64 [ 16, %while.body.lr.ph.i ], [ %indvars.iv.next8.i, %cond.true29.i ]
21 %i.05.i = phi i64 [ 0, %while.body.lr.ph.i ], [ %indvars.iv7.i, %cond.true29.i ]
22 %sext.i = shl i64 %i.05.i, 32
23 %idx.ext.i = ashr exact i64 %sext.i, 32
24 %add.ptr.sum.i = add i64 %idx.ext.i, 16
25 br label %for.body.i
26
27for.body.i: ; preds = %for.body.i, %while.body.i
28 %indvars.iv.i = phi i64 [ 0, %while.body.i ], [ %indvars.iv.next.i, %for.body.i ]
29 %add.ptr.sum = add i64 %add.ptr.sum.i, %indvars.iv.i
David Blaikie79e6c742015-02-27 19:29:02 +000030 %arrayidx22.i = getelementptr inbounds i8, i8* %base, i64 %add.ptr.sum
David Blaikiea79ac142015-02-27 21:17:42 +000031 %0 = load i8, i8* %arrayidx22.i, align 1
Andrew Trick23ef0d62012-01-14 03:17:23 +000032 %indvars.iv.next.i = add i64 %indvars.iv.i, 1
33 %cmp = call i1 @check() nounwind
34 br i1 %cmp, label %for.end.i, label %for.body.i
35
36for.end.i: ; preds = %for.body.i
David Blaikie79e6c742015-02-27 19:29:02 +000037 %add.ptr.i144 = getelementptr inbounds i8, i8* %base, i64 %add.ptr.sum.i
Andrew Trick23ef0d62012-01-14 03:17:23 +000038 %cmp2 = tail call i1 @foo(i8* %add.ptr.i144, i8* %add.ptr.i144, i8* undef) nounwind
39 br i1 %cmp2, label %cond.true29.i, label %cond.false35.i
40
41cond.true29.i: ; preds = %for.end.i
42 %indvars.iv.next8.i = add i64 %indvars.iv7.i, 16
43 br i1 false, label %exit, label %while.body.i
44
45cond.false35.i: ; preds = %for.end.i
46 unreachable
47
48exit: ; preds = %cond.true29.i, %cond.true.i
49 ret i32 0
50}
Andrew Trickc908b432012-01-20 07:41:13 +000051
52%struct.anon.7.91.199.307.415.475.559.643.751.835.943.1003.1111.1219.1351.1375.1399.1435.1471.1483.1519.1531.1651.1771 = type { i32, i32, i32 }
53
54@tags = external global [5000 x %struct.anon.7.91.199.307.415.475.559.643.751.835.943.1003.1111.1219.1351.1375.1399.1435.1471.1483.1519.1531.1651.1771], align 16
55
Andrew Trick16abc8a2012-01-20 21:21:27 +000056; PR11782: SCEVExpander assert
57;
58; Test phi reuse after LSR that requires SCEVExpander to hoist an
59; interesting GEP.
60;
Andrew Trickc908b432012-01-20 07:41:13 +000061; CHECK: @test2
62; CHECK: %entry
63; CHECK-NOT: mov
Chandler Carruth4190b502012-04-16 13:49:17 +000064; CHECK: je
Andrew Trickc908b432012-01-20 07:41:13 +000065define void @test2(i32 %n) nounwind uwtable {
66entry:
67 br i1 undef, label %while.end, label %for.cond468
68
69for.cond468: ; preds = %if.then477, %entry
70 %indvars.iv1163 = phi i64 [ %indvars.iv.next1164, %if.then477 ], [ 1, %entry ]
David Blaikief72d05b2015-03-13 18:20:45 +000071 %k.0.in = phi i32* [ %last, %if.then477 ], [ getelementptr inbounds ([5000 x %struct.anon.7.91.199.307.415.475.559.643.751.835.943.1003.1111.1219.1351.1375.1399.1435.1471.1483.1519.1531.1651.1771], [5000 x %struct.anon.7.91.199.307.415.475.559.643.751.835.943.1003.1111.1219.1351.1375.1399.1435.1471.1483.1519.1531.1651.1771]* @tags, i64 0, i64 0, i32 2), %entry ]
David Blaikiea79ac142015-02-27 21:17:42 +000072 %k.0 = load i32, i32* %k.0.in, align 4
Andrew Trickc908b432012-01-20 07:41:13 +000073 %0 = trunc i64 %indvars.iv1163 to i32
74 %cmp469 = icmp slt i32 %0, %n
75 br i1 %cmp469, label %for.body471, label %for.inc498
76
77for.body471: ; preds = %for.cond468
David Blaikie79e6c742015-02-27 19:29:02 +000078 %first = getelementptr inbounds [5000 x %struct.anon.7.91.199.307.415.475.559.643.751.835.943.1003.1111.1219.1351.1375.1399.1435.1471.1483.1519.1531.1651.1771], [5000 x %struct.anon.7.91.199.307.415.475.559.643.751.835.943.1003.1111.1219.1351.1375.1399.1435.1471.1483.1519.1531.1651.1771]* @tags, i64 0, i64 %indvars.iv1163, i32 1
David Blaikiea79ac142015-02-27 21:17:42 +000079 %1 = load i32, i32* %first, align 4
Andrew Trickc908b432012-01-20 07:41:13 +000080 br i1 undef, label %if.then477, label %for.inc498
81
82if.then477: ; preds = %for.body471
David Blaikie79e6c742015-02-27 19:29:02 +000083 %last = getelementptr inbounds [5000 x %struct.anon.7.91.199.307.415.475.559.643.751.835.943.1003.1111.1219.1351.1375.1399.1435.1471.1483.1519.1531.1651.1771], [5000 x %struct.anon.7.91.199.307.415.475.559.643.751.835.943.1003.1111.1219.1351.1375.1399.1435.1471.1483.1519.1531.1651.1771]* @tags, i64 0, i64 %indvars.iv1163, i32 2
Andrew Trickc908b432012-01-20 07:41:13 +000084 %indvars.iv.next1164 = add i64 %indvars.iv1163, 1
85 br label %for.cond468
86
87for.inc498: ; preds = %for.inc498, %for.body471, %for.cond468
88 br label %for.inc498
89
90while.end: ; preds = %entry
91 ret void
92}
Andrew Tricka7a3de12012-05-22 17:39:59 +000093
94; PR12898: SCEVExpander crash
95; Test redundant phi elimination when the deleted phi's increment is
96; itself a phi.
97;
98; CHECK: @test3
99; CHECK: %for.body3.lr.ph.us.i.loopexit
Krzysztof Parzyszek8271be92016-10-12 19:50:57 +0000100; CHECK-NEXT: Parent Loop
Andrew Tricka7a3de12012-05-22 17:39:59 +0000101; CHECK-NEXT: Inner Loop
Krzysztof Parzyszek3cb5ffe2016-10-12 20:39:33 +0000102; CHECK-NEXT: incq
Andrew Tricka7a3de12012-05-22 17:39:59 +0000103; CHECK: testb
Chuang-Yu Chengd3fb38c2016-04-05 14:06:20 +0000104; CHECK: je
Andrew Tricka7a3de12012-05-22 17:39:59 +0000105; CHECK: jmp
106define fastcc void @test3(double* nocapture %u) nounwind uwtable ssp {
107entry:
108 br i1 undef, label %meshBB1, label %meshBB5
109
110for.inc8.us.i: ; preds = %for.body3.us.i
111 br i1 undef, label %meshBB1, label %meshBB
112
113for.body3.us.i: ; preds = %meshBB, %for.body3.lr.ph.us.i
114 %indvars.iv.i.SV.phi = phi i64 [ %indvars.iv.next.i, %meshBB ], [ 0, %for.body3.lr.ph.us.i ]
115 %storemerge13.us.i.SV.phi = phi i32 [ 0, %meshBB ], [ 0, %for.body3.lr.ph.us.i ]
116 %Opq.sa.calc12 = sub i32 undef, 227
117 %0 = add nsw i64 %indvars.iv.i.SV.phi, %indvars.iv8.i.SV.phi26
118 %1 = trunc i64 %0 to i32
119 %mul.i.us.i = mul nsw i32 0, %1
David Blaikie79e6c742015-02-27 19:29:02 +0000120 %arrayidx5.us.i = getelementptr inbounds double, double* %u, i64 %indvars.iv.i.SV.phi
David Blaikiea79ac142015-02-27 21:17:42 +0000121 %2 = load double, double* %arrayidx5.us.i, align 8
Andrew Tricka7a3de12012-05-22 17:39:59 +0000122 %indvars.iv.next.i = add i64 %indvars.iv.i.SV.phi, 1
123 br i1 undef, label %for.inc8.us.i, label %meshBB
124
125for.body3.lr.ph.us.i: ; preds = %meshBB1, %meshBB
126 %indvars.iv8.i.SV.phi26 = phi i64 [ undef, %meshBB1 ], [ %indvars.iv8.i.SV.phi24, %meshBB ]
David Blaikie79e6c742015-02-27 19:29:02 +0000127 %arrayidx.us.i = getelementptr inbounds double, double* undef, i64 %indvars.iv8.i.SV.phi26
Andrew Tricka7a3de12012-05-22 17:39:59 +0000128 %3 = add i64 %indvars.iv8.i.SV.phi26, 1
129 br label %for.body3.us.i
130
131for.inc8.us.i2: ; preds = %meshBB5
132 unreachable
133
134eval_At_times_u.exit: ; preds = %meshBB5
135 ret void
136
137meshBB: ; preds = %for.body3.us.i, %for.inc8.us.i
138 %indvars.iv8.i.SV.phi24 = phi i64 [ undef, %for.body3.us.i ], [ %3, %for.inc8.us.i ]
139 %meshStackVariable.phi = phi i32 [ %Opq.sa.calc12, %for.body3.us.i ], [ undef, %for.inc8.us.i ]
140 br i1 undef, label %for.body3.lr.ph.us.i, label %for.body3.us.i
141
142meshBB1: ; preds = %for.inc8.us.i, %entry
143 br label %for.body3.lr.ph.us.i
144
145meshBB5: ; preds = %entry
146 br i1 undef, label %eval_At_times_u.exit, label %for.inc8.us.i2
147}