1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2 ; RUN: opt -passes=ipsccp -S %s | FileCheck %s
4 define i16 @range_from_and_nuw(i32 %a) {
5 ; CHECK-LABEL: define i16 @range_from_and_nuw(
6 ; CHECK-SAME: i32 [[A:%.*]]) {
8 ; CHECK-NEXT: [[AND1:%.*]] = and i32 [[A]], 65535
9 ; CHECK-NEXT: [[TRUNC1:%.*]] = trunc nuw i32 [[AND1]] to i16
10 ; CHECK-NEXT: ret i16 [[TRUNC1]]
13 %and1 = and i32 %a, 65535
14 %trunc1 = trunc i32 %and1 to i16
18 define i8 @range_from_or_nsw(i16 %a) {
19 ; CHECK-LABEL: define range(i8 -128, 0) i8 @range_from_or_nsw(
20 ; CHECK-SAME: i16 [[A:%.*]]) {
22 ; CHECK-NEXT: [[AND1:%.*]] = or i16 [[A]], -128
23 ; CHECK-NEXT: [[TRUNC1:%.*]] = trunc nsw i16 [[AND1]] to i8
24 ; CHECK-NEXT: ret i8 [[TRUNC1]]
27 %and1 = or i16 %a, 65408
28 %trunc1 = trunc i16 %and1 to i8
32 define i16 @range_from_and_nuw_nsw(i32 %a) {
33 ; CHECK-LABEL: define range(i16 0, -32768) i16 @range_from_and_nuw_nsw(
34 ; CHECK-SAME: i32 [[A:%.*]]) {
36 ; CHECK-NEXT: [[AND1:%.*]] = and i32 [[A]], 32767
37 ; CHECK-NEXT: [[TRUNC1:%.*]] = trunc nuw nsw i32 [[AND1]] to i16
38 ; CHECK-NEXT: ret i16 [[TRUNC1]]
41 %and1 = and i32 %a, 32767
42 %trunc1 = trunc i32 %and1 to i16
46 define <4 x i16> @range_from_and_nuw_vec(<4 x i32> %a) {
47 ; CHECK-LABEL: define <4 x i16> @range_from_and_nuw_vec(
48 ; CHECK-SAME: <4 x i32> [[A:%.*]]) {
50 ; CHECK-NEXT: [[AND1:%.*]] = and <4 x i32> [[A]], <i32 65535, i32 65535, i32 65535, i32 65535>
51 ; CHECK-NEXT: [[TRUNC1:%.*]] = trunc nuw <4 x i32> [[AND1]] to <4 x i16>
52 ; CHECK-NEXT: ret <4 x i16> [[TRUNC1]]
55 %and1 = and <4 x i32> %a, <i32 65535, i32 65535, i32 65535, i32 65535>
56 %trunc1 = trunc <4 x i32> %and1 to <4 x i16>
60 define i4 @range_from_sge_sle(i8 %a) {
61 ; CHECK-LABEL: define i4 @range_from_sge_sle(
62 ; CHECK-SAME: i8 [[A:%.*]]) {
64 ; CHECK-NEXT: [[SGT:%.*]] = icmp sge i8 [[A]], 0
65 ; CHECK-NEXT: [[SLT:%.*]] = icmp sle i8 [[A]], 15
66 ; CHECK-NEXT: [[AND:%.*]] = and i1 [[SGT]], [[SLT]]
67 ; CHECK-NEXT: br i1 [[AND]], label [[THEN:%.*]], label [[ELSE:%.*]]
69 ; CHECK-NEXT: [[AND1:%.*]] = and i8 [[A]], 7
70 ; CHECK-NEXT: [[TRUNC1:%.*]] = trunc nuw i8 [[A]] to i4
71 ; CHECK-NEXT: [[TRUNC2:%.*]] = trunc nuw nsw i8 [[AND1]] to i4
72 ; CHECK-NEXT: [[XOR1:%.*]] = xor i4 [[TRUNC1]], [[TRUNC2]]
73 ; CHECK-NEXT: ret i4 [[XOR1]]
75 ; CHECK-NEXT: [[TRUNC3:%.*]] = trunc i8 [[A]] to i4
76 ; CHECK-NEXT: ret i4 [[TRUNC3]]
79 %sgt = icmp sge i8 %a, 0
80 %slt = icmp sle i8 %a, 15
81 %and = and i1 %sgt, %slt
82 br i1 %and, label %then, label %else
87 %trunc1 = trunc i8 %a to i4
88 %trunc2 = trunc i8 %and1 to i4
89 %xor1 = xor i4 %trunc1, %trunc2
93 %trunc3 = trunc i8 %a to i4
97 define i16 @range_from_sext(i16 %a) {
98 ; CHECK-LABEL: define i16 @range_from_sext(
99 ; CHECK-SAME: i16 [[A:%.*]]) {
101 ; CHECK-NEXT: [[SEXT1:%.*]] = sext i16 [[A]] to i32
102 ; CHECK-NEXT: [[TRUNC1:%.*]] = trunc nsw i32 [[SEXT1]] to i16
103 ; CHECK-NEXT: ret i16 [[TRUNC1]]
106 %sext1 = sext i16 %a to i32
107 %trunc1 = trunc i32 %sext1 to i16
111 define i16 @range_from_zext(i16 %a) {
112 ; CHECK-LABEL: define i16 @range_from_zext(
113 ; CHECK-SAME: i16 [[A:%.*]]) {
115 ; CHECK-NEXT: [[ZEXT1:%.*]] = zext i16 [[A]] to i32
116 ; CHECK-NEXT: [[TRUNC1:%.*]] = trunc nuw i32 [[ZEXT1]] to i16
117 ; CHECK-NEXT: ret i16 [[TRUNC1]]
120 %zext1 = zext i16 %a to i32
121 %trunc1 = trunc i32 %zext1 to i16
125 define i1 @range_from_select_i1_nuw(i1 %c) {
126 ; CHECK-LABEL: define i1 @range_from_select_i1_nuw(
127 ; CHECK-SAME: i1 [[C:%.*]]) {
129 ; CHECK-NEXT: [[SELECT1:%.*]] = select i1 [[C]], i16 0, i16 1
130 ; CHECK-NEXT: [[TRUNC1:%.*]] = trunc nuw i16 [[SELECT1]] to i1
131 ; CHECK-NEXT: ret i1 [[TRUNC1]]
134 %select1 = select i1 %c, i16 0, i16 1
135 %trunc1 = trunc i16 %select1 to i1
139 define i1 @range_from_select_i1_nsw(i1 %c) {
140 ; CHECK-LABEL: define i1 @range_from_select_i1_nsw(
141 ; CHECK-SAME: i1 [[C:%.*]]) {
143 ; CHECK-NEXT: [[SELECT1:%.*]] = select i1 [[C]], i16 0, i16 -1
144 ; CHECK-NEXT: [[TRUNC1:%.*]] = trunc nsw i16 [[SELECT1]] to i1
145 ; CHECK-NEXT: ret i1 [[TRUNC1]]
148 %select1 = select i1 %c, i16 0, i16 -1
149 %trunc1 = trunc i16 %select1 to i1
153 define i1 @range_from_select_i1_fail(i1 %c) {
154 ; CHECK-LABEL: define i1 @range_from_select_i1_fail(
155 ; CHECK-SAME: i1 [[C:%.*]]) {
157 ; CHECK-NEXT: [[SELECT1:%.*]] = select i1 [[C]], i16 1, i16 -1
158 ; CHECK-NEXT: [[TRUNC1:%.*]] = trunc i16 [[SELECT1]] to i1
159 ; CHECK-NEXT: ret i1 [[TRUNC1]]
162 %select1 = select i1 %c, i16 1, i16 -1
163 %trunc1 = trunc i16 %select1 to i1
167 define i8 @range_from_trunc_fail(i32 %a) {
168 ; CHECK-LABEL: define i8 @range_from_trunc_fail(
169 ; CHECK-SAME: i32 [[A:%.*]]) {
171 ; CHECK-NEXT: [[TRUNC1:%.*]] = trunc i32 [[A]] to i16
172 ; CHECK-NEXT: [[TRUNC2:%.*]] = trunc i16 [[TRUNC1]] to i8
173 ; CHECK-NEXT: ret i8 [[TRUNC2]]
176 %trunc1 = trunc i32 %a to i16
177 %trunc2 = trunc i16 %trunc1 to i8