[PATCH] D148230: ValueTracking: fadd +0 cannot return -0
Matt Arsenault via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 13 08:57:36 PDT 2023
arsenm added inline comments.
================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:4369
+ if (KnownRHS.KnownFPClasses == fcPosZero && Op->getOpcode() == Instruction::FAdd)
+ Known.knownNot(fcNegZero);
+
----------------
foad wrote:
> arsenm wrote:
> > kpn wrote:
> > > We're in the default FP environment here since we're looking at FAdd and FSub instructions. The check for FAdd isn't needed?
> > I was just copying from CannotBeNegativeZero but I guess we can improve on it at the same time
> As I understand it, with default rounding the only addition that can return -0 is -0 + -0. So if either operand is known not to be -0, the result cannot be -0. And the only subtraction that can return -0 is -0 - +0.
Checking what instcombine thinks,
```
define float @fsub_p0_p0(float %arg0) {
%sub = fsub float 0.0, 0.0
ret float %sub
}
define float @fsub_n0_n0(float %arg0) {
%sub = fsub float -0.0, -0.0
ret float %sub
}
define float @fsub_p0_n0(float %arg0) {
%sub = fsub float 0.0, -0.0
ret float %sub
}
define float @fsub_n0_p0(float %arg0) {
%sub = fsub float -0.0, 0.0
ret float %sub
}
```
```
define float @fsub_p0_p0(float %arg0) {
ret float 0.000000e+00
}
define float @fsub_n0_n0(float %arg0) {
ret float 0.000000e+00
}
define float @fsub_p0_n0(float %arg0) {
ret float 0.000000e+00
}
define float @fsub_n0_p0(float %arg0) {
ret float -0.000000e+00
}
```
The missing optimization we could do here is check if DAZ is enabled and also cover denormal inputs
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D148230/new/
https://reviews.llvm.org/D148230
More information about the llvm-commits
mailing list