[llvm] 9d2b830 - [BasicAA] Avoid alias query if result cannot be used (NFCI)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 17 15:03:01 PDT 2020


Author: Nikita Popov
Date: 2020-10-18T00:00:15+02:00
New Revision: 9d2b8300b768715bb3e0e151de37136f29b29590

URL: https://github.com/llvm/llvm-project/commit/9d2b8300b768715bb3e0e151de37136f29b29590
DIFF: https://github.com/llvm/llvm-project/commit/9d2b8300b768715bb3e0e151de37136f29b29590.diff

LOG: [BasicAA] Avoid alias query if result cannot be used (NFCI)

Rather then querying first and then checking additional conditions,
check the conditions first. They are much cheaper than the alias
query.

Added: 
    

Modified: 
    llvm/lib/Analysis/BasicAliasAnalysis.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index 13157eee71ef..aac36f3a9637 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -1307,24 +1307,16 @@ AliasResult BasicAAResult::aliasGEP(
         aliasCheck(UnderlyingV1, LocationSize::unknown(), AAMDNodes(),
                    UnderlyingV2, LocationSize::unknown(), AAMDNodes(), AAQI);
 
-    // Check for geps of non-aliasing underlying pointers where the offsets are
-    // identical.
-    if ((BaseAlias == MayAlias) && V1Size == V2Size) {
-      // Do the base pointers alias assuming type and size.
+    // For GEPs with identical sizes and offsets, we can preserve the size
+    // and AAInfo when performing the alias check on the underlying objects.
+    if (BaseAlias == MayAlias && V1Size == V2Size &&
+        GEP1BaseOffset == GEP2BaseOffset &&
+        DecompGEP1.VarIndices == DecompGEP2.VarIndices &&
+        !GEP1MaxLookupReached && !GEP2MaxLookupReached) {
       AliasResult PreciseBaseAlias = aliasCheck(
           UnderlyingV1, V1Size, V1AAInfo, UnderlyingV2, V2Size, V2AAInfo, AAQI);
-      if (PreciseBaseAlias == NoAlias) {
-        // See if the computed offset from the common pointer tells us about the
-        // relation of the resulting pointer.
-        // If the max search depth is reached the result is undefined
-        if (GEP2MaxLookupReached || GEP1MaxLookupReached)
-          return MayAlias;
-
-        // Same offsets.
-        if (GEP1BaseOffset == GEP2BaseOffset &&
-            DecompGEP1.VarIndices == DecompGEP2.VarIndices)
-          return NoAlias;
-      }
+      if (PreciseBaseAlias == NoAlias)
+        return NoAlias;
     }
 
     // If we get a No or May, then return it immediately, no amount of analysis


        


More information about the llvm-commits mailing list