[llvm] ea7a3e6 - [X86] simplifyX86varShift - use KnownBits.getMaxValue().ult() to check for out of bounds shift amounts

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 3 08:03:06 PST 2022


Author: Simon Pilgrim
Date: 2022-02-03T16:02:45Z
New Revision: ea7a3e6a6a131ef61dbc2dd5802e7cb6caf56f74

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

LOG: [X86] simplifyX86varShift - use KnownBits.getMaxValue().ult() to check for out of bounds shift amounts

This is easier to grok than MaskedValueIsZero for high bits.

Added: 
    

Modified: 
    llvm/lib/Target/X86/X86InstCombineIntrinsic.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/X86/X86InstCombineIntrinsic.cpp b/llvm/lib/Target/X86/X86InstCombineIntrinsic.cpp
index ff8710634e89c..1b021ada6b668 100644
--- a/llvm/lib/Target/X86/X86InstCombineIntrinsic.cpp
+++ b/llvm/lib/Target/X86/X86InstCombineIntrinsic.cpp
@@ -354,10 +354,9 @@ static Value *simplifyX86varShift(const IntrinsicInst &II,
 
   // If the shift amount is guaranteed to be in-range we can replace it with a
   // generic shift.
-  APInt UpperBits =
-      APInt::getHighBitsSet(BitWidth, BitWidth - Log2_32(BitWidth));
-  if (llvm::MaskedValueIsZero(Amt, UpperBits,
-                              II.getModule()->getDataLayout())) {
+  KnownBits KnownAmt =
+      llvm::computeKnownBits(Amt, II.getModule()->getDataLayout());
+  if (KnownAmt.getMaxValue().ult(BitWidth)) {
     return (LogicalShift ? (ShiftLeft ? Builder.CreateShl(Vec, Amt)
                                       : Builder.CreateLShr(Vec, Amt))
                          : Builder.CreateAShr(Vec, Amt));


        


More information about the llvm-commits mailing list