llvm.org GIT mirror llvm / 382ffde
[LoopPred] Fix a blatantly obvious bug in r358684 The bug is that I didn't check whether the operand of the invariant_loads were themselves invariant. I don't know how this got missed in the patch and review. I even had an unreduced test case locally, and I remember handling this case, but I must have lost it in one of the rebases. Oops. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358688 91177308-0d34-0410-b5e6-96231b3b80d8 Philip Reames 5 months ago
2 changed file(s) with 65 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
509509 // TODO: This should be sunk inside SCEV.
510510 if (const SCEVUnknown *U = dyn_cast(S))
511511 if (const auto *LI = dyn_cast(U->getValue()))
512 if (LI->isUnordered())
512 if (LI->isUnordered() && L->hasLoopInvariantOperands(LI))
513513 if (AA->pointsToConstantMemory(LI->getOperand(0)) ||
514514 LI->getMetadata(LLVMContext::MD_invariant_load) != nullptr)
515515 return true;
125125 ret i32 %result
126126 }
127127
128 ; Case where we have an invariant load, but it's not loading from a loop
129 ; invariant location.
130 define i32 @neg_varying_invariant_load_op(i32* %array, i32* %lengths, i32 %n) {
131 ; CHECK-LABEL: @neg_varying_invariant_load_op(
132 ; CHECK-NEXT: entry:
133 ; CHECK-NEXT: [[TMP5:%.*]] = icmp eq i32 [[N:%.*]], 0
134 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
135 ; CHECK: loop.preheader:
136 ; CHECK-NEXT: br label [[LOOP:%.*]]
137 ; CHECK: loop:
138 ; CHECK-NEXT: [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
139 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
140 ; CHECK-NEXT: [[UNKNOWN:%.*]] = load volatile i1, i1* @UNKNOWN
141 ; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 [[UNKNOWN]]) [ "deopt"() ]
142 ; CHECK-NEXT: [[LENGTH_ADDR:%.*]] = getelementptr i32, i32* [[LENGTHS:%.*]], i32 [[I]]
143 ; CHECK-NEXT: [[LEN:%.*]] = load i32, i32* [[LENGTH_ADDR]], align 4, !invariant.load !0
144 ; CHECK-NEXT: [[WITHIN_BOUNDS:%.*]] = icmp ult i32 [[I]], [[LEN]]
145 ; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 [[WITHIN_BOUNDS]], i32 9) [ "deopt"() ]
146 ; CHECK-NEXT: [[I_I64:%.*]] = zext i32 [[I]] to i64
147 ; CHECK-NEXT: [[ARRAY_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY:%.*]], i64 [[I_I64]]
148 ; CHECK-NEXT: [[ARRAY_I:%.*]] = load i32, i32* [[ARRAY_I_PTR]], align 4
149 ; CHECK-NEXT: [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC]], [[ARRAY_I]]
150 ; CHECK-NEXT: [[I_NEXT]] = add nuw i32 [[I]], 1
151 ; CHECK-NEXT: [[CONTINUE:%.*]] = icmp ult i32 [[I_NEXT]], [[N]]
152 ; CHECK-NEXT: br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
153 ; CHECK: exit.loopexit:
154 ; CHECK-NEXT: [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
155 ; CHECK-NEXT: br label [[EXIT]]
156 ; CHECK: exit:
157 ; CHECK-NEXT: [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
158 ; CHECK-NEXT: ret i32 [[RESULT]]
159 ;
160 entry:
161 %tmp5 = icmp eq i32 %n, 0
162 br i1 %tmp5, label %exit, label %loop.preheader
163
164 loop.preheader:
165 br label %loop
166
167 loop:
168 %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
169 %i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ]
170 %unknown = load volatile i1, i1* @UNKNOWN
171 call void (i1, ...) @llvm.experimental.guard(i1 %unknown) [ "deopt"() ]
172
173 %length.addr = getelementptr i32, i32* %lengths, i32 %i
174 %len = load i32, i32* %length.addr, align 4, !invariant.load !{}
175 %within.bounds = icmp ult i32 %i, %len
176 call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds, i32 9) [ "deopt"() ]
177
178 %i.i64 = zext i32 %i to i64
179 %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
180 %array.i = load i32, i32* %array.i.ptr, align 4
181 %loop.acc.next = add i32 %loop.acc, %array.i
182
183 %i.next = add nuw i32 %i, 1
184 %continue = icmp ult i32 %i.next, %n
185 br i1 %continue, label %loop, label %exit
186
187 exit:
188 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ]
189 ret i32 %result
190 }
191
128192 ; This is a case where moving the load which provides the limit for the latch
129193 ; would be invalid, so we can't preform the tempting transform. Loading the
130194 ; latch limit may fault since we could always fail the guard.