[llvm] 3df3f3d - [BasicAA] Handle gep with unknown sizes earlier (NFCI)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 28 06:49:00 PDT 2021


Author: Nikita Popov
Date: 2021-03-28T15:48:49+02:00
New Revision: 3df3f3df4539c3df7519caf33ea73d80eba653bd

URL: https://github.com/llvm/llvm-project/commit/3df3f3df4539c3df7519caf33ea73d80eba653bd
DIFF: https://github.com/llvm/llvm-project/commit/3df3f3df4539c3df7519caf33ea73d80eba653bd.diff

LOG: [BasicAA] Handle gep with unknown sizes earlier (NFCI)

If the sizes of both memory locations are unknown, we can only
perform a check on the underlying objects. There's no point in
going through GEP decomposition in this case.

Added: 
    

Modified: 
    llvm/lib/Analysis/BasicAliasAnalysis.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index 9594f7b43f24..4f41b28a3a0d 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -1012,6 +1012,20 @@ AliasResult BasicAAResult::aliasGEP(
     const GEPOperator *GEP1, LocationSize V1Size, const AAMDNodes &V1AAInfo,
     const Value *V2, LocationSize V2Size, const AAMDNodes &V2AAInfo,
     const Value *UnderlyingV1, const Value *UnderlyingV2, AAQueryInfo &AAQI) {
+  if (!V1Size.hasValue() && !V2Size.hasValue()) {
+    // TODO: This limitation exists for compile-time reasons. Relax it if we
+    // can avoid exponential pathological cases.
+    if (!isa<GEPOperator>(V2))
+      return MayAlias;
+
+    // If both accesses have unknown size, we can only check whether the base
+    // objects don't alias.
+    AliasResult BaseAlias = getBestAAResults().alias(
+        MemoryLocation::getBeforeOrAfter(UnderlyingV1),
+        MemoryLocation::getBeforeOrAfter(UnderlyingV2), AAQI);
+    return BaseAlias == NoAlias ? NoAlias : MayAlias;
+  }
+
   DecomposedGEP DecompGEP1 = DecomposeGEPExpression(GEP1, DL, &AC, DT);
   DecomposedGEP DecompGEP2 = DecomposeGEPExpression(V2, DL, &AC, DT);
 
@@ -1043,11 +1057,6 @@ AliasResult BasicAAResult::aliasGEP(
         V1Size.hasValue() && DecompGEP1.Offset.sle(-V1Size.getValue()) &&
         isBaseOfObject(DecompGEP1.Base))
     return NoAlias;
-  } else {
-    // TODO: This limitation exists for compile-time reasons. Relax it if we
-    // can avoid exponential pathological cases.
-    if (!V1Size.hasValue() && !V2Size.hasValue())
-      return MayAlias;
   }
 
   // For GEPs with identical offsets, we can preserve the size and AAInfo


        


More information about the llvm-commits mailing list