Skip to content

Commit a5d953d

Browse files
committed
Add and update tests for any fp zero
1 parent dd50785 commit a5d953d

File tree

2 files changed

+82
-4
lines changed

2 files changed

+82
-4
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8046,6 +8046,7 @@ Instruction *InstCombinerImpl::visitFCmpInst(FCmpInst &I) {
80468046
if (match(Op0, m_Instruction(LHSI)) && match(Op1, m_Constant(RHSC))) {
80478047
switch (LHSI->getOpcode()) {
80488048
case Instruction::Select:
8049+
// fcmp eq (cond ? x : -x), 0 --> fcmp eq x, 0
80498050
if (FCmpInst::isEquality(Pred) && match(RHSC, m_AnyZeroFP()) &&
80508051
(match(LHSI,
80518052
m_Select(m_Value(), m_Value(X), m_FNeg(m_Deferred(X)))) ||

llvm/test/Transforms/InstCombine/fcmp.ll

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,13 +1631,90 @@ define <8 x i1> @fcmp_one_sel_x_negx_vec(<8 x float> %x) {
16311631
ret <8 x i1> %res
16321632
}
16331633

1634-
define i1 @fcmp_sel_x_negx_with_any_cond(float %x, i1 %c) {
1635-
; CHECK-LABEL: @fcmp_sel_x_negx_with_any_cond(
1636-
; CHECK-NEXT: [[RES:%.*]] = fcmp ueq float [[X:%.*]], 0.000000e+00
1634+
define <2 x i1> @fcmp_oeq_sel_x_negx_with_any_fpzero_vec(<2 x i1> %cond, <2 x float> %x) {
1635+
; CHECK-LABEL: @fcmp_oeq_sel_x_negx_with_any_fpzero_vec(
1636+
; CHECK-NEXT: [[ICMP:%.*]] = fcmp oeq <2 x float> [[X:%.*]], zeroinitializer
1637+
; CHECK-NEXT: ret <2 x i1> [[ICMP]]
1638+
;
1639+
%fneg = fneg <2 x float> %x
1640+
%sel = select <2 x i1> %cond, <2 x float> %x, <2 x float> %fneg
1641+
%icmp = fcmp oeq <2 x float> %sel, <float 0.0, float -0.0>
1642+
ret <2 x i1> %icmp
1643+
}
1644+
1645+
define <2 x i1> @fcmp_one_sel_x_negx_with_any_fpzero_vec(<2 x i1> %cond, <2 x float> %x) {
1646+
; CHECK-LABEL: @fcmp_one_sel_x_negx_with_any_fpzero_vec(
1647+
; CHECK-NEXT: [[ICMP:%.*]] = fcmp one <2 x float> [[X:%.*]], zeroinitializer
1648+
; CHECK-NEXT: ret <2 x i1> [[ICMP]]
1649+
;
1650+
%fneg = fneg <2 x float> %x
1651+
%sel = select <2 x i1> %cond, <2 x float> %x, <2 x float> %fneg
1652+
%icmp = fcmp one <2 x float> %sel, <float 0.0, float -0.0>
1653+
ret <2 x i1> %icmp
1654+
}
1655+
1656+
define <2 x i1> @fcmp_ueq_sel_x_negx_with_any_fpzero_vec(<2 x i1> %cond, <2 x float> %x) {
1657+
; CHECK-LABEL: @fcmp_ueq_sel_x_negx_with_any_fpzero_vec(
1658+
; CHECK-NEXT: [[ICMP:%.*]] = fcmp ueq <2 x float> [[X:%.*]], zeroinitializer
1659+
; CHECK-NEXT: ret <2 x i1> [[ICMP]]
1660+
;
1661+
%fneg = fneg <2 x float> %x
1662+
%sel = select <2 x i1> %cond, <2 x float> %x, <2 x float> %fneg
1663+
%icmp = fcmp ueq <2 x float> %sel, <float 0.0, float -0.0>
1664+
ret <2 x i1> %icmp
1665+
}
1666+
1667+
define <2 x i1> @fcmp_une_sel_x_negx_with_any_fpzero_vec(<2 x i1> %cond, <2 x float> %x) {
1668+
; CHECK-LABEL: @fcmp_une_sel_x_negx_with_any_fpzero_vec(
1669+
; CHECK-NEXT: [[ICMP:%.*]] = fcmp une <2 x float> [[X:%.*]], zeroinitializer
1670+
; CHECK-NEXT: ret <2 x i1> [[ICMP]]
1671+
;
1672+
%fneg = fneg <2 x float> %x
1673+
%sel = select <2 x i1> %cond, <2 x float> %x, <2 x float> %fneg
1674+
%icmp = fcmp une <2 x float> %sel, <float 0.0, float -0.0>
1675+
ret <2 x i1> %icmp
1676+
}
1677+
1678+
define i1 @fcmp_ueq_sel_x_negx_with_fmf(float %x, i1 %c) {
1679+
; CHECK-LABEL: @fcmp_ueq_sel_x_negx_with_fmf(
1680+
; CHECK-NEXT: [[RES:%.*]] = fcmp fast ueq float [[X:%.*]], 0.000000e+00
16371681
; CHECK-NEXT: ret i1 [[RES]]
16381682
;
16391683
%neg = fneg float %x
16401684
%sel = select i1 %c, float %x, float %neg
1641-
%res = fcmp ueq float %sel, 0.000000e+00
1685+
%res = fcmp fast ueq float %sel, 0.000000e+00
1686+
ret i1 %res
1687+
}
1688+
1689+
define i1 @fcmp_une_sel_x_negx_with_fmf(float %x, i1 %c) {
1690+
; CHECK-LABEL: @fcmp_une_sel_x_negx_with_fmf(
1691+
; CHECK-NEXT: [[RES:%.*]] = fcmp fast une float [[X:%.*]], 0.000000e+00
1692+
; CHECK-NEXT: ret i1 [[RES]]
1693+
;
1694+
%neg = fneg float %x
1695+
%sel = select i1 %c, float %x, float %neg
1696+
%res = fcmp fast une float %sel, 0.000000e+00
1697+
ret i1 %res
1698+
}
1699+
1700+
define i1 @fcmp_oeq_sel_x_negx_with_fmf(float %x, i1 %c) {
1701+
; CHECK-LABEL: @fcmp_oeq_sel_x_negx_with_fmf(
1702+
; CHECK-NEXT: [[RES:%.*]] = fcmp fast oeq float [[X:%.*]], 0.000000e+00
1703+
; CHECK-NEXT: ret i1 [[RES]]
1704+
;
1705+
%neg = fneg float %x
1706+
%sel = select i1 %c, float %x, float %neg
1707+
%res = fcmp fast oeq float %sel, 0.000000e+00
1708+
ret i1 %res
1709+
}
1710+
1711+
define i1 @fcmp_one_sel_x_negx_with_fmf(float %x, i1 %c) {
1712+
; CHECK-LABEL: @fcmp_one_sel_x_negx_with_fmf(
1713+
; CHECK-NEXT: [[RES:%.*]] = fcmp fast one float [[X:%.*]], 0.000000e+00
1714+
; CHECK-NEXT: ret i1 [[RES]]
1715+
;
1716+
%neg = fneg float %x
1717+
%sel = select i1 %c, float %x, float %neg
1718+
%res = fcmp fast one float %sel, 0.000000e+00
16421719
ret i1 %res
16431720
}

0 commit comments

Comments
 (0)