1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
3 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
5 ; Perform the shift first and merge the truncs as long as all zero/sign
6 ; bits created by the shift are removed by the trunc.
10 define i8 @trunc_lshr_trunc(i64 %a) {
11 ; CHECK-LABEL: @trunc_lshr_trunc(
12 ; CHECK-NEXT: [[C1:%.*]] = lshr i64 [[A:%.*]], 8
13 ; CHECK-NEXT: [[D:%.*]] = trunc i64 [[C1]] to i8
14 ; CHECK-NEXT: ret i8 [[D]]
16 %b = trunc i64 %a to i32
18 %d = trunc i32 %c to i8
22 define <2 x i8> @trunc_shl_trunc(<2 x i64> %a) {
23 ; CHECK-LABEL: @trunc_shl_trunc(
24 ; CHECK-NEXT: [[B:%.*]] = trunc <2 x i64> [[A:%.*]] to <2 x i32>
25 ; CHECK-NEXT: [[C:%.*]] = shl <2 x i32> [[B]], <i32 9, i32 7>
26 ; CHECK-NEXT: [[D:%.*]] = trunc <2 x i32> [[C]] to <2 x i8>
27 ; CHECK-NEXT: ret <2 x i8> [[D]]
29 %b = trunc <2 x i64> %a to <2 x i32>
30 %c = shl <2 x i32> %b, <i32 9, i32 7>
31 %d = trunc <2 x i32> %c to <2 x i8>
35 define <2 x i8> @trunc_lshr_trunc_uniform(<2 x i64> %a) {
36 ; CHECK-LABEL: @trunc_lshr_trunc_uniform(
37 ; CHECK-NEXT: [[C1:%.*]] = lshr <2 x i64> [[A:%.*]], <i64 8, i64 8>
38 ; CHECK-NEXT: [[D:%.*]] = trunc <2 x i64> [[C1]] to <2 x i8>
39 ; CHECK-NEXT: ret <2 x i8> [[D]]
41 %b = trunc <2 x i64> %a to <2 x i32>
42 %c = lshr <2 x i32> %b, <i32 8, i32 8>
43 %d = trunc <2 x i32> %c to <2 x i8>
47 define <2 x i8> @trunc_lshr_trunc_nonuniform(<2 x i64> %a) {
48 ; CHECK-LABEL: @trunc_lshr_trunc_nonuniform(
49 ; CHECK-NEXT: [[C1:%.*]] = lshr <2 x i64> [[A:%.*]], <i64 8, i64 2>
50 ; CHECK-NEXT: [[D:%.*]] = trunc <2 x i64> [[C1]] to <2 x i8>
51 ; CHECK-NEXT: ret <2 x i8> [[D]]
53 %b = trunc <2 x i64> %a to <2 x i32>
54 %c = lshr <2 x i32> %b, <i32 8, i32 2>
55 %d = trunc <2 x i32> %c to <2 x i8>
59 define <2 x i8> @trunc_lshr_trunc_uniform_undef(<2 x i64> %a) {
60 ; CHECK-LABEL: @trunc_lshr_trunc_uniform_undef(
61 ; CHECK-NEXT: [[C1:%.*]] = lshr <2 x i64> [[A:%.*]], <i64 24, i64 undef>
62 ; CHECK-NEXT: [[D:%.*]] = trunc <2 x i64> [[C1]] to <2 x i8>
63 ; CHECK-NEXT: ret <2 x i8> [[D]]
65 %b = trunc <2 x i64> %a to <2 x i32>
66 %c = lshr <2 x i32> %b, <i32 24, i32 undef>
67 %d = trunc <2 x i32> %c to <2 x i8>
71 define i8 @trunc_lshr_trunc_outofrange(i64 %a) {
72 ; CHECK-LABEL: @trunc_lshr_trunc_outofrange(
73 ; CHECK-NEXT: [[B:%.*]] = trunc i64 [[A:%.*]] to i32
74 ; CHECK-NEXT: [[C:%.*]] = lshr i32 [[B]], 25
75 ; CHECK-NEXT: [[D:%.*]] = trunc i32 [[C]] to i8
76 ; CHECK-NEXT: ret i8 [[D]]
78 %b = trunc i64 %a to i32
80 %d = trunc i32 %c to i8
84 define <2 x i8> @trunc_lshr_trunc_nonuniform_outofrange(<2 x i64> %a) {
85 ; CHECK-LABEL: @trunc_lshr_trunc_nonuniform_outofrange(
86 ; CHECK-NEXT: [[B:%.*]] = trunc <2 x i64> [[A:%.*]] to <2 x i32>
87 ; CHECK-NEXT: [[C:%.*]] = lshr <2 x i32> [[B]], <i32 8, i32 25>
88 ; CHECK-NEXT: [[D:%.*]] = trunc <2 x i32> [[C]] to <2 x i8>
89 ; CHECK-NEXT: ret <2 x i8> [[D]]
91 %b = trunc <2 x i64> %a to <2 x i32>
92 %c = lshr <2 x i32> %b, <i32 8, i32 25>
93 %d = trunc <2 x i32> %c to <2 x i8>
97 define i8 @trunc_ashr_trunc(i64 %a) {
98 ; CHECK-LABEL: @trunc_ashr_trunc(
99 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i64 [[A:%.*]], 8
100 ; CHECK-NEXT: [[D:%.*]] = trunc i64 [[TMP1]] to i8
101 ; CHECK-NEXT: ret i8 [[D]]
103 %b = trunc i64 %a to i32
105 %d = trunc i32 %c to i8
109 define i8 @trunc_ashr_trunc_exact(i64 %a) {
110 ; CHECK-LABEL: @trunc_ashr_trunc_exact(
111 ; CHECK-NEXT: [[TMP1:%.*]] = lshr exact i64 [[A:%.*]], 8
112 ; CHECK-NEXT: [[D:%.*]] = trunc i64 [[TMP1]] to i8
113 ; CHECK-NEXT: ret i8 [[D]]
115 %b = trunc i64 %a to i32
116 %c = ashr exact i32 %b, 8
117 %d = trunc i32 %c to i8
121 define <2 x i8> @trunc_ashr_trunc_uniform(<2 x i64> %a) {
122 ; CHECK-LABEL: @trunc_ashr_trunc_uniform(
123 ; CHECK-NEXT: [[TMP1:%.*]] = lshr <2 x i64> [[A:%.*]], <i64 8, i64 8>
124 ; CHECK-NEXT: [[D:%.*]] = trunc <2 x i64> [[TMP1]] to <2 x i8>
125 ; CHECK-NEXT: ret <2 x i8> [[D]]
127 %b = trunc <2 x i64> %a to <2 x i32>
128 %c = ashr <2 x i32> %b, <i32 8, i32 8>
129 %d = trunc <2 x i32> %c to <2 x i8>
133 define <2 x i8> @trunc_ashr_trunc_nonuniform(<2 x i64> %a) {
134 ; CHECK-LABEL: @trunc_ashr_trunc_nonuniform(
135 ; CHECK-NEXT: [[C1:%.*]] = ashr <2 x i64> [[A:%.*]], <i64 0, i64 23>
136 ; CHECK-NEXT: [[D:%.*]] = trunc <2 x i64> [[C1]] to <2 x i8>
137 ; CHECK-NEXT: ret <2 x i8> [[D]]
139 %b = trunc <2 x i64> %a to <2 x i32>
140 %c = ashr <2 x i32> %b, <i32 0, i32 23>
141 %d = trunc <2 x i32> %c to <2 x i8>
145 define <2 x i8> @trunc_ashr_trunc_uniform_undef(<2 x i64> %a) {
146 ; CHECK-LABEL: @trunc_ashr_trunc_uniform_undef(
147 ; CHECK-NEXT: [[C1:%.*]] = ashr <2 x i64> [[A:%.*]], <i64 8, i64 undef>
148 ; CHECK-NEXT: [[D:%.*]] = trunc <2 x i64> [[C1]] to <2 x i8>
149 ; CHECK-NEXT: ret <2 x i8> [[D]]
151 %b = trunc <2 x i64> %a to <2 x i32>
152 %c = ashr <2 x i32> %b, <i32 8, i32 undef>
153 %d = trunc <2 x i32> %c to <2 x i8>
157 define i8 @trunc_ashr_trunc_outofrange(i64 %a) {
158 ; CHECK-LABEL: @trunc_ashr_trunc_outofrange(
159 ; CHECK-NEXT: [[B:%.*]] = trunc i64 [[A:%.*]] to i32
160 ; CHECK-NEXT: [[C:%.*]] = ashr i32 [[B]], 25
161 ; CHECK-NEXT: [[D:%.*]] = trunc i32 [[C]] to i8
162 ; CHECK-NEXT: ret i8 [[D]]
164 %b = trunc i64 %a to i32
166 %d = trunc i32 %c to i8
170 define <2 x i8> @trunc_ashr_trunc_nonuniform_outofrange(<2 x i64> %a) {
171 ; CHECK-LABEL: @trunc_ashr_trunc_nonuniform_outofrange(
172 ; CHECK-NEXT: [[B:%.*]] = trunc <2 x i64> [[A:%.*]] to <2 x i32>
173 ; CHECK-NEXT: [[C:%.*]] = ashr <2 x i32> [[B]], <i32 8, i32 25>
174 ; CHECK-NEXT: [[D:%.*]] = trunc <2 x i32> [[C]] to <2 x i8>
175 ; CHECK-NEXT: ret <2 x i8> [[D]]
177 %b = trunc <2 x i64> %a to <2 x i32>
178 %c = ashr <2 x i32> %b, <i32 8, i32 25>
179 %d = trunc <2 x i32> %c to <2 x i8>
183 define i8 @trunc_ashr_trunc_multiuse(i64 %a) {
184 ; CHECK-LABEL: @trunc_ashr_trunc_multiuse(
185 ; CHECK-NEXT: [[B:%.*]] = trunc i64 [[A:%.*]] to i32
186 ; CHECK-NEXT: [[C:%.*]] = ashr i32 [[B]], 9
187 ; CHECK-NEXT: [[D:%.*]] = trunc i32 [[C]] to i8
188 ; CHECK-NEXT: call void @use(i32 [[C]])
189 ; CHECK-NEXT: ret i8 [[D]]
191 %b = trunc i64 %a to i32
193 %d = trunc i32 %c to i8
194 call void @use(i32 %c)