From 3d837ad7041f88c9bf308d9de0b941e2e7eb4a6c Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Wed, 24 Feb 2021 09:06:12 -0500 Subject: [PATCH] Revert "[ValueTracking] computeKnownBitsFromShiftOperator - remove non-zero shift amount handling." This reverts commit d37400168ce2f1f9ccc91847431f5b8c020a7d67. Breaks Analysis/./AnalysisTests/ComputeKnownBitsTest.KnownNonZeroShift --- llvm/lib/Analysis/ValueTracking.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index a979a7d8cbf21..9e5c8b49767ea 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -1018,10 +1018,15 @@ static void computeKnownBitsFromShiftOperator( // If we know the shifter operand is nonzero, we can sometimes infer more // known bits. However this is expensive to compute, so be lazy about it and // only compute it when absolutely necessary. + Optional ShifterOperandIsNonZero; + // Early exit if we can't constrain any well-defined shift amount. if (!(ShiftAmtKZ & (PowerOf2Ceil(BitWidth) - 1)) && !(ShiftAmtKO & (PowerOf2Ceil(BitWidth) - 1))) { - return; + ShifterOperandIsNonZero = + isKnownNonZero(I->getOperand(1), DemandedElts, Depth + 1, Q); + if (!*ShifterOperandIsNonZero) + return; } Known.Zero.setAllBits(); @@ -1033,6 +1038,17 @@ static void computeKnownBitsFromShiftOperator( continue; if ((ShiftAmt | ShiftAmtKO) != ShiftAmt) continue; + // If we know the shifter is nonzero, we may be able to infer more known + // bits. This check is sunk down as far as possible to avoid the expensive + // call to isKnownNonZero if the cheaper checks above fail. + if (ShiftAmt == 0) { + if (!ShifterOperandIsNonZero.hasValue()) + ShifterOperandIsNonZero = + isKnownNonZero(I->getOperand(1), DemandedElts, Depth + 1, Q); + if (*ShifterOperandIsNonZero) + continue; + } + Known = KnownBits::commonBits( Known, KF(Known2, KnownBits::makeConstant(APInt(32, ShiftAmt)))); }