1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=instcombine < %s | FileCheck %s
5 ; Tests to show cases where computeKnownBits should be able to determine
6 ; the known bits of a phi edge based off a conditional branch feeding the phi.
9 ; %x either eq 7 or is set to 7
10 define i64 @limit_i64_eq_7(i64 %x) {
11 ; CHECK-LABEL: @limit_i64_eq_7(
13 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[X:%.*]], 7
14 ; CHECK-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[BODY:%.*]]
16 ; CHECK-NEXT: br label [[END]]
18 ; CHECK-NEXT: [[RES:%.*]] = phi i64 [ [[X]], [[ENTRY:%.*]] ], [ 7, [[BODY]] ]
19 ; CHECK-NEXT: ret i64 [[RES]]
22 %cmp = icmp eq i64 %x, 7
23 br i1 %cmp, label %end, label %body
27 %res = phi i64 [ %x, %entry ], [ 7, %body ]
31 ; %x either eq 255 or is set to 255
32 define i64 @limit_i64_ne_255(i64 %x) {
33 ; CHECK-LABEL: @limit_i64_ne_255(
35 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i64 [[X:%.*]], 255
36 ; CHECK-NEXT: call void @use(i1 [[CMP]])
37 ; CHECK-NEXT: br i1 [[CMP]], label [[BODY:%.*]], label [[END:%.*]]
39 ; CHECK-NEXT: br label [[END]]
41 ; CHECK-NEXT: [[RES:%.*]] = phi i64 [ [[X]], [[ENTRY:%.*]] ], [ 255, [[BODY]] ]
42 ; CHECK-NEXT: ret i64 [[RES]]
45 %cmp = icmp ne i64 %x, 255
46 call void @use(i1 %cmp)
47 br i1 %cmp, label %body, label %end
51 %res = phi i64 [ %x, %entry ], [ 255, %body ]
56 ; %x either ule 15 or is masked with 15
57 define i64 @limit_i64_ule_15(i64 %x) {
58 ; CHECK-LABEL: @limit_i64_ule_15(
60 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[X:%.*]], 16
61 ; CHECK-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[BODY:%.*]]
63 ; CHECK-NEXT: [[MASK:%.*]] = and i64 [[X]], 15
64 ; CHECK-NEXT: br label [[END]]
66 ; CHECK-NEXT: [[X_MASK:%.*]] = phi i64 [ [[X]], [[ENTRY:%.*]] ], [ [[MASK]], [[BODY]] ]
67 ; CHECK-NEXT: ret i64 [[X_MASK]]
70 %cmp = icmp ule i64 %x, 15
71 br i1 %cmp, label %end, label %body
73 %mask = and i64 %x, 15
76 %x.mask = phi i64 [ %x, %entry ], [ %mask, %body ]
77 %res = and i64 %x.mask, 15
81 ; %x either uge 8 or is masked with 7
82 define i64 @limit_i64_uge_8(i64 %x) {
83 ; CHECK-LABEL: @limit_i64_uge_8(
85 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 [[X:%.*]], 7
86 ; CHECK-NEXT: br i1 [[CMP]], label [[BODY:%.*]], label [[END:%.*]]
88 ; CHECK-NEXT: [[MASK:%.*]] = and i64 [[X]], 7
89 ; CHECK-NEXT: br label [[END]]
91 ; CHECK-NEXT: [[X_MASK:%.*]] = phi i64 [ [[X]], [[ENTRY:%.*]] ], [ [[MASK]], [[BODY]] ]
92 ; CHECK-NEXT: ret i64 [[X_MASK]]
95 %cmp = icmp uge i64 %x, 8
96 br i1 %cmp, label %body, label %end
101 %x.mask = phi i64 [ %x, %entry ], [ %mask, %body ]
102 %res = and i64 %x.mask, 7
106 ; %x either ult 8 or is masked with 7
107 define i64 @limit_i64_ult_8(i64 %x) {
108 ; CHECK-LABEL: @limit_i64_ult_8(
110 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[X:%.*]], 8
111 ; CHECK-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[BODY:%.*]]
113 ; CHECK-NEXT: [[MASK:%.*]] = and i64 [[X]], 7
114 ; CHECK-NEXT: br label [[END]]
116 ; CHECK-NEXT: [[X_MASK:%.*]] = phi i64 [ [[X]], [[ENTRY:%.*]] ], [ [[MASK]], [[BODY]] ]
117 ; CHECK-NEXT: ret i64 [[X_MASK]]
120 %cmp = icmp ult i64 %x, 8
121 br i1 %cmp, label %end, label %body
123 %mask = and i64 %x, 7
126 %x.mask = phi i64 [ %x, %entry ], [ %mask, %body ]
127 %res = and i64 %x.mask, 7
131 ; %x either ugt 7 or is masked with 7
132 define i64 @limit_i64_ugt_7(i64 %x) {
133 ; CHECK-LABEL: @limit_i64_ugt_7(
135 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 [[X:%.*]], 7
136 ; CHECK-NEXT: br i1 [[CMP]], label [[BODY:%.*]], label [[END:%.*]]
138 ; CHECK-NEXT: [[MASK:%.*]] = and i64 [[X]], 7
139 ; CHECK-NEXT: br label [[END]]
141 ; CHECK-NEXT: [[X_MASK:%.*]] = phi i64 [ [[X]], [[ENTRY:%.*]] ], [ [[MASK]], [[BODY]] ]
142 ; CHECK-NEXT: ret i64 [[X_MASK]]
145 %cmp = icmp ugt i64 %x, 7
146 br i1 %cmp, label %body, label %end
148 %mask = and i64 %x, 7
151 %x.mask = phi i64 [ %x, %entry ], [ %mask, %body ]
152 %res = and i64 %x.mask, 7
160 ; %x either ule 15 or is masked with 15
161 define i64 @limit_i64_ule_15_mask3(i64 %x) {
162 ; CHECK-LABEL: @limit_i64_ule_15_mask3(
164 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[X:%.*]], 16
165 ; CHECK-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[BODY:%.*]]
167 ; CHECK-NEXT: [[MASK:%.*]] = and i64 [[X]], 15
168 ; CHECK-NEXT: br label [[END]]
170 ; CHECK-NEXT: [[X_MASK:%.*]] = phi i64 [ [[X]], [[ENTRY:%.*]] ], [ [[MASK]], [[BODY]] ]
171 ; CHECK-NEXT: [[RES:%.*]] = and i64 [[X_MASK]], 3
172 ; CHECK-NEXT: ret i64 [[RES]]
175 %cmp = icmp ule i64 %x, 15
176 br i1 %cmp, label %end, label %body
178 %mask = and i64 %x, 15
181 %x.mask = phi i64 [ %x, %entry ], [ %mask, %body ]
182 %res = and i64 %x.mask, 3
186 ; %x either ult 8 or is masked with 7
187 define i64 @limit_i64_ult_8_mask1(i64 %x) {
188 ; CHECK-LABEL: @limit_i64_ult_8_mask1(
190 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[X:%.*]], 8
191 ; CHECK-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[BODY:%.*]]
193 ; CHECK-NEXT: [[MASK:%.*]] = and i64 [[X]], 7
194 ; CHECK-NEXT: br label [[END]]
196 ; CHECK-NEXT: [[X_MASK:%.*]] = phi i64 [ [[X]], [[ENTRY:%.*]] ], [ [[MASK]], [[BODY]] ]
197 ; CHECK-NEXT: [[RES:%.*]] = and i64 [[X_MASK]], 1
198 ; CHECK-NEXT: ret i64 [[RES]]
201 %cmp = icmp ult i64 %x, 8
202 br i1 %cmp, label %end, label %body
204 %mask = and i64 %x, 7
207 %x.mask = phi i64 [ %x, %entry ], [ %mask, %body ]
208 %res = and i64 %x.mask, 1