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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
declare i5 @llvm.smin.i5(i5, i5)
declare <2 x i8> @llvm.smax.v2i8(<2 x i8>, <2 x i8>)
declare i5 @llvm.umin.i5(i5, i5)
declare <3 x i5> @llvm.umax.v3i5(<3 x i5>, <3 x i5>)
define i5 @smin_smin_common_op_00(i1 %cond, i5 %x, i5 %y, i5 %z) {
; CHECK-LABEL: @smin_smin_common_op_00(
; CHECK-NEXT: [[MINMAXOP:%.*]] = select i1 [[COND:%.*]], i5 [[X:%.*]], i5 [[Y:%.*]]
; CHECK-NEXT: [[SEL:%.*]] = call i5 @llvm.smin.i5(i5 [[MINMAXOP]], i5 [[Z:%.*]])
; CHECK-NEXT: ret i5 [[SEL]]
;
%m1 = call i5 @llvm.smin.i5(i5 %z, i5 %x)
%m2 = call i5 @llvm.smin.i5(i5 %z, i5 %y)
%sel = select i1 %cond, i5 %m1, i5 %m2
ret i5 %sel
}
define <2 x i8> @smax_smax_common_op_01(<2 x i1> %cond, <2 x i8> %x, <2 x i8> %y, <2 x i8> %z) {
; CHECK-LABEL: @smax_smax_common_op_01(
; CHECK-NEXT: [[MINMAXOP:%.*]] = select <2 x i1> [[COND:%.*]], <2 x i8> [[X:%.*]], <2 x i8> [[Y:%.*]]
; CHECK-NEXT: [[SEL:%.*]] = call <2 x i8> @llvm.smax.v2i8(<2 x i8> [[MINMAXOP]], <2 x i8> [[Z:%.*]])
; CHECK-NEXT: ret <2 x i8> [[SEL]]
;
%m1 = call <2 x i8> @llvm.smax.v2i8(<2 x i8> %z, <2 x i8> %x)
%m2 = call <2 x i8> @llvm.smax.v2i8(<2 x i8> %y, <2 x i8> %z)
%sel = select <2 x i1> %cond, <2 x i8> %m1, <2 x i8> %m2
ret <2 x i8> %sel
}
define i5 @umin_umin_common_op_10(i1 %cond, i5 %x, i5 %y, i5 %z, ptr %p) {
; CHECK-LABEL: @umin_umin_common_op_10(
; CHECK-NEXT: [[M1:%.*]] = call i5 @llvm.umin.i5(i5 [[X:%.*]], i5 [[Z:%.*]])
; CHECK-NEXT: store i5 [[M1]], ptr [[P:%.*]], align 1
; CHECK-NEXT: [[MINMAXOP:%.*]] = select i1 [[COND:%.*]], i5 [[X]], i5 [[Y:%.*]]
; CHECK-NEXT: [[SEL:%.*]] = call i5 @llvm.umin.i5(i5 [[MINMAXOP]], i5 [[Z]])
; CHECK-NEXT: ret i5 [[SEL]]
;
%m1 = call i5 @llvm.umin.i5(i5 %x, i5 %z)
store i5 %m1, ptr %p
%m2 = call i5 @llvm.umin.i5(i5 %z, i5 %y)
%sel = select i1 %cond, i5 %m1, i5 %m2
ret i5 %sel
}
define <3 x i5> @umax_umax_common_op_11(i1 %cond, <3 x i5> %x, <3 x i5> %y, <3 x i5> %z, ptr %p) {
; CHECK-LABEL: @umax_umax_common_op_11(
; CHECK-NEXT: [[M2:%.*]] = call <3 x i5> @llvm.umax.v3i5(<3 x i5> [[Y:%.*]], <3 x i5> [[Z:%.*]])
; CHECK-NEXT: store <3 x i5> [[M2]], ptr [[P:%.*]], align 2
; CHECK-NEXT: [[MINMAXOP:%.*]] = select i1 [[COND:%.*]], <3 x i5> [[X:%.*]], <3 x i5> [[Y]]
; CHECK-NEXT: [[SEL:%.*]] = call <3 x i5> @llvm.umax.v3i5(<3 x i5> [[MINMAXOP]], <3 x i5> [[Z]])
; CHECK-NEXT: ret <3 x i5> [[SEL]]
;
%m1 = call <3 x i5> @llvm.umax.v3i5(<3 x i5> %x, <3 x i5> %z)
%m2 = call <3 x i5> @llvm.umax.v3i5(<3 x i5> %y, <3 x i5> %z)
store <3 x i5> %m2, ptr %p
%sel = select i1 %cond, <3 x i5> %m1, <3 x i5> %m2
ret <3 x i5> %sel
}
; negative test - intrinsic mismatch
define i5 @smin_umin_common_op_11(i1 %cond, i5 %x, i5 %y, i5 %z) {
; CHECK-LABEL: @smin_umin_common_op_11(
; CHECK-NEXT: [[M1:%.*]] = call i5 @llvm.smin.i5(i5 [[X:%.*]], i5 [[Z:%.*]])
; CHECK-NEXT: [[M2:%.*]] = call i5 @llvm.umin.i5(i5 [[Y:%.*]], i5 [[Z]])
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], i5 [[M1]], i5 [[M2]]
; CHECK-NEXT: ret i5 [[SEL]]
;
%m1 = call i5 @llvm.smin.i5(i5 %x, i5 %z)
%m2 = call i5 @llvm.umin.i5(i5 %y, i5 %z)
%sel = select i1 %cond, i5 %m1, i5 %m2
ret i5 %sel
}
; negative test - require shared operand
define i5 @smin_smin_no_common_op(i1 %cond, i5 %x, i5 %y, i5 %z, i5 %w) {
; CHECK-LABEL: @smin_smin_no_common_op(
; CHECK-NEXT: [[M1:%.*]] = call i5 @llvm.smin.i5(i5 [[Z:%.*]], i5 [[X:%.*]])
; CHECK-NEXT: [[M2:%.*]] = call i5 @llvm.smin.i5(i5 [[W:%.*]], i5 [[Y:%.*]])
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], i5 [[M1]], i5 [[M2]]
; CHECK-NEXT: ret i5 [[SEL]]
;
%m1 = call i5 @llvm.smin.i5(i5 %z, i5 %x)
%m2 = call i5 @llvm.smin.i5(i5 %w, i5 %y)
%sel = select i1 %cond, i5 %m1, i5 %m2
ret i5 %sel
}
; negative test - too many uses
define i5 @umin_umin_common_op_10_uses(i1 %cond, i5 %x, i5 %y, i5 %z, ptr %p1, ptr %p2) {
; CHECK-LABEL: @umin_umin_common_op_10_uses(
; CHECK-NEXT: [[M1:%.*]] = call i5 @llvm.umin.i5(i5 [[X:%.*]], i5 [[Z:%.*]])
; CHECK-NEXT: store i5 [[M1]], ptr [[P1:%.*]], align 1
; CHECK-NEXT: [[M2:%.*]] = call i5 @llvm.umin.i5(i5 [[Z]], i5 [[Y:%.*]])
; CHECK-NEXT: store i5 [[M2]], ptr [[P2:%.*]], align 1
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], i5 [[M1]], i5 [[M2]]
; CHECK-NEXT: ret i5 [[SEL]]
;
%m1 = call i5 @llvm.umin.i5(i5 %x, i5 %z)
store i5 %m1, ptr %p1
%m2 = call i5 @llvm.umin.i5(i5 %z, i5 %y)
store i5 %m2, ptr %p2
%sel = select i1 %cond, i5 %m1, i5 %m2
ret i5 %sel
}
define i5 @smin_select_const_const(i1 %b) {
; CHECK-LABEL: @smin_select_const_const(
; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i5 -3, i5 5
; CHECK-NEXT: ret i5 [[C]]
;
%s = select i1 %b, i5 -3, i5 8
%c = call i5 @llvm.smin.i5(i5 %s, i5 5)
ret i5 %c
}
define <2 x i8> @smax_select_const_const(<2 x i1> %b) {
; CHECK-LABEL: @smax_select_const_const(
; CHECK-NEXT: [[C:%.*]] = select <2 x i1> [[B:%.*]], <2 x i8> <i8 1, i8 42>, <2 x i8> <i8 5, i8 43>
; CHECK-NEXT: ret <2 x i8> [[C]]
;
%s = select <2 x i1> %b, <2 x i8> <i8 1, i8 3>, <2 x i8> <i8 5, i8 43>
%c = call <2 x i8> @llvm.smax.v2i8(<2 x i8> %s, <2 x i8> <i8 0, i8 42>)
ret <2 x i8> %c
}
define i5 @umin_select_const_const(i1 %b) {
; CHECK-LABEL: @umin_select_const_const(
; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i5 4, i5 3
; CHECK-NEXT: ret i5 [[C]]
;
%s = select i1 %b, i5 8, i5 3
%c = call i5 @llvm.umin.i5(i5 4, i5 %s)
ret i5 %c
}
define <3 x i5> @umax_select_const_const(<3 x i1> %b) {
; CHECK-LABEL: @umax_select_const_const(
; CHECK-NEXT: [[C:%.*]] = select <3 x i1> [[B:%.*]], <3 x i5> <i5 5, i5 8, i5 -16>, <3 x i5> <i5 7, i5 8, i5 -16>
; CHECK-NEXT: ret <3 x i5> [[C]]
;
%s = select <3 x i1> %b, <3 x i5> <i5 2, i5 3, i5 4>, <3 x i5> <i5 7, i5 8, i5 9>
%c = call <3 x i5> @llvm.umax.v3i5(<3 x i5> <i5 5, i5 8, i5 16>, <3 x i5> %s)
ret <3 x i5> %c
}
define i5 @smin_select_const(i1 %b, i5 %x) {
; CHECK-LABEL: @smin_select_const(
; CHECK-NEXT: [[TMP1:%.*]] = call i5 @llvm.smin.i5(i5 [[X:%.*]], i5 5)
; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i5 -3, i5 [[TMP1]]
; CHECK-NEXT: ret i5 [[C]]
;
%s = select i1 %b, i5 -3, i5 %x
%c = call i5 @llvm.smin.i5(i5 %s, i5 5)
ret i5 %c
}
define <2 x i8> @smax_select_const(<2 x i1> %b, <2 x i8> %x) {
; CHECK-LABEL: @smax_select_const(
; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i8> @llvm.smax.v2i8(<2 x i8> [[X:%.*]], <2 x i8> <i8 0, i8 42>)
; CHECK-NEXT: [[C:%.*]] = select <2 x i1> [[B:%.*]], <2 x i8> [[TMP1]], <2 x i8> <i8 5, i8 43>
; CHECK-NEXT: ret <2 x i8> [[C]]
;
%s = select <2 x i1> %b, <2 x i8> %x, <2 x i8> <i8 5, i8 43>
%c = call <2 x i8> @llvm.smax.v2i8(<2 x i8> %s, <2 x i8> <i8 0, i8 42>)
ret <2 x i8> %c
}
define i5 @umin_select_const(i1 %b, i5 %x) {
; CHECK-LABEL: @umin_select_const(
; CHECK-NEXT: [[TMP1:%.*]] = call i5 @llvm.umin.i5(i5 [[X:%.*]], i5 4)
; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i5 [[TMP1]], i5 3
; CHECK-NEXT: ret i5 [[C]]
;
%s = select i1 %b, i5 %x, i5 3
%c = call i5 @llvm.umin.i5(i5 4, i5 %s)
ret i5 %c
}
define <3 x i5> @umax_select_const(<3 x i1> %b, <3 x i5> %x) {
; CHECK-LABEL: @umax_select_const(
; CHECK-NEXT: [[TMP1:%.*]] = call <3 x i5> @llvm.umax.v3i5(<3 x i5> [[X:%.*]], <3 x i5> <i5 5, i5 8, i5 1>)
; CHECK-NEXT: [[C:%.*]] = select <3 x i1> [[B:%.*]], <3 x i5> <i5 5, i5 8, i5 4>, <3 x i5> [[TMP1]]
; CHECK-NEXT: ret <3 x i5> [[C]]
;
%s = select <3 x i1> %b, <3 x i5> <i5 2, i5 3, i5 4>, <3 x i5> %x
%c = call <3 x i5> @llvm.umax.v3i5(<3 x i5> <i5 5, i5 8, i5 1>, <3 x i5> %s)
ret <3 x i5> %c
}
declare i32 @llvm.smax.i32(i32, i32);
declare i32 @llvm.smin.i32(i32, i32);
declare i8 @llvm.umax.i8(i8, i8);
declare i8 @llvm.umin.i8(i8, i8);
; Each of the following 4 tests would infinite loop because
; we had conflicting transforms for icmp and select using
; known bits.
define i32 @smax_smin(i32 %x) {
; CHECK-LABEL: @smax_smin(
; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[X:%.*]], 0
; CHECK-NEXT: [[S:%.*]] = zext i1 [[TMP1]] to i32
; CHECK-NEXT: ret i32 [[S]]
;
%m = call i32 @llvm.smax.i32(i32 %x, i32 0)
%c = icmp slt i32 %x, 1
%s = select i1 %c, i32 %m, i32 1
ret i32 %s
}
define i32 @smin_smax(i32 %x) {
; CHECK-LABEL: @smin_smax(
; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[X:%.*]], -2
; CHECK-NEXT: [[S:%.*]] = select i1 [[TMP1]], i32 -1, i32 -2
; CHECK-NEXT: ret i32 [[S]]
;
%m = call i32 @llvm.smin.i32(i32 %x, i32 -1)
%c = icmp sgt i32 %x, -2
%s = select i1 %c, i32 %m, i32 -2
ret i32 %s
}
define i8 @umax_umin(i8 %x) {
; CHECK-LABEL: @umax_umin(
; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i8 [[X:%.*]], -127
; CHECK-NEXT: [[S:%.*]] = select i1 [[TMP1]], i8 -128, i8 -127
; CHECK-NEXT: ret i8 [[S]]
;
%m = call i8 @llvm.umax.i8(i8 %x, i8 128)
%c = icmp ult i8 %x, 129
%s = select i1 %c, i8 %m, i8 129
ret i8 %s
}
define i8 @umin_umax(i8 %x) {
; CHECK-LABEL: @umin_umax(
; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i8 [[X:%.*]], 126
; CHECK-NEXT: [[S:%.*]] = select i1 [[TMP1]], i8 127, i8 126
; CHECK-NEXT: ret i8 [[S]]
;
%m = call i8 @llvm.umin.i8(i8 %x, i8 127)
%c = icmp ugt i8 %x, 126
%s = select i1 %c, i8 %m, i8 126
ret i8 %s
}
define i8 @not_smax(i8 %i41, i8 %i43) {
; CHECK-LABEL: @not_smax(
; CHECK-NEXT: [[I44:%.*]] = icmp slt i8 [[I41:%.*]], [[I43:%.*]]
; CHECK-NEXT: [[I46:%.*]] = sub nsw i8 [[I41]], [[I43]]
; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[I44]], i8 0, i8 [[I46]]
; CHECK-NEXT: ret i8 [[SPEC_SELECT]]
;
%i44 = icmp slt i8 %i41, %i43
%i46 = sub nsw i8 %i41, %i43
%spec.select = select i1 %i44, i8 0, i8 %i46
ret i8 %spec.select
}
define i8 @not_smax_swap(i8 %i41, i8 %i43) {
; CHECK-LABEL: @not_smax_swap(
; CHECK-NEXT: [[I44:%.*]] = icmp sgt i8 [[I41:%.*]], [[I43:%.*]]
; CHECK-NEXT: [[I46:%.*]] = sub nsw i8 [[I41]], [[I43]]
; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[I44]], i8 [[I46]], i8 0
; CHECK-NEXT: ret i8 [[SPEC_SELECT]]
;
%i44 = icmp sgt i8 %i41, %i43
%i46 = sub nsw i8 %i41, %i43
%spec.select = select i1 %i44, i8 %i46, i8 0
ret i8 %spec.select
}
define i8 @not_smin(i8 %i41, i8 %i43) {
; CHECK-LABEL: @not_smin(
; CHECK-NEXT: [[I44:%.*]] = icmp sgt i8 [[I41:%.*]], [[I43:%.*]]
; CHECK-NEXT: [[I46:%.*]] = sub nsw i8 [[I41]], [[I43]]
; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[I44]], i8 0, i8 [[I46]]
; CHECK-NEXT: ret i8 [[SPEC_SELECT]]
;
%i44 = icmp sgt i8 %i41, %i43
%i46 = sub nsw i8 %i41, %i43
%spec.select = select i1 %i44, i8 0, i8 %i46
ret i8 %spec.select
}
define i8 @not_smin_swap(i8 %i41, i8 %i43) {
; CHECK-LABEL: @not_smin_swap(
; CHECK-NEXT: [[I44:%.*]] = icmp slt i8 [[I41:%.*]], [[I43:%.*]]
; CHECK-NEXT: [[I46:%.*]] = sub nsw i8 [[I41]], [[I43]]
; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[I44]], i8 [[I46]], i8 0
; CHECK-NEXT: ret i8 [[SPEC_SELECT]]
;
%i44 = icmp slt i8 %i41, %i43
%i46 = sub nsw i8 %i41, %i43
%spec.select = select i1 %i44, i8 %i46, i8 0
ret i8 %spec.select
}
|