1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes='loop-vectorize,loop-load-elim' -S %s | FileCheck %s
4 @glob.1 = external global [100 x double]
5 @glob.2 = external global [100 x double]
7 ; Test for PR57825 to make sure LAA is properly invalidated after versioning
9 define void @test(ptr %arg, i64 %arg1) {
12 ; CHECK-NEXT: br label [[INNER_1_LVER_CHECK:%.*]]
13 ; CHECK: inner.1.lver.check:
14 ; CHECK-NEXT: [[PTR_PHI:%.*]] = phi ptr [ [[ARG:%.*]], [[BB:%.*]] ], [ @glob.1, [[OUTER_LATCH:%.*]] ]
15 ; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr double, ptr [[PTR_PHI]], i64 3
16 ; CHECK-NEXT: [[IDENT_CHECK:%.*]] = icmp ne i64 [[ARG1:%.*]], 1
17 ; CHECK-NEXT: br i1 [[IDENT_CHECK]], label [[INNER_1_PH_LVER_ORIG:%.*]], label [[INNER_1_PH:%.*]]
18 ; CHECK: inner.1.ph.lver.orig:
19 ; CHECK-NEXT: br label [[INNER_1_LVER_ORIG:%.*]]
20 ; CHECK: inner.1.lver.orig:
21 ; CHECK-NEXT: [[IV_1_LVER_ORIG:%.*]] = phi i64 [ 0, [[INNER_1_PH_LVER_ORIG]] ], [ [[IV_NEXT_LVER_ORIG:%.*]], [[INNER_1_LVER_ORIG]] ]
22 ; CHECK-NEXT: [[PTR_IV_1_LVER_ORIG:%.*]] = phi ptr [ @glob.2, [[INNER_1_PH_LVER_ORIG]] ], [ [[PTR_IV_1_NEXT_LVER_ORIG:%.*]], [[INNER_1_LVER_ORIG]] ]
23 ; CHECK-NEXT: [[TMP25_LVER_ORIG:%.*]] = mul nuw nsw i64 [[IV_1_LVER_ORIG]], [[ARG1]]
24 ; CHECK-NEXT: [[GEP_2_LVER_ORIG:%.*]] = getelementptr inbounds double, ptr [[GEP_1]], i64 [[TMP25_LVER_ORIG]]
25 ; CHECK-NEXT: store double 0.000000e+00, ptr [[GEP_2_LVER_ORIG]], align 8
26 ; CHECK-NEXT: [[GEP_3_LVER_ORIG:%.*]] = getelementptr double, ptr [[PTR_PHI]], i64 [[TMP25_LVER_ORIG]]
27 ; CHECK-NEXT: [[GEP_4_LVER_ORIG:%.*]] = getelementptr double, ptr [[GEP_3_LVER_ORIG]], i64 2
28 ; CHECK-NEXT: [[TMP29_LVER_ORIG:%.*]] = load double, ptr [[GEP_4_LVER_ORIG]], align 8
29 ; CHECK-NEXT: [[PTR_IV_1_NEXT_LVER_ORIG]] = getelementptr inbounds double, ptr [[PTR_IV_1_LVER_ORIG]], i64 1
30 ; CHECK-NEXT: [[IV_NEXT_LVER_ORIG]] = add nuw nsw i64 [[IV_1_LVER_ORIG]], 1
31 ; CHECK-NEXT: [[C_1_LVER_ORIG:%.*]] = icmp eq i64 [[IV_1_LVER_ORIG]], 1
32 ; CHECK-NEXT: br i1 [[C_1_LVER_ORIG]], label [[INNER_1_EXIT_LOOPEXIT:%.*]], label [[INNER_1_LVER_ORIG]]
34 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, ptr [[PTR_PHI]], i64 16
35 ; CHECK-NEXT: [[LOAD_INITIAL:%.*]] = load double, ptr [[SCEVGEP]], align 8
36 ; CHECK-NEXT: br label [[INNER_1:%.*]]
38 ; CHECK-NEXT: [[STORE_FORWARDED:%.*]] = phi double [ [[LOAD_INITIAL]], [[INNER_1_PH]] ], [ 0.000000e+00, [[INNER_1]] ]
39 ; CHECK-NEXT: [[IV_1:%.*]] = phi i64 [ 0, [[INNER_1_PH]] ], [ [[IV_NEXT:%.*]], [[INNER_1]] ]
40 ; CHECK-NEXT: [[PTR_IV_1:%.*]] = phi ptr [ @glob.2, [[INNER_1_PH]] ], [ [[PTR_IV_1_NEXT:%.*]], [[INNER_1]] ]
41 ; CHECK-NEXT: [[TMP25:%.*]] = mul nuw nsw i64 [[IV_1]], [[ARG1]]
42 ; CHECK-NEXT: [[GEP_2:%.*]] = getelementptr inbounds double, ptr [[GEP_1]], i64 [[TMP25]]
43 ; CHECK-NEXT: store double 0.000000e+00, ptr [[GEP_2]], align 8
44 ; CHECK-NEXT: [[GEP_3:%.*]] = getelementptr double, ptr [[PTR_PHI]], i64 [[TMP25]]
45 ; CHECK-NEXT: [[GEP_4:%.*]] = getelementptr double, ptr [[GEP_3]], i64 2
46 ; CHECK-NEXT: [[TMP29:%.*]] = load double, ptr [[GEP_4]], align 8
47 ; CHECK-NEXT: [[PTR_IV_1_NEXT]] = getelementptr inbounds double, ptr [[PTR_IV_1]], i64 1
48 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV_1]], 1
49 ; CHECK-NEXT: [[C_1:%.*]] = icmp eq i64 [[IV_1]], 1
50 ; CHECK-NEXT: br i1 [[C_1]], label [[INNER_1_EXIT_LOOPEXIT1:%.*]], label [[INNER_1]]
51 ; CHECK: inner.1.exit.loopexit:
52 ; CHECK-NEXT: [[LCSSA_PTR_IV_1_PH:%.*]] = phi ptr [ [[PTR_IV_1_LVER_ORIG]], [[INNER_1_LVER_ORIG]] ]
53 ; CHECK-NEXT: br label [[INNER_1_EXIT:%.*]]
54 ; CHECK: inner.1.exit.loopexit1:
55 ; CHECK-NEXT: [[LCSSA_PTR_IV_1_PH2:%.*]] = phi ptr [ [[PTR_IV_1]], [[INNER_1]] ]
56 ; CHECK-NEXT: br label [[INNER_1_EXIT]]
57 ; CHECK: inner.1.exit:
58 ; CHECK-NEXT: [[LCSSA_PTR_IV_1:%.*]] = phi ptr [ [[LCSSA_PTR_IV_1_PH]], [[INNER_1_EXIT_LOOPEXIT]] ], [ [[LCSSA_PTR_IV_1_PH2]], [[INNER_1_EXIT_LOOPEXIT1]] ]
59 ; CHECK-NEXT: [[GEP_5:%.*]] = getelementptr inbounds double, ptr [[LCSSA_PTR_IV_1]], i64 1
60 ; CHECK-NEXT: br label [[INNER_2:%.*]]
62 ; CHECK-NEXT: [[INDVAR:%.*]] = phi i64 [ [[INDVAR_NEXT:%.*]], [[INNER_2]] ], [ 0, [[INNER_1_EXIT]] ]
63 ; CHECK-NEXT: [[PTR_IV_2:%.*]] = phi ptr [ [[GEP_5]], [[INNER_1_EXIT]] ], [ [[PTR_IV_2_NEXT:%.*]], [[INNER_2]] ]
64 ; CHECK-NEXT: [[PTR_IV_2_NEXT]] = getelementptr inbounds double, ptr [[PTR_IV_2]], i64 1
65 ; CHECK-NEXT: [[INDVAR_NEXT]] = add i64 [[INDVAR]], 1
66 ; CHECK-NEXT: br i1 false, label [[INNER_3_LVER_CHECK:%.*]], label [[INNER_2]]
67 ; CHECK: inner.3.lver.check:
68 ; CHECK-NEXT: [[INDVAR_LCSSA:%.*]] = phi i64 [ [[INDVAR]], [[INNER_2]] ]
69 ; CHECK-NEXT: [[LCSSA_PTR_IV_2:%.*]] = phi ptr [ [[PTR_IV_2]], [[INNER_2]] ]
70 ; CHECK-NEXT: [[GEP_6:%.*]] = getelementptr inbounds double, ptr [[PTR_PHI]], i64 1
71 ; CHECK-NEXT: [[GEP_7:%.*]] = getelementptr inbounds double, ptr [[LCSSA_PTR_IV_2]], i64 1
72 ; CHECK-NEXT: [[TMP0:%.*]] = shl i64 [[INDVAR_LCSSA]], 3
73 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[TMP0]], 24
74 ; CHECK-NEXT: [[SCEVGEP3:%.*]] = getelementptr i8, ptr [[LCSSA_PTR_IV_1]], i64 [[TMP1]]
75 ; CHECK-NEXT: [[BOUND0:%.*]] = icmp ult ptr [[GEP_7]], [[GEP_1]]
76 ; CHECK-NEXT: [[BOUND1:%.*]] = icmp ult ptr [[PTR_PHI]], [[SCEVGEP3]]
77 ; CHECK-NEXT: [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]]
78 ; CHECK-NEXT: br i1 [[FOUND_CONFLICT]], label [[INNER_3_PH_LVER_ORIG:%.*]], label [[INNER_3_PH:%.*]]
79 ; CHECK: inner.3.ph.lver.orig:
80 ; CHECK-NEXT: br label [[INNER_3_LVER_ORIG:%.*]]
81 ; CHECK: inner.3.lver.orig:
82 ; CHECK-NEXT: [[IV_2_LVER_ORIG:%.*]] = phi i64 [ 0, [[INNER_3_PH_LVER_ORIG]] ], [ [[IV_2_NEXT_LVER_ORIG:%.*]], [[INNER_3_LVER_ORIG]] ]
83 ; CHECK-NEXT: [[GEP_8_LVER_ORIG:%.*]] = getelementptr inbounds double, ptr [[GEP_6]], i64 [[IV_2_LVER_ORIG]]
84 ; CHECK-NEXT: store double 0.000000e+00, ptr [[GEP_7]], align 8
85 ; CHECK-NEXT: store double 0.000000e+00, ptr [[GEP_8_LVER_ORIG]], align 8
86 ; CHECK-NEXT: [[GEP_9_LVER_ORIG:%.*]] = getelementptr double, ptr [[PTR_PHI]], i64 [[IV_2_LVER_ORIG]]
87 ; CHECK-NEXT: [[TMP18_LVER_ORIG:%.*]] = load double, ptr [[GEP_9_LVER_ORIG]], align 8
88 ; CHECK-NEXT: [[IV_2_NEXT_LVER_ORIG]] = add nuw nsw i64 [[IV_2_LVER_ORIG]], 1
89 ; CHECK-NEXT: [[C_2_LVER_ORIG:%.*]] = icmp eq i64 [[IV_2_LVER_ORIG]], 1
90 ; CHECK-NEXT: br i1 [[C_2_LVER_ORIG]], label [[OUTER_LATCH_LOOPEXIT:%.*]], label [[INNER_3_LVER_ORIG]]
92 ; CHECK-NEXT: [[LOAD_INITIAL5:%.*]] = load double, ptr [[PTR_PHI]], align 8
93 ; CHECK-NEXT: br label [[INNER_3:%.*]]
95 ; CHECK-NEXT: [[STORE_FORWARDED6:%.*]] = phi double [ [[LOAD_INITIAL5]], [[INNER_3_PH]] ], [ 0.000000e+00, [[INNER_3]] ]
96 ; CHECK-NEXT: [[IV_2:%.*]] = phi i64 [ 0, [[INNER_3_PH]] ], [ [[IV_2_NEXT:%.*]], [[INNER_3]] ]
97 ; CHECK-NEXT: [[GEP_8:%.*]] = getelementptr inbounds double, ptr [[GEP_6]], i64 [[IV_2]]
98 ; CHECK-NEXT: store double 0.000000e+00, ptr [[GEP_7]], align 8
99 ; CHECK-NEXT: store double 0.000000e+00, ptr [[GEP_8]], align 8
100 ; CHECK-NEXT: [[GEP_9:%.*]] = getelementptr double, ptr [[PTR_PHI]], i64 [[IV_2]]
101 ; CHECK-NEXT: [[TMP18:%.*]] = load double, ptr [[GEP_9]], align 8
102 ; CHECK-NEXT: [[IV_2_NEXT]] = add nuw nsw i64 [[IV_2]], 1
103 ; CHECK-NEXT: [[C_2:%.*]] = icmp eq i64 [[IV_2]], 1
104 ; CHECK-NEXT: br i1 [[C_2]], label [[OUTER_LATCH_LOOPEXIT4:%.*]], label [[INNER_3]]
105 ; CHECK: outer.latch.loopexit:
106 ; CHECK-NEXT: br label [[OUTER_LATCH]]
107 ; CHECK: outer.latch.loopexit4:
108 ; CHECK-NEXT: br label [[OUTER_LATCH]]
109 ; CHECK: outer.latch:
110 ; CHECK-NEXT: br label [[INNER_1_LVER_CHECK]]
113 br label %outer.header
115 outer.header: ; preds = %bb21, %bb
116 %ptr.phi = phi ptr [ %arg, %bb ], [ @glob.1, %outer.latch ]
117 %gep.1 = getelementptr inbounds double, ptr %ptr.phi, i64 3
121 %iv.1 = phi i64 [ 0, %outer.header ], [ %iv.next, %inner.1 ]
122 %ptr.iv.1 = phi ptr [ @glob.2, %outer.header ], [ %ptr.iv.1.next, %inner.1 ]
123 %tmp25 = mul nuw nsw i64 %iv.1, %arg1
124 %gep.2 = getelementptr inbounds double, ptr %gep.1, i64 %tmp25
125 store double 0.000000e+00, ptr %gep.2, align 8
126 %gep.3 = getelementptr double, ptr %ptr.phi, i64 %tmp25
127 %gep.4 = getelementptr double, ptr %gep.3, i64 2
128 %tmp29 = load double, ptr %gep.4, align 8
129 %ptr.iv.1.next = getelementptr inbounds double, ptr %ptr.iv.1, i64 1
130 %iv.next = add nuw nsw i64 %iv.1, 1
131 %c.1 = icmp eq i64 %iv.1, 1
132 br i1 %c.1, label %inner.1.exit, label %inner.1
134 inner.1.exit: ; preds = %bb22
135 %lcssa.ptr.iv.1 = phi ptr [ %ptr.iv.1, %inner.1 ]
136 %gep.5 = getelementptr inbounds double, ptr %lcssa.ptr.iv.1, i64 1
140 %ptr.iv.2 = phi ptr [ %gep.5, %inner.1.exit ], [ %ptr.iv.2.next, %inner.2 ]
141 %ptr.iv.2.next = getelementptr inbounds double, ptr %ptr.iv.2, i64 1
142 br i1 false, label %inner.2.exit, label %inner.2
145 %lcssa.ptr.iv.2 = phi ptr [ %ptr.iv.2, %inner.2 ]
146 %gep.6 = getelementptr inbounds double, ptr %ptr.phi, i64 1
147 %gep.7 = getelementptr inbounds double, ptr %lcssa.ptr.iv.2, i64 1
150 inner.3: ; preds = %bb14, %bb10
151 %iv.2 = phi i64 [ 0, %inner.2.exit ], [ %iv.2.next, %inner.3 ]
152 %gep.8 = getelementptr inbounds double, ptr %gep.6, i64 %iv.2
153 store double 0.000000e+00, ptr %gep.7, align 8
154 store double 0.000000e+00, ptr %gep.8, align 8
155 %gep.9 = getelementptr double, ptr %ptr.phi, i64 %iv.2
156 %tmp18 = load double, ptr %gep.9, align 8
157 %iv.2.next = add nuw nsw i64 %iv.2, 1
158 %c.2 = icmp eq i64 %iv.2, 1
159 br i1 %c.2, label %outer.latch, label %inner.3
162 br label %outer.header