This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Handle -(X-Y) --> (Y-X) for unary fneg when NSZ
ClosedPublic

Authored by cameron.mcinally on May 29 2019, 10:33 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptMay 29 2019, 10:33 AM

@jyknight

I'd be open to opinions on if this optimization should be throttled for NaNs too. My understanding is that IEEE-754 does not specify the sign of NaN results for FSub, so it doesn't matter if an FNeg is performed on the result or not.

That said, in practice, whether this combine is performed or not could change the sign of a NaN....

spatel accepted this revision.Jun 10 2019, 2:48 PM

This matches the existing fold with 2 fsubs, and I agree with the comment in the description regarding IEEE-754 - fsub doesn't need to preserve the sign bit of a NaN. LGTM.

This revision is now accepted and ready to land.Jun 10 2019, 2:48 PM
This revision was automatically updated to reflect the committed changes.