llvm.org GIT mirror llvm / 8ebaf90
teach SCEV that the scale and addition of an inbounds gep don't NSW. This fixes a FIXME in scev-aa.ll (allowing a new no-alias result) and generally makes things more precise. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@125449 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 9 years ago
3 changed file(s) with 36 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
28692869 // Add expression, because the Instruction may be guarded by control flow
28702870 // and the no-overflow bits may not be valid for the expression in any
28712871 // context.
2872 bool isInBounds = GEP->isInBounds();
28722873
28732874 const Type *IntPtrTy = getEffectiveSCEVType(GEP->getType());
28742875 Value *Base = GEP->getOperand(0);
28972898 IndexS = getTruncateOrSignExtend(IndexS, IntPtrTy);
28982899
28992900 // Multiply the index by the element size to compute the element offset.
2900 const SCEV *LocalOffset = getMulExpr(IndexS, ElementSize);
2901 const SCEV *LocalOffset = getMulExpr(IndexS, ElementSize, /*NUW*/ false,
2902 /*NSW*/ isInBounds);
29012903
29022904 // Add the element offset to the running total offset.
29032905 TotalOffset = getAddExpr(TotalOffset, LocalOffset);
29082910 const SCEV *BaseS = getSCEV(Base);
29092911
29102912 // Add the total offset from all the GEP indices to the base.
2911 return getAddExpr(BaseS, TotalOffset);
2913 return getAddExpr(BaseS, TotalOffset, /*NUW*/ false,
2914 /*NSW*/ isInBounds);
29122915 }
29132916
29142917 /// GetMinTrailingZeros - Determine the minimum number of zero bits that S is
7575 _ZSt4fillIPiiEvT_S1_RKT0_.exit: ; preds = %entry, %for.cond.for.end_crit_edge.i.i
7676 ret void
7777 }
78
79 ; Various checks for inbounds geps.
80 define void @test3(i32* %begin, i32* %end) nounwind ssp {
81 entry:
82 %cmp7.i.i = icmp eq i32* %begin, %end
83 br i1 %cmp7.i.i, label %_ZSt4fillIPiiEvT_S1_RKT0_.exit, label %for.body.i.i
84
85 for.body.i.i: ; preds = %entry, %for.body.i.i
86 %indvar.i.i = phi i64 [ %tmp, %for.body.i.i ], [ 0, %entry ]
87 ; CHECK: %indvar.i.i
88 ; CHECK: {0,+,1}<%for.body.i.i>
89 %tmp = add nsw i64 %indvar.i.i, 1
90 ; CHECK: %tmp =
91 ; CHECK: {1,+,1}<%for.body.i.i>
92 %ptrincdec.i.i = getelementptr inbounds i32* %begin, i64 %tmp
93 ; CHECK: %ptrincdec.i.i =
94 ; CHECK: {(4 + %begin),+,4}<%for.body.i.i>
95 %__first.addr.08.i.i = getelementptr inbounds i32* %begin, i64 %indvar.i.i
96 ; CHECK: %__first.addr.08.i.i
97 ; CHECK: {%begin,+,4}<%for.body.i.i>
98 store i32 0, i32* %__first.addr.08.i.i, align 4
99 %cmp.i.i = icmp eq i32* %ptrincdec.i.i, %end
100 br i1 %cmp.i.i, label %_ZSt4fillIPiiEvT_S1_RKT0_.exit, label %for.body.i.i
101 ; CHECK: Loop %for.body.i.i: Unpredictable backedge-taken count.
102 ; CHECK: Loop %for.body.i.i: Unpredictable max backedge-taken count.
103 _ZSt4fillIPiiEvT_S1_RKT0_.exit: ; preds = %for.body.i.i, %entry
104 ret void
105 }
189189 ret void
190190 }
191191
192 ; TODO: This is theoretically provable to be NoAlias.
193192 ; CHECK: Function: nonnegative: 2 pointers, 0 call sites
194 ; CHECK: MayAlias: i64* %arrayidx, i64* %p
193 ; CHECK: NoAlias: i64* %arrayidx, i64* %p
195194
196195 define void @nonnegative(i64* %p) nounwind {
197196 entry:
210209 ret void
211210 }
212211
213 ; CHECK: 13 no alias responses
214 ; CHECK: 27 may alias responses
212 ; CHECK: 14 no alias responses
213 ; CHECK: 26 may alias responses
215214 ; CHECK: 18 must alias responses