diff options
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp index 0115678b409..6d68a557988 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp @@ -83,7 +83,9 @@ static bool canEvaluateShiftedShift(unsigned FirstShiftAmt, // If the 2nd shift is bigger than the 1st, we can fold: // shr(c1) + shl(c2) -> shl(c3) + and(c4) // but it isn't profitable unless we know the and'd out bits are already zero. - if (SecondShiftAmt > FirstShiftAmt) { + // Also check that the 2nd shift is valid (less than the type width) or we'll + // crash trying to produce the bit mask for the 'and'. + if (SecondShiftAmt > FirstShiftAmt && SecondShiftAmt < TypeWidth) { unsigned MaskShift = TypeWidth - SecondShiftAmt; APInt Mask = APInt::getLowBitsSet(TypeWidth, FirstShiftAmt) << MaskShift; if (IC.MaskedValueIsZero(SecondShift->getOperand(0), Mask, 0, CxtI)) |