1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 ; These would crash if we didn't check for a negative shift.
6 ; https://llvm.org/bugs/show_bug.cgi?id=12967
8 define void @pr12967() {
9 ; CHECK-LABEL: @pr12967(
11 ; CHECK-NEXT: br label %loop
13 ; CHECK-NEXT: br label %loop
19 %c = phi i32 [ %shl, %loop ], [ undef, %entry ]
21 %shl = lshr i32 %shr, -2
25 ; https://llvm.org/bugs/show_bug.cgi?id=26760
27 define void @pr26760() {
28 ; CHECK-LABEL: @pr26760(
30 ; CHECK-NEXT: br label %loop
32 ; CHECK-NEXT: br label %loop
38 %c = phi i32 [ %shl, %loop ], [ undef, %entry ]
40 %shl = shl i32 %shr, -2
44 ; Converting the 2 shifts to SHL 6 without the AND is wrong.
45 ; https://llvm.org/bugs/show_bug.cgi?id=8547
47 define i32 @pr8547(i32* %g) {
48 ; CHECK-LABEL: @pr8547(
49 ; CHECK-NEXT: codeRepl:
50 ; CHECK-NEXT: br label %for.cond
52 ; CHECK-NEXT: [[STOREMERGE:%.*]] = phi i32 [ 0, %codeRepl ], [ 5, %for.cond ]
53 ; CHECK-NEXT: store i32 [[STOREMERGE]], i32* %g, align 4
54 ; CHECK-NEXT: [[TMP0:%.*]] = shl nuw nsw i32 [[STOREMERGE]], 6
55 ; CHECK-NEXT: [[CONV2:%.*]] = and i32 [[TMP0]], 64
56 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[CONV2]], 0
57 ; CHECK-NEXT: br i1 [[TOBOOL]], label %for.cond, label %codeRepl2
59 ; CHECK-NEXT: ret i32 [[CONV2]]
65 %storemerge = phi i32 [ 0, %codeRepl ], [ 5, %for.cond ]
66 store i32 %storemerge, i32* %g, align 4
67 %shl = shl i32 %storemerge, 30
68 %conv2 = lshr i32 %shl, 24
69 %tobool = icmp eq i32 %conv2, 0
70 br i1 %tobool, label %for.cond, label %codeRepl2