[Local] collectBitParts - for bswap-only matches, limit shift amounts to whole bytes...
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Fri, 14 May 2021 10:42:41 +0000 (11:42 +0100)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Fri, 14 May 2021 10:42:52 +0000 (11:42 +0100)
llvm/lib/Transforms/Utils/Local.cpp

index 1f0646d..1c1d46b 100644 (file)
@@ -2940,6 +2940,10 @@ collectBitParts(Value *V, bool MatchBSwaps, bool MatchBitReversals,
       if (BitShift.uge(BitWidth))
         return Result;
 
+      // For bswap-only, limit shift amounts to whole bytes, for an early exit.
+      if (!MatchBitReversals && (BitShift.getZExtValue() % 8) != 0)
+        return Result;
+
       const auto &Res =
           collectBitParts(X, MatchBSwaps, MatchBitReversals, BPS, Depth + 1);
       if (!Res)
@@ -3055,6 +3059,10 @@ collectBitParts(Value *V, bool MatchBSwaps, bool MatchBitReversals,
       if (cast<IntrinsicInst>(I)->getIntrinsicID() == Intrinsic::fshr)
         ModAmt = BitWidth - ModAmt;
 
+      // For bswap-only, limit shift amounts to whole bytes, for an early exit.
+      if (!MatchBitReversals && (ModAmt % 8) != 0)
+        return Result;
+
       const auto &LHS =
           collectBitParts(X, MatchBSwaps, MatchBitReversals, BPS, Depth + 1);
       const auto &RHS =