[InstCombine] try to convert vector insert+extract to trunc; 2nd try
authorSanjay Patel <spatel@rotateright.com>
Mon, 1 Oct 2018 14:40:00 +0000 (14:40 +0000)
committerSanjay Patel <spatel@rotateright.com>
Mon, 1 Oct 2018 14:40:00 +0000 (14:40 +0000)
commit31b07198f190f3c8a1724b5451327b0f0451c9d3
tree3fab70c7c5f853227e7d671138061d610a73e727
parent1743ebe369f94289d418dd67b18aec26f2ef10b2
[InstCombine] try to convert vector insert+extract to trunc; 2nd try

This was originally committed at rL343407, but reverted at
rL343458 because it crashed trying to handle a case where
the destination type is FP. This version of the patch adds
a check for that possibility. Tests added at rL343480.

Original commit message:

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.

Differential Revision: https://reviews.llvm.org/D52439

llvm-svn: 343482
llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
llvm/test/Transforms/InstCombine/extractelement.ll