This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Remove nnan requirement for transformation to fabs from select
ClosedPublic

Authored by Krishnakariya on Jul 27 2021, 6:22 AM.

Details

Summary

In this patch, the "nnan" requirement is removed for the canonicalization of select with fcmp to fabs.
(i) FSub logic: Remove check for nnan flag presence in fsub. Example: https://alive2.llvm.org/ce/z/751svg (fsub).
(ii) FNeg logic: Remove check for the presence of nnan and nsz flag in fneg. Example: https://alive2.llvm.org/ce/z/a_fsdp (fneg).

Diff Detail

Event Timeline

Krishnakariya created this revision.Jul 27 2021, 6:22 AM
Krishnakariya requested review of this revision.Jul 27 2021, 6:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 27 2021, 6:22 AM

It would be good to mention in the description *why* this is being done, why this is okay (alive2 link would suffice)

Krishnakariya edited the summary of this revision. (Show Details)Jul 27 2021, 6:38 AM

It would be good to mention in the description *why* this is being done, why this is okay (alive2 link would suffice)

Sure, I have updated the description.

This was discussed as a follow-up for D101727.
I originally added the nnan check to these transforms to be extra safe (and so watch for potential fallout on out-of-tree targets), but it's not necessary in the default LLVM FP environment to preserve exact bits of a nnan.
Ie, the sign of nnan will always be cleared by fabs, but not in the original code.

I'm not sure what the tests are showing. I would expect there to be 4 tests corresponding to each code change with no nnan that are now getting transformed?
Please pre-commit all tests with baseline CHECKs as a preliminary patch (no review is needed for that).
If you do not have commit access, now is a good time to request it. :)
https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access

Added new tests

Added new tests

That looks fine - please commit the tests to main, so we'll just have test *diffs* in this patch.
You do not need to open a new Phab review for the tests only.
Just push an NFC patch to main once you get commit access.

Updated diff after pre-committing tests.

This revision was not accepted when it landed; it landed in state Needs Review.Aug 3 2021, 5:23 AM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.

I committed this patch by mistake. I am extremely sorry about this.
I've reverted the commit.

I committed this patch by mistake. I am extremely sorry about this.
I've reverted the commit.

FWIW reading through the disscussion i would think this has been basically accepted, if not stamped yet for formal reasons of wanting the tests to be precommitted.

I committed this patch by mistake. I am extremely sorry about this.
I've reverted the commit.

FWIW reading through the disscussion i would think this has been basically accepted, if not stamped yet for formal reasons of wanting the tests to be precommitted.

I have pre-committed the tests and updated the diff. Commit link: https://reviews.llvm.org/rG56e7b6c3924d7ba8db70c38235a77ed8208795eb .

spatel reopened this revision.Aug 6 2021, 2:51 PM

I was out for a few days, so I missed the last few comments. IIUC, the patch was reverted, so I'll re-open the review, mark as accepted, and then you can commit cleanly.

spatel accepted this revision.Aug 6 2021, 2:51 PM

LGTM

This revision is now accepted and ready to land.Aug 6 2021, 2:51 PM

Updating the same diff to commit this patch.

nick added a subscriber: nick.Aug 8 2021, 2:33 PM
nick added inline comments.
llvm/test/Transforms/InstCombine/fabs.ll
252–253

The comment had not been updated and is wrong now.

Krishnakariya added inline comments.Aug 9 2021, 10:29 AM
llvm/test/Transforms/InstCombine/fabs.ll
252–253

Ohh, thanks for finding it out! I am removing this comment.