Skip to content

Commit 7252513

Browse files
committed
[ValueTracking] Add tests for computeKnownBits of llvm.vector.reduce.xor; NFC
1 parent 2490859 commit 7252513

File tree

1 file changed

+151
-0
lines changed

1 file changed

+151
-0
lines changed

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

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,5 +1241,156 @@ define i8 @known_reduce_and_fail(<2 x i8> %xx) {
12411241
ret i8 %r
12421242
}
12431243

1244+
define i8 @known_reduce_xor_even(<2 x i8> %xx) {
1245+
; CHECK-LABEL: @known_reduce_xor_even(
1246+
; CHECK-NEXT: [[X:%.*]] = or <2 x i8> [[XX:%.*]], <i8 5, i8 3>
1247+
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.xor.v2i8(<2 x i8> [[X]])
1248+
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 1
1249+
; CHECK-NEXT: ret i8 [[R]]
1250+
;
1251+
%x = or <2 x i8> %xx, <i8 5, i8 3>
1252+
%v = call i8 @llvm.vector.reduce.xor(<2 x i8> %x)
1253+
%r = and i8 %v, 1
1254+
ret i8 %r
1255+
}
1256+
1257+
define i8 @known_reduce_xor_even2(<2 x i8> %xx) {
1258+
; CHECK-LABEL: @known_reduce_xor_even2(
1259+
; CHECK-NEXT: [[X:%.*]] = and <2 x i8> [[XX:%.*]], <i8 15, i8 15>
1260+
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.xor.v2i8(<2 x i8> [[X]])
1261+
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 16
1262+
; CHECK-NEXT: ret i8 [[R]]
1263+
;
1264+
%x = and <2 x i8> %xx, <i8 15, i8 15>
1265+
%v = call i8 @llvm.vector.reduce.xor(<2 x i8> %x)
1266+
%r = and i8 %v, 16
1267+
ret i8 %r
1268+
}
1269+
1270+
define i8 @known_reduce_xor_even_fail(<2 x i8> %xx) {
1271+
; CHECK-LABEL: @known_reduce_xor_even_fail(
1272+
; CHECK-NEXT: [[X:%.*]] = or <2 x i8> [[XX:%.*]], <i8 5, i8 3>
1273+
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.xor.v2i8(<2 x i8> [[X]])
1274+
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 2
1275+
; CHECK-NEXT: ret i8 [[R]]
1276+
;
1277+
%x = or <2 x i8> %xx, <i8 5, i8 3>
1278+
%v = call i8 @llvm.vector.reduce.xor(<2 x i8> %x)
1279+
%r = and i8 %v, 2
1280+
ret i8 %r
1281+
}
1282+
1283+
define i8 @known_reduce_xor_odd(<3 x i8> %xx) {
1284+
; CHECK-LABEL: @known_reduce_xor_odd(
1285+
; CHECK-NEXT: [[X:%.*]] = or <3 x i8> [[XX:%.*]], <i8 5, i8 3, i8 9>
1286+
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.xor.v3i8(<3 x i8> [[X]])
1287+
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 1
1288+
; CHECK-NEXT: ret i8 [[R]]
1289+
;
1290+
%x = or <3 x i8> %xx, <i8 5, i8 3, i8 9>
1291+
%v = call i8 @llvm.vector.reduce.xor.v3i8(<3 x i8> %x)
1292+
%r = and i8 %v, 1
1293+
ret i8 %r
1294+
}
1295+
1296+
define i8 @known_reduce_xor_odd2(<3 x i8> %xx) {
1297+
; CHECK-LABEL: @known_reduce_xor_odd2(
1298+
; CHECK-NEXT: [[X:%.*]] = and <3 x i8> [[XX:%.*]], <i8 15, i8 15, i8 31>
1299+
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.xor.v3i8(<3 x i8> [[X]])
1300+
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 32
1301+
; CHECK-NEXT: ret i8 [[R]]
1302+
;
1303+
%x = and <3 x i8> %xx, <i8 15, i8 15, i8 31>
1304+
%v = call i8 @llvm.vector.reduce.xor.v3i8(<3 x i8> %x)
1305+
%r = and i8 %v, 32
1306+
ret i8 %r
1307+
}
1308+
1309+
define i8 @known_reduce_xor_odd2_fail(<3 x i8> %xx) {
1310+
; CHECK-LABEL: @known_reduce_xor_odd2_fail(
1311+
; CHECK-NEXT: [[X:%.*]] = and <3 x i8> [[XX:%.*]], <i8 15, i8 15, i8 31>
1312+
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.xor.v3i8(<3 x i8> [[X]])
1313+
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 16
1314+
; CHECK-NEXT: ret i8 [[R]]
1315+
;
1316+
%x = and <3 x i8> %xx, <i8 15, i8 15, i8 31>
1317+
%v = call i8 @llvm.vector.reduce.xor.v3i8(<3 x i8> %x)
1318+
%r = and i8 %v, 16
1319+
ret i8 %r
1320+
}
1321+
1322+
define i8 @known_reduce_xor_odd_fail(<3 x i8> %xx) {
1323+
; CHECK-LABEL: @known_reduce_xor_odd_fail(
1324+
; CHECK-NEXT: [[X:%.*]] = or <3 x i8> [[XX:%.*]], <i8 5, i8 3, i8 9>
1325+
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.xor.v3i8(<3 x i8> [[X]])
1326+
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 2
1327+
; CHECK-NEXT: ret i8 [[R]]
1328+
;
1329+
%x = or <3 x i8> %xx, <i8 5, i8 3, i8 9>
1330+
%v = call i8 @llvm.vector.reduce.xor.v3i8(<3 x i8> %x)
1331+
%r = and i8 %v, 2
1332+
ret i8 %r
1333+
}
1334+
1335+
define i8 @nonzero_reduce_xor_vscale_even(<vscale x 2 x i8> %xx) {
1336+
; CHECK-LABEL: @nonzero_reduce_xor_vscale_even(
1337+
; CHECK-NEXT: [[X:%.*]] = or <vscale x 2 x i8> [[XX:%.*]], shufflevector (<vscale x 2 x i8> insertelement (<vscale x 2 x i8> poison, i8 1, i64 0), <vscale x 2 x i8> poison, <vscale x 2 x i32> zeroinitializer)
1338+
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.xor.nxv2i8(<vscale x 2 x i8> [[X]])
1339+
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 1
1340+
; CHECK-NEXT: ret i8 [[R]]
1341+
;
1342+
%one = insertelement <vscale x 2 x i8> poison, i8 1, i64 0
1343+
%ones = shufflevector <vscale x 2 x i8> %one, <vscale x 2 x i8> poison, <vscale x 2 x i32> zeroinitializer
1344+
%x = or <vscale x 2 x i8> %xx, %ones
1345+
%v = call i8 @llvm.vector.reduce.xor.nxv2i8(<vscale x 2 x i8> %x)
1346+
%r = and i8 %v, 1
1347+
ret i8 %r
1348+
}
1349+
1350+
define i8 @nonzero_reduce_xor_vscale_odd(<vscale x 3 x i8> %xx) {
1351+
; CHECK-LABEL: @nonzero_reduce_xor_vscale_odd(
1352+
; CHECK-NEXT: [[X:%.*]] = or <vscale x 3 x i8> [[XX:%.*]], shufflevector (<vscale x 3 x i8> insertelement (<vscale x 3 x i8> poison, i8 1, i64 0), <vscale x 3 x i8> poison, <vscale x 3 x i32> zeroinitializer)
1353+
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.xor.nxv3i8(<vscale x 3 x i8> [[X]])
1354+
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 1
1355+
; CHECK-NEXT: ret i8 [[R]]
1356+
;
1357+
%one = insertelement <vscale x 3 x i8> poison, i8 1, i64 0
1358+
%ones = shufflevector <vscale x 3 x i8> %one, <vscale x 3 x i8> poison, <vscale x 3 x i32> zeroinitializer
1359+
%x = or <vscale x 3 x i8> %xx, %ones
1360+
%v = call i8 @llvm.vector.reduce.xor.nxv3i8(<vscale x 3 x i8> %x)
1361+
%r = and i8 %v, 1
1362+
ret i8 %r
1363+
}
1364+
1365+
define i8 @nonzero_reduce_xor_vscale_even_fail(<vscale x 2 x i8> %xx) {
1366+
; CHECK-LABEL: @nonzero_reduce_xor_vscale_even_fail(
1367+
; CHECK-NEXT: [[X:%.*]] = or <vscale x 2 x i8> [[XX:%.*]], shufflevector (<vscale x 2 x i8> insertelement (<vscale x 2 x i8> poison, i8 1, i64 0), <vscale x 2 x i8> poison, <vscale x 2 x i32> zeroinitializer)
1368+
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.xor.nxv2i8(<vscale x 2 x i8> [[X]])
1369+
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 2
1370+
; CHECK-NEXT: ret i8 [[R]]
1371+
;
1372+
%one = insertelement <vscale x 2 x i8> poison, i8 1, i64 0
1373+
%ones = shufflevector <vscale x 2 x i8> %one, <vscale x 2 x i8> poison, <vscale x 2 x i32> zeroinitializer
1374+
%x = or <vscale x 2 x i8> %xx, %ones
1375+
%v = call i8 @llvm.vector.reduce.xor.nxv2i8(<vscale x 2 x i8> %x)
1376+
%r = and i8 %v, 2
1377+
ret i8 %r
1378+
}
1379+
1380+
define i8 @nonzero_reduce_xor_vscale_odd_fail(<vscale x 3 x i8> %xx) {
1381+
; CHECK-LABEL: @nonzero_reduce_xor_vscale_odd_fail(
1382+
; CHECK-NEXT: [[X:%.*]] = or <vscale x 3 x i8> [[XX:%.*]], shufflevector (<vscale x 3 x i8> insertelement (<vscale x 3 x i8> poison, i8 1, i64 0), <vscale x 3 x i8> poison, <vscale x 3 x i32> zeroinitializer)
1383+
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.xor.nxv3i8(<vscale x 3 x i8> [[X]])
1384+
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 2
1385+
; CHECK-NEXT: ret i8 [[R]]
1386+
;
1387+
%one = insertelement <vscale x 3 x i8> poison, i8 1, i64 0
1388+
%ones = shufflevector <vscale x 3 x i8> %one, <vscale x 3 x i8> poison, <vscale x 3 x i32> zeroinitializer
1389+
%x = or <vscale x 3 x i8> %xx, %ones
1390+
%v = call i8 @llvm.vector.reduce.xor.nxv3i8(<vscale x 3 x i8> %x)
1391+
%r = and i8 %v, 2
1392+
ret i8 %r
1393+
}
1394+
12441395
declare void @use(i1)
12451396
declare void @sink(i8)

0 commit comments

Comments
 (0)