diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2012-08-28 13:59:23 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2012-08-28 13:59:23 +0000 |
commit | 37dca6331d6bfadfb80b3c68a1cabd6bdf1a13be (patch) | |
tree | 74a910be83bba420e45c12b54c4d01aef1ede0dd /lib/Transforms | |
parent | aac7c650a6cac09d42c5fda8d3761bc9c871ff03 (diff) |
InstCombine: Defensively avoid undefined shifts by limiting the amount to the bit width.
No test case, undefined shifts get folded early, but can occur when other
transforms generate a constant. Thanks to Duncan for bringing this up.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@162755 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index 65a64b8321..2119115ca7 100644 --- a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -467,7 +467,7 @@ Instruction *InstCombiner::visitUDiv(BinaryOperator &I) { Value *X; ConstantInt *C1; if (match(Op0, m_LShr(m_Value(X), m_ConstantInt(C1)))) { - APInt NC = C2->getValue().shl(C1->getZExtValue()); + APInt NC = C2->getValue().shl(C1->getLimitedValue(C1->getBitWidth()-1)); return BinaryOperator::CreateUDiv(X, Builder->getInt(NC)); } } @@ -548,7 +548,7 @@ Instruction *InstCombiner::visitSDiv(BinaryOperator &I) { Value *X; ConstantInt *C1; if (match(Op0, m_AShr(m_Value(X), m_ConstantInt(C1)))) { - APInt NC = C2->getValue().shl(C1->getZExtValue()); + APInt NC = C2->getValue().shl(C1->getLimitedValue(C1->getBitWidth()-1)); return BinaryOperator::CreateSDiv(X, Builder->getInt(NC)); } } |