1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -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_lshr_trunc_uniform(<2 x i64> %a) {
23 ; CHECK-LABEL: @trunc_lshr_trunc_uniform(
24 ; CHECK-NEXT: [[C1:%.*]] = lshr <2 x i64> [[A:%.*]], <i64 8, i64 8>
25 ; CHECK-NEXT: [[D:%.*]] = trunc <2 x i64> [[C1]] to <2 x i8>
26 ; CHECK-NEXT: ret <2 x i8> [[D]]
28 %b = trunc <2 x i64> %a to <2 x i32>
29 %c = lshr <2 x i32> %b, <i32 8, i32 8>
30 %d = trunc <2 x i32> %c to <2 x i8>
34 define <2 x i8> @trunc_lshr_trunc_nonuniform(<2 x i64> %a) {
35 ; CHECK-LABEL: @trunc_lshr_trunc_nonuniform(
36 ; CHECK-NEXT: [[C1:%.*]] = lshr <2 x i64> [[A:%.*]], <i64 8, i64 2>
37 ; CHECK-NEXT: [[D:%.*]] = trunc <2 x i64> [[C1]] to <2 x i8>
38 ; CHECK-NEXT: ret <2 x i8> [[D]]
40 %b = trunc <2 x i64> %a to <2 x i32>
41 %c = lshr <2 x i32> %b, <i32 8, i32 2>
42 %d = trunc <2 x i32> %c to <2 x i8>
46 define <2 x i8> @trunc_lshr_trunc_uniform_undef(<2 x i64> %a) {
47 ; CHECK-LABEL: @trunc_lshr_trunc_uniform_undef(
48 ; CHECK-NEXT: [[C1:%.*]] = lshr <2 x i64> [[A:%.*]], <i64 24, i64 undef>
49 ; CHECK-NEXT: [[D:%.*]] = trunc <2 x i64> [[C1]] to <2 x i8>
50 ; CHECK-NEXT: ret <2 x i8> [[D]]
52 %b = trunc <2 x i64> %a to <2 x i32>
53 %c = lshr <2 x i32> %b, <i32 24, i32 undef>
54 %d = trunc <2 x i32> %c to <2 x i8>
58 define i8 @trunc_lshr_trunc_outofrange(i64 %a) {
59 ; CHECK-LABEL: @trunc_lshr_trunc_outofrange(
60 ; CHECK-NEXT: [[B:%.*]] = trunc i64 [[A:%.*]] to i32
61 ; CHECK-NEXT: [[C:%.*]] = lshr i32 [[B]], 25
62 ; CHECK-NEXT: [[D:%.*]] = trunc i32 [[C]] to i8
63 ; CHECK-NEXT: ret i8 [[D]]
65 %b = trunc i64 %a to i32
67 %d = trunc i32 %c to i8
71 define <2 x i8> @trunc_lshr_trunc_nonuniform_outofrange(<2 x i64> %a) {
72 ; CHECK-LABEL: @trunc_lshr_trunc_nonuniform_outofrange(
73 ; CHECK-NEXT: [[B:%.*]] = trunc <2 x i64> [[A:%.*]] to <2 x i32>
74 ; CHECK-NEXT: [[C:%.*]] = lshr <2 x i32> [[B]], <i32 8, i32 25>
75 ; CHECK-NEXT: [[D:%.*]] = trunc <2 x i32> [[C]] to <2 x i8>
76 ; CHECK-NEXT: ret <2 x i8> [[D]]
78 %b = trunc <2 x i64> %a to <2 x i32>
79 %c = lshr <2 x i32> %b, <i32 8, i32 25>
80 %d = trunc <2 x i32> %c to <2 x i8>
84 define i8 @trunc_ashr_trunc(i64 %a) {
85 ; CHECK-LABEL: @trunc_ashr_trunc(
86 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i64 [[A:%.*]], 8
87 ; CHECK-NEXT: [[D:%.*]] = trunc i64 [[TMP1]] to i8
88 ; CHECK-NEXT: ret i8 [[D]]
90 %b = trunc i64 %a to i32
92 %d = trunc i32 %c to i8
96 define i8 @trunc_ashr_trunc_exact(i64 %a) {
97 ; CHECK-LABEL: @trunc_ashr_trunc_exact(
98 ; CHECK-NEXT: [[TMP1:%.*]] = lshr exact i64 [[A:%.*]], 8
99 ; CHECK-NEXT: [[D:%.*]] = trunc i64 [[TMP1]] to i8
100 ; CHECK-NEXT: ret i8 [[D]]
102 %b = trunc i64 %a to i32
103 %c = ashr exact i32 %b, 8
104 %d = trunc i32 %c to i8
108 define <2 x i8> @trunc_ashr_trunc_uniform(<2 x i64> %a) {
109 ; CHECK-LABEL: @trunc_ashr_trunc_uniform(
110 ; CHECK-NEXT: [[TMP1:%.*]] = lshr <2 x i64> [[A:%.*]], <i64 8, i64 8>
111 ; CHECK-NEXT: [[D:%.*]] = trunc <2 x i64> [[TMP1]] to <2 x i8>
112 ; CHECK-NEXT: ret <2 x i8> [[D]]
114 %b = trunc <2 x i64> %a to <2 x i32>
115 %c = ashr <2 x i32> %b, <i32 8, i32 8>
116 %d = trunc <2 x i32> %c to <2 x i8>
120 define <2 x i8> @trunc_ashr_trunc_nonuniform(<2 x i64> %a) {
121 ; CHECK-LABEL: @trunc_ashr_trunc_nonuniform(
122 ; CHECK-NEXT: [[C1:%.*]] = ashr <2 x i64> [[A:%.*]], <i64 0, i64 23>
123 ; CHECK-NEXT: [[D:%.*]] = trunc <2 x i64> [[C1]] to <2 x i8>
124 ; CHECK-NEXT: ret <2 x i8> [[D]]
126 %b = trunc <2 x i64> %a to <2 x i32>
127 %c = ashr <2 x i32> %b, <i32 0, i32 23>
128 %d = trunc <2 x i32> %c to <2 x i8>
132 define <2 x i8> @trunc_ashr_trunc_uniform_undef(<2 x i64> %a) {
133 ; CHECK-LABEL: @trunc_ashr_trunc_uniform_undef(
134 ; CHECK-NEXT: [[C1:%.*]] = ashr <2 x i64> [[A:%.*]], <i64 8, i64 undef>
135 ; CHECK-NEXT: [[D:%.*]] = trunc <2 x i64> [[C1]] to <2 x i8>
136 ; CHECK-NEXT: ret <2 x i8> [[D]]
138 %b = trunc <2 x i64> %a to <2 x i32>
139 %c = ashr <2 x i32> %b, <i32 8, i32 undef>
140 %d = trunc <2 x i32> %c to <2 x i8>
144 define i8 @trunc_ashr_trunc_outofrange(i64 %a) {
145 ; CHECK-LABEL: @trunc_ashr_trunc_outofrange(
146 ; CHECK-NEXT: [[B:%.*]] = trunc i64 [[A:%.*]] to i32
147 ; CHECK-NEXT: [[C:%.*]] = ashr i32 [[B]], 25
148 ; CHECK-NEXT: [[D:%.*]] = trunc i32 [[C]] to i8
149 ; CHECK-NEXT: ret i8 [[D]]
151 %b = trunc i64 %a to i32
153 %d = trunc i32 %c to i8
157 define <2 x i8> @trunc_ashr_trunc_nonuniform_outofrange(<2 x i64> %a) {
158 ; CHECK-LABEL: @trunc_ashr_trunc_nonuniform_outofrange(
159 ; CHECK-NEXT: [[B:%.*]] = trunc <2 x i64> [[A:%.*]] to <2 x i32>
160 ; CHECK-NEXT: [[C:%.*]] = ashr <2 x i32> [[B]], <i32 8, i32 25>
161 ; CHECK-NEXT: [[D:%.*]] = trunc <2 x i32> [[C]] to <2 x i8>
162 ; CHECK-NEXT: ret <2 x i8> [[D]]
164 %b = trunc <2 x i64> %a to <2 x i32>
165 %c = ashr <2 x i32> %b, <i32 8, i32 25>
166 %d = trunc <2 x i32> %c to <2 x i8>
170 define i8 @trunc_ashr_trunc_multiuse(i64 %a) {
171 ; CHECK-LABEL: @trunc_ashr_trunc_multiuse(
172 ; CHECK-NEXT: [[B:%.*]] = trunc i64 [[A:%.*]] to i32
173 ; CHECK-NEXT: [[C:%.*]] = ashr i32 [[B]], 9
174 ; CHECK-NEXT: [[D:%.*]] = trunc i32 [[C]] to i8
175 ; CHECK-NEXT: call void @use(i32 [[C]])
176 ; CHECK-NEXT: ret i8 [[D]]
178 %b = trunc i64 %a to i32
180 %d = trunc i32 %c to i8
181 call void @use(i32 %c)