1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 define i64 @test_lshr() {
5 ; CHECK-LABEL: @test_lshr(
7 ; CHECK-NEXT: br label [[LOOP:%.*]]
9 ; CHECK-NEXT: br i1 undef, label [[EXIT:%.*]], label [[LOOP]]
11 ; CHECK-NEXT: ret i64 1023
16 %iv.lshr = phi i64 [1023, %entry], [%iv.lshr.next, %loop]
17 %iv.lshr.next = lshr i64 %iv.lshr, 1
18 br i1 undef, label %exit, label %loop
20 %res = or i64 %iv.lshr, 1023
24 define i64 @test_ashr_zeros() {
25 ; CHECK-LABEL: @test_ashr_zeros(
27 ; CHECK-NEXT: br label [[LOOP:%.*]]
29 ; CHECK-NEXT: br i1 undef, label [[EXIT:%.*]], label [[LOOP]]
31 ; CHECK-NEXT: ret i64 1023
36 %iv.ashr = phi i64 [1023, %entry], [%iv.ashr.next, %loop]
37 %iv.ashr.next = ashr i64 %iv.ashr, 1
38 br i1 undef, label %exit, label %loop
40 %res = or i64 %iv.ashr, 1023
44 define i64 @test_ashr_ones() {
45 ; CHECK-LABEL: @test_ashr_ones(
47 ; CHECK-NEXT: br label [[LOOP:%.*]]
49 ; CHECK-NEXT: br i1 undef, label [[EXIT:%.*]], label [[LOOP]]
51 ; CHECK-NEXT: ret i64 -1
56 %iv.ashr = phi i64 [-1023, %entry], [%iv.ashr.next, %loop]
57 %iv.ashr.next = ashr i64 %iv.ashr, 1
58 br i1 undef, label %exit, label %loop
60 %res = or i64 %iv.ashr, 1023
64 ; Same as previous, but swapped operands to phi
65 define i64 @test_ashr_ones2() {
66 ; CHECK-LABEL: @test_ashr_ones2(
68 ; CHECK-NEXT: br label [[LOOP:%.*]]
70 ; CHECK-NEXT: br i1 undef, label [[EXIT:%.*]], label [[LOOP]]
72 ; CHECK-NEXT: ret i64 -1
77 %iv.ashr = phi i64 [%iv.ashr.next, %loop], [-1023, %entry]
78 %iv.ashr.next = ashr i64 %iv.ashr, 1
79 br i1 undef, label %exit, label %loop
81 %res = or i64 %iv.ashr, 1023
86 ; negative case for when start is unknown
87 define i64 @test_ashr_unknown(i64 %start) {
88 ; CHECK-LABEL: @test_ashr_unknown(
90 ; CHECK-NEXT: br label [[LOOP:%.*]]
92 ; CHECK-NEXT: [[IV_ASHR:%.*]] = phi i64 [ [[START:%.*]], [[ENTRY:%.*]] ], [ [[IV_ASHR_NEXT:%.*]], [[LOOP]] ]
93 ; CHECK-NEXT: [[IV_ASHR_NEXT]] = ashr i64 [[IV_ASHR]], 1
94 ; CHECK-NEXT: br i1 undef, label [[EXIT:%.*]], label [[LOOP]]
96 ; CHECK-NEXT: [[RES:%.*]] = or i64 [[IV_ASHR]], 1023
97 ; CHECK-NEXT: ret i64 [[RES]]
102 %iv.ashr = phi i64 [%start, %entry], [%iv.ashr.next, %loop]
103 %iv.ashr.next = ashr i64 %iv.ashr, 1
104 br i1 undef, label %exit, label %loop
106 %res = or i64 %iv.ashr, 1023
110 ; Negative case where we don't have a (shift) recurrence because the operands
111 ; of the ashr are swapped. (This does end up being a divide recurrence.)
112 define i64 @test_ashr_wrong_op(i64 %start) {
113 ; CHECK-LABEL: @test_ashr_wrong_op(
115 ; CHECK-NEXT: br label [[LOOP:%.*]]
117 ; CHECK-NEXT: [[IV_ASHR:%.*]] = phi i64 [ [[START:%.*]], [[ENTRY:%.*]] ], [ [[IV_ASHR_NEXT:%.*]], [[LOOP]] ]
118 ; CHECK-NEXT: [[IV_ASHR_NEXT]] = lshr i64 1, [[IV_ASHR]]
119 ; CHECK-NEXT: br i1 undef, label [[EXIT:%.*]], label [[LOOP]]
121 ; CHECK-NEXT: [[RES:%.*]] = or i64 [[IV_ASHR]], 1023
122 ; CHECK-NEXT: ret i64 [[RES]]
127 %iv.ashr = phi i64 [%start, %entry], [%iv.ashr.next, %loop]
128 %iv.ashr.next = ashr i64 1, %iv.ashr
129 br i1 undef, label %exit, label %loop
131 %res = or i64 %iv.ashr, 1023
136 define i64 @test_shl() {
137 ; CHECK-LABEL: @test_shl(
139 ; CHECK-NEXT: br label [[LOOP:%.*]]
141 ; CHECK-NEXT: br i1 undef, label [[EXIT:%.*]], label [[LOOP]]
143 ; CHECK-NEXT: ret i64 0
148 %iv.shl = phi i64 [8, %entry], [%iv.shl.next, %loop]
149 %iv.shl.next = shl i64 %iv.shl, 1
150 br i1 undef, label %exit, label %loop
152 %res = and i64 %iv.shl, 7