This is an archive of the discontinued LLVM Phabricator instance.

[AArch64][GlobalISel] Port some AArch64 target specific MUL combines from SDAG.
ClosedPublic

Authored by aemerson on Nov 9 2020, 10:01 PM.

Details

Summary

These do things like turn a multiply of a pow-2+1 into a shift and and add, which is a common pattern that pops up, and is universally better than expensive madd instructions with a constant.

I've added check lines to an existing codegen test since the code being ported is almost identical, however the mul by negative pow2 constant tests don't generate the same code because we're missing some generic G_MUL combines still.

Diff Detail

Event Timeline

aemerson created this revision.Nov 9 2020, 10:01 PM
aemerson requested review of this revision.Nov 9 2020, 10:01 PM
paquette added inline comments.Nov 10 2020, 9:07 AM
llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp
110

Should this include G_SEXT_INREG and G_SEXTLOAD as well?

115

Should this include G_ZEXTLOAD as well?

157

Should this be conservative around G_ICMP as well? It can be selected using SUBS/ADDS.

225

Remove?

aemerson added inline comments.Nov 10 2020, 11:06 AM
llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp
110

Maybe the inreg, but I don't think the extload should be included.

157

Can a G_MUL be folded into an icmp?

225

This should probably actually be the copy, since we shouldn't be modifying an instruction without notifying the observer.

aemerson updated this revision to Diff 304264.Nov 10 2020, 11:16 AM

Check for SEXT_INREG and use copy instead of modifying operand reg.

paquette added inline comments.Nov 10 2020, 11:28 AM
llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp
157

Oh, I guess not. There's no flag-setting variant of mul, so that wouldn't make sense. So it's fine, I think.

225

I guess ApplyFn could take in the observer as an argument, or appleAArch64MulConstCombine could notify the observer around the call?

This revision is now accepted and ready to land.Nov 10 2020, 1:31 PM
aemerson added inline comments.Nov 10 2020, 2:42 PM
llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp
225

Yeah. It’s a bit annoying that we have to pass all this into each match/apply.

This revision was landed with ongoing or failed builds.Nov 10 2020, 10:21 PM
This revision was automatically updated to reflect the committed changes.