[SelectionDAG] Optimize build_vector of truncates and shifts
authorSebastian Neubauer <sebastian.neubauer@amd.com>
Fri, 31 Jan 2020 13:18:18 +0000 (14:18 +0100)
committerSebastian Neubauer <sebastian.neubauer@amd.com>
Mon, 10 Feb 2020 14:04:07 +0000 (15:04 +0100)
commit7cddd15e5616a1872106a6664e1d622a3adad7cc
treefc169051f4af7475c1bf2ec2ab0c6f77cceadc61
parent5a1778057f72b8e0444a7932144a3fa441b641bc
[SelectionDAG] Optimize build_vector of truncates and shifts

Add a simplification to fuse a manual vector extract with shifts and
truncate into a bitcast.

Unpacking and packing values into vectors is only optimized with
extractelement instructions, not when manually unpacked using shifts
and truncates.
This patch simplifies shifts and truncates into a bitcast if possible.

Simplify (build_vec (trunc $1)
                    (trunc (srl $1 width))
                    (trunc (srl $1 (2 * width))) ...)
to (bitcast $1)

Differential Revision: https://reviews.llvm.org/D73892
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/AMDGPU/scalar_to_vector.ll
llvm/test/CodeGen/AMDGPU/vector_shuffle.packed.ll