Skip to content

Commit 239fb20

Browse files
committed
InstSimplify: Add baseline tests for reported regression
Missed a fold after ddb3f12
1 parent 1ae1d77 commit 239fb20

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed

llvm/test/Transforms/InstSimplify/floating-point-compare.ll

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,6 +1544,122 @@ entry:
15441544
ret i1 %one
15451545
}
15461546

1547+
; Make sure we recognize fcmp < 0 is recognized as impossible here when simplifying the fcmp
1548+
define float @fast_square_must_be_positive_ieee(float %arg, float %arg1) {
1549+
; CHECK-LABEL: @fast_square_must_be_positive_ieee(
1550+
; CHECK-NEXT: bb:
1551+
; CHECK-NEXT: [[I:%.*]] = fmul float [[ARG:%.*]], [[ARG]]
1552+
; CHECK-NEXT: [[I2:%.*]] = fmul float [[ARG1:%.*]], [[ARG1]]
1553+
; CHECK-NEXT: [[I3:%.*]] = fadd float [[I2]], [[I]]
1554+
; CHECK-NEXT: ret float [[I3]]
1555+
;
1556+
bb:
1557+
%i = fmul float %arg, %arg
1558+
%i2 = fmul float %arg1, %arg1
1559+
%i3 = fadd float %i2, %i
1560+
%i4 = fcmp olt float %i3, 0.000000e+00
1561+
%i5 = select i1 %i4, float 0.000000e+00, float %i3
1562+
ret float %i5
1563+
}
1564+
1565+
; Make sure we recognize fcmp < 0 is recognized as impossible here when simplifying the fcmp
1566+
define float @fast_square_must_be_positive_ieee_nnan(float %arg, float %arg1) {
1567+
; CHECK-LABEL: @fast_square_must_be_positive_ieee_nnan(
1568+
; CHECK-NEXT: bb:
1569+
; CHECK-NEXT: [[I:%.*]] = fmul float [[ARG:%.*]], [[ARG]]
1570+
; CHECK-NEXT: [[I2:%.*]] = fmul float [[ARG1:%.*]], [[ARG1]]
1571+
; CHECK-NEXT: [[I3:%.*]] = fadd float [[I2]], [[I]]
1572+
; CHECK-NEXT: ret float [[I3]]
1573+
;
1574+
bb:
1575+
%i = fmul float %arg, %arg
1576+
%i2 = fmul float %arg1, %arg1
1577+
%i3 = fadd float %i2, %i
1578+
%i4 = fcmp nnan olt float %i3, 0.000000e+00
1579+
%i5 = select i1 %i4, float 0.000000e+00, float %i3
1580+
ret float %i5
1581+
}
1582+
1583+
; Make sure we recognize fcmp < 0 is recognized as impossible here when simplifying the fcmp
1584+
define float @fast_square_must_be_positive_daz(float %arg, float %arg1) #0 {
1585+
; CHECK-LABEL: @fast_square_must_be_positive_daz(
1586+
; CHECK-NEXT: bb:
1587+
; CHECK-NEXT: [[I:%.*]] = fmul float [[ARG:%.*]], [[ARG]]
1588+
; CHECK-NEXT: [[I2:%.*]] = fmul float [[ARG1:%.*]], [[ARG1]]
1589+
; CHECK-NEXT: [[I3:%.*]] = fadd float [[I2]], [[I]]
1590+
; CHECK-NEXT: [[I4:%.*]] = fcmp olt float [[I3]], 0.000000e+00
1591+
; CHECK-NEXT: [[I5:%.*]] = select i1 [[I4]], float 0.000000e+00, float [[I3]]
1592+
; CHECK-NEXT: ret float [[I5]]
1593+
;
1594+
bb:
1595+
%i = fmul float %arg, %arg
1596+
%i2 = fmul float %arg1, %arg1
1597+
%i3 = fadd float %i2, %i
1598+
%i4 = fcmp olt float %i3, 0.000000e+00
1599+
%i5 = select i1 %i4, float 0.000000e+00, float %i3
1600+
ret float %i5
1601+
}
1602+
1603+
; Make sure we recognize fcmp < 0 is recognized as impossible here when simplifying the fcmp
1604+
define float @fast_square_must_be_positive_daz_nnan(float %arg, float %arg1) #0 {
1605+
; CHECK-LABEL: @fast_square_must_be_positive_daz_nnan(
1606+
; CHECK-NEXT: bb:
1607+
; CHECK-NEXT: [[I:%.*]] = fmul float [[ARG:%.*]], [[ARG]]
1608+
; CHECK-NEXT: [[I2:%.*]] = fmul float [[ARG1:%.*]], [[ARG1]]
1609+
; CHECK-NEXT: [[I3:%.*]] = fadd float [[I2]], [[I]]
1610+
; CHECK-NEXT: [[I4:%.*]] = fcmp nnan olt float [[I3]], 0.000000e+00
1611+
; CHECK-NEXT: [[I5:%.*]] = select i1 [[I4]], float 0.000000e+00, float [[I3]]
1612+
; CHECK-NEXT: ret float [[I5]]
1613+
;
1614+
bb:
1615+
%i = fmul float %arg, %arg
1616+
%i2 = fmul float %arg1, %arg1
1617+
%i3 = fadd float %i2, %i
1618+
%i4 = fcmp nnan olt float %i3, 0.000000e+00
1619+
%i5 = select i1 %i4, float 0.000000e+00, float %i3
1620+
ret float %i5
1621+
}
1622+
1623+
; Make the compare to negative constant is folded out
1624+
define float @must_be_olt_negative_constant_daz(float %arg, float %arg1) #0 {
1625+
; CHECK-LABEL: @must_be_olt_negative_constant_daz(
1626+
; CHECK-NEXT: bb:
1627+
; CHECK-NEXT: [[I:%.*]] = fmul float [[ARG:%.*]], [[ARG]]
1628+
; CHECK-NEXT: [[I2:%.*]] = fmul float [[ARG1:%.*]], [[ARG1]]
1629+
; CHECK-NEXT: [[I3:%.*]] = fadd float [[I2]], [[I]]
1630+
; CHECK-NEXT: [[I4:%.*]] = fcmp olt float [[I3]], -1.000000e+00
1631+
; CHECK-NEXT: [[I5:%.*]] = select i1 [[I4]], float 0.000000e+00, float [[I3]]
1632+
; CHECK-NEXT: ret float [[I5]]
1633+
;
1634+
bb:
1635+
%i = fmul float %arg, %arg
1636+
%i2 = fmul float %arg1, %arg1
1637+
%i3 = fadd float %i2, %i
1638+
%i4 = fcmp olt float %i3, -1.0
1639+
%i5 = select i1 %i4, float 0.000000e+00, float %i3
1640+
ret float %i5
1641+
}
1642+
1643+
; Make the compare to negative constant is folded out
1644+
define float @must_be_olt_negative_constant_daz_nnan(float %arg, float %arg1) #0 {
1645+
; CHECK-LABEL: @must_be_olt_negative_constant_daz_nnan(
1646+
; CHECK-NEXT: bb:
1647+
; CHECK-NEXT: [[I:%.*]] = fmul float [[ARG:%.*]], [[ARG]]
1648+
; CHECK-NEXT: [[I2:%.*]] = fmul float [[ARG1:%.*]], [[ARG1]]
1649+
; CHECK-NEXT: [[I3:%.*]] = fadd float [[I2]], [[I]]
1650+
; CHECK-NEXT: [[I4:%.*]] = fcmp nnan olt float [[I3]], -1.000000e+00
1651+
; CHECK-NEXT: [[I5:%.*]] = select i1 [[I4]], float 0.000000e+00, float [[I3]]
1652+
; CHECK-NEXT: ret float [[I5]]
1653+
;
1654+
bb:
1655+
%i = fmul float %arg, %arg
1656+
%i2 = fmul float %arg1, %arg1
1657+
%i3 = fadd float %i2, %i
1658+
%i4 = fcmp nnan olt float %i3, -1.0
1659+
%i5 = select i1 %i4, float 0.000000e+00, float %i3
1660+
ret float %i5
1661+
}
1662+
15471663
declare <2 x double> @llvm.fabs.v2f64(<2 x double>)
15481664
declare <2 x float> @llvm.fabs.v2f32(<2 x float>)
15491665
declare <2 x float> @llvm.maxnum.v2f32(<2 x float>, <2 x float>)
@@ -1563,3 +1679,5 @@ declare double @llvm.sqrt.f64(double)
15631679
declare double @llvm.copysign.f64(double, double)
15641680
declare half @llvm.fabs.f16(half)
15651681
declare void @llvm.assume(i1 noundef)
1682+
1683+
attributes #0 = { "denormal-fp-math"="preserve-sign,preserve-sign" }

0 commit comments

Comments
 (0)