bswap: Fix up recent vector CONSTRUCTOR optimization [PR98568]
authorJakub Jelinek <jakub@redhat.com>
Thu, 7 Jan 2021 08:57:40 +0000 (09:57 +0100)
committerJakub Jelinek <jakub@redhat.com>
Thu, 7 Jan 2021 08:57:40 +0000 (09:57 +0100)
commitd02a8b63e5aef49ab6973c64a2225236895763a1
tree870dab1a33b91c1c4108ff01508567926a465419
parent1b5669752426d225b0088d57d1d2fffba9625032
bswap: Fix up recent vector CONSTRUCTOR optimization [PR98568]

As the testcase shows, bswap can match even byte-swapping or indentity
from low part of some wider SSA_NAME.
For bswap replacement other than for vector CONSTRUCTOR the code has been
using NOP_EXPR casts if the types weren't compatible, but for vectors
we need to use VIEW_CONVERT_EXPR.  The problem with the latter is that
we require that it has the same size, which isn't guaranteed, so this patch
in those cases first adds a narrowing NOP_EXPR cast and only afterwards
does a VIEW_CONVERT_EXPR.

2021-01-07  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/98568
* gimple-ssa-store-merging.c (bswap_view_convert): New function.
(bswap_replace): Use it.

* g++.dg/torture/pr98568.C: New test.
gcc/gimple-ssa-store-merging.c
gcc/testsuite/g++.dg/torture/pr98568.C [new file with mode: 0644]