Skip to content

Commit d883817

Browse files
committed
[ValueTracking] Add tests for computeKnownBits of llvm.vector.reduce.{add,mul}; NFC
1 parent 2e43aa5 commit d883817

File tree

1 file changed

+184
-0
lines changed

1 file changed

+184
-0
lines changed

llvm/test/Transforms/InstCombine/known-bits.ll

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,5 +1124,189 @@ define i8 @known_reduce_xor_odd_fail(<3 x i8> %xx) {
11241124
ret i8 %r
11251125
}
11261126

1127+
define i8 @known_reduce_add(<2 x i8> %xx) {
1128+
; CHECK-LABEL: @known_reduce_add(
1129+
; CHECK-NEXT: [[X:%.*]] = and <2 x i8> [[XX:%.*]], <i8 3, i8 3>
1130+
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.add.v2i8(<2 x i8> [[X]])
1131+
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 8
1132+
; CHECK-NEXT: ret i8 [[R]]
1133+
;
1134+
%x = and <2 x i8> %xx, <i8 3, i8 3>
1135+
%v = call i8 @llvm.vector.reduce.add(<2 x i8> %x)
1136+
%r = and i8 %v, 8
1137+
ret i8 %r
1138+
}
1139+
1140+
define i8 @known_reduce_add_fail(<2 x i8> %xx) {
1141+
; CHECK-LABEL: @known_reduce_add_fail(
1142+
; CHECK-NEXT: [[X:%.*]] = and <2 x i8> [[XX:%.*]], <i8 3, i8 3>
1143+
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.add.v2i8(<2 x i8> [[X]])
1144+
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 4
1145+
; CHECK-NEXT: ret i8 [[R]]
1146+
;
1147+
%x = and <2 x i8> %xx, <i8 3, i8 3>
1148+
%v = call i8 @llvm.vector.reduce.add(<2 x i8> %x)
1149+
%r = and i8 %v, 4
1150+
ret i8 %r
1151+
}
1152+
1153+
define i8 @known_reduce_add_fail2(<4 x i8> %xx) {
1154+
; CHECK-LABEL: @known_reduce_add_fail2(
1155+
; CHECK-NEXT: [[X:%.*]] = and <4 x i8> [[XX:%.*]], <i8 3, i8 3, i8 3, i8 3>
1156+
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.add.v4i8(<4 x i8> [[X]])
1157+
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 8
1158+
; CHECK-NEXT: ret i8 [[R]]
1159+
;
1160+
%x = and <4 x i8> %xx, <i8 3, i8 3, i8 3, i8 3>
1161+
%v = call i8 @llvm.vector.reduce.add.v4i8(<4 x i8> %x)
1162+
%r = and i8 %v, 8
1163+
ret i8 %r
1164+
}
1165+
1166+
define i8 @known_reduce_add2(<4 x i8> %xx) {
1167+
; CHECK-LABEL: @known_reduce_add2(
1168+
; CHECK-NEXT: [[X:%.*]] = and <4 x i8> [[XX:%.*]], <i8 3, i8 3, i8 3, i8 3>
1169+
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.add.v4i8(<4 x i8> [[X]])
1170+
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 32
1171+
; CHECK-NEXT: ret i8 [[R]]
1172+
;
1173+
%x = and <4 x i8> %xx, <i8 3, i8 3, i8 3, i8 3>
1174+
%v = call i8 @llvm.vector.reduce.add.v4i8(<4 x i8> %x)
1175+
%r = and i8 %v, 32
1176+
ret i8 %r
1177+
}
1178+
1179+
define i8 @known_reduce_add3(<2 x i8> %xx) {
1180+
; CHECK-LABEL: @known_reduce_add3(
1181+
; CHECK-NEXT: [[X:%.*]] = or <2 x i8> [[XX:%.*]], <i8 1, i8 1>
1182+
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.add.v2i8(<2 x i8> [[X]])
1183+
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 1
1184+
; CHECK-NEXT: ret i8 [[R]]
1185+
;
1186+
%x = or <2 x i8> %xx, <i8 1, i8 1>
1187+
%v = call i8 @llvm.vector.reduce.add(<2 x i8> %x)
1188+
%r = and i8 %v, 1
1189+
ret i8 %r
1190+
}
1191+
1192+
define i8 @known_reduce_add33(<3 x i8> %xx) {
1193+
; CHECK-LABEL: @known_reduce_add33(
1194+
; CHECK-NEXT: [[X:%.*]] = or <3 x i8> [[XX:%.*]], <i8 1, i8 1, i8 1>
1195+
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.add.v3i8(<3 x i8> [[X]])
1196+
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 1
1197+
; CHECK-NEXT: ret i8 [[R]]
1198+
;
1199+
%x = or <3 x i8> %xx, <i8 1, i8 1, i8 1>
1200+
%v = call i8 @llvm.vector.reduce.add.v3i8(<3 x i8> %x)
1201+
%r = and i8 %v, 1
1202+
ret i8 %r
1203+
}
1204+
1205+
define i8 @known_reduce_add34(<4 x i8> %xx) {
1206+
; CHECK-LABEL: @known_reduce_add34(
1207+
; CHECK-NEXT: [[X:%.*]] = or <4 x i8> [[XX:%.*]], <i8 1, i8 1, i8 1, i8 1>
1208+
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.add.v4i8(<4 x i8> [[X]])
1209+
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 1
1210+
; CHECK-NEXT: ret i8 [[R]]
1211+
;
1212+
%x = or <4 x i8> %xx, <i8 1, i8 1, i8 1, i8 1>
1213+
%v = call i8 @llvm.vector.reduce.add.v4i8(<4 x i8> %x)
1214+
%r = and i8 %v, 1
1215+
ret i8 %r
1216+
}
1217+
1218+
define i8 @known_reduce_add4(<2 x i8> %xx) {
1219+
; CHECK-LABEL: @known_reduce_add4(
1220+
; CHECK-NEXT: [[X0:%.*]] = and <2 x i8> [[XX:%.*]], <i8 2, i8 2>
1221+
; CHECK-NEXT: [[X:%.*]] = or disjoint <2 x i8> [[X0]], <i8 1, i8 1>
1222+
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.add.v2i8(<2 x i8> [[X]])
1223+
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 2
1224+
; CHECK-NEXT: ret i8 [[R]]
1225+
;
1226+
%x0 = and <2 x i8> %xx, <i8 3, i8 3>
1227+
%x = or <2 x i8> %x0, <i8 1, i8 1>
1228+
%v = call i8 @llvm.vector.reduce.add(<2 x i8> %x)
1229+
%r = and i8 %v, 2
1230+
ret i8 %r
1231+
}
1232+
1233+
define i8 @known_reduce_add4_fail(<2 x i8> %xx) {
1234+
; CHECK-LABEL: @known_reduce_add4_fail(
1235+
; CHECK-NEXT: [[X:%.*]] = or <2 x i8> [[XX:%.*]], <i8 1, i8 1>
1236+
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.add.v2i8(<2 x i8> [[X]])
1237+
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 2
1238+
; CHECK-NEXT: ret i8 [[R]]
1239+
;
1240+
%x = or <2 x i8> %xx, <i8 1, i8 1>
1241+
%v = call i8 @llvm.vector.reduce.add(<2 x i8> %x)
1242+
%r = and i8 %v, 2
1243+
ret i8 %r
1244+
}
1245+
1246+
define i8 @known_reduce_mul(<2 x i8> %xx) {
1247+
; CHECK-LABEL: @known_reduce_mul(
1248+
; CHECK-NEXT: [[X:%.*]] = and <2 x i8> [[XX:%.*]], <i8 3, i8 3>
1249+
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.mul.v2i8(<2 x i8> [[X]])
1250+
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 16
1251+
; CHECK-NEXT: ret i8 [[R]]
1252+
;
1253+
%x = and <2 x i8> %xx, <i8 3, i8 3>
1254+
%v = call i8 @llvm.vector.reduce.mul(<2 x i8> %x)
1255+
%r = and i8 %v, 16
1256+
ret i8 %r
1257+
}
1258+
1259+
define i8 @known_reduce_mul_fail(<2 x i8> %xx) {
1260+
; CHECK-LABEL: @known_reduce_mul_fail(
1261+
; CHECK-NEXT: [[X:%.*]] = and <2 x i8> [[XX:%.*]], <i8 3, i8 3>
1262+
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.mul.v2i8(<2 x i8> [[X]])
1263+
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 8
1264+
; CHECK-NEXT: ret i8 [[R]]
1265+
;
1266+
%x = and <2 x i8> %xx, <i8 3, i8 3>
1267+
%v = call i8 @llvm.vector.reduce.mul(<2 x i8> %x)
1268+
%r = and i8 %v, 8
1269+
ret i8 %r
1270+
}
1271+
1272+
define i8 @known_reduce_mul_fail2(<3 x i8> %xx) {
1273+
; CHECK-LABEL: @known_reduce_mul_fail2(
1274+
; CHECK-NEXT: [[X:%.*]] = and <3 x i8> [[XX:%.*]], <i8 3, i8 3, i8 3>
1275+
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.mul.v3i8(<3 x i8> [[X]])
1276+
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 32
1277+
; CHECK-NEXT: ret i8 [[R]]
1278+
;
1279+
%x = and <3 x i8> %xx, <i8 3, i8 3, i8 3>
1280+
%v = call i8 @llvm.vector.reduce.mul.v3i8(<3 x i8> %x)
1281+
%r = and i8 %v, 32
1282+
ret i8 %r
1283+
}
1284+
1285+
define i8 @known_reduce_mul2(<3 x i8> %xx) {
1286+
; CHECK-LABEL: @known_reduce_mul2(
1287+
; CHECK-NEXT: [[X:%.*]] = and <3 x i8> [[XX:%.*]], <i8 3, i8 3, i8 3>
1288+
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.mul.v3i8(<3 x i8> [[X]])
1289+
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 64
1290+
; CHECK-NEXT: ret i8 [[R]]
1291+
;
1292+
%x = and <3 x i8> %xx, <i8 3, i8 3, i8 3>
1293+
%v = call i8 @llvm.vector.reduce.mul.v3i8(<3 x i8> %x)
1294+
%r = and i8 %v, 64
1295+
ret i8 %r
1296+
}
1297+
1298+
define i8 @known_reduce_mul3(<2 x i8> %xx) {
1299+
; CHECK-LABEL: @known_reduce_mul3(
1300+
; CHECK-NEXT: [[X:%.*]] = or <2 x i8> [[XX:%.*]], <i8 1, i8 1>
1301+
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.mul.v2i8(<2 x i8> [[X]])
1302+
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 1
1303+
; CHECK-NEXT: ret i8 [[R]]
1304+
;
1305+
%x = or <2 x i8> %xx, <i8 1, i8 1>
1306+
%v = call i8 @llvm.vector.reduce.mul(<2 x i8> %x)
1307+
%r = and i8 %v, 1
1308+
ret i8 %r
1309+
}
1310+
11271311
declare void @use(i1)
11281312
declare void @sink(i8)

0 commit comments

Comments
 (0)