[llvm] 62b74f7 - [GVN][NFC] Refactor analyzeLoadFromClobberingWrite

via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 31 17:40:12 PDT 2021


Author: qixingxue
Date: 2021-04-01T08:35:35+08:00
New Revision: 62b74f75645f53610c1d3c5387072fc4fff98bb9

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

LOG: [GVN][NFC] Refactor analyzeLoadFromClobberingWrite

This commit adjusts the order of two swappable if statements to
make code cleaner.

Reviewed By: lattner, nikic
Differential Revision: https://reviews.llvm.org/D99648

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/VNCoercion.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/VNCoercion.cpp b/llvm/lib/Transforms/Utils/VNCoercion.cpp
index 61cd8595a73b8..6336af25ef982 100644
--- a/llvm/lib/Transforms/Utils/VNCoercion.cpp
+++ b/llvm/lib/Transforms/Utils/VNCoercion.cpp
@@ -189,14 +189,6 @@ static int analyzeLoadFromClobberingWrite(Type *LoadTy, Value *LoadPtr,
   if (StoreBase != LoadBase)
     return -1;
 
-  // If the load and store are to the exact same address, they should have been
-  // a must alias.  AA must have gotten confused.
-  // FIXME: Study to see if/when this happens.  One case is forwarding a memset
-  // to a load from the base of the memset.
-
-  // If the load and store don't overlap at all, the store doesn't provide
-  // anything to the load.  In this case, they really don't alias at all, AA
-  // must have gotten confused.
   uint64_t LoadSize = DL.getTypeSizeInBits(LoadTy).getFixedSize();
 
   if ((WriteSizeInBits & 7) | (LoadSize & 7))
@@ -204,15 +196,6 @@ static int analyzeLoadFromClobberingWrite(Type *LoadTy, Value *LoadPtr,
   uint64_t StoreSize = WriteSizeInBits / 8; // Convert to bytes.
   LoadSize /= 8;
 
-  bool isAAFailure = false;
-  if (StoreOffset < LoadOffset)
-    isAAFailure = StoreOffset + int64_t(StoreSize) <= LoadOffset;
-  else
-    isAAFailure = LoadOffset + int64_t(LoadSize) <= StoreOffset;
-
-  if (isAAFailure)
-    return -1;
-
   // If the Load isn't completely contained within the stored bits, we don't
   // have all the bits to feed it.  We could do something crazy in the future
   // (issue a smaller load then merge the bits in) but this seems unlikely to be
@@ -221,6 +204,18 @@ static int analyzeLoadFromClobberingWrite(Type *LoadTy, Value *LoadPtr,
       StoreOffset + StoreSize < LoadOffset + LoadSize)
     return -1;
 
+  // If the load and store are to the exact same address, they should have been
+  // a must alias.  AA must have gotten confused.
+  // FIXME: Study to see if/when this happens.  One case is forwarding a memset
+  // to a load from the base of the memset.
+
+  // If the load and store don't overlap at all, the store doesn't provide
+  // anything to the load.  In this case, they really don't alias at all, AA
+  // must have gotten confused.  The if statement above ensure the condition
+  // that StoreOffset <= LoadOffset.
+  if (StoreOffset + int64_t(StoreSize) <= LoadOffset)
+    return -1;
+
   // Okay, we can do this transformation.  Return the number of bytes into the
   // store that the load is.
   return LoadOffset - StoreOffset;


        


More information about the llvm-commits mailing list