Skip to content

Commit 54fe6c9

Browse files
committed
[InstCombine] add tests for set/clear masked bits; NFC
1 parent ed5363a commit 54fe6c9

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

llvm/test/Transforms/InstCombine/select-with-bitwise-ops.ll

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
target datalayout = "n8:16:32:64"
55

6+
declare void @use(i8)
7+
declare void @use_vec(<2 x i8>)
8+
69
define i32 @select_icmp_eq_and_1_0_or_2(i32 %x, i32 %y) {
710
; CHECK-LABEL: @select_icmp_eq_and_1_0_or_2(
811
; CHECK-NEXT: [[AND:%.*]] = shl i32 [[X:%.*]], 1
@@ -1449,3 +1452,115 @@ define i32 @shift_xor_multiuse_cmp_and(i32 %x, i32 %y, i32 %z, i32 %w) {
14491452
%res2 = mul i32 %res, %and2 ; to bump up the use count of the and
14501453
ret i32 %res2
14511454
}
1455+
1456+
define i8 @set_bits(i8 %x, i1 %b) {
1457+
; CHECK-LABEL: @set_bits(
1458+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], -6
1459+
; CHECK-NEXT: [[OR:%.*]] = or i8 [[X]], 5
1460+
; CHECK-NEXT: [[COND:%.*]] = select i1 [[B:%.*]], i8 [[OR]], i8 [[AND]]
1461+
; CHECK-NEXT: ret i8 [[COND]]
1462+
;
1463+
%and = and i8 %x, 250
1464+
%or = or i8 %x, 5
1465+
%cond = select i1 %b, i8 %or, i8 %and
1466+
ret i8 %cond
1467+
}
1468+
1469+
define i8 @set_bits_not_inverse_constant(i8 %x, i1 %b) {
1470+
; CHECK-LABEL: @set_bits_not_inverse_constant(
1471+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], -6
1472+
; CHECK-NEXT: [[OR:%.*]] = or i8 [[X]], 7
1473+
; CHECK-NEXT: [[COND:%.*]] = select i1 [[B:%.*]], i8 [[OR]], i8 [[AND]]
1474+
; CHECK-NEXT: ret i8 [[COND]]
1475+
;
1476+
%and = and i8 %x, 250
1477+
%or = or i8 %x, 7
1478+
%cond = select i1 %b, i8 %or, i8 %and
1479+
ret i8 %cond
1480+
}
1481+
1482+
define i8 @set_bits_extra_use1(i8 %x, i1 %b) {
1483+
; CHECK-LABEL: @set_bits_extra_use1(
1484+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], -6
1485+
; CHECK-NEXT: call void @use(i8 [[AND]])
1486+
; CHECK-NEXT: [[OR:%.*]] = or i8 [[X]], 5
1487+
; CHECK-NEXT: [[COND:%.*]] = select i1 [[B:%.*]], i8 [[OR]], i8 [[AND]]
1488+
; CHECK-NEXT: ret i8 [[COND]]
1489+
;
1490+
%and = and i8 %x, 250
1491+
call void @use(i8 %and)
1492+
%or = or i8 %x, 5
1493+
%cond = select i1 %b, i8 %or, i8 %and
1494+
ret i8 %cond
1495+
}
1496+
1497+
define i8 @set_bits_extra_use2(i8 %x, i1 %b) {
1498+
; CHECK-LABEL: @set_bits_extra_use2(
1499+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], -6
1500+
; CHECK-NEXT: [[OR:%.*]] = or i8 [[X]], 5
1501+
; CHECK-NEXT: call void @use(i8 [[OR]])
1502+
; CHECK-NEXT: [[COND:%.*]] = select i1 [[B:%.*]], i8 [[OR]], i8 [[AND]]
1503+
; CHECK-NEXT: ret i8 [[COND]]
1504+
;
1505+
%and = and i8 %x, 250
1506+
%or = or i8 %x, 5
1507+
call void @use(i8 %or)
1508+
%cond = select i1 %b, i8 %or, i8 %and
1509+
ret i8 %cond
1510+
}
1511+
1512+
define <2 x i8> @clear_bits(<2 x i8> %x, <2 x i1> %b) {
1513+
; CHECK-LABEL: @clear_bits(
1514+
; CHECK-NEXT: [[AND:%.*]] = and <2 x i8> [[X:%.*]], <i8 37, i8 37>
1515+
; CHECK-NEXT: [[OR:%.*]] = or <2 x i8> [[X]], <i8 -38, i8 -38>
1516+
; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[B:%.*]], <2 x i8> [[AND]], <2 x i8> [[OR]]
1517+
; CHECK-NEXT: ret <2 x i8> [[COND]]
1518+
;
1519+
%and = and <2 x i8> %x, <i8 37, i8 37>
1520+
%or = or <2 x i8> %x, <i8 218, i8 218>
1521+
%cond = select <2 x i1> %b, <2 x i8> %and, <2 x i8> %or
1522+
ret <2 x i8> %cond
1523+
}
1524+
1525+
define <2 x i8> @clear_bits_not_inverse_constant(<2 x i8> %x, <2 x i1> %b) {
1526+
; CHECK-LABEL: @clear_bits_not_inverse_constant(
1527+
; CHECK-NEXT: [[AND:%.*]] = and <2 x i8> [[X:%.*]], <i8 undef, i8 37>
1528+
; CHECK-NEXT: [[OR:%.*]] = or <2 x i8> [[X]], <i8 -38, i8 -38>
1529+
; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[B:%.*]], <2 x i8> [[AND]], <2 x i8> [[OR]]
1530+
; CHECK-NEXT: ret <2 x i8> [[COND]]
1531+
;
1532+
%and = and <2 x i8> %x, <i8 undef, i8 37>
1533+
%or = or <2 x i8> %x, <i8 218, i8 218>
1534+
%cond = select <2 x i1> %b, <2 x i8> %and, <2 x i8> %or
1535+
ret <2 x i8> %cond
1536+
}
1537+
1538+
define <2 x i8> @clear_bits_extra_use1(<2 x i8> %x, i1 %b) {
1539+
; CHECK-LABEL: @clear_bits_extra_use1(
1540+
; CHECK-NEXT: [[AND:%.*]] = and <2 x i8> [[X:%.*]], <i8 37, i8 37>
1541+
; CHECK-NEXT: call void @use_vec(<2 x i8> [[AND]])
1542+
; CHECK-NEXT: [[OR:%.*]] = or <2 x i8> [[X]], <i8 -38, i8 -38>
1543+
; CHECK-NEXT: [[COND:%.*]] = select i1 [[B:%.*]], <2 x i8> [[AND]], <2 x i8> [[OR]]
1544+
; CHECK-NEXT: ret <2 x i8> [[COND]]
1545+
;
1546+
%and = and <2 x i8> %x, <i8 37, i8 37>
1547+
call void @use_vec(<2 x i8> %and)
1548+
%or = or <2 x i8> %x, <i8 218, i8 218>
1549+
%cond = select i1 %b, <2 x i8> %and, <2 x i8> %or
1550+
ret <2 x i8> %cond
1551+
}
1552+
1553+
define i8 @clear_bits_extra_use2(i8 %x, i1 %b) {
1554+
; CHECK-LABEL: @clear_bits_extra_use2(
1555+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], -6
1556+
; CHECK-NEXT: [[OR:%.*]] = or i8 [[X]], 5
1557+
; CHECK-NEXT: call void @use(i8 [[OR]])
1558+
; CHECK-NEXT: [[COND:%.*]] = select i1 [[B:%.*]], i8 [[AND]], i8 [[OR]]
1559+
; CHECK-NEXT: ret i8 [[COND]]
1560+
;
1561+
%and = and i8 %x, 250
1562+
%or = or i8 %x, 5
1563+
call void @use(i8 %or)
1564+
%cond = select i1 %b, i8 %and, i8 %or
1565+
ret i8 %cond
1566+
}

0 commit comments

Comments
 (0)