Skip to content

Commit

Permalink
[LoopUtils, LV] Fix PR26734
Browse files Browse the repository at this point in the history
The vectorization of first-order recurrences (r261346) caused PR26734. When
detecting these recurrences, we need to ensure that the previous value is
actually defined inside the loop. This patch includes the fix and test case.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@262624 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
mssimpso committed Mar 3, 2016
1 parent 4cb228f commit 72b5335
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Transforms/Utils/LoopUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ bool RecurrenceDescriptor::isFirstOrderRecurrence(PHINode *Phi, Loop *TheLoop,
// Get the previous value. The previous value comes from the latch edge while
// the initial value comes form the preheader edge.
auto *Previous = dyn_cast<Instruction>(Phi->getIncomingValueForBlock(Latch));
if (!Previous)
if (!Previous || !TheLoop->contains(Previous))
return false;

// Ensure every user of the phi node is dominated by the previous value. The
Expand Down
49 changes: 49 additions & 0 deletions test/Transforms/LoopVectorize/AArch64/first-order-recurrence.ll
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,52 @@ for.end.loopexit:
for.end:
ret void
}

; CHECK-LABEL: @PR26734
;
; void PR26734(short *a, int *b, int *c, int d, short *e) {
; for (; d != 21; d++) {
; *b &= *c;
; *e = *a - 6;
; *c = *e;
; }
; }
;
; CHECK-NOT: vector.ph:
;
define void @PR26734(i16* %a, i32* %b, i32* %c, i32 %d, i16* %e) {
entry:
%cmp4 = icmp eq i32 %d, 21
br i1 %cmp4, label %entry.for.end_crit_edge, label %for.body.lr.ph

entry.for.end_crit_edge:
%.pre = load i32, i32* %b, align 4
br label %for.end

for.body.lr.ph:
%0 = load i16, i16* %a, align 2
%sub = add i16 %0, -6
%conv2 = sext i16 %sub to i32
%c.promoted = load i32, i32* %c, align 4
%b.promoted = load i32, i32* %b, align 4
br label %for.body

for.body:
%inc7 = phi i32 [ %d, %for.body.lr.ph ], [ %inc, %for.body ]
%and6 = phi i32 [ %b.promoted, %for.body.lr.ph ], [ %and, %for.body ]
%conv25 = phi i32 [ %c.promoted, %for.body.lr.ph ], [ %conv2, %for.body ]
%and = and i32 %and6, %conv25
%inc = add nsw i32 %inc7, 1
%cmp = icmp eq i32 %inc, 21
br i1 %cmp, label %for.cond.for.end_crit_edge, label %for.body

for.cond.for.end_crit_edge:
%and.lcssa = phi i32 [ %and, %for.body ]
store i32 %conv2, i32* %c, align 4
store i32 %and.lcssa, i32* %b, align 4
store i16 %sub, i16* %e, align 2
br label %for.end

for.end:
ret void
}

0 comments on commit 72b5335

Please sign in to comment.