This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] look through bswaps for equality comparisons
ClosedPublic

Authored by spatel on Jun 28 2017, 10:06 AM.

Details

Summary

I noticed this missed optimization in the CGP memcmp() expansion, and then saw that we don't have the fold in InstCombine.

It wasn't immediately clear to me that a vector bswap swaps the bytes of each element in the vector while leaving the elements in place. Should I add a blurb about that in the LangRef?

Diff Detail

Event Timeline

spatel created this revision.Jun 28 2017, 10:06 AM
RKSimon edited edge metadata.EditedJun 28 2017, 10:27 AM

You should be able to do the same for bitreverse as well.

Worth handling the cmp( bswap(x), constant ) -> cmp( x, bswap(constant) ) case as well?

spatel updated this revision to Diff 104496.Jun 28 2017, 1:15 PM

Patch updated:

  1. Added bitreverse transform since that's a close relative.
  2. I made the constant operand matcher a TODO for now since I don't have evidence of it.

Interesting side note: we probably don't want to make this change in the memcmp expansion yet because we produce worse (sometimes substantially worse) code for both PPC and x86 with this transform. Ie, we fail to use a byte-reversing memory instruction, and/or we have more register usage and several extra instructions because of that.

RKSimon accepted this revision.Jun 29 2017, 2:27 AM

LGTM, I think updating the langref to explain that bswap/bitreverse apply within each vector element (and not across them) is a good idea.

This revision is now accepted and ready to land.Jun 29 2017, 2:27 AM
spatel closed this revision.Jul 3 2017, 5:54 AM

This was closed with rL306980 (Phab was dead when that commit was made).