This is an archive of the discontinued LLVM Phabricator instance.

InstSimplify: Add a hook for shufflevector
ClosedPublic

Authored by zvi on Mar 31 2017, 1:14 AM.

Details

Summary

Add a hook for simplification of shufflevector's with the following rules:

  • Constant folding - NFC, as it was already being done by the default handler.
  • If only one of the operands is constant, constant fold the shuffle if the mask does not select elements from the variable operand - to show the hook is firing and affecting the test-cases.

Diff Detail

Repository
rL LLVM

Event Timeline

zvi created this revision.Mar 31 2017, 1:14 AM
spatel edited edge metadata.

Why would a shuffle with undef mask automatically return undef? For example:
shufflevector <2 x i8> <i8 42, i8 42>, <2 x i8> <i8 42, i8 42>, <2 x i32> undef

Should this be constant folded to <i8 42, i8 42> , <2 x i8> undef or something else?

lib/Analysis/InstructionSimplify.cpp
4091–4092

Prefer 'auto *' to make the pointer-ness of the cast explicit.

zvi added a comment.EditedMar 31 2017, 9:10 AM

Why would a shuffle with undef mask automatically return undef? For example:
shufflevector <2 x i8> <i8 42, i8 42>, <2 x i8> <i8 42, i8 42>, <2 x i32> undef

Should this be constant folded to <i8 42, i8 42> , <2 x i8> undef or something else?

I was asking myself the same question when i saw this in both InstCombine and in ConstanFolding. SimplifyDemandedVectorElts behaves the same.
I couldn't deduce this is allowed from reading the language reference.

zvi updated this revision to Diff 93681.Mar 31 2017, 10:30 AM

auto->auto*

zvi marked an inline comment as done.Mar 31 2017, 10:30 AM
zvi updated this revision to Diff 93775.Apr 2 2017, 4:00 AM
zvi edited the summary of this revision. (Show Details)

Backing out of the undef mask simpflication which as per pr32486 is probably wrong. Replaced with a different simplification to show the hook is firing.

spatel added inline comments.Apr 3 2017, 10:42 AM
lib/Analysis/InstructionSimplify.cpp
4097–4099

Why do we need to copy this list of ints? Just read them with ShuffleVectorInst::getMaskValue() and set the MaskSelects0/1 flags right here.

zvi updated this revision to Diff 93894.Apr 3 2017, 11:20 AM

Fixed Sanjay's comment by removing unnecessary container of mask indices.

zvi marked an inline comment as done.Apr 3 2017, 11:21 AM
spatel accepted this revision.Apr 3 2017, 1:26 PM

LGTM.

This revision is now accepted and ready to land.Apr 3 2017, 1:26 PM
This revision was automatically updated to reflect the committed changes.