This is an archive of the discontinued LLVM Phabricator instance.

[InstSimplify] folds for negation of sign-bit
ClosedPublic

Authored by spatel on Oct 19 2016, 12:05 PM.

Details

Summary

0 - X --> X, if X is 0 or the minimum signed value
0 - X --> 0, if X is 0 or the minimum signed value and the sub is NSW

I noticed this pattern might be created in the backend after the change from D25485, so if I haven't flubbed the logic, we'll want to add a similar fold for the DAG.

Diff Detail

Event Timeline

spatel updated this revision to Diff 75187.Oct 19 2016, 12:05 PM
spatel retitled this revision from to [InstSimplify] folds for negation of sign-bit.
spatel updated this object.
spatel added reviewers: efriedma, sanjoy, majnemer.
spatel added a subscriber: llvm-commits.
efriedma accepted this revision.Oct 19 2016, 1:28 PM
efriedma edited edge metadata.

LGTM.

lib/Analysis/InstructionSimplify.cpp
692

I'm sort of concerned that calling computeKnownBits here could lead to compile-time performance problems, given that instsimplify is supposed to be inexpensive, and the condition is very unlikely to succeed in most code. I don't have any evidence it's actually an issue, though; maybe computeKnownBits is cheap enough that it doesn't matter.

This revision is now accepted and ready to land.Oct 19 2016, 1:28 PM
spatel added inline comments.Oct 19 2016, 1:56 PM
lib/Analysis/InstructionSimplify.cpp
692

Yes, I wasn't sure about doing a specific match for 'and' or 'shl' instead. I saw that we are using computeKnownBits in other places in this file though, so I thought it would be ok.

It's probably fine, but something to watch out for in the future if someone ever spends some time digging into instcombine/instsimplify compile-time.

This revision was automatically updated to reflect the committed changes.