[BasicAA] Delay getAllocTypeSize() call (NFC)
authorNikita Popov <npopov@redhat.com>
Mon, 12 Sep 2022 16:29:53 +0000 (18:29 +0200)
committerNikita Popov <npopov@redhat.com>
Tue, 13 Sep 2022 08:24:50 +0000 (10:24 +0200)
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

index 9593381..a5bc835 100644 (file)
@@ -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);