This is an archive of the discontinued LLVM Phabricator instance.

[SelectionDAG] Initial support for FSHL/FSHR funnel shift opcodes (PR39467)
ClosedPublic

Authored by RKSimon on Nov 19 2018, 6:54 AM.

Details

Summary

This is an initial patch to add a minimum level of support for funnel shifts to the SelectionDAG and to begin wiring it up to the X86 SHLD/SHRD instructions.

Some partial legalization code has been added to handle the case for 'SlowSHLD' where we want to expand instead and I've added a few DAG combines so we don't get regressions from the existing DAG builder expansion code.

Diff Detail

Repository
rL LLVM

Event Timeline

RKSimon created this revision.Nov 19 2018, 6:54 AM
lebedev.ri added inline comments.
lib/CodeGen/SelectionDAG/TargetLowering.cpp
4131

dl -> DL

nikic added inline comments.Nov 19 2018, 7:24 AM
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
6957

Similar to what the DAG builder code does, would it make sense to also check for the reverse direction rotate here?

lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
5744

Would it be possible to unconditionally create FSHL/FSHR here, drop the expansion code below and rely on the expansion in DAG legalization only?

RKSimon added inline comments.Nov 19 2018, 7:54 AM
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
6957

Makes sense - always (and a SUB) or just for constant shift amounts?

lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
5744

At least not until all the legalization + promotion code is in place - I'd prefer to do that in future patches.

nikic added inline comments.Nov 20 2018, 5:48 AM
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
6957

Hard to say. If say FSHL is legal, but ROTL is not, but ROTR is, then it probably does not make sense to convert a legal FSHL to SUB, ROTR. Though that situation seems rather contrived.

Maybe it's best to wait with this transformation until it becomes necessary (if/when FSH is built directly.)

RKSimon updated this revision to Diff 176404.Dec 3 2018, 7:48 AM

Added TODO for fshl/fshr -> rotl/rotr combines

RKSimon marked an inline comment as done.Dec 3 2018, 7:50 AM

Any more comments?

lib/CodeGen/SelectionDAG/DAGCombiner.cpp
6957

I've added a TODO comment for now

I just see a few inline nits. Adding Fabian in case he has any feedback.

lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
1170

I realize this comment is copied, but it wasn't really adding value the first 3 times we said it either. :)

test/CodeGen/X86/funnel-shift.ll
17

Update test comment - no mask/cmov needed.

207

Update test comment - no mask/cmov needed.

340

Update test comment? Do you know why we got opposite directions here?

RKSimon added inline comments.Dec 4 2018, 12:10 AM
test/CodeGen/X86/funnel-shift.ll
340

It looks like the shldl is commuted during regalloc.

RKSimon updated this revision to Diff 176612.Dec 4 2018, 5:53 AM

Addressed @spatel's comments

RKSimon marked 4 inline comments as done.Dec 4 2018, 5:55 AM
RKSimon added inline comments.
lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
1170

I agree its superfluous - I've removed this from all the VectorLegalizer cases in the patch. Naturally I'd commit is as NFC pre-commit.

Don't know if there are missing pieces, but the existing pieces look good.

spatel accepted this revision.Dec 4 2018, 9:42 AM

LGTM. We can handle any of the TODO items as follow-ups.

This revision is now accepted and ready to land.Dec 4 2018, 9:42 AM
This revision was automatically updated to reflect the committed changes.
foad added a subscriber: foad.Mar 31 2020, 10:03 AM
foad added inline comments.
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
5744

I've tried to do this in D77152.