aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/BasicAliasAnalysis.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2023-11-21 15:55:57 +0100
committerNikita Popov <npopov@redhat.com>2023-11-21 16:32:27 +0100
commita3908d33b17cb9655d336039bf6a9bd798930eb4 (patch)
tree85b8d0e28053e51d14c0eb392317a0a8640710e5 /llvm/lib/Analysis/BasicAliasAnalysis.cpp
parent2749f52ec46bf64d6f15d0708d917d1eec9e357b (diff)
downloadllvm-a3908d33b17cb9655d336039bf6a9bd798930eb4.zip
llvm-a3908d33b17cb9655d336039bf6a9bd798930eb4.tar.gz
llvm-a3908d33b17cb9655d336039bf6a9bd798930eb4.tar.bz2
[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.
Diffstat (limited to 'llvm/lib/Analysis/BasicAliasAnalysis.cpp')
-rw-r--r--llvm/lib/Analysis/BasicAliasAnalysis.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index 4d2f81e..70f81f6 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);