]> git.ipfire.org Git - thirdparty/gcc.git/commit
match.pd: Fix up recent __builtin_bswap16 simplifications [PR101642]
authorJakub Jelinek <jakub@redhat.com>
Wed, 28 Jul 2021 16:41:50 +0000 (18:41 +0200)
committerJakub Jelinek <jakub@redhat.com>
Wed, 28 Jul 2021 16:41:50 +0000 (18:41 +0200)
commitb4fc4df94f703e3b191f503ebe7186500e45d081
treea5840c6f9c59a31c842761a14fc8a1ec86ad2ba1
parentde0214a055d9a43dd3576557f928982a57a3db38
match.pd: Fix up recent __builtin_bswap16 simplifications [PR101642]

The following testcase ICEs.  The problem is that for __builtin_bswap16
(and only that, others are fine) the argument of the builtin is promoted
to int while the patterns assume it is not and is the same as that of
the return type.
For the bswap simplifications before these new ones it just means we
fail to optimize stuff like __builtin_bswap16 (__builtin_bswap16 (x))
because there are casts in between, but the last one, equality comparison
of __builtin_bswap16 with integer constant results in ICE, because
we create comparison with incompatible types of the operands, and the
other might be fine because usually we bit and the operand before promoting,
but I think it is too dangerous to rely on it, one day we find out that
because it is operand to such a built in, we can throw away any changes
that affect the upper bits and all of sudden it would misbehave.

So, this patch introduces converts that shouldn't do anything for
bswap{32,64,128} and should fix these issues for bswap16.

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

PR middle-end/101642
* match.pd (bswap16 (x) == bswap16 (y)): Cast both operands
to type of bswap16 for comparison.
(bswap16 (x) == cst): Cast bswap16 operand to type of cst.

* gcc.c-torture/compile/pr101642.c: New test.
gcc/match.pd
gcc/testsuite/gcc.c-torture/compile/pr101642.c [new file with mode: 0644]