llvm.org GIT mirror llvm / 5740d62
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265960 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 3 years ago
2 changed file(s) with 25 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
8282 // If the 2nd shift is bigger than the 1st, we can fold:
8383 // shr(c1) + shl(c2) -> shl(c3) + and(c4)
8484 // but it isn't profitable unless we know the and'd out bits are already zero.
85 if (SecondShiftAmt > FirstShiftAmt) {
85 // Also check that the 2nd shift is valid (less than the type width) or we'll
86 // crash trying to produce the bit mask for the 'and'.
87 if (SecondShiftAmt > FirstShiftAmt && SecondShiftAmt < TypeWidth) {
8688 unsigned MaskShift = TypeWidth - SecondShiftAmt;
8789 APInt Mask = APInt::getLowBitsSet(TypeWidth, FirstShiftAmt) << MaskShift;
8890 if (IC.MaskedValueIsZero(SecondShift->getOperand(0), Mask, 0, CxtI))
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
11 ; RUN: opt < %s -instcombine -S | FileCheck %s
22
3 ; This would crash if we didn't check for a negative shift.
3 ; These would crash if we didn't check for a negative shift.
4
5 ; https://llvm.org/bugs/show_bug.cgi?id=12967
46
57 define void @pr12967() {
68 ; CHECK-LABEL: @pr12967(
1921 br label %loop
2022 }
2123
24 ; https://llvm.org/bugs/show_bug.cgi?id=26760
25
26 define void @pr26760() {
27 ; CHECK-LABEL: @pr26760(
28 ; CHECK-NEXT: entry:
29 ; CHECK-NEXT: br label %loop
30 ; CHECK: loop:
31 ; CHECK-NEXT: br label %loop
32 ;
33 entry:
34 br label %loop
35
36 loop:
37 %c = phi i32 [ %shl, %loop ], [ undef, %entry ]
38 %shr = lshr i32 %c, 7
39 %shl = shl i32 %shr, -2
40 br label %loop
41 }
42