1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 declare i8 @llvm.smin.i8(i8, i8)
5 declare i8 @llvm.umin.i8(i8, i8)
6 declare i8 @llvm.smax.i8(i8, i8)
7 declare i8 @llvm.umax.i8(i8, i8)
8 declare <2 x i8> @llvm.smin.v2i8(<2 x i8>, <2 x i8>)
9 declare <2 x i8> @llvm.umin.v2i8(<2 x i8>, <2 x i8>)
10 declare <2 x i8> @llvm.smax.v2i8(<2 x i8>, <2 x i8>)
11 declare <2 x i8> @llvm.umax.v2i8(<2 x i8>, <2 x i8>)
13 declare void @llvm.assume(i1)
14 declare void @barrier()
16 define <2 x i8> @umax_xor_Cpow2(<2 x i8> %x) {
17 ; CHECK-LABEL: @umax_xor_Cpow2(
18 ; CHECK-NEXT: [[R:%.*]] = or <2 x i8> [[X:%.*]], <i8 -128, i8 -128>
19 ; CHECK-NEXT: ret <2 x i8> [[R]]
21 %x_xor = xor <2 x i8> %x, <i8 128, i8 128>
22 %r = call <2 x i8> @llvm.umax.v2i8(<2 x i8> %x, <2 x i8> %x_xor)
26 define i8 @umin_xor_Cpow2(i8 %x) {
27 ; CHECK-LABEL: @umin_xor_Cpow2(
28 ; CHECK-NEXT: [[R:%.*]] = and i8 [[X:%.*]], -65
29 ; CHECK-NEXT: ret i8 [[R]]
31 %x_xor = xor i8 %x, 64
32 %r = call i8 @llvm.umin.i8(i8 %x, i8 %x_xor)
36 define i8 @smax_xor_Cpow2_pos(i8 %x) {
37 ; CHECK-LABEL: @smax_xor_Cpow2_pos(
38 ; CHECK-NEXT: [[R:%.*]] = or i8 [[X:%.*]], 32
39 ; CHECK-NEXT: ret i8 [[R]]
41 %x_xor = xor i8 %x, 32
42 %r = call i8 @llvm.smax.i8(i8 %x, i8 %x_xor)
46 define <2 x i8> @smin_xor_Cpow2_pos(<2 x i8> %x) {
47 ; CHECK-LABEL: @smin_xor_Cpow2_pos(
48 ; CHECK-NEXT: [[R:%.*]] = and <2 x i8> [[X:%.*]], <i8 -17, i8 -17>
49 ; CHECK-NEXT: ret <2 x i8> [[R]]
51 %x_xor = xor <2 x i8> %x, <i8 16, i8 16>
52 %r = call <2 x i8> @llvm.smin.v2i8(<2 x i8> %x, <2 x i8> %x_xor)
56 define <2 x i8> @smax_xor_Cpow2_neg(<2 x i8> %x) {
57 ; CHECK-LABEL: @smax_xor_Cpow2_neg(
58 ; CHECK-NEXT: [[R:%.*]] = and <2 x i8> [[X:%.*]], <i8 127, i8 127>
59 ; CHECK-NEXT: ret <2 x i8> [[R]]
61 %x_xor = xor <2 x i8> %x, <i8 128, i8 128>
62 %r = call <2 x i8> @llvm.smax.v2i8(<2 x i8> %x, <2 x i8> %x_xor)
66 define i8 @smin_xor_Cpow2_neg(i8 %x) {
67 ; CHECK-LABEL: @smin_xor_Cpow2_neg(
68 ; CHECK-NEXT: [[R:%.*]] = or i8 [[X:%.*]], -128
69 ; CHECK-NEXT: ret i8 [[R]]
71 %x_xor = xor i8 %x, 128
72 %r = call i8 @llvm.smin.i8(i8 %x, i8 %x_xor)
76 define i8 @umax_xor_pow2(i8 %x, i8 %y) {
77 ; CHECK-LABEL: @umax_xor_pow2(
78 ; CHECK-NEXT: [[NY:%.*]] = sub i8 0, [[Y:%.*]]
79 ; CHECK-NEXT: [[YP2:%.*]] = and i8 [[NY]], [[Y]]
80 ; CHECK-NEXT: [[R:%.*]] = or i8 [[YP2]], [[X:%.*]]
81 ; CHECK-NEXT: ret i8 [[R]]
85 %x_xor = xor i8 %x, %yp2
86 %r = call i8 @llvm.umax.i8(i8 %x, i8 %x_xor)
90 define <2 x i8> @umin_xor_pow2(<2 x i8> %x, <2 x i8> %y) {
91 ; CHECK-LABEL: @umin_xor_pow2(
92 ; CHECK-NEXT: [[NY:%.*]] = sub <2 x i8> zeroinitializer, [[Y:%.*]]
93 ; CHECK-NEXT: [[YP2:%.*]] = and <2 x i8> [[NY]], [[Y]]
94 ; CHECK-NEXT: [[TMP1:%.*]] = xor <2 x i8> [[YP2]], <i8 -1, i8 -1>
95 ; CHECK-NEXT: [[R:%.*]] = and <2 x i8> [[TMP1]], [[X:%.*]]
96 ; CHECK-NEXT: ret <2 x i8> [[R]]
98 %ny = sub <2 x i8> <i8 0, i8 0>, %y
99 %yp2 = and <2 x i8> %y, %ny
100 %x_xor = xor <2 x i8> %x, %yp2
101 %r = call <2 x i8> @llvm.umin.v2i8(<2 x i8> %x, <2 x i8> %x_xor)
105 define i8 @smax_xor_pow2_unk(i8 %x, i8 %y) {
106 ; CHECK-LABEL: @smax_xor_pow2_unk(
107 ; CHECK-NEXT: [[NY:%.*]] = sub i8 0, [[Y:%.*]]
108 ; CHECK-NEXT: [[YP2:%.*]] = and i8 [[NY]], [[Y]]
109 ; CHECK-NEXT: [[X_XOR:%.*]] = xor i8 [[YP2]], [[X:%.*]]
110 ; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.smax.i8(i8 [[X]], i8 [[X_XOR]])
111 ; CHECK-NEXT: ret i8 [[R]]
114 %yp2 = and i8 %y, %ny
115 %x_xor = xor i8 %x, %yp2
116 %r = call i8 @llvm.smax.i8(i8 %x, i8 %x_xor)
120 define <2 x i8> @smin_xor_pow2_unk(<2 x i8> %x, <2 x i8> %y) {
121 ; CHECK-LABEL: @smin_xor_pow2_unk(
122 ; CHECK-NEXT: [[NY:%.*]] = sub <2 x i8> zeroinitializer, [[Y:%.*]]
123 ; CHECK-NEXT: [[YP2:%.*]] = and <2 x i8> [[NY]], [[Y]]
124 ; CHECK-NEXT: [[X_XOR:%.*]] = xor <2 x i8> [[YP2]], [[X:%.*]]
125 ; CHECK-NEXT: [[R:%.*]] = call <2 x i8> @llvm.smin.v2i8(<2 x i8> [[X]], <2 x i8> [[X_XOR]])
126 ; CHECK-NEXT: ret <2 x i8> [[R]]
128 %ny = sub <2 x i8> <i8 0, i8 0>, %y
129 %yp2 = and <2 x i8> %y, %ny
130 %x_xor = xor <2 x i8> %x, %yp2
131 %r = call <2 x i8> @llvm.smin.v2i8(<2 x i8> %x, <2 x i8> %x_xor)
135 define i8 @smax_xor_pow2_neg(i8 %x, i8 %y) {
136 ; CHECK-LABEL: @smax_xor_pow2_neg(
137 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[Y:%.*]], -128
138 ; CHECK-NEXT: br i1 [[CMP]], label [[NEG:%.*]], label [[POS:%.*]]
140 ; CHECK-NEXT: [[R:%.*]] = and i8 [[X:%.*]], 127
141 ; CHECK-NEXT: ret i8 [[R]]
143 ; CHECK-NEXT: call void @barrier()
144 ; CHECK-NEXT: ret i8 0
147 %yp2 = and i8 %y, %ny
148 %cmp = icmp slt i8 %yp2, 0
149 br i1 %cmp, label %neg, label %pos
151 %x_xor = xor i8 %x, %yp2
152 %r = call i8 @llvm.smax.i8(i8 %x, i8 %x_xor)
159 define i8 @smin_xor_pow2_pos(i8 %x, i8 %y) {
160 ; CHECK-LABEL: @smin_xor_pow2_pos(
161 ; CHECK-NEXT: [[NY:%.*]] = sub i8 0, [[Y:%.*]]
162 ; CHECK-NEXT: [[YP2:%.*]] = and i8 [[NY]], [[Y]]
163 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[YP2]], 0
164 ; CHECK-NEXT: br i1 [[CMP]], label [[NEG:%.*]], label [[POS:%.*]]
166 ; CHECK-NEXT: [[TMP1:%.*]] = xor i8 [[YP2]], -1
167 ; CHECK-NEXT: [[R:%.*]] = and i8 [[TMP1]], [[X:%.*]]
168 ; CHECK-NEXT: ret i8 [[R]]
170 ; CHECK-NEXT: call void @barrier()
171 ; CHECK-NEXT: ret i8 0
174 %yp2 = and i8 %y, %ny
175 %cmp = icmp sgt i8 %yp2, 0
176 br i1 %cmp, label %neg, label %pos
178 %x_xor = xor i8 %x, %yp2
179 %r = call i8 @llvm.smin.i8(i8 %x, i8 %x_xor)