This is an archive of the discontinued LLVM Phabricator instance.

[Sparc] Use ANDN instead of AND if constant can be encoded more efficiently
ClosedPublic

Authored by dcederman on Aug 20 2018, 3:43 AM.

Details

Summary

In the case of (and reg, constant) or (or reg, constant), it can be beneficial to use a ANDNrr/ORNrr instruction instead of ANDrr/ORrr, if the complement of the constant can be encoded using a single SETHI instruction instead of a SETHI/ORri pair.

If the constant has more than one use, it is probably better to keep it in its original form.

Diff Detail

Event Timeline

dcederman created this revision.Aug 20 2018, 3:43 AM
jyknight accepted this revision.Aug 26 2018, 9:17 AM

Seems unclear to me that the "more than one use" bit is the right assumption. But sure, let's go with that for now.

lib/Target/Sparc/SparcInstrInfo.td
103

Please add the rationale for "N->hasOneUse()" in a comment here, not just in commit message.

This revision is now accepted and ready to land.Aug 26 2018, 9:17 AM

When I was testing the code I saw that it sometimes generated two versions of the same constant, one with the single SETHI with the complement form, and one with the standard SETHI/ORri pair. So I added the hasOneUse() part to prevent the case when a constant is encoded using three instructions instead of just one or two.

This revision was automatically updated to reflect the committed changes.