[llvm] 31cc0ab - [BasicAA] Delay getAllocTypeSize() call (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 13 01:25:02 PDT 2022


Author: Nikita Popov
Date: 2022-09-13T10:24:50+02:00
New Revision: 31cc0ab321441b8666406a09c2dfa3acd508959e

URL: https://github.com/llvm/llvm-project/commit/31cc0ab321441b8666406a09c2dfa3acd508959e
DIFF: https://github.com/llvm/llvm-project/commit/31cc0ab321441b8666406a09c2dfa3acd508959e.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/Analysis/BasicAliasAnalysis.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index 9593381fa1b2a..a5bc8353e1823 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<ConstantInt>(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);


        


More information about the llvm-commits mailing list