Hi Tim and other reviewers,
In DAG Combiner function visitCONCAT_VECTORS, it tries to do following optimization:
fold (concat_vectors (BUILD_VECTOR A, B, ...), (BUILD_VECTOR C, D, ...)) -> (BUILD_VECTOR A, B, ..., C, D, ...)
But this optimization doesn't check whether A/B and C/D are different types. The test case in this patch shows that two SHL may be optimized into a v4i16 BUILD_VECTOR from four i32 constant 0.
There are two ways to fix this bug:
(1) Check whether two BUILD_VECTOR are from different types, if not, truncate the larger type.
(2) When combine 2 SHL, try to generate v4i16 BUILD_VECTOR from v4i16 constant 0. But we can't make sure no other optimization may generate such v4i16 from i32. We choose the first way.
Review please.
Thanks
-Hao
I think the logic here would be simpler if you defined an "EVT MinTy" and then truncated all inputs down to that in the loop. The trivial truncate operations will be automatically discarded in SelectionDAG::getNode.