diff options
author | Simon Pilgrim <llvm-dev@redking.me.uk> | 2020-11-19 13:49:13 +0000 |
---|---|---|
committer | Simon Pilgrim <llvm-dev@redking.me.uk> | 2020-11-19 13:50:49 +0000 |
commit | fceaff41d6b7048768294dbe436fb3016fd29fc1 (patch) | |
tree | 0d06717f3081353cf4763e8a121d0e58c6ac0d06 /llvm/lib/Analysis/ValueTracking.cpp | |
parent | 006b3bdeddb0234f53a1ab72e427ef74184461f5 (diff) | |
download | llvm-fceaff41d6b7048768294dbe436fb3016fd29fc1.zip llvm-fceaff41d6b7048768294dbe436fb3016fd29fc1.tar.gz llvm-fceaff41d6b7048768294dbe436fb3016fd29fc1.tar.bz2 |
[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.
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index a3c139d..cdd07a6 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(); |