Skip to content

Commit f9f52c8

Browse files
committed
[NFCI][SCEV] getPointerBase(): de-recursify
Summary: This is boringly straight-forward, each iteration we see if V is some expression that we can look into, and if it has a single pointer operand, then set V to that operand and repeat. Reviewers: efriedma, mkazantsev, reames, nikic Reviewed By: nikic Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D82632
1 parent f4aaed3 commit f9f52c8

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3953,23 +3953,25 @@ const SCEV *ScalarEvolution::getPointerBase(const SCEV *V) {
39533953
if (!V->getType()->isPointerTy())
39543954
return V;
39553955

3956-
if (const SCEVCastExpr *Cast = dyn_cast<SCEVCastExpr>(V)) {
3957-
return getPointerBase(Cast->getOperand());
3958-
} else if (const SCEVNAryExpr *NAry = dyn_cast<SCEVNAryExpr>(V)) {
3959-
const SCEV *PtrOp = nullptr;
3960-
for (const SCEV *NAryOp : NAry->operands()) {
3961-
if (NAryOp->getType()->isPointerTy()) {
3962-
// Cannot find the base of an expression with multiple pointer operands.
3963-
if (PtrOp)
3964-
return V;
3965-
PtrOp = NAryOp;
3956+
while (true) {
3957+
if (const SCEVCastExpr *Cast = dyn_cast<SCEVCastExpr>(V)) {
3958+
V = Cast->getOperand();
3959+
} else if (const SCEVNAryExpr *NAry = dyn_cast<SCEVNAryExpr>(V)) {
3960+
const SCEV *PtrOp = nullptr;
3961+
for (const SCEV *NAryOp : NAry->operands()) {
3962+
if (NAryOp->getType()->isPointerTy()) {
3963+
// Cannot find the base of an expression with multiple pointer ops.
3964+
if (PtrOp)
3965+
return V;
3966+
PtrOp = NAryOp;
3967+
}
39663968
}
3967-
}
3968-
if (!PtrOp)
3969+
if (!PtrOp) // All operands were non-pointer.
3970+
return V;
3971+
V = PtrOp;
3972+
} else // Not something we can look further into.
39693973
return V;
3970-
return getPointerBase(PtrOp);
39713974
}
3972-
return V;
39733975
}
39743976

39753977
/// Push users of the given Instruction onto the given Worklist.

0 commit comments

Comments
 (0)