diff options
author | Hans Wennborg <hans@hanshq.net> | 2018-08-17 07:04:47 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2018-08-17 07:04:47 +0000 |
commit | 02e459e41c9db24a82329b92870bb3533cfecedd (patch) | |
tree | 5b2a9e03d191031ce6f4d0cb6abf149222e3a9b9 | |
parent | 2c9adfa4a6145410f512350f39eb4d15c6e87240 (diff) |
Merging r339515:
------------------------------------------------------------------------
r339515 | d0k | 2018-08-12 13:43:03 +0200 (Sun, 12 Aug 2018) | 4 lines
[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.
------------------------------------------------------------------------
git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_70@339985 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Analysis/InstructionSimplify.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp index f991291f565..5e72798d459 100644 --- a/lib/Analysis/InstructionSimplify.cpp +++ b/lib/Analysis/InstructionSimplify.cpp @@ -1338,7 +1338,7 @@ static Value *SimplifyLShrInst(Value *Op0, Value *Op1, bool isExact, 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; } @@ -1878,9 +1878,9 @@ static Value *SimplifyAndInst(Value *Op0, Value *Op1, const SimplifyQuery &Q, 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, |