aboutsummaryrefslogtreecommitdiff
path: root/gcc/match.pd
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2021-07-28 18:41:50 +0200
committerJakub Jelinek <jakub@redhat.com>2021-07-28 18:41:50 +0200
commitb4fc4df94f703e3b191f503ebe7186500e45d081 (patch)
treea5840c6f9c59a31c842761a14fc8a1ec86ad2ba1 /gcc/match.pd
parentde0214a055d9a43dd3576557f928982a57a3db38 (diff)
downloadgcc-b4fc4df94f703e3b191f503ebe7186500e45d081.zip
gcc-b4fc4df94f703e3b191f503ebe7186500e45d081.tar.gz
gcc-b4fc4df94f703e3b191f503ebe7186500e45d081.tar.bz2
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.
Diffstat (limited to 'gcc/match.pd')
-rw-r--r--gcc/match.pd8
1 files changed, 5 insertions, 3 deletions
diff --git a/gcc/match.pd b/gcc/match.pd
index 4d41b70..19cbad7 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3641,11 +3641,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(bitop @0 (bswap @1))))
(for cmp (eq ne)
(simplify
- (cmp (bswap @0) (bswap @1))
- (cmp @0 @1))
+ (cmp (bswap@2 @0) (bswap @1))
+ (with { tree ctype = TREE_TYPE (@2); }
+ (cmp (convert:ctype @0) (convert:ctype @1))))
(simplify
(cmp (bswap @0) INTEGER_CST@1)
- (cmp @0 (bswap @1))))
+ (with { tree ctype = TREE_TYPE (@1); }
+ (cmp (convert:ctype @0) (bswap @1)))))
/* (bswap(x) >> C1) & C2 can sometimes be simplified to (x >> C3) & C2. */
(simplify
(bit_and (convert1? (rshift@0 (convert2? (bswap@4 @1)) INTEGER_CST@2))