[llvm] fceaff4 - [ValueTracking] computeKnownBitsFromShiftOperator - move shift amount analysis to top of the function. NFCI.

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 19 05:56:19 PST 2020


Author: Simon Pilgrim
Date: 2020-11-19T13:50:49Z
New Revision: fceaff41d6b7048768294dbe436fb3016fd29fc1

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

LOG: [ValueTracking] computeKnownBitsFromShiftOperator - move shift amount analysis to top of the function. NFCI.

These are all lightweight to compute and helps avoid issues with Known being used to hold both the shift amount and then the shifted result.

Minor cleanup for D90479.

Added: 
    

Modified: 
    llvm/lib/Analysis/ValueTracking.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index a3c139dbbfa4..cdd07a63cf23 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -992,7 +992,15 @@ static void computeKnownBitsFromShiftOperator(
   computeKnownBits(I->getOperand(0), DemandedElts, Known2, Depth + 1, Q);
   computeKnownBits(I->getOperand(1), DemandedElts, Known, Depth + 1, Q);
 
-  if (Known.isConstant()) {
+  // Note: We cannot use Known.Zero.getLimitedValue() here, because if
+  // BitWidth > 64 and any upper bits are known, we'll end up returning the
+  // limit value (which implies all bits are known).
+  uint64_t ShiftAmtKZ = Known.Zero.zextOrTrunc(64).getZExtValue();
+  uint64_t ShiftAmtKO = Known.One.zextOrTrunc(64).getZExtValue();
+  bool ShiftAmtIsConstant = Known.isConstant();
+  bool MaxShiftAmtIsOutOfRange = Known.getMaxValue().uge(BitWidth);
+
+  if (ShiftAmtIsConstant) {
     Known = KF(Known2, Known);
 
     // If the known bits conflict, this must be an overflowing left shift, so
@@ -1008,17 +1016,11 @@ static void computeKnownBitsFromShiftOperator(
   // LHS, the value could be poison, but bail out because the check below is
   // expensive.
   // TODO: Should we just carry on?
-  if (Known.getMaxValue().uge(BitWidth)) {
+  if (MaxShiftAmtIsOutOfRange) {
     Known.resetAll();
     return;
   }
 
-  // Note: We cannot use Known.Zero.getLimitedValue() here, because if
-  // BitWidth > 64 and any upper bits are known, we'll end up returning the
-  // limit value (which implies all bits are known).
-  uint64_t ShiftAmtKZ = Known.Zero.zextOrTrunc(64).getZExtValue();
-  uint64_t ShiftAmtKO = Known.One.zextOrTrunc(64).getZExtValue();
-
   // It would be more-clearly correct to use the two temporaries for this
   // calculation. Reusing the APInts here to prevent unnecessary allocations.
   Known.resetAll();


        


More information about the llvm-commits mailing list