From 31cc0ab321441b8666406a09c2dfa3acd508959e Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 12 Sep 2022 18:29:53 +0200 Subject: [PATCH] [BasicAA] Delay getAllocTypeSize() call (NFC) This call is expensive, so don't perform it for zero indices. Also rename the variable to use Alloc rather than Alloca, this doesn't have anything to do with allocas in particular. --- llvm/lib/Analysis/BasicAliasAnalysis.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp index 9593381..a5bc835 100644 --- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp @@ -605,24 +605,25 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL, continue; } - TypeSize AllocaTypeSize = DL.getTypeAllocSize(GTI.getIndexedType()); // For an array/pointer, add the element offset, explicitly scaled. if (const ConstantInt *CIdx = dyn_cast(Index)) { if (CIdx->isZero()) continue; // Don't attempt to analyze GEPs if the scalable index is not zero. - if (AllocaTypeSize.isScalable()) { + TypeSize AllocTypeSize = DL.getTypeAllocSize(GTI.getIndexedType()); + if (AllocTypeSize.isScalable()) { Decomposed.Base = V; return Decomposed; } - Decomposed.Offset += AllocaTypeSize.getFixedSize() * + Decomposed.Offset += AllocTypeSize.getFixedSize() * CIdx->getValue().sextOrTrunc(MaxIndexSize); continue; } - if (AllocaTypeSize.isScalable()) { + TypeSize AllocTypeSize = DL.getTypeAllocSize(GTI.getIndexedType()); + if (AllocTypeSize.isScalable()) { Decomposed.Base = V; return Decomposed; } @@ -638,7 +639,7 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL, CastedValue(Index, 0, SExtBits, TruncBits), DL, 0, AC, DT); // Scale by the type size. - unsigned TypeSize = AllocaTypeSize.getFixedSize(); + unsigned TypeSize = AllocTypeSize.getFixedSize(); LE = LE.mul(APInt(IndexSize, TypeSize), GEPOp->isInBounds()); Decomposed.Offset += LE.Offset.sext(MaxIndexSize); APInt Scale = LE.Scale.sext(MaxIndexSize); -- 2.7.4