diff options
author | Richard Biener <rguenther@suse.de> | 2022-02-23 13:47:01 +0100 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2022-02-23 13:51:43 +0100 |
commit | fdc46830f1b793dc791099acfadc3f0f8cc24c0e (patch) | |
tree | e258eabd0bfcca853c5e450e99b215becdbe18f5 /gcc/match.pd | |
parent | f4ed267fa5b82d6dafbc8afc82baf45bfcae549c (diff) | |
download | gcc-fdc46830f1b793dc791099acfadc3f0f8cc24c0e.zip gcc-fdc46830f1b793dc791099acfadc3f0f8cc24c0e.tar.gz gcc-fdc46830f1b793dc791099acfadc3f0f8cc24c0e.tar.bz2 |
middle-end/104644 - recursion with bswap match.pd pattern
The following patch avoids infinite recursion during generic folding.
The (cmp (bswap @0) INTEGER_CST@1) simplification relies on
(bswap @1) actually being simplified, if it is not simplified, we just
move the bswap from one operand to the other and if @0 is also INTEGER_CST,
we apply the same rule next.
The reason why bswap @1 isn't folded to INTEGER_CST is that the INTEGER_CST
has TREE_OVERFLOW set on it and fold-const-call.cc predicate punts in
such cases:
static inline bool
integer_cst_p (tree t)
{
return TREE_CODE (t) == INTEGER_CST && !TREE_OVERFLOW (t);
}
The patch uses ! modifier to ensure the bswap is simplified and
extends support to GENERIC by means of requiring !EXPR_P which
is not perfect but a conservative approximation.
2022-02-22 Richard Biener <rguenther@suse.de>
PR tree-optimization/104644
* doc/match-and-simplify.texi: Amend ! documentation.
* genmatch.cc (expr::gen_transform): Code-generate ! support
for GENERIC.
(parser::parse_expr): Allow ! for GENERIC.
* match.pd (cmp (bswap @0) INTEGER_CST@1): Use ! modifier on
bswap.
* gcc.dg/pr104644.c: New test.
Co-Authored-by: Jakub Jelinek <jakub@redhat.com>
Diffstat (limited to 'gcc/match.pd')
-rw-r--r-- | gcc/match.pd | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/gcc/match.pd b/gcc/match.pd index cad6184..cf78a11 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3962,7 +3962,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (simplify (cmp (bswap @0) INTEGER_CST@1) (with { tree ctype = TREE_TYPE (@1); } - (cmp (convert:ctype @0) (bswap @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)) |