This is an archive of the discontinued LLVM Phabricator instance.

[AArch64]Fix an assertion failure about concating two build_vector in DAG Combiner
ClosedPublic

Authored by HaoLiu on Jul 8 2014, 3:53 AM.

Details

Reviewers
t.p.northover
Summary

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

Diff Detail

Event Timeline

HaoLiu updated this revision to Diff 11150.Jul 8 2014, 3:53 AM
HaoLiu retitled this revision from to [AArch64]Fix an assertion failure about concating two build_vector in DAG Combiner.
HaoLiu updated this object.
HaoLiu edited the test plan for this revision. (Show Details)
HaoLiu added a reviewer: t.p.northover.
HaoLiu added a subscriber: Unknown Object (MLST).
t.p.northover edited edge metadata.Jul 8 2014, 5:06 AM

Hi Hao,

I think you picked the right place to fix this. Even if you did patch AArch64, the bug would still be latent in the DAGCombiner.

I've just got one comment on the logic, really:

lib/CodeGen/SelectionDAG/DAGCombiner.cpp
10377–10378

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.

HaoLiu updated this revision to Diff 11187.Jul 9 2014, 12:11 AM
HaoLiu edited edge metadata.

Hi Tim,

Your suggestion is good to simplify the logic.
I've refactored the patch.

Thanks,
-Hao

t.p.northover accepted this revision.Jul 9 2014, 7:35 AM
t.p.northover edited edge metadata.

Hi Hao,

I think this looks good now. Thanks for updating the patch!

Tim.

This revision is now accepted and ready to land.Jul 9 2014, 7:35 AM