[llvm] r339515 - [InstSimplify] Guard against large shift amounts.
Hans Wennborg via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 17 00:05:28 PDT 2018
Merged to 7.0 in r339985.
On Sun, Aug 12, 2018 at 1:43 PM, Benjamin Kramer via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: d0k
> Date: Sun Aug 12 04:43:03 2018
> New Revision: 339515
>
> URL: http://llvm.org/viewvc/llvm-project?rev=339515&view=rev
> Log:
> [InstSimplify] Guard against large shift amounts.
>
> These are always UB, but can happen for large integer inputs. Testing it
> is very fragile as -simplifycfg will nuke the UB top-down.
>
> Modified:
> llvm/trunk/lib/Analysis/InstructionSimplify.cpp
>
> Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=339515&r1=339514&r2=339515&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
> +++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Sun Aug 12 04:43:03 2018
> @@ -1338,7 +1338,7 @@ static Value *SimplifyLShrInst(Value *Op
> const KnownBits YKnown = computeKnownBits(Y, Q.DL, 0, Q.AC, Q.CxtI, Q.DT);
> const unsigned Width = Op0->getType()->getScalarSizeInBits();
> const unsigned EffWidthY = Width - YKnown.countMinLeadingZeros();
> - if (EffWidthY <= ShRAmt->getZExtValue())
> + if (ShRAmt->uge(EffWidthY))
> return X;
> }
>
> @@ -1880,9 +1880,9 @@ static Value *SimplifyAndInst(Value *Op0
> match(Op0, m_c_Or(m_CombineAnd(m_NUWShl(m_Value(X), m_APInt(ShAmt)),
> m_Value(XShifted)),
> m_Value(Y)))) {
> - const unsigned ShftCnt = ShAmt->getZExtValue();
> - const KnownBits YKnown = computeKnownBits(Y, Q.DL, 0, Q.AC, Q.CxtI, Q.DT);
> const unsigned Width = Op0->getType()->getScalarSizeInBits();
> + const unsigned ShftCnt = ShAmt->getLimitedValue(Width);
> + const KnownBits YKnown = computeKnownBits(Y, Q.DL, 0, Q.AC, Q.CxtI, Q.DT);
> const unsigned EffWidthY = Width - YKnown.countMinLeadingZeros();
> if (EffWidthY <= ShftCnt) {
> const KnownBits XKnown = computeKnownBits(X, Q.DL, 0, Q.AC, Q.CxtI,
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list