This is an archive of the discontinued LLVM Phabricator instance.

[X86][SSE] Add support for target shuffle constant folding
ClosedPublic

Authored by RKSimon on Nov 29 2016, 11:10 AM.

Details

Summary

Initial support for target shuffle constant folding in cases where all shuffle inputs are constant. We may be able to relax this and merge shuffles with only some constant inputs in the future.

I've added the helper function getTargetConstantBitsFromNode (based off a similar function in X86ShuffleDecodeConstantPool.cpp) that could be reused for other cases requiring constant vector extraction.

Diff Detail

Repository
rL LLVM

Event Timeline

RKSimon updated this revision to Diff 79608.Nov 29 2016, 11:10 AM
RKSimon retitled this revision from to [X86][SSE] Add support for target shuffle constant folding.
RKSimon updated this object.
RKSimon set the repository for this revision to rL LLVM.
RKSimon added a subscriber: llvm-commits.
zvi added inline comments.Nov 30 2016, 2:29 AM
lib/Target/X86/X86ISelLowering.cpp
5073 ↗(On Diff #79608)

Consider reducing the negations to something like:
(!(COp && (isa<UndefValue>(COp) || isa<ConstantInt>(COp) ||

isa<ConstantFP>(COp))))
5084 ↗(On Diff #79608)

Consider using dyn_cast for these two if's

26414 ↗(On Diff #79608)

I'm asking for educational reasons and not because I don't agree with this:
Why is if at least one constant is used once (and not all or none) is the combine profitable?

RKSimon updated this revision to Diff 79731.Nov 30 2016, 6:42 AM

Updated based on Zvi's feedback.

RKSimon marked 2 inline comments as done.Nov 30 2016, 6:47 AM
RKSimon added inline comments.
lib/Target/X86/X86ISelLowering.cpp
26414 ↗(On Diff #79608)

It's an attempt to avoid introducing extra constant vectors - if any are only used once then we're at worse just replacing one vector with another. Similarly if we'd used a variable mask shuffle then we'll be at worse replacing that. Otherwise we're making the assumption that a few extra basic shuffles is a price worth paying for avoiding extra constant pool vector loads.

zvi accepted this revision.Nov 30 2016, 8:09 AM
zvi edited edge metadata.

LGTM

lib/Target/X86/X86ISelLowering.cpp
26414 ↗(On Diff #79608)

Thanks, that makes sense.

This revision is now accepted and ready to land.Nov 30 2016, 8:09 AM
This revision was automatically updated to reflect the committed changes.