[llvm] a3908d3 - [BasicAA] Optimize index size adjustment (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 21 07:32:40 PST 2023
Author: Nikita Popov
Date: 2023-11-21T16:32:27+01:00
New Revision: a3908d33b17cb9655d336039bf6a9bd798930eb4
URL: https://github.com/llvm/llvm-project/commit/a3908d33b17cb9655d336039bf6a9bd798930eb4
DIFF: https://github.com/llvm/llvm-project/commit/a3908d33b17cb9655d336039bf6a9bd798930eb4.diff
LOG: [BasicAA] Optimize index size adjustment (NFC)
In most cases we do not actually have to perform an index size
adjustment. Don't perform any APInt operations in that case.
Added:
Modified:
llvm/lib/Analysis/BasicAliasAnalysis.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index 4d2f81ea4cfca66..70f81f6c20d004a 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -457,10 +457,13 @@ static LinearExpression GetLinearExpression(
/// an issue, for example, in particular for 32b pointers with negative indices
/// that rely on two's complement wrap-arounds for precise alias information
/// where the maximum index size is 64b.
-static APInt adjustToIndexSize(const APInt &Offset, unsigned IndexSize) {
+static void adjustToIndexSize(APInt &Offset, unsigned IndexSize) {
assert(IndexSize <= Offset.getBitWidth() && "Invalid IndexSize!");
unsigned ShiftBits = Offset.getBitWidth() - IndexSize;
- return (Offset << ShiftBits).ashr(ShiftBits);
+ if (ShiftBits != 0) {
+ Offset <<= ShiftBits;
+ Offset.ashrInPlace(ShiftBits);
+ }
}
namespace {
@@ -685,7 +688,7 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL,
// Make sure that we have a scale that makes sense for this target's
// index size.
- Scale = adjustToIndexSize(Scale, IndexSize);
+ adjustToIndexSize(Scale, IndexSize);
if (!!Scale) {
VariableGEPIndex Entry = {LE.Val, Scale, CxtI, LE.IsNSW,
@@ -696,7 +699,7 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL,
// Take care of wrap-arounds
if (GepHasConstantOffset)
- Decomposed.Offset = adjustToIndexSize(Decomposed.Offset, IndexSize);
+ adjustToIndexSize(Decomposed.Offset, IndexSize);
// Analyze the base pointer next.
V = GEPOp->getOperand(0);
More information about the llvm-commits
mailing list