Skip to content

Commit a3908d3

Browse files
committed
[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.
1 parent 2749f52 commit a3908d3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

llvm/lib/Analysis/BasicAliasAnalysis.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,13 @@ static LinearExpression GetLinearExpression(
457457
/// an issue, for example, in particular for 32b pointers with negative indices
458458
/// that rely on two's complement wrap-arounds for precise alias information
459459
/// where the maximum index size is 64b.
460-
static APInt adjustToIndexSize(const APInt &Offset, unsigned IndexSize) {
460+
static void adjustToIndexSize(APInt &Offset, unsigned IndexSize) {
461461
assert(IndexSize <= Offset.getBitWidth() && "Invalid IndexSize!");
462462
unsigned ShiftBits = Offset.getBitWidth() - IndexSize;
463-
return (Offset << ShiftBits).ashr(ShiftBits);
463+
if (ShiftBits != 0) {
464+
Offset <<= ShiftBits;
465+
Offset.ashrInPlace(ShiftBits);
466+
}
464467
}
465468

466469
namespace {
@@ -685,7 +688,7 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL,
685688

686689
// Make sure that we have a scale that makes sense for this target's
687690
// index size.
688-
Scale = adjustToIndexSize(Scale, IndexSize);
691+
adjustToIndexSize(Scale, IndexSize);
689692

690693
if (!!Scale) {
691694
VariableGEPIndex Entry = {LE.Val, Scale, CxtI, LE.IsNSW,
@@ -696,7 +699,7 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL,
696699

697700
// Take care of wrap-arounds
698701
if (GepHasConstantOffset)
699-
Decomposed.Offset = adjustToIndexSize(Decomposed.Offset, IndexSize);
702+
adjustToIndexSize(Decomposed.Offset, IndexSize);
700703

701704
// Analyze the base pointer next.
702705
V = GEPOp->getOperand(0);

0 commit comments

Comments
 (0)