This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] try to convert vector insert+extract to trunc
ClosedPublic

Authored by spatel on Sep 24 2018, 2:54 PM.

Details

Summary

This transform is requested for the backend in:
https://bugs.llvm.org/show_bug.cgi?id=39016
...but I figured it was worth doing in IR too, and it's probably easier to implement here, so that's this patch.

In the simplest case, we are just truncating a scalar value. If the extract index doesn't correspond to the LSBs of the scalar, then we have to shift-right before the truncate. Endian-ness makes this tricky, but hopefully the ASCII-art helps visualize the transform.

Diff Detail

Event Timeline

spatel created this revision.Sep 24 2018, 2:54 PM

Worth testing with more exotic types? <2 x i24> to <6 x i8> ?

Worth testing with more exotic types? <2 x i24> to <6 x i8> ?

Sure - but we can get even crazier than that. :)
Will update shortly...

spatel updated this revision to Diff 167166.Sep 26 2018, 11:07 AM

Patch updated - no code changes, but:

  1. Added crazy type example (3 x i15).
  2. I committed the negative/partial negative tests along with the new test in rL343128.
RKSimon accepted this revision.Sep 29 2018, 2:26 AM

LGTM

This revision is now accepted and ready to land.Sep 29 2018, 2:26 AM
This revision was automatically updated to reflect the committed changes.
spatel reopened this revision.Oct 1 2018, 6:24 AM

Reverted at rL343458 because we can create bogus trunc insts (not sure how yet).

This revision is now accepted and ready to land.Oct 1 2018, 6:24 AM
spatel planned changes to this revision.Oct 1 2018, 6:24 AM
This revision was not accepted when it landed; it landed in state Changes Planned.Oct 1 2018, 7:41 AM
This revision was automatically updated to reflect the committed changes.
spatel added a comment.Oct 1 2018, 7:49 AM

Reverted at rL343458 because we can create bogus trunc insts (not sure how yet).

I forgot to add a check for casting to an FP type in the original patch, so we died trying to perform an integer op on a float.
For now, I just added that check, but I think we should be able to handle patterns with FP types too, so I added a TODO comment.