diff options
author | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-10-05 11:38:59 +0000 |
---|---|---|
committer | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-10-05 11:38:59 +0000 |
commit | bf1426ea170b77b52efb471bcc62db4cc923d594 (patch) | |
tree | 3a7a8b7f9c7e9c3afc2ea544f0459e8e8419cdd9 | |
parent | eb93b162383d4c5bbddd56234c45f78e7e98a197 (diff) | |
download | gcc-bf1426ea170b77b52efb471bcc62db4cc923d594.tar.gz |
2016-10-05 Richard Biener <rguenther@suse.de>
PR middle-end/77826
* genmatch.c (dt_operand::gen_match_op): Amend operand_equal_p
with types_match for GIMPLE code gen to handle type mismatched
constants properly.
(dt_operand::gen): Adjust.
* match.pd ((X /[ex] A) * A -> X): Properly handle converted
and constant A.
* gcc.dg/torture/pr77826.c: New testcase.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@240776 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 10 | ||||
-rw-r--r-- | gcc/genmatch.c | 16 | ||||
-rw-r--r-- | gcc/match.pd | 10 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/torture/pr77826.c | 12 |
5 files changed, 45 insertions, 8 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0fd86c50900..43858919d12 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,15 @@ 2016-10-05 Richard Biener <rguenther@suse.de> + PR middle-end/77826 + * genmatch.c (dt_operand::gen_match_op): Amend operand_equal_p + with types_match for GIMPLE code gen to handle type mismatched + constants properly. + (dt_operand::gen): Adjust. + * match.pd ((X /[ex] A) * A -> X): Properly handle converted + and constant A. + +2016-10-05 Richard Biener <rguenther@suse.de> + * match.pd (copysign(x, CST) -> [-]abs (x)): New pattern. 2016-10-05 Richard Biener <rguenther@suse.de> diff --git a/gcc/genmatch.c b/gcc/genmatch.c index c3f128cd26e..5883ba39420 100644 --- a/gcc/genmatch.c +++ b/gcc/genmatch.c @@ -1562,7 +1562,7 @@ struct dt_operand : public dt_node void gen (FILE *, int, bool); unsigned gen_predicate (FILE *, int, const char *, bool); - unsigned gen_match_op (FILE *, int, const char *); + unsigned gen_match_op (FILE *, int, const char *, bool); unsigned gen_gimple_expr (FILE *, int); unsigned gen_generic_expr (FILE *, int, const char *); @@ -2589,12 +2589,18 @@ dt_operand::gen_predicate (FILE *f, int indent, const char *opname, bool gimple) a capture-match. */ unsigned -dt_operand::gen_match_op (FILE *f, int indent, const char *opname) +dt_operand::gen_match_op (FILE *f, int indent, const char *opname, bool gimple) { char match_opname[20]; match_dop->get_name (match_opname); - fprintf_indent (f, indent, "if (%s == %s || operand_equal_p (%s, %s, 0))\n", - opname, match_opname, opname, match_opname); + if (gimple) + fprintf_indent (f, indent, "if (%s == %s || (operand_equal_p (%s, %s, 0) " + "&& types_match (%s, %s)))\n", + opname, match_opname, opname, match_opname, + opname, match_opname); + else + fprintf_indent (f, indent, "if (%s == %s || operand_equal_p (%s, %s, 0))\n", + opname, match_opname, opname, match_opname); fprintf_indent (f, indent + 2, "{\n"); return 1; } @@ -2991,7 +2997,7 @@ dt_operand::gen (FILE *f, int indent, bool gimple) else if (type == DT_TRUE) ; else if (type == DT_MATCH) - n_braces = gen_match_op (f, indent, opname); + n_braces = gen_match_op (f, indent, opname, gimple); else gcc_unreachable (); diff --git a/gcc/match.pd b/gcc/match.pd index e4b5d4d7556..1d80613fdf8 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1781,9 +1781,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* (X /[ex] A) * A -> X. */ (simplify - (mult (convert? (exact_div @0 @1)) @1) - /* Look through a sign-changing conversion. */ - (convert @0)) + (mult (convert1? (exact_div @0 @1)) (convert2? @2)) + /* We cannot use matching captures here, since in the case of + constants we don't see the second conversion. Look through + a sign-changing or widening conversions. */ + (if (operand_equal_p (@1, @2, 0) + && element_precision (@0) <= element_precision (type)) + (convert @0))) /* Canonicalization of binary operations. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 818e5a4be23..fa1f310d694 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2016-10-05 Richard Biener <rguenther@suse.de> + PR middle-end/77826 + * gcc.dg/torture/pr77826.c: New testcase. + +2016-10-05 Richard Biener <rguenther@suse.de> + * gcc.dg/fold-copysign-1.c: New testcase. 2016-10-05 Andreas Schwab <schwab@suse.de> diff --git a/gcc/testsuite/gcc.dg/torture/pr77826.c b/gcc/testsuite/gcc.dg/torture/pr77826.c new file mode 100644 index 00000000000..13e188f28ff --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr77826.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ + +void +fi(unsigned long int *v0, unsigned int ow, int q2) +{ + if (ow + q2 != 0) + if (q2 == 1) + { + *v0 |= q2; + q2 ^= *v0; + } +} |