[llvm] a4586bd - [Loads] Extract some checks into a lambda (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 18 06:04:45 PDT 2024


Author: Nikita Popov
Date: 2024-09-18T15:04:36+02:00
New Revision: a4586bd2d4fa7d6c0100893496a9383fd581e2e9

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

LOG: [Loads] Extract some checks into a lambda (NFC)

This makes it easier to add additional checks.

Added: 
    

Modified: 
    llvm/lib/Analysis/Loads.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/Loads.cpp b/llvm/lib/Analysis/Loads.cpp
index a88469ab81a8c8..957ac883490c45 100644
--- a/llvm/lib/Analysis/Loads.cpp
+++ b/llvm/lib/Analysis/Loads.cpp
@@ -93,20 +93,26 @@ static bool isDereferenceableAndAlignedPointer(
                                               Visited, MaxDepth);
   }
 
-  bool CheckForNonNull, CheckForFreed;
-  APInt KnownDerefBytes(Size.getBitWidth(),
-                        V->getPointerDereferenceableBytes(DL, CheckForNonNull,
-                                                          CheckForFreed));
-  if (KnownDerefBytes.getBoolValue() && KnownDerefBytes.uge(Size) &&
-      !CheckForFreed)
-    if (!CheckForNonNull ||
-        isKnownNonZero(V, SimplifyQuery(DL, DT, AC, CtxI))) {
-      // As we recursed through GEPs to get here, we've incrementally checked
-      // that each step advanced by a multiple of the alignment. If our base is
-      // properly aligned, then the original offset accessed must also be.
-      APInt Offset(DL.getTypeStoreSizeInBits(V->getType()), 0);
-      return isAligned(V, Offset, Alignment, DL);
-    }
+  auto IsKnownDeref = [&]() {
+    bool CheckForNonNull, CheckForFreed;
+    APInt KnownDerefBytes(Size.getBitWidth(),
+                          V->getPointerDereferenceableBytes(DL, CheckForNonNull,
+                                                            CheckForFreed));
+    if (!KnownDerefBytes.getBoolValue() || !KnownDerefBytes.uge(Size) ||
+        CheckForFreed)
+      return false;
+    if (CheckForNonNull &&
+        !isKnownNonZero(V, SimplifyQuery(DL, DT, AC, CtxI)))
+      return false;
+    return true;
+  };
+  if (IsKnownDeref()) {
+    // As we recursed through GEPs to get here, we've incrementally checked
+    // that each step advanced by a multiple of the alignment. If our base is
+    // properly aligned, then the original offset accessed must also be.
+    APInt Offset(DL.getTypeStoreSizeInBits(V->getType()), 0);
+    return isAligned(V, Offset, Alignment, DL);
+  }
 
   /// TODO refactor this function to be able to search independently for
   /// Dereferencability and Alignment requirements.


        


More information about the llvm-commits mailing list