[llvm] b12192f - [ScalarEvolution] Clarify implementation of getPointerBase().
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 23 12:58:30 PDT 2021
Author: Eli Friedman
Date: 2021-06-23T12:55:59-07:00
New Revision: b12192f7cd8c12898c161c573aad41ac65721c80
URL: https://github.com/llvm/llvm-project/commit/b12192f7cd8c12898c161c573aad41ac65721c80
DIFF: https://github.com/llvm/llvm-project/commit/b12192f7cd8c12898c161c573aad41ac65721c80.diff
LOG: [ScalarEvolution] Clarify implementation of getPointerBase().
getPointerBase should only be looking through Add and AddRec
expressions; other expressions either aren't pointers, or can't be
looked through.
Technically, this is a functional change. For a multiply or min/max
expression, if they have exactly one pointer operand, and that operand
is the first operand, the behavior here changes. Similarly, if an AddRec
has a pointer-type step, the behavior changes. But that shouldn't be
happening in practice, and we plan to make such expressions illegal.
Added:
Modified:
llvm/lib/Analysis/ScalarEvolution.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index e330ed27c792..8bd8e28e5f10 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -4287,16 +4287,16 @@ const SCEV *ScalarEvolution::getPointerBase(const SCEV *V) {
return V;
while (true) {
- if (const SCEVIntegralCastExpr *Cast = dyn_cast<SCEVIntegralCastExpr>(V)) {
- V = Cast->getOperand();
- } else if (const SCEVNAryExpr *NAry = dyn_cast<SCEVNAryExpr>(V)) {
+ if (auto *AddRec = dyn_cast<SCEVAddRecExpr>(V)) {
+ V = AddRec->getStart();
+ } else if (auto *Add = dyn_cast<SCEVAddExpr>(V)) {
const SCEV *PtrOp = nullptr;
- for (const SCEV *NAryOp : NAry->operands()) {
- if (NAryOp->getType()->isPointerTy()) {
+ for (const SCEV *AddOp : Add->operands()) {
+ if (AddOp->getType()->isPointerTy()) {
// Cannot find the base of an expression with multiple pointer ops.
if (PtrOp)
return V;
- PtrOp = NAryOp;
+ PtrOp = AddOp;
}
}
if (!PtrOp) // All operands were non-pointer.
More information about the llvm-commits
mailing list