[llvm] 6ec5646 - [SCEV] Construct GEP expression more efficiently (NFCI)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 1 10:03:29 PST 2020
Author: Nikita Popov
Date: 2020-11-01T19:00:57+01:00
New Revision: 6ec56467cbc6d426168fb486654f42121622cbb9
URL: https://github.com/llvm/llvm-project/commit/6ec56467cbc6d426168fb486654f42121622cbb9
DIFF: https://github.com/llvm/llvm-project/commit/6ec56467cbc6d426168fb486654f42121622cbb9.diff
LOG: [SCEV] Construct GEP expression more efficiently (NFCI)
Instead of performing a sequence of pairwise additions, directly
construct a multi-operand add expression.
This should be NFC modulo any SCEV canonicalization deficiencies.
Added:
Modified:
llvm/lib/Analysis/ScalarEvolution.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index d214fcef09de..aa3e92cd7b78 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -3421,9 +3421,9 @@ ScalarEvolution::getGEPExpr(GEPOperator *GEP,
SCEV::NoWrapFlags Wrap = GEP->isInBounds() ? SCEV::FlagNSW
: SCEV::FlagAnyWrap;
- const SCEV *TotalOffset = getZero(IntIdxTy);
Type *CurTy = GEP->getType();
bool FirstIter = true;
+ SmallVector<const SCEV *, 4> AddOps{BaseExpr};
for (const SCEV *IndexExpr : IndexExprs) {
// Compute the (potentially symbolic) offset in bytes for this index.
if (StructType *STy = dyn_cast<StructType>(CurTy)) {
@@ -3431,9 +3431,7 @@ ScalarEvolution::getGEPExpr(GEPOperator *GEP,
ConstantInt *Index = cast<SCEVConstant>(IndexExpr)->getValue();
unsigned FieldNo = Index->getZExtValue();
const SCEV *FieldOffset = getOffsetOfExpr(IntIdxTy, STy, FieldNo);
-
- // Add the field offset to the running total offset.
- TotalOffset = getAddExpr(TotalOffset, FieldOffset);
+ AddOps.push_back(FieldOffset);
// Update CurTy to the type of the field at Index.
CurTy = STy->getTypeAtIndex(Index);
@@ -3454,14 +3452,12 @@ ScalarEvolution::getGEPExpr(GEPOperator *GEP,
// Multiply the index by the element size to compute the element offset.
const SCEV *LocalOffset = getMulExpr(IndexExpr, ElementSize, Wrap);
-
- // Add the element offset to the running total offset.
- TotalOffset = getAddExpr(TotalOffset, LocalOffset);
+ AddOps.push_back(LocalOffset);
}
}
- // Add the total offset from all the GEP indices to the base.
- return getAddExpr(BaseExpr, TotalOffset, Wrap);
+ // Add the base and all the offsets together.
+ return getAddExpr(AddOps, Wrap);
}
std::tuple<SCEV *, FoldingSetNodeID, void *>
More information about the llvm-commits
mailing list