This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Fold insert sequence if first ins has multiple users.
ClosedPublic

Authored by fhahn on Aug 23 2017, 7:30 AM.

Details

Summary

If the first insertelement instruction has multiple users and inserts at
position 0, we can re-use this instruction when folding a chain of
insertelement instructions. As we need to generate the first
insertelement instruction anyways, this should be a strict improvement.

We could get rid of the restriction of inserting at position 0 by
creating a different shufflemask, but it is probably worth to keep the
first insertelement instruction with position 0, as this is easier to do
efficiently than at other positions I think.

Diff Detail

Event Timeline

fhahn created this revision.Aug 23 2017, 7:30 AM
grosser edited edge metadata.Aug 23 2017, 10:44 AM

Very nice. This looks good from my perspective!

fpetrogalli added inline comments.Aug 24 2017, 2:25 AM
test/Transforms/InstCombine/broadcast.ll
63

Hi Florian,
this looks good to me too, but shouldn't you also check that the transformation is not happening if any of the lanes of %ins1, other than the first one, is not an undef? Or is this case covered somewhere else?

Francesco

fhahn updated this revision to Diff 112708.Aug 25 2017, 10:13 AM

Thanks Francesco, I've added a test case for both cases and fixed the condition.

fhahn marked an inline comment as done.Aug 25 2017, 10:13 AM
fpetrogalli accepted this revision.Aug 29 2017, 3:39 AM

This LGTM now.

Thanks,

Francesco

This revision is now accepted and ready to land.Aug 29 2017, 3:39 AM
fhahn closed this revision.Aug 30 2017, 3:55 AM