llvm.org GIT mirror llvm / 334f714
[IndVars] Change the order to compute WidenAddRec in widenIVUse. When both WidenIV::getWideRecurrence and WidenIV::getExtendedOperandRecurrence return non-null but different WideAddRec, if getWideRecurrence is called before getExtendedOperandRecurrence, we won't bother to call getExtendedOperandRecurrence again. But As we know it is possible that after SCEV folding, we cannot prove the legality using the SCEVAddRecExpr returned by getWideRecurrence. Meanwhile if getExtendedOperandRecurrence returns non-null WideAddRec, we know for sure that it is legal to do widening for current instruction. So it is better to put getExtendedOperandRecurrence before getWideRecurrence, which will increase the chance of successful widening. Differential Revision: https://reviews.llvm.org/D26059 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286987 91177308-0d34-0410-b5e6-96231b3b80d8 Wei Mi 2 years ago
3 changed file(s) with 65 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
14111411 }
14121412
14131413 // Does this user itself evaluate to a recurrence after widening?
1414 WidenedRecTy WideAddRec = getWideRecurrence(DU);
1414 WidenedRecTy WideAddRec = getExtendedOperandRecurrence(DU);
14151415 if (!WideAddRec.first)
1416 WideAddRec = getExtendedOperandRecurrence(DU);
1416 WideAddRec = getWideRecurrence(DU);
14171417
14181418 assert((WideAddRec.first == nullptr) == (WideAddRec.second == Unknown));
14191419 if (!WideAddRec.first) {
2020 ; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i32, i32* %C, i64 [[TMP1]]
2121 ; CHECK-NEXT: [[TMP2:%.*]] = load i32, i32* [[ARRAYIDX2]], align 4
2222 ; CHECK-NEXT: [[ADD3:%.*]] = add nsw i32 [[TMP0]], [[TMP2]]
23 ; CHECK-NEXT: [[TRUNC0:%.*]] = trunc i64 [[TMP1]] to i32
24 ; CHECK-NEXT: [[DIV0:%.*]] = udiv i32 5, [[TRUNC0]]
25 ; CHECK-NEXT: [[ADD4:%.*]] = add nsw i32 [[ADD3]], [[DIV0]]
2326 ; CHECK-NEXT: [[ARRAYIDX5:%.*]] = getelementptr inbounds i32, i32* %A, i64 [[INDVARS_IV]]
24 ; CHECK-NEXT: store i32 [[ADD3]], i32* [[ARRAYIDX5]], align 4
27 ; CHECK-NEXT: store i32 [[ADD4]], i32* [[ARRAYIDX5]], align 4
2528 ; CHECK-NEXT: br label %for.inc
2629 ; CHECK: for.inc:
2730 ; CHECK-NEXT: [[INDVARS_IV_NEXT:%.*]] = add nuw nsw i64 [[INDVARS_IV]], 1
5053 %arrayidx2 = getelementptr inbounds i32, i32* %C, i64 %idxprom1
5154 %1 = load i32, i32* %arrayidx2, align 4
5255 %add3 = add nsw i32 %0, %1
56 %div0 = udiv i32 5, %add
57 %add4 = add nsw i32 %add3, %div0
5358 %idxprom4 = zext i32 %i.02 to i64
5459 %arrayidx5 = getelementptr inbounds i32, i32* %A, i64 %idxprom4
55 store i32 %add3, i32* %arrayidx5, align 4
60 store i32 %add4, i32* %arrayidx5, align 4
5661 br label %for.inc
5762
5863 for.inc: ; preds = %for.body
6868
6969 declare void @dummy(i32)
7070 declare void @dummy.i64(i64)
71
72
73 define void @loop_2(i32 %size, i32 %nsteps, i32 %hsize, i32* %lined, i8 %tmp1) {
74 ; CHECK-LABEL: @loop_2(
75 entry:
76 %cmp215 = icmp sgt i32 %size, 1
77 %tmp0 = bitcast i32* %lined to i8*
78 br label %for.body
79
80 for.body:
81 %j = phi i32 [ 0, %entry ], [ %inc6, %for.inc ]
82 %mul = mul nsw i32 %j, %size
83 %add = add nsw i32 %mul, %hsize
84 br i1 %cmp215, label %for.body2, label %for.inc
85
86 ; check that the induction variable of the inner loop has been widened after indvars.
87 ; CHECK: [[INNERLOOPINV:%[^ ]+]] = add nsw i64
88 ; CHECK: for.body2:
89 ; CHECK-NEXT: %indvars.iv = phi i64 [ 1, %for.body2.preheader ], [ %indvars.iv.next, %for.body2 ]
90 ; CHECK-NEXT: [[WIDENED:%[^ ]+]] = add nsw i64 [[INNERLOOPINV]], %indvars.iv
91 ; CHECK-NEXT: %add.ptr = getelementptr inbounds i8, i8* %tmp0, i64 [[WIDENED]]
92 for.body2:
93 %k = phi i32 [ %inc, %for.body2 ], [ 1, %for.body ]
94 %add4 = add nsw i32 %add, %k
95 %idx.ext = sext i32 %add4 to i64
96 %add.ptr = getelementptr inbounds i8, i8* %tmp0, i64 %idx.ext
97 store i8 %tmp1, i8* %add.ptr, align 1
98 %inc = add nsw i32 %k, 1
99 %cmp2 = icmp slt i32 %inc, %size
100 br i1 %cmp2, label %for.body2, label %for.body3
101
102 ; check that the induction variable of the inner loop has been widened after indvars.
103 ; CHECK: for.body3.preheader:
104 ; CHECK: [[INNERLOOPINV:%[^ ]+]] = zext i32
105 ; CHECK: for.body3:
106 ; CHECK-NEXT: %indvars.iv2 = phi i64 [ 1, %for.body3.preheader ], [ %indvars.iv.next3, %for.body3 ]
107 ; CHECK-NEXT: [[WIDENED:%[^ ]+]] = add nuw nsw i64 [[INNERLOOPINV]], %indvars.iv2
108 ; CHECK-NEXT: %add.ptr2 = getelementptr inbounds i8, i8* %tmp0, i64 [[WIDENED]]
109 for.body3:
110 %l = phi i32 [ %inc2, %for.body3 ], [ 1, %for.body2 ]
111 %add5 = add nuw i32 %add, %l
112 %idx.ext2 = zext i32 %add5 to i64
113 %add.ptr2 = getelementptr inbounds i8, i8* %tmp0, i64 %idx.ext2
114 store i8 %tmp1, i8* %add.ptr2, align 1
115 %inc2 = add nsw i32 %l, 1
116 %cmp3 = icmp slt i32 %inc2, %size
117 br i1 %cmp3, label %for.body3, label %for.inc
118
119 for.inc:
120 %inc6 = add nsw i32 %j, 1
121 %cmp = icmp slt i32 %inc6, %nsteps
122 br i1 %cmp, label %for.body, label %for.end.loopexit
123
124 for.end.loopexit:
125 ret void
126 }