Skip to content

Commit 3dec6fe

Browse files
committed
[InstCombine] Add pre-commit tests. NFC.
1 parent 0ff8b79 commit 3dec6fe

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

llvm/test/Transforms/InstCombine/logical-select.ll

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,3 +1521,124 @@ bb:
15211521
%and2 = or i1 %and1, %cmp
15221522
ret i1 %and2
15231523
}
1524+
1525+
define i1 @test_logical_and_icmp_samesign(i8 %x) {
1526+
; CHECK-LABEL: @test_logical_and_icmp_samesign(
1527+
; CHECK-NEXT: [[CMP1:%.*]] = icmp ne i8 [[X:%.*]], 9
1528+
; CHECK-NEXT: [[CMP2:%.*]] = icmp samesign ult i8 [[X]], 11
1529+
; CHECK-NEXT: [[AND:%.*]] = select i1 [[CMP1]], i1 [[CMP2]], i1 false
1530+
; CHECK-NEXT: ret i1 [[AND]]
1531+
;
1532+
%cmp1 = icmp ne i8 %x, 9
1533+
%cmp2 = icmp samesign ult i8 %x, 11
1534+
%and = select i1 %cmp1, i1 %cmp2, i1 false
1535+
ret i1 %and
1536+
}
1537+
1538+
define i1 @test_logical_or_icmp_samesign(i8 %x) {
1539+
; CHECK-LABEL: @test_logical_or_icmp_samesign(
1540+
; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i8 [[X:%.*]], -9
1541+
; CHECK-NEXT: [[CMP2:%.*]] = icmp samesign ult i8 [[X]], -11
1542+
; CHECK-NEXT: [[OR:%.*]] = select i1 [[CMP1]], i1 true, i1 [[CMP2]]
1543+
; CHECK-NEXT: ret i1 [[OR]]
1544+
;
1545+
%cmp1 = icmp eq i8 %x, -9
1546+
%cmp2 = icmp samesign ult i8 %x, -11
1547+
%or = select i1 %cmp1, i1 true, i1 %cmp2
1548+
ret i1 %or
1549+
}
1550+
1551+
define i1 @test_double_logical_and_icmp_samesign1(i1 %cond, i32 %y) {
1552+
; CHECK-LABEL: @test_double_logical_and_icmp_samesign1(
1553+
; CHECK-NEXT: [[CMP1:%.*]] = icmp ne i32 [[Y:%.*]], 5
1554+
; CHECK-NEXT: [[SEL1:%.*]] = select i1 [[COND:%.*]], i1 [[CMP1]], i1 false
1555+
; CHECK-NEXT: [[CMP2:%.*]] = icmp samesign ult i32 [[Y]], 4
1556+
; CHECK-NEXT: [[SEL2:%.*]] = select i1 [[SEL1]], i1 [[CMP2]], i1 false
1557+
; CHECK-NEXT: ret i1 [[SEL2]]
1558+
;
1559+
%cmp1 = icmp ne i32 %y, 5
1560+
%sel1 = select i1 %cond, i1 %cmp1, i1 false
1561+
%cmp2 = icmp samesign ult i32 %y, 4
1562+
%sel2 = select i1 %sel1, i1 %cmp2, i1 false
1563+
ret i1 %sel2
1564+
}
1565+
1566+
define i1 @test_double_logical_and_icmp_samesign2(i1 %cond, i32 %y) {
1567+
; CHECK-LABEL: @test_double_logical_and_icmp_samesign2(
1568+
; CHECK-NEXT: [[CMP1:%.*]] = icmp samesign ugt i32 [[Y:%.*]], 65535
1569+
; CHECK-NEXT: [[SEL1:%.*]] = select i1 [[COND:%.*]], i1 [[CMP1]], i1 false
1570+
; CHECK-NEXT: [[CMP2:%.*]] = icmp samesign ult i32 [[Y]], 1114112
1571+
; CHECK-NEXT: [[SEL2:%.*]] = select i1 [[SEL1]], i1 [[CMP2]], i1 false
1572+
; CHECK-NEXT: ret i1 [[SEL2]]
1573+
;
1574+
%cmp1 = icmp samesign ugt i32 %y, 65535
1575+
%sel1 = select i1 %cond, i1 %cmp1, i1 false
1576+
%cmp2 = icmp samesign ult i32 %y, 1114112
1577+
%sel2 = select i1 %sel1, i1 %cmp2, i1 false
1578+
ret i1 %sel2
1579+
}
1580+
1581+
define <2 x i1> @test_logical_and_icmp_samesign_vec(<2 x i8> %x) {
1582+
; CHECK-LABEL: @test_logical_and_icmp_samesign_vec(
1583+
; CHECK-NEXT: [[CMP1:%.*]] = icmp ne <2 x i8> [[X:%.*]], splat (i8 9)
1584+
; CHECK-NEXT: [[CMP2:%.*]] = icmp samesign ult <2 x i8> [[X]], splat (i8 11)
1585+
; CHECK-NEXT: [[AND:%.*]] = select <2 x i1> [[CMP1]], <2 x i1> [[CMP2]], <2 x i1> zeroinitializer
1586+
; CHECK-NEXT: ret <2 x i1> [[AND]]
1587+
;
1588+
%cmp1 = icmp ne <2 x i8> %x, splat(i8 9)
1589+
%cmp2 = icmp samesign ult <2 x i8> %x, splat(i8 11)
1590+
%and = select <2 x i1> %cmp1, <2 x i1> %cmp2, <2 x i1> zeroinitializer
1591+
ret <2 x i1> %and
1592+
}
1593+
1594+
define <2 x i1> @test_logical_and_icmp_samesign_vec_with_poison_cond(<2 x i8> %x) {
1595+
; CHECK-LABEL: @test_logical_and_icmp_samesign_vec_with_poison_cond(
1596+
; CHECK-NEXT: [[CMP1:%.*]] = icmp ne <2 x i8> [[X:%.*]], <i8 9, i8 poison>
1597+
; CHECK-NEXT: [[CMP2:%.*]] = icmp samesign ult <2 x i8> [[X]], splat (i8 11)
1598+
; CHECK-NEXT: [[AND:%.*]] = select <2 x i1> [[CMP1]], <2 x i1> [[CMP2]], <2 x i1> zeroinitializer
1599+
; CHECK-NEXT: ret <2 x i1> [[AND]]
1600+
;
1601+
%cmp1 = icmp ne <2 x i8> %x, <i8 9, i8 poison>
1602+
%cmp2 = icmp samesign ult <2 x i8> %x, splat(i8 11)
1603+
%and = select <2 x i1> %cmp1, <2 x i1> %cmp2, <2 x i1> zeroinitializer
1604+
ret <2 x i1> %and
1605+
}
1606+
1607+
define i1 @test_logical_and_icmp_samesign_do_not_imply(i8 %x) {
1608+
; CHECK-LABEL: @test_logical_and_icmp_samesign_do_not_imply(
1609+
; CHECK-NEXT: [[AND:%.*]] = icmp ult i8 [[X:%.*]], 11
1610+
; CHECK-NEXT: ret i1 [[AND]]
1611+
;
1612+
%cmp1 = icmp ne i8 %x, -9
1613+
%cmp2 = icmp samesign ult i8 %x, 11
1614+
%and = select i1 %cmp1, i1 %cmp2, i1 false
1615+
ret i1 %and
1616+
}
1617+
1618+
define i1 @test_logical_and_icmp_no_samesign(i8 %x) {
1619+
; CHECK-LABEL: @test_logical_and_icmp_no_samesign(
1620+
; CHECK-NEXT: [[CMP1:%.*]] = icmp ne i8 [[X:%.*]], 9
1621+
; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i8 [[X]], 11
1622+
; CHECK-NEXT: [[AND:%.*]] = and i1 [[CMP1]], [[CMP2]]
1623+
; CHECK-NEXT: ret i1 [[AND]]
1624+
;
1625+
%cmp1 = icmp ne i8 %x, 9
1626+
%cmp2 = icmp ult i8 %x, 11
1627+
%and = select i1 %cmp1, i1 %cmp2, i1 false
1628+
ret i1 %and
1629+
}
1630+
1631+
; Negative tests
1632+
1633+
define <2 x i1> @test_logical_and_icmp_samesign_vec_with_poison_tv(<2 x i8> %x) {
1634+
; CHECK-LABEL: @test_logical_and_icmp_samesign_vec_with_poison_tv(
1635+
; CHECK-NEXT: [[CMP1:%.*]] = icmp ne <2 x i8> [[X:%.*]], splat (i8 9)
1636+
; CHECK-NEXT: [[CMP2:%.*]] = icmp samesign ult <2 x i8> [[X]], <i8 11, i8 poison>
1637+
; CHECK-NEXT: [[AND:%.*]] = select <2 x i1> [[CMP1]], <2 x i1> [[CMP2]], <2 x i1> zeroinitializer
1638+
; CHECK-NEXT: ret <2 x i1> [[AND]]
1639+
;
1640+
%cmp1 = icmp ne <2 x i8> %x, splat(i8 9)
1641+
%cmp2 = icmp samesign ult <2 x i8> %x, <i8 11, i8 poison>
1642+
%and = select <2 x i1> %cmp1, <2 x i1> %cmp2, <2 x i1> zeroinitializer
1643+
ret <2 x i1> %and
1644+
}

0 commit comments

Comments
 (0)