From: Nikita Popov Date: Mon, 12 Sep 2022 16:29:53 +0000 (+0200) Subject: [BasicAA] Delay getAllocTypeSize() call (NFC) X-Git-Tag: upstream/17.0.6~33697 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=31cc0ab321441b8666406a09c2dfa3acd508959e;p=platform%2Fupstream%2Fllvm.git [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. --- 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);