Skip to content

Commit 53207a9

Browse files
committedApr 11, 2016
[LoopUtils, LV] Fix PR27246 (first-order recurrences)
This patch ensures that when we detect first-order recurrences, we reject a phi node if its previous value is also a phi node. During vectorization the initial and previous values of the recurrence are shuffled together to create the value for the current iteration. However, phi nodes are not widened like other instructions. This fixes PR27246. Differential Revision: http://reviews.llvm.org/D18971 llvm-svn: 265983
1 parent bbf78cd commit 53207a9

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed
 

Diff for: ‎llvm/lib/Transforms/Utils/LoopUtils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ bool RecurrenceDescriptor::isFirstOrderRecurrence(PHINode *Phi, Loop *TheLoop,
541541
// Get the previous value. The previous value comes from the latch edge while
542542
// the initial value comes form the preheader edge.
543543
auto *Previous = dyn_cast<Instruction>(Phi->getIncomingValueForBlock(Latch));
544-
if (!Previous || !TheLoop->contains(Previous))
544+
if (!Previous || !TheLoop->contains(Previous) || isa<PHINode>(Previous))
545545
return false;
546546

547547
// Ensure every user of the phi node is dominated by the previous value. The

Diff for: ‎llvm/test/Transforms/LoopVectorize/AArch64/first-order-recurrence.ll

+41
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,44 @@ for.cond.for.end_crit_edge:
256256
for.end:
257257
ret void
258258
}
259+
260+
; CHECK-LABEL: @PR27246
261+
;
262+
; int PR27246() {
263+
; unsigned int e, n;
264+
; for (int i = 1; i < 49; ++i) {
265+
; for (int k = i; k > 1; --k)
266+
; e = k;
267+
; n = e;
268+
; }
269+
; return n;
270+
; }
271+
;
272+
; CHECK-NOT: vector.ph:
273+
;
274+
define i32 @PR27246() {
275+
entry:
276+
br label %for.cond1.preheader
277+
278+
for.cond1.preheader:
279+
%i.016 = phi i32 [ 1, %entry ], [ %inc, %for.cond.cleanup3 ]
280+
%e.015 = phi i32 [ undef, %entry ], [ %e.1.lcssa, %for.cond.cleanup3 ]
281+
br label %for.cond1
282+
283+
for.cond.cleanup:
284+
%e.1.lcssa.lcssa = phi i32 [ %e.1.lcssa, %for.cond.cleanup3 ]
285+
ret i32 %e.1.lcssa.lcssa
286+
287+
for.cond1:
288+
%e.1 = phi i32 [ %k.0, %for.cond1 ], [ %e.015, %for.cond1.preheader ]
289+
%k.0 = phi i32 [ %dec, %for.cond1 ], [ %i.016, %for.cond1.preheader ]
290+
%cmp2 = icmp sgt i32 %k.0, 1
291+
%dec = add nsw i32 %k.0, -1
292+
br i1 %cmp2, label %for.cond1, label %for.cond.cleanup3
293+
294+
for.cond.cleanup3:
295+
%e.1.lcssa = phi i32 [ %e.1, %for.cond1 ]
296+
%inc = add nuw nsw i32 %i.016, 1
297+
%exitcond = icmp eq i32 %inc, 49
298+
br i1 %exitcond, label %for.cond.cleanup, label %for.cond1.preheader
299+
}

0 commit comments

Comments
 (0)
Please sign in to comment.