This is an archive of the discontinued LLVM Phabricator instance.

[InstSimplify] Use commutable matchers to shorten some code
ClosedPublic

Authored by craig.topper on May 25 2017, 10:26 PM.

Details

Summary

This code was replicated two additional times to handle commuted cases, but I think a commutable matcher can take care of it.

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.May 25 2017, 10:26 PM
spatel edited edge metadata.May 26 2017, 9:36 AM

Looks like good clean-up, but we only have 2 existing tests for these folds. There should be 4 commuted variants?

It's an independent change, but if we used m_APInt here, the code would be cleaner still and automatically work with splat vectors. You could make the additional commuted tests use vector types to serve double-duty if you want to add coverage for both of those changes.

Side note regarding commutation: just above here, simplifyAndOrOfICmps() calls simplifyPossiblyCastedAndOrOfICmps() with the params swapped to handle commutation, but some of the folds under there (ConstantRange checks at least) don't need to be commuted. Barring an inlining and analysis miracle, we're probably doing extra work for no reason on those, so untangling that would save compile-time.

So should I do the m_APInt change first so I can plug the commuted test hole with the vector tests?

Also should the matcher for the ands be commutable too?

Also should the matcher for the ands be commutable too?

If we can make that work too, that would be great. :)
I don't have a preference about whether we change this in one step or more. Whatever seems easier to you. As long as we have at least a couple more tests, we should be sure that it all works as expected.

Rebase on top of the patch to use m_APInt

spatel accepted this revision.May 26 2017, 11:11 AM

LGTM.

This revision is now accepted and ready to land.May 26 2017, 11:11 AM
This revision was automatically updated to reflect the committed changes.