This is an archive of the discontinued LLVM Phabricator instance.

[X86][AVX] Fold loads + splats into broadcast instructions
ClosedPublic

Authored by RKSimon on Dec 7 2015, 2:46 PM.

Details

Summary

On AVX and AVX2, BROADCAST instructions can load a scalar into all elements of a target vector.

This patch improves the lowering of 'splat' shuffles of a loaded vector into a broadcast - currently the lowering only works for cases where we are splatting the zero'th element, which is now generalised to any element.

Fix for PR23022

Diff Detail

Repository
rL LLVM

Event Timeline

RKSimon updated this revision to Diff 42111.Dec 7 2015, 2:46 PM
RKSimon retitled this revision from to [X86][AVX] Fold loads + splats into broadcast instructions.
RKSimon updated this object.
RKSimon added reviewers: qcolombet, spatel, andreadb.
RKSimon set the repository for this revision to rL LLVM.
RKSimon added a subscriber: llvm-commits.
andreadb accepted this revision.Dec 8 2015, 4:51 AM
andreadb edited edge metadata.

Hi Simon,

the patch looks good to me. Thanks!

-Andrea

This revision is now accepted and ready to land.Dec 8 2015, 4:51 AM
spatel added inline comments.Dec 8 2015, 8:46 AM
lib/Target/X86/X86ISelLowering.cpp
8109 ↗(On Diff #42111)

I don't know if this is even possible in practice: do we need to guard against volatile loads since the transform is shrinking the size of the load?

MayFoldLoad() calls isNormalLoad(), but neither of those check volatility, so if this fires on a volatile load, it looks like we get the original load and a splat load:

vmovaps	(%rdi), %ymm0
vbroadcastsd	16(%rdi), %ymm0
RKSimon added inline comments.Dec 8 2015, 9:26 AM
lib/Target/X86/X86ISelLowering.cpp
8109 ↗(On Diff #42111)

We do something similar in LowerAsSplatVectorLoad - so I'll add a !Ld->isVolatile() check.

This revision was automatically updated to reflect the committed changes.