forked from llvm-mirror/llvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use ValueOffsetPair to enhance value reuse during SCEV expansion.
In D12090, the ExprValueMap was added to reuse existing value during SCEV expansion. However, const folding and sext/zext distribution can make the reuse still difficult. A simplified case is: suppose we know S1 expands to V1 in ExprValueMap, and S1 = S2 + C_a S3 = S2 + C_b where C_a and C_b are different SCEVConstants. Then we'd like to expand S3 as V1 - C_a + C_b instead of expanding S2 literally. It is helpful when S2 is a complex SCEV expr and S2 has no entry in ExprValueMap, which is usually caused by the fact that S3 is generated from S1 after const folding. In order to do that, we represent ExprValueMap as a mapping from SCEV to ValueOffsetPair. We will save both S1->{V1, 0} and S2->{V1, C_a} into the ExprValueMap when we create SCEV for V1. When S3 is expanded, it will first expand S2 to V1 - C_a because of S2->{V1, C_a} in the map, then expand S3 to V1 - C_a + C_b. Differential Revision: https://reviews.llvm.org/D21313 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276136 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
Showing
5 changed files
with
191 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
test/Analysis/ScalarEvolution/scev-expander-existing-value-offset.ll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
; RUN: opt < %s -loop-vectorize -force-vector-interleave=1 -force-vector-width=4 -S |FileCheck %s | ||
; SCEV expansion uses existing value or value + offset to reduce duplicate code expansion so foo should only generate one select inst after loop vectorization. | ||
; CHECK-LABEL: @foo( | ||
; CHECK: select | ||
; CHECK-NOT: select | ||
|
||
@ySrcL = common global i8* null, align 8 | ||
@smL = common global i32 0, align 4 | ||
|
||
define void @foo(i32 %rwL, i32 %kL, i32 %xfL) { | ||
entry: | ||
%sub = add nsw i32 %rwL, -1 | ||
%shr = ashr i32 %xfL, 6 | ||
%cmp.i = icmp slt i32 %sub, %shr | ||
%cond.i = select i1 %cmp.i, i32 %sub, i32 %shr | ||
%cmp6 = icmp sgt i32 %cond.i, %kL | ||
br i1 %cmp6, label %for.body.lr.ph, label %for.end | ||
|
||
for.body.lr.ph: ; preds = %entry | ||
%tmp = load i8*, i8** @ySrcL, align 8 | ||
%tmp1 = sext i32 %kL to i64 | ||
%tmp2 = sext i32 %cond.i to i64 | ||
br label %for.body | ||
|
||
for.body: ; preds = %for.body, %for.body.lr.ph | ||
%indvars.iv = phi i64 [ %tmp1, %for.body.lr.ph ], [ %indvars.iv.next, %for.body ] | ||
%reduct.07 = phi i32 [ 0, %for.body.lr.ph ], [ %add, %for.body ] | ||
%arrayidx = getelementptr inbounds i8, i8* %tmp, i64 %indvars.iv | ||
%tmp3 = load i8, i8* %arrayidx, align 1 | ||
%conv = zext i8 %tmp3 to i32 | ||
%add = add nsw i32 %conv, %reduct.07 | ||
%indvars.iv.next = add nsw i64 %indvars.iv, 1 | ||
%cmp = icmp slt i64 %indvars.iv.next, %tmp2 | ||
br i1 %cmp, label %for.body, label %for.end.loopexit | ||
|
||
for.end.loopexit: ; preds = %for.body | ||
%add.lcssa = phi i32 [ %add, %for.body ] | ||
br label %for.end | ||
|
||
for.end: ; preds = %for.end.loopexit, %entry | ||
%reduct.0.lcssa = phi i32 [ 0, %entry ], [ %add.lcssa, %for.end.loopexit ] | ||
store i32 %reduct.0.lcssa, i32* @smL, align 4 | ||
ret void | ||
} | ||
; RUN: opt < %s -loop-vectorize -force-vector-interleave=1 -force-vector-width=4 -S |FileCheck %s | ||
; SCEV expansion uses existing value or value + offset to reduce duplicate code expansion so foo should only generate one select inst after loop vectorization. | ||
; CHECK-LABEL: @foo( | ||
; CHECK: select | ||
; CHECK-NOT: select | ||
|
||
@ySrcL = common global i8* null, align 8 | ||
@smL = common global i32 0, align 4 | ||
|
||
define void @foo(i32 %rwL, i32 %kL, i32 %xfL) { | ||
entry: | ||
%sub = add nsw i32 %rwL, -1 | ||
%shr = ashr i32 %xfL, 6 | ||
%cmp.i = icmp slt i32 %sub, %shr | ||
%cond.i = select i1 %cmp.i, i32 %sub, i32 %shr | ||
%cmp6 = icmp sgt i32 %cond.i, %kL | ||
br i1 %cmp6, label %for.body.lr.ph, label %for.end | ||
|
||
for.body.lr.ph: ; preds = %entry | ||
%tmp = load i8*, i8** @ySrcL, align 8 | ||
%tmp1 = sext i32 %kL to i64 | ||
%tmp2 = sext i32 %cond.i to i64 | ||
br label %for.body | ||
|
||
for.body: ; preds = %for.body, %for.body.lr.ph | ||
%indvars.iv = phi i64 [ %tmp1, %for.body.lr.ph ], [ %indvars.iv.next, %for.body ] | ||
%reduct.07 = phi i32 [ 0, %for.body.lr.ph ], [ %add, %for.body ] | ||
%arrayidx = getelementptr inbounds i8, i8* %tmp, i64 %indvars.iv | ||
%tmp3 = load i8, i8* %arrayidx, align 1 | ||
%conv = zext i8 %tmp3 to i32 | ||
%add = add nsw i32 %conv, %reduct.07 | ||
%indvars.iv.next = add nsw i64 %indvars.iv, 1 | ||
%cmp = icmp slt i64 %indvars.iv.next, %tmp2 | ||
br i1 %cmp, label %for.body, label %for.end.loopexit | ||
|
||
for.end.loopexit: ; preds = %for.body | ||
%add.lcssa = phi i32 [ %add, %for.body ] | ||
br label %for.end | ||
|
||
for.end: ; preds = %for.end.loopexit, %entry | ||
%reduct.0.lcssa = phi i32 [ 0, %entry ], [ %add.lcssa, %for.end.loopexit ] | ||
store i32 %reduct.0.lcssa, i32* @smL, align 4 | ||
ret void | ||
} |