This is an archive of the discontinued LLVM Phabricator instance.

InstructionSimplify: Relanding r301766
ClosedPublic

Authored by zvi on May 4 2017, 7:10 AM.

Details

Summary

Re-applying r301766 with a fix to a typo and a regression test.

The log message for r301766 was:

InstructionSimplify: Canonicalize shuffle operands. NFC-ish.

Summary:
 Apply canonicalization rules:
    1. Input vectors with no elements selected from can be replaced with undef.
    2. If only one input vector is constant it shall be the second one.

This allows constant-folding to cover more ad-hoc simplifications that
were in place and avoid duplication for RHS and LHS checks.

There are more rules we may want to add in the future when we see a
justification. e.g. mask elements that select undef elements can be
replaced with undef.

Diff Detail

Repository
rL LLVM

Event Timeline

zvi created this revision.May 4 2017, 7:10 AM
zvi added inline comments.May 4 2017, 7:14 AM
lib/Analysis/InstructionSimplify.cpp
4094 ↗(On Diff #97823)

This line was replaced to fix the typo in D32338:

Idx = Idx < (int)MaskNumElts ? Idx + MaskNumElts : Idx - MaskNumElts;
spatel added inline comments.May 4 2017, 1:52 PM
lib/Analysis/InstructionSimplify.cpp
4087–4088 ↗(On Diff #97823)

Is the plan to actually do this canonicalization of constant to 2nd operand in InstCombine? If so, wouldn't it make sense to add a "commute" or "commuteMask" (this is what it's called in the DAG) function directly to ShuffleVectorInst and then use that here?

4091 ↗(On Diff #97823)

Use 'int &' instead of 'auto &'.

4094 ↗(On Diff #97823)

assert(Idx >= 0 && Idx < InVecNumElts * 2) ?

zvi added inline comments.May 7 2017, 7:16 AM
lib/Analysis/InstructionSimplify.cpp
4087–4088 ↗(On Diff #97823)

Sounds good. How about we do this as a follow-up patch?

zvi updated this revision to Diff 98101.May 7 2017, 8:01 AM

Fixes for two of Sanjay's comments

zvi marked an inline comment as done.May 7 2017, 8:02 AM
zvi marked an inline comment as done.
spatel accepted this revision.May 7 2017, 8:21 AM

LGTM.

lib/Analysis/InstructionSimplify.cpp
4087–4088 ↗(On Diff #97823)

Sure - I just want to avoid having multiple copies of this code. If we can unify this somewhere for IR and the DAG that would be even better.

This revision is now accepted and ready to land.May 7 2017, 8:21 AM
This revision was automatically updated to reflect the committed changes.