Skip to content

Commit b5ae437

Browse files
committed
[LAA] strip unnecessary getUniqueCastUse
733b8b2 ([LAA] Simplify identification of speculatable strides [nfc]) refactored getStrideFromPointer() to compute directly on SCEVs, and return an SCEV expression instead of a Value. However, it left behind a call to getUniqueCastUse(), which is completely unnecessary. Remove this, showing a positive test update, and simplify the surrounding program logic.
1 parent 0833a2b commit b5ae437

File tree

2 files changed

+18
-33
lines changed

2 files changed

+18
-33
lines changed

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2656,7 +2656,7 @@ void LoopAccessInfo::analyzeLoop(AAResults *AA, LoopInfo *LI,
26562656
SymbolicStrides, UncomputablePtr, false);
26572657
if (!CanDoRTIfNeeded) {
26582658
auto *I = dyn_cast_or_null<Instruction>(UncomputablePtr);
2659-
recordAnalysis("CantIdentifyArrayBounds", I)
2659+
recordAnalysis("CantIdentifyArrayBounds", I)
26602660
<< "cannot identify array bounds";
26612661
LLVM_DEBUG(dbgs() << "LAA: We can't vectorize because we can't find "
26622662
<< "the array bounds.\n");
@@ -2873,21 +2873,6 @@ static Value *stripGetElementPtr(Value *Ptr, ScalarEvolution *SE, Loop *Lp) {
28732873
return GEP->getOperand(InductionOperand);
28742874
}
28752875

2876-
/// If a value has only one user that is a CastInst, return it.
2877-
static Value *getUniqueCastUse(Value *Ptr, Loop *Lp, Type *Ty) {
2878-
Value *UniqueCast = nullptr;
2879-
for (User *U : Ptr->users()) {
2880-
CastInst *CI = dyn_cast<CastInst>(U);
2881-
if (CI && CI->getType() == Ty) {
2882-
if (!UniqueCast)
2883-
UniqueCast = CI;
2884-
else
2885-
return nullptr;
2886-
}
2887-
}
2888-
return UniqueCast;
2889-
}
2890-
28912876
/// Get the stride of a pointer access in a loop. Looks for symbolic
28922877
/// strides "a[i*stride]". Returns the symbolic stride, or null otherwise.
28932878
static const SCEV *getStrideFromPointer(Value *Ptr, ScalarEvolution *SE, Loop *Lp) {
@@ -2950,21 +2935,14 @@ static const SCEV *getStrideFromPointer(Value *Ptr, ScalarEvolution *SE, Loop *L
29502935
return nullptr;
29512936

29522937
// Look for the loop invariant symbolic value.
2953-
const SCEVUnknown *U = dyn_cast<SCEVUnknown>(V);
2954-
if (!U) {
2955-
const auto *C = dyn_cast<SCEVIntegralCastExpr>(V);
2956-
if (!C)
2957-
return nullptr;
2958-
U = dyn_cast<SCEVUnknown>(C->getOperand());
2959-
if (!U)
2960-
return nullptr;
2938+
if (isa<SCEVUnknown>(V))
2939+
return V;
29612940

2962-
// Match legacy behavior - this is not needed for correctness
2963-
if (!getUniqueCastUse(U->getValue(), Lp, V->getType()))
2964-
return nullptr;
2965-
}
2941+
if (const auto *C = dyn_cast<SCEVIntegralCastExpr>(V))
2942+
if (isa<SCEVUnknown>(C->getOperand()))
2943+
return V;
29662944

2967-
return V;
2945+
return nullptr;
29682946
}
29692947

29702948
void LoopAccessInfo::collectStridedAccess(Value *MemAccess) {

llvm/test/Analysis/LoopAccessAnalysis/symbolic-stride.ll

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,23 @@ define void @single_stride_castexpr_multiuse(i32 %offset, ptr %src, ptr %dst, i1
170170
; CHECK-NEXT: %gep.src = getelementptr inbounds i32, ptr %src, i64 %iv.3
171171
; CHECK-NEXT: Grouped accesses:
172172
; CHECK-NEXT: Group [[GRP3]]:
173-
; CHECK-NEXT: (Low: (((4 * %iv.1) + %dst) umin ((4 * %iv.1) + (4 * (sext i32 %offset to i64) * (200 + (-1 * (zext i32 %offset to i64))<nsw>)<nsw>) + %dst)) High: (4 + (((4 * %iv.1) + %dst) umax ((4 * %iv.1) + (4 * (sext i32 %offset to i64) * (200 + (-1 * (zext i32 %offset to i64))<nsw>)<nsw>) + %dst))))
174-
; CHECK-NEXT: Member: {((4 * %iv.1) + %dst),+,(4 * (sext i32 %offset to i64))<nsw>}<%inner.loop>
173+
; CHECK-NEXT: (Low: ((4 * %iv.1) + %dst) High: (804 + (4 * %iv.1) + (-4 * (zext i32 %offset to i64))<nsw> + %dst))
174+
; CHECK-NEXT: Member: {((4 * %iv.1) + %dst),+,4}<%inner.loop>
175175
; CHECK-NEXT: Group [[GRP4]]:
176-
; CHECK-NEXT: (Low: ((4 * (zext i32 %offset to i64))<nuw><nsw> + %src) High: (804 + %src))
177-
; CHECK-NEXT: Member: {((4 * (zext i32 %offset to i64))<nuw><nsw> + %src),+,4}<%inner.loop>
176+
; CHECK-NEXT: (Low: (4 + %src) High: (808 + (-4 * (zext i32 %offset to i64))<nsw> + %src))
177+
; CHECK-NEXT: Member: {(4 + %src),+,4}<%inner.loop>
178178
; CHECK-EMPTY:
179179
; CHECK-NEXT: Non vectorizable stores to invariant address were not found in loop.
180180
; CHECK-NEXT: SCEV assumptions:
181+
; CHECK-NEXT: Equal predicate: %offset == 1
181182
; CHECK-EMPTY:
182183
; CHECK-NEXT: Expressions re-written:
184+
; CHECK-NEXT: [PSE] %gep.src = getelementptr inbounds i32, ptr %src, i64 %iv.3:
185+
; CHECK-NEXT: {((4 * (zext i32 %offset to i64))<nuw><nsw> + %src),+,4}<%inner.loop>
186+
; CHECK-NEXT: --> {(4 + %src),+,4}<%inner.loop>
187+
; CHECK-NEXT: [PSE] %gep.dst = getelementptr i32, ptr %dst, i64 %iv.2:
188+
; CHECK-NEXT: {((4 * %iv.1) + %dst),+,(4 * (sext i32 %offset to i64))<nsw>}<%inner.loop>
189+
; CHECK-NEXT: --> {((4 * %iv.1) + %dst),+,4}<%inner.loop>
183190
; CHECK-NEXT: outer.header:
184191
; CHECK-NEXT: Report: loop is not the innermost loop
185192
; CHECK-NEXT: Dependences:

0 commit comments

Comments
 (0)