This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Add isel pattern for (mul (and X, 0xffffffff), 3<<C) with Zba.
ClosedPublic

Authored by craig.topper on Jul 19 2022, 10:50 PM.

Details

Summary

We can use slli.uw by C followed by sh1add. Similar can be done
for multiples of 5 and 9. We need to make sure that C is less than
32 to stay in bounds of the 5-bit immediate for slli.uw.

We have existing patterns for (mul X, 3<<C) that use sh1add
followed by slli. That order doesn't allow the and to be folded.

Diff Detail

Event Timeline

craig.topper created this revision.Jul 19 2022, 10:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 19 2022, 10:50 PM
craig.topper requested review of this revision.Jul 19 2022, 10:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 19 2022, 10:50 PM

Rebase on pre-committed tests

reames accepted this revision.Jul 27 2022, 7:38 AM

LGTM - I really want to say there's a more generic way to handle this, but after a bit of thought, I don't have any specific suggestions. Given that, land this and we can generalize later if needed.

This revision is now accepted and ready to land.Jul 27 2022, 7:38 AM

Went and glanced at surrounding code again, a couple of thoughts for follow up.

There's a whole bunch of mul by constant patterns. It'd be really nice to sink the shift before those for e.g. 11 << 2 and variants.

Not sure how to write this, but the general form of this would be something like:
if (is interesting constant after shifting and not before) {

emit shift
match shifted constant pattern

}

Not sure how worthwhile this is, just thinking about generality of code structure.

This revision was landed with ongoing or failed builds.Jul 27 2022, 9:45 AM
This revision was automatically updated to reflect the committed changes.