Skip to content

Commit efba0d0

Browse files
committed
Modifies code and updates relevant tests
1 parent 71f8f99 commit efba0d0

File tree

2 files changed

+192
-41
lines changed

2 files changed

+192
-41
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8046,11 +8046,36 @@ Instruction *InstCombinerImpl::visitFCmpInst(FCmpInst &I) {
80468046
if (match(Op0, m_Instruction(LHSI)) && match(Op1, m_Constant(RHSC))) {
80478047
switch (LHSI->getOpcode()) {
80488048
case Instruction::FSub:
8049-
if ((Pred == FCmpInst::FCMP_OGT || Pred == FCmpInst::FCMP_OLT ||
8050-
Pred == FCmpInst::FCMP_ONE) &&
8051-
match(RHSC, m_AnyZeroFP()) &&
8052-
match(LHSI, m_FSub(m_Value(X), m_Value(Y))))
8053-
return new FCmpInst(Pred, X, Y);
8049+
switch (Pred) {
8050+
default:
8051+
break;
8052+
case FCmpInst::FCMP_UGT:
8053+
case FCmpInst::FCMP_ULT:
8054+
case FCmpInst::FCMP_UNE:
8055+
case FCmpInst::FCMP_OEQ:
8056+
case FCmpInst::FCMP_OGE:
8057+
case FCmpInst::FCMP_OLE: {
8058+
BinaryOperator *SubI = cast<BinaryOperator>(LHSI);
8059+
if (!computeKnownFPClass(SubI->getOperand(0), SubI->getFastMathFlags(),
8060+
fcInf, LHSI, 0)
8061+
.isKnownNeverInfinity() &&
8062+
!computeKnownFPClass(SubI->getOperand(1), SubI->getFastMathFlags(),
8063+
fcInf, LHSI, 0)
8064+
.isKnownNeverInfinity())
8065+
break;
8066+
}
8067+
LLVM_FALLTHROUGH;
8068+
case FCmpInst::FCMP_OGT:
8069+
case FCmpInst::FCMP_OLT:
8070+
case FCmpInst::FCMP_ONE:
8071+
case FCmpInst::FCMP_UEQ:
8072+
case FCmpInst::FCMP_UGE:
8073+
case FCmpInst::FCMP_ULE:
8074+
if (match(RHSC, m_AnyZeroFP()) &&
8075+
match(LHSI, m_FSub(m_Value(X), m_Value(Y))))
8076+
return new FCmpInst(Pred, X, Y);
8077+
break;
8078+
}
80548079
break;
80558080
case Instruction::PHI:
80568081
if (Instruction *NV = foldOpIntoPhi(I, cast<PHINode>(LHSI)))

llvm/test/Transforms/InstCombine/fcmp.ll

Lines changed: 162 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,38 +1517,164 @@ define i1 @fcmp_one_fsub_const(float %x, float %y) {
15171517
ret i1 %cmp
15181518
}
15191519

1520-
define <8 x i1> @fcmp_vec_ogt_fsub_const(<8 x float> %x, <8 x float> %y) {
1521-
; CHECK-LABEL: @fcmp_vec_ogt_fsub_const(
1522-
; CHECK-NEXT: [[CMP:%.*]] = fcmp ogt <8 x float> [[X:%.*]], [[Y:%.*]]
1520+
define i1 @fcmp_oeq_fsub_const(float %x, float %y) {
1521+
; CHECK-LABEL: @fcmp_oeq_fsub_const(
1522+
; CHECK-NEXT: [[FS:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
1523+
; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[FS]], 0.000000e+00
1524+
; CHECK-NEXT: ret i1 [[CMP]]
1525+
;
1526+
%fs = fsub float %x, %y
1527+
%cmp = fcmp oeq float %fs, 0.000000e+00
1528+
ret i1 %cmp
1529+
}
1530+
1531+
define i1 @fcmp_oge_fsub_const(float %x, float %y) {
1532+
; CHECK-LABEL: @fcmp_oge_fsub_const(
1533+
; CHECK-NEXT: [[FS:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
1534+
; CHECK-NEXT: [[CMP:%.*]] = fcmp oge float [[FS]], 0.000000e+00
1535+
; CHECK-NEXT: ret i1 [[CMP]]
1536+
;
1537+
%fs = fsub float %x, %y
1538+
%cmp = fcmp oge float %fs, 0.000000e+00
1539+
ret i1 %cmp
1540+
}
1541+
1542+
define i1 @fcmp_ole_fsub_const(float %x, float %y) {
1543+
; CHECK-LABEL: @fcmp_ole_fsub_const(
1544+
; CHECK-NEXT: [[FS:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
1545+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ole float [[FS]], 0.000000e+00
1546+
; CHECK-NEXT: ret i1 [[CMP]]
1547+
;
1548+
%fs = fsub float %x, %y
1549+
%cmp = fcmp ole float %fs, 0.000000e+00
1550+
ret i1 %cmp
1551+
}
1552+
1553+
define i1 @fcmp_ueq_fsub_const(float %x, float %y) {
1554+
; CHECK-LABEL: @fcmp_ueq_fsub_const(
1555+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ueq float [[X:%.*]], [[Y:%.*]]
1556+
; CHECK-NEXT: ret i1 [[CMP]]
1557+
;
1558+
%fs = fsub float %x, %y
1559+
%cmp = fcmp ueq float %fs, 0.000000e+00
1560+
ret i1 %cmp
1561+
}
1562+
1563+
define i1 @fcmp_uge_fsub_const(float %x, float %y) {
1564+
; CHECK-LABEL: @fcmp_uge_fsub_const(
1565+
; CHECK-NEXT: [[CMP:%.*]] = fcmp uge float [[X:%.*]], [[Y:%.*]]
1566+
; CHECK-NEXT: ret i1 [[CMP]]
1567+
;
1568+
%fs = fsub float %x, %y
1569+
%cmp = fcmp uge float %fs, 0.000000e+00
1570+
ret i1 %cmp
1571+
}
1572+
1573+
define i1 @fcmp_ule_fsub_const(float %x, float %y) {
1574+
; CHECK-LABEL: @fcmp_ule_fsub_const(
1575+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ule float [[X:%.*]], [[Y:%.*]]
1576+
; CHECK-NEXT: ret i1 [[CMP]]
1577+
;
1578+
%fs = fsub float %x, %y
1579+
%cmp = fcmp ule float %fs, 0.000000e+00
1580+
ret i1 %cmp
1581+
}
1582+
1583+
define i1 @fcmp_ugt_fsub_const(float %x, float %y) {
1584+
; CHECK-LABEL: @fcmp_ugt_fsub_const(
1585+
; CHECK-NEXT: [[FS:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
1586+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ugt float [[FS]], 0.000000e+00
1587+
; CHECK-NEXT: ret i1 [[CMP]]
1588+
;
1589+
%fs = fsub float %x, %y
1590+
%cmp = fcmp ugt float %fs, 0.000000e+00
1591+
ret i1 %cmp
1592+
}
1593+
1594+
define i1 @fcmp_ult_fsub_const(float %x, float %y) {
1595+
; CHECK-LABEL: @fcmp_ult_fsub_const(
1596+
; CHECK-NEXT: [[FS:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
1597+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ult float [[FS]], 0.000000e+00
1598+
; CHECK-NEXT: ret i1 [[CMP]]
1599+
;
1600+
%fs = fsub float %x, %y
1601+
%cmp = fcmp ult float %fs, 0.000000e+00
1602+
ret i1 %cmp
1603+
}
1604+
1605+
define i1 @fcmp_une_fsub_const(float %x, float %y) {
1606+
; CHECK-LABEL: @fcmp_une_fsub_const(
1607+
; CHECK-NEXT: [[FS:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
1608+
; CHECK-NEXT: [[CMP:%.*]] = fcmp une float [[FS]], 0.000000e+00
1609+
; CHECK-NEXT: ret i1 [[CMP]]
1610+
;
1611+
%fs = fsub float %x, %y
1612+
%cmp = fcmp une float %fs, 0.000000e+00
1613+
ret i1 %cmp
1614+
}
1615+
1616+
define <8 x i1> @fcmp_vec_uge_fast_fsub_const(<8 x float> %x, <8 x float> %y) {
1617+
; CHECK-LABEL: @fcmp_vec_uge_fast_fsub_const(
1618+
; CHECK-NEXT: [[CMP:%.*]] = fcmp uge <8 x float> [[X:%.*]], [[Y:%.*]]
15231619
; CHECK-NEXT: ret <8 x i1> [[CMP]]
15241620
;
1525-
%fs = fsub <8 x float> %x, %y
1526-
%cmp = fcmp ogt <8 x float> %fs, zeroinitializer
1621+
%fs = fsub fast <8 x float> %x, %y
1622+
%cmp = fcmp uge <8 x float> %fs, zeroinitializer
15271623
ret <8 x i1> %cmp
15281624
}
15291625

1530-
define <8 x i1> @fcmp_vec_olt_fsub_const(<8 x float> %x, <8 x float> %y) {
1531-
; CHECK-LABEL: @fcmp_vec_olt_fsub_const(
1532-
; CHECK-NEXT: [[CMP:%.*]] = fcmp olt <8 x float> [[X:%.*]], [[Y:%.*]]
1626+
define <8 x i1> @fcmp_vec_ule_fast_fsub_const(<8 x float> %x, <8 x float> %y) {
1627+
; CHECK-LABEL: @fcmp_vec_ule_fast_fsub_const(
1628+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ule <8 x float> [[X:%.*]], [[Y:%.*]]
15331629
; CHECK-NEXT: ret <8 x i1> [[CMP]]
15341630
;
1535-
%fs = fsub <8 x float> %x, %y
1536-
%cmp = fcmp olt <8 x float> %fs, zeroinitializer
1631+
%fs = fsub fast <8 x float> %x, %y
1632+
%cmp = fcmp ule <8 x float> %fs, zeroinitializer
15371633
ret <8 x i1> %cmp
15381634
}
15391635

1540-
define <8 x i1> @fcmp_vec_one_fsub_const(<8 x float> %x, <8 x float> %y) {
1541-
; CHECK-LABEL: @fcmp_vec_one_fsub_const(
1542-
; CHECK-NEXT: [[CMP:%.*]] = fcmp one <8 x float> [[X:%.*]], [[Y:%.*]]
1636+
define <8 x i1> @fcmp_vec_ueq_fast_fsub_const(<8 x float> %x, <8 x float> %y) {
1637+
; CHECK-LABEL: @fcmp_vec_ueq_fast_fsub_const(
1638+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ueq <8 x float> [[X:%.*]], [[Y:%.*]]
15431639
; CHECK-NEXT: ret <8 x i1> [[CMP]]
15441640
;
1545-
%fs = fsub <8 x float> %x, %y
1546-
%cmp = fcmp one <8 x float> %fs, zeroinitializer
1641+
%fs = fsub fast <8 x float> %x, %y
1642+
%cmp = fcmp ueq <8 x float> %fs, zeroinitializer
15471643
ret <8 x i1> %cmp
15481644
}
15491645

1550-
define <8 x i1> @fcmp_vec_ogt_fm_fsub_const(<8 x float> %x, <8 x float> %y) {
1551-
; CHECK-LABEL: @fcmp_vec_ogt_fm_fsub_const(
1646+
define <8 x i1> @fcmp_vec_oge_fast_fsub_const(<8 x float> %x, <8 x float> %y) {
1647+
; CHECK-LABEL: @fcmp_vec_oge_fast_fsub_const(
1648+
; CHECK-NEXT: [[CMP:%.*]] = fcmp oge <8 x float> [[X:%.*]], [[Y:%.*]]
1649+
; CHECK-NEXT: ret <8 x i1> [[CMP]]
1650+
;
1651+
%fs = fsub fast <8 x float> %x, %y
1652+
%cmp = fcmp oge <8 x float> %fs, zeroinitializer
1653+
ret <8 x i1> %cmp
1654+
}
1655+
1656+
define <8 x i1> @fcmp_vec_ole_fast_fsub_const(<8 x float> %x, <8 x float> %y) {
1657+
; CHECK-LABEL: @fcmp_vec_ole_fast_fsub_const(
1658+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ole <8 x float> [[X:%.*]], [[Y:%.*]]
1659+
; CHECK-NEXT: ret <8 x i1> [[CMP]]
1660+
;
1661+
%fs = fsub fast <8 x float> %x, %y
1662+
%cmp = fcmp ole <8 x float> %fs, zeroinitializer
1663+
ret <8 x i1> %cmp
1664+
}
1665+
1666+
define <8 x i1> @fcmp_vec_oeq_fast_fsub_const(<8 x float> %x, <8 x float> %y) {
1667+
; CHECK-LABEL: @fcmp_vec_oeq_fast_fsub_const(
1668+
; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq <8 x float> [[X:%.*]], [[Y:%.*]]
1669+
; CHECK-NEXT: ret <8 x i1> [[CMP]]
1670+
;
1671+
%fs = fsub fast <8 x float> %x, %y
1672+
%cmp = fcmp oeq <8 x float> %fs, zeroinitializer
1673+
ret <8 x i1> %cmp
1674+
}
1675+
1676+
define <8 x i1> @fcmp_vec_ogt_fast_fsub_const(<8 x float> %x, <8 x float> %y) {
1677+
; CHECK-LABEL: @fcmp_vec_ogt_fast_fsub_const(
15521678
; CHECK-NEXT: [[CMP:%.*]] = fcmp ogt <8 x float> [[X:%.*]], [[Y:%.*]]
15531679
; CHECK-NEXT: ret <8 x i1> [[CMP]]
15541680
;
@@ -1557,8 +1683,8 @@ define <8 x i1> @fcmp_vec_ogt_fm_fsub_const(<8 x float> %x, <8 x float> %y) {
15571683
ret <8 x i1> %cmp
15581684
}
15591685

1560-
define <8 x i1> @fcmp_vec_olt_fm_fsub_const(<8 x float> %x, <8 x float> %y) {
1561-
; CHECK-LABEL: @fcmp_vec_olt_fm_fsub_const(
1686+
define <8 x i1> @fcmp_vec_olt_fast_fsub_const(<8 x float> %x, <8 x float> %y) {
1687+
; CHECK-LABEL: @fcmp_vec_olt_fast_fsub_const(
15621688
; CHECK-NEXT: [[CMP:%.*]] = fcmp olt <8 x float> [[X:%.*]], [[Y:%.*]]
15631689
; CHECK-NEXT: ret <8 x i1> [[CMP]]
15641690
;
@@ -1567,8 +1693,8 @@ define <8 x i1> @fcmp_vec_olt_fm_fsub_const(<8 x float> %x, <8 x float> %y) {
15671693
ret <8 x i1> %cmp
15681694
}
15691695

1570-
define <8 x i1> @fcmp_vec_one_fm_fsub_const(<8 x float> %x, <8 x float> %y) {
1571-
; CHECK-LABEL: @fcmp_vec_one_fm_fsub_const(
1696+
define <8 x i1> @fcmp_vec_one_fast_fsub_const(<8 x float> %x, <8 x float> %y) {
1697+
; CHECK-LABEL: @fcmp_vec_one_fast_fsub_const(
15721698
; CHECK-NEXT: [[CMP:%.*]] = fcmp one <8 x float> [[X:%.*]], [[Y:%.*]]
15731699
; CHECK-NEXT: ret <8 x i1> [[CMP]]
15741700
;
@@ -1577,32 +1703,32 @@ define <8 x i1> @fcmp_vec_one_fm_fsub_const(<8 x float> %x, <8 x float> %y) {
15771703
ret <8 x i1> %cmp
15781704
}
15791705

1580-
define <8 x i1> @ffcmp_vec_ogt_fsub_const(<8 x float> %x, <8 x float> %y) {
1581-
; CHECK-LABEL: @ffcmp_vec_ogt_fsub_const(
1582-
; CHECK-NEXT: [[CMP:%.*]] = fcmp ogt <8 x float> [[X:%.*]], [[Y:%.*]]
1706+
define <8 x i1> @fcmp_vec_ugt_fast_fsub_const(<8 x float> %x, <8 x float> %y) {
1707+
; CHECK-LABEL: @fcmp_vec_ugt_fast_fsub_const(
1708+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ugt <8 x float> [[X:%.*]], [[Y:%.*]]
15831709
; CHECK-NEXT: ret <8 x i1> [[CMP]]
15841710
;
1585-
%fs = fsub <8 x float> %x, %y
1586-
%cmp = fcmp fast ogt <8 x float> %fs, zeroinitializer
1711+
%fs = fsub fast <8 x float> %x, %y
1712+
%cmp = fcmp ugt <8 x float> %fs, zeroinitializer
15871713
ret <8 x i1> %cmp
15881714
}
15891715

1590-
define <8 x i1> @ffcmp_vec_olt_fsub_const(<8 x float> %x, <8 x float> %y) {
1591-
; CHECK-LABEL: @ffcmp_vec_olt_fsub_const(
1592-
; CHECK-NEXT: [[CMP:%.*]] = fcmp olt <8 x float> [[X:%.*]], [[Y:%.*]]
1716+
define <8 x i1> @fcmp_vec_ult_fast_fsub_const(<8 x float> %x, <8 x float> %y) {
1717+
; CHECK-LABEL: @fcmp_vec_ult_fast_fsub_const(
1718+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ult <8 x float> [[X:%.*]], [[Y:%.*]]
15931719
; CHECK-NEXT: ret <8 x i1> [[CMP]]
15941720
;
1595-
%fs = fsub <8 x float> %x, %y
1596-
%cmp = fcmp fast olt <8 x float> %fs, zeroinitializer
1721+
%fs = fsub fast <8 x float> %x, %y
1722+
%cmp = fcmp ult <8 x float> %fs, zeroinitializer
15971723
ret <8 x i1> %cmp
15981724
}
15991725

1600-
define <8 x i1> @ffcmp_vec_one_fsub_const(<8 x float> %x, <8 x float> %y) {
1601-
; CHECK-LABEL: @ffcmp_vec_one_fsub_const(
1602-
; CHECK-NEXT: [[CMP:%.*]] = fcmp one <8 x float> [[X:%.*]], [[Y:%.*]]
1726+
define <8 x i1> @fcmp_vec_une_fast_fsub_const(<8 x float> %x, <8 x float> %y) {
1727+
; CHECK-LABEL: @fcmp_vec_une_fast_fsub_const(
1728+
; CHECK-NEXT: [[CMP:%.*]] = fcmp une <8 x float> [[X:%.*]], [[Y:%.*]]
16031729
; CHECK-NEXT: ret <8 x i1> [[CMP]]
16041730
;
1605-
%fs = fsub <8 x float> %x, %y
1606-
%cmp = fcmp fast one <8 x float> %fs, zeroinitializer
1731+
%fs = fsub fast <8 x float> %x, %y
1732+
%cmp = fcmp une <8 x float> %fs, zeroinitializer
16071733
ret <8 x i1> %cmp
16081734
}

0 commit comments

Comments
 (0)