This is an archive of the discontinued LLVM Phabricator instance.

[SystemZ] Recognize RISBG opportunities involving a truncate
ClosedPublic

Authored by RolandF on Jun 16 2016, 3:48 PM.

Details

Summary

Recognize RISBG opportunities where the end result is narrower than the original input - where a truncate separates the shift/and operations.

The motivating case is some code in postgres which looks like:

srlg %r2, %r0, 11
nilh %r2, 255

Diff Detail

Repository
rL LLVM

Event Timeline

RolandF updated this revision to Diff 61046.Jun 16 2016, 3:48 PM
RolandF retitled this revision from to Recognize narrowing RISBG opportunities.
RolandF updated this object.
RolandF retitled this revision from Recognize narrowing RISBG opportunities to [SystemZ] Recognize RISBG opportunities involving a truncate.Jun 17 2016, 8:13 AM
RolandF updated this object.
RolandF added a reviewer: uweigand.
uweigand edited edge metadata.Jun 17 2016, 9:03 AM

Please also update the comment before "struct RxSBGOperands", where it explains:

The output value has BitSize bits, although Input may be
narrower (in which case the upper bits are don't care).

to now also include the possibility that Input is wider than BitSize bits.

Finally, please extend the test cases in test/CodeGen/SystemZ/r?sbg-*.ll to also cover this case (both good cases where a truncation can be eliminated, and bad cases where it cannot).

Thanks for working on improving the SystemZ back end!

lib/Target/SystemZ/SystemZISelDAGToDAG.cpp
748 ↗(On Diff #61046)

I think we need the same guard against RNSBG here that we have in the AND case.

928 ↗(On Diff #61046)

Can you explain why you think this is needed? (And if it is indeed needed here, why not below in tryRxSBG?)

RolandF updated this revision to Diff 61435.Jun 21 2016, 1:28 PM
RolandF edited edge metadata.

Added tests.
Added check for RNSBG.
Added TRUNCATE profitability check to tryRxSBG.
Added comment to TRUNCATE profitability check.
Updated comment on struct RxSBGOperands.

RolandF marked an inline comment as done.Jun 21 2016, 1:31 PM
RolandF added inline comments.
lib/Target/SystemZ/SystemZISelDAGToDAG.cpp
928 ↗(On Diff #61046)

The existing approach is to prefer a simple and/shift/rotate operation over an R*SBG operation if it will do the same job. Since there are both 32-bit and 64-bit ands/shifts/rotates, truncation is typically free. Counting truncation as an operation for the profitability check will result in preferring an R*SBG operation over its simple equivalent. I can add a comment.

And yes, I missed the check in tryRxSBG. It should check for truncate there as well.

uweigand accepted this revision.Jun 22 2016, 1:43 AM
uweigand edited edge metadata.

LGTM, thanks!

This revision is now accepted and ready to land.Jun 22 2016, 1:43 AM
This revision was automatically updated to reflect the committed changes.