This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Fold or(zext(bswap(x)),shl(zext(bswap(y)),bw/2)) -> bswap(or(zext(x),shl(zext(y), bw/2))
ClosedPublic

Authored by RKSimon on Apr 28 2020, 2:06 PM.

Details

Summary

This adds a general combine that can be used to fold:

or(zext(OP(x)), shl(zext(OP(y)),bw/2))
-->
OP(or(zext(x), shl(zext(y),bw/2)))

Allowing us to widen 'concat-able' style or+zext patterns - I've just set this up for BSWAP but we could use this for other similar ops (BITREVERSE for instance).

We already do something similar for binop(bswap(x),bswap(y)) --> bswap(binop(x,y))

Fixes PR45715

Diff Detail

Event Timeline

RKSimon created this revision.Apr 28 2020, 2:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 28 2020, 2:06 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
lebedev.ri accepted this revision.May 1 2020, 11:38 PM

This looks good to me, but i'm not sure this will work more generally.
I.e., i will be surprized if the or tree reaches us in the proper form,
without reassociation into some other form we aren't expecting.
Especially for larger tree depths.

This revision is now accepted and ready to land.May 1 2020, 11:38 PM
This revision was automatically updated to reflect the committed changes.