diff options
author | Sanjay Patel <spatel@rotateright.com> | 2016-04-11 16:50:32 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2016-04-11 16:50:32 +0000 |
commit | 816ec8882a741f1dca2703dc604b409043e6a05b (patch) | |
tree | 494976f4110a35d2d82b2a2ef5e33881950e9a1b /llvm/lib | |
parent | d6201b83ac6f81ec574331aba4dbb89f36ff4d99 (diff) | |
download | bcm5719-llvm-816ec8882a741f1dca2703dc604b409043e6a05b.tar.gz bcm5719-llvm-816ec8882a741f1dca2703dc604b409043e6a05b.zip |
[InstCombine] don't try to shift an illegal amount (PR26760)
This is the straightforward fix for PR26760:
https://llvm.org/bugs/show_bug.cgi?id=26760
But we still need to make some changes to generalize this helper function
and then send the lshr case into here.
llvm-svn: 265960
Diffstat (limited to 'llvm/lib')
-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)) |