[llvm] 28aa7d3 - [Local] collectBitParts - early-out from binops. NFCI.

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Sat May 15 05:06:37 PDT 2021


Author: Simon Pilgrim
Date: 2021-05-15T13:04:10+01:00
New Revision: 28aa7d378abd97cad8e591dd9e9687cda22b0f37

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

LOG: [Local] collectBitParts - early-out from binops. NFCI.

Minor speedup by not bothering to attempt to collect the second operand's bit parts if we already know its failed in the first operand.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 14f54ed8bf16..74bcd0c14827 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -2903,17 +2903,18 @@ collectBitParts(Value *V, bool MatchBSwaps, bool MatchBitReversals,
 
     // If this is an or instruction, it may be an inner node of the bswap.
     if (match(V, m_Or(m_Value(X), m_Value(Y)))) {
+      // Check we have both sources and they are from the same provider.
       const auto &A =
           collectBitParts(X, MatchBSwaps, MatchBitReversals, BPS, Depth + 1);
+      if (!A || !A->Provider)
+        return Result;
+
       const auto &B =
           collectBitParts(Y, MatchBSwaps, MatchBitReversals, BPS, Depth + 1);
-      if (!A || !B)
+      if (!B || A->Provider != B->Provider)
         return Result;
 
       // Try and merge the two together.
-      if (!A->Provider || A->Provider != B->Provider)
-        return Result;
-
       Result = BitPart(A->Provider, BitWidth);
       for (unsigned BitIdx = 0; BitIdx < BitWidth; ++BitIdx) {
         if (A->Provenance[BitIdx] != BitPart::Unset &&
@@ -3061,13 +3062,15 @@ collectBitParts(Value *V, bool MatchBSwaps, bool MatchBitReversals,
       if (!MatchBitReversals && (ModAmt % 8) != 0)
         return Result;
 
+      // Check we have both sources and they are from the same provider.
       const auto &LHS =
           collectBitParts(X, MatchBSwaps, MatchBitReversals, BPS, Depth + 1);
+      if (!LHS || !LHS->Provider)
+          return Result;
+
       const auto &RHS =
           collectBitParts(Y, MatchBSwaps, MatchBitReversals, BPS, Depth + 1);
-
-      // Check we have both sources and they are from the same provider.
-      if (!LHS || !RHS || !LHS->Provider || LHS->Provider != RHS->Provider)
+      if (!RHS || LHS->Provider != RHS->Provider)
         return Result;
 
       unsigned StartBitRHS = BitWidth - ModAmt;


        


More information about the llvm-commits mailing list