trunc-shift-trunc.ll
5.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instcombine -S | FileCheck %s
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"
; Perform the shift first and merge the truncs as long as all zero/sign
; bits created by the shift are removed by the trunc.
declare void @use(i32)
define i8 @trunc_lshr_trunc(i64 %a) {
; CHECK-LABEL: @trunc_lshr_trunc(
; CHECK-NEXT: [[C1:%.*]] = lshr i64 [[A:%.*]], 8
; CHECK-NEXT: [[D:%.*]] = trunc i64 [[C1]] to i8
; CHECK-NEXT: ret i8 [[D]]
;
%b = trunc i64 %a to i32
%c = lshr i32 %b, 8
%d = trunc i32 %c to i8
ret i8 %d
}
define <2 x i8> @trunc_lshr_trunc_uniform(<2 x i64> %a) {
; CHECK-LABEL: @trunc_lshr_trunc_uniform(
; CHECK-NEXT: [[C1:%.*]] = lshr <2 x i64> [[A:%.*]], <i64 8, i64 8>
; CHECK-NEXT: [[D:%.*]] = trunc <2 x i64> [[C1]] to <2 x i8>
; CHECK-NEXT: ret <2 x i8> [[D]]
;
%b = trunc <2 x i64> %a to <2 x i32>
%c = lshr <2 x i32> %b, <i32 8, i32 8>
%d = trunc <2 x i32> %c to <2 x i8>
ret <2 x i8> %d
}
define <2 x i8> @trunc_lshr_trunc_nonuniform(<2 x i64> %a) {
; CHECK-LABEL: @trunc_lshr_trunc_nonuniform(
; CHECK-NEXT: [[C1:%.*]] = lshr <2 x i64> [[A:%.*]], <i64 8, i64 2>
; CHECK-NEXT: [[D:%.*]] = trunc <2 x i64> [[C1]] to <2 x i8>
; CHECK-NEXT: ret <2 x i8> [[D]]
;
%b = trunc <2 x i64> %a to <2 x i32>
%c = lshr <2 x i32> %b, <i32 8, i32 2>
%d = trunc <2 x i32> %c to <2 x i8>
ret <2 x i8> %d
}
define <2 x i8> @trunc_lshr_trunc_uniform_undef(<2 x i64> %a) {
; CHECK-LABEL: @trunc_lshr_trunc_uniform_undef(
; CHECK-NEXT: [[C1:%.*]] = lshr <2 x i64> [[A:%.*]], <i64 24, i64 0>
; CHECK-NEXT: [[D:%.*]] = trunc <2 x i64> [[C1]] to <2 x i8>
; CHECK-NEXT: ret <2 x i8> [[D]]
;
%b = trunc <2 x i64> %a to <2 x i32>
%c = lshr <2 x i32> %b, <i32 24, i32 undef>
%d = trunc <2 x i32> %c to <2 x i8>
ret <2 x i8> %d
}
define i8 @trunc_lshr_trunc_outofrange(i64 %a) {
; CHECK-LABEL: @trunc_lshr_trunc_outofrange(
; CHECK-NEXT: [[B:%.*]] = trunc i64 [[A:%.*]] to i32
; CHECK-NEXT: [[C:%.*]] = lshr i32 [[B]], 25
; CHECK-NEXT: [[D:%.*]] = trunc i32 [[C]] to i8
; CHECK-NEXT: ret i8 [[D]]
;
%b = trunc i64 %a to i32
%c = lshr i32 %b, 25
%d = trunc i32 %c to i8
ret i8 %d
}
define <2 x i8> @trunc_lshr_trunc_nonuniform_outofrange(<2 x i64> %a) {
; CHECK-LABEL: @trunc_lshr_trunc_nonuniform_outofrange(
; CHECK-NEXT: [[B:%.*]] = trunc <2 x i64> [[A:%.*]] to <2 x i32>
; CHECK-NEXT: [[C:%.*]] = lshr <2 x i32> [[B]], <i32 8, i32 25>
; CHECK-NEXT: [[D:%.*]] = trunc <2 x i32> [[C]] to <2 x i8>
; CHECK-NEXT: ret <2 x i8> [[D]]
;
%b = trunc <2 x i64> %a to <2 x i32>
%c = lshr <2 x i32> %b, <i32 8, i32 25>
%d = trunc <2 x i32> %c to <2 x i8>
ret <2 x i8> %d
}
define i8 @trunc_ashr_trunc(i64 %a) {
; CHECK-LABEL: @trunc_ashr_trunc(
; CHECK-NEXT: [[TMP1:%.*]] = lshr i64 [[A:%.*]], 8
; CHECK-NEXT: [[D:%.*]] = trunc i64 [[TMP1]] to i8
; CHECK-NEXT: ret i8 [[D]]
;
%b = trunc i64 %a to i32
%c = ashr i32 %b, 8
%d = trunc i32 %c to i8
ret i8 %d
}
define i8 @trunc_ashr_trunc_exact(i64 %a) {
; CHECK-LABEL: @trunc_ashr_trunc_exact(
; CHECK-NEXT: [[TMP1:%.*]] = lshr exact i64 [[A:%.*]], 8
; CHECK-NEXT: [[D:%.*]] = trunc i64 [[TMP1]] to i8
; CHECK-NEXT: ret i8 [[D]]
;
%b = trunc i64 %a to i32
%c = ashr exact i32 %b, 8
%d = trunc i32 %c to i8
ret i8 %d
}
define <2 x i8> @trunc_ashr_trunc_uniform(<2 x i64> %a) {
; CHECK-LABEL: @trunc_ashr_trunc_uniform(
; CHECK-NEXT: [[TMP1:%.*]] = lshr <2 x i64> [[A:%.*]], <i64 8, i64 8>
; CHECK-NEXT: [[D:%.*]] = trunc <2 x i64> [[TMP1]] to <2 x i8>
; CHECK-NEXT: ret <2 x i8> [[D]]
;
%b = trunc <2 x i64> %a to <2 x i32>
%c = ashr <2 x i32> %b, <i32 8, i32 8>
%d = trunc <2 x i32> %c to <2 x i8>
ret <2 x i8> %d
}
define <2 x i8> @trunc_ashr_trunc_nonuniform(<2 x i64> %a) {
; CHECK-LABEL: @trunc_ashr_trunc_nonuniform(
; CHECK-NEXT: [[C1:%.*]] = ashr <2 x i64> [[A:%.*]], <i64 0, i64 23>
; CHECK-NEXT: [[D:%.*]] = trunc <2 x i64> [[C1]] to <2 x i8>
; CHECK-NEXT: ret <2 x i8> [[D]]
;
%b = trunc <2 x i64> %a to <2 x i32>
%c = ashr <2 x i32> %b, <i32 0, i32 23>
%d = trunc <2 x i32> %c to <2 x i8>
ret <2 x i8> %d
}
define <2 x i8> @trunc_ashr_trunc_uniform_undef(<2 x i64> %a) {
; CHECK-LABEL: @trunc_ashr_trunc_uniform_undef(
; CHECK-NEXT: [[C1:%.*]] = ashr <2 x i64> [[A:%.*]], <i64 8, i64 0>
; CHECK-NEXT: [[D:%.*]] = trunc <2 x i64> [[C1]] to <2 x i8>
; CHECK-NEXT: ret <2 x i8> [[D]]
;
%b = trunc <2 x i64> %a to <2 x i32>
%c = ashr <2 x i32> %b, <i32 8, i32 undef>
%d = trunc <2 x i32> %c to <2 x i8>
ret <2 x i8> %d
}
define i8 @trunc_ashr_trunc_outofrange(i64 %a) {
; CHECK-LABEL: @trunc_ashr_trunc_outofrange(
; CHECK-NEXT: [[B:%.*]] = trunc i64 [[A:%.*]] to i32
; CHECK-NEXT: [[C:%.*]] = ashr i32 [[B]], 25
; CHECK-NEXT: [[D:%.*]] = trunc i32 [[C]] to i8
; CHECK-NEXT: ret i8 [[D]]
;
%b = trunc i64 %a to i32
%c = ashr i32 %b, 25
%d = trunc i32 %c to i8
ret i8 %d
}
define <2 x i8> @trunc_ashr_trunc_nonuniform_outofrange(<2 x i64> %a) {
; CHECK-LABEL: @trunc_ashr_trunc_nonuniform_outofrange(
; CHECK-NEXT: [[B:%.*]] = trunc <2 x i64> [[A:%.*]] to <2 x i32>
; CHECK-NEXT: [[C:%.*]] = ashr <2 x i32> [[B]], <i32 8, i32 25>
; CHECK-NEXT: [[D:%.*]] = trunc <2 x i32> [[C]] to <2 x i8>
; CHECK-NEXT: ret <2 x i8> [[D]]
;
%b = trunc <2 x i64> %a to <2 x i32>
%c = ashr <2 x i32> %b, <i32 8, i32 25>
%d = trunc <2 x i32> %c to <2 x i8>
ret <2 x i8> %d
}
define i8 @trunc_ashr_trunc_multiuse(i64 %a) {
; CHECK-LABEL: @trunc_ashr_trunc_multiuse(
; CHECK-NEXT: [[B:%.*]] = trunc i64 [[A:%.*]] to i32
; CHECK-NEXT: [[C:%.*]] = ashr i32 [[B]], 9
; CHECK-NEXT: [[D:%.*]] = trunc i32 [[C]] to i8
; CHECK-NEXT: call void @use(i32 [[C]])
; CHECK-NEXT: ret i8 [[D]]
;
%b = trunc i64 %a to i32
%c = ashr i32 %b, 9
%d = trunc i32 %c to i8
call void @use(i32 %c)
ret i8 %d
}