[gcc(refs/vendors/redhat/heads/gcc-8-branch)] match.pd: Disallow side-effects in GENERIC for non-COND_EXPR to COND_EXPR simplifications [PR93744]
Jakub Jelinek
jakub@gcc.gnu.org
Thu Sep 17 16:42:50 GMT 2020
https://gcc.gnu.org/g:3401cfb9d81e1e4db4a26b8050b1ec75ef92473e
commit 3401cfb9d81e1e4db4a26b8050b1ec75ef92473e
Author: Jakub Jelinek <jakub@redhat.com>
Date: Sat Feb 15 12:53:44 2020 +0100
match.pd: Disallow side-effects in GENERIC for non-COND_EXPR to COND_EXPR simplifications [PR93744]
As the following testcases show (the first one reported, last two
found by code inspection), we need to disallow side-effects
in simplifications that turn some unconditional expression into conditional
one. From my little understanding of genmatch.c, it is able to
automatically disallow side effects if the same operand is used multiple
times in the match pattern, maybe if it is used multiple times in the
replacement pattern, and if it is used in conditional contexts in the match
pattern, could it be taught to handle this case too? If yes, perhaps
just the first hunk could be usable for 8/9 backports (+ the testcases).
2020-02-15 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/93744
* match.pd (((m1 >/</>=/<= m2) * d -> (m1 >/</>=/<= m2) ? d : 0,
A - ((A - B) & -(C cmp D)) -> (C cmp D) ? B : A,
A + ((B - A) & -(C cmp D)) -> (C cmp D) ? B : A): For GENERIC, make
sure @2 in the first and @1 in the other patterns has no side-effects.
* gcc.c-torture/execute/pr93744-1.c: New test.
* gcc.c-torture/execute/pr93744-2.c: New test.
* gcc.c-torture/execute/pr93744-3.c: New test.
Diff:
---
gcc/ChangeLog | 7 +++++++
gcc/match.pd | 3 ++-
gcc/testsuite/ChangeLog | 7 +++++++
gcc/testsuite/gcc.c-torture/execute/pr93744-1.c | 14 ++++++++++++++
gcc/testsuite/gcc.c-torture/execute/pr93744-2.c | 21 +++++++++++++++++++++
gcc/testsuite/gcc.c-torture/execute/pr93744-3.c | 21 +++++++++++++++++++++
6 files changed, 72 insertions(+), 1 deletion(-)
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index bae39b6211e..97bdc9b7265 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2020-02-15 Jakub Jelinek <jakub@redhat.com>
+
+ PR tree-optimization/93744
+ * match.pd (((m1 >/</>=/<= m2) * d -> (m1 >/</>=/<= m2) ? d : 0): For
+ GENERIC, make sure @2 in the first and @1 in the other patterns has no
+ side-effects.
+
2020-02-14 Eric Botcazou <ebotcazou@adacore.com>
PR target/93704
diff --git a/gcc/match.pd b/gcc/match.pd
index 8e0265b2b33..0f287b05d6a 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1229,7 +1229,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(for cmp (gt lt ge le)
(simplify
(mult (convert (cmp @0 @1)) @2)
- (cond (cmp @0 @1) @2 { build_zero_cst (type); })))
+ (if (GIMPLE || !TREE_SIDE_EFFECTS (@2))
+ (cond (cmp @0 @1) @2 { build_zero_cst (type); }))))
/* For integral types with undefined overflow and C != 0 fold
x * C EQ/NE y * C into x EQ/NE y. */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 22621ddb7f6..71afaedc6dc 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2020-02-15 Jakub Jelinek <jakub@redhat.com>
+
+ PR tree-optimization/93744
+ * gcc.c-torture/execute/pr93744-1.c: New test.
+ * gcc.c-torture/execute/pr93744-2.c: New test.
+ * gcc.c-torture/execute/pr93744-3.c: New test.
+
2020-02-14 Jakub Jelinek <jakub@redhat.com>
PR c++/61414
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr93744-1.c b/gcc/testsuite/gcc.c-torture/execute/pr93744-1.c
new file mode 100644
index 00000000000..3229c9b2bd6
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr93744-1.c
@@ -0,0 +1,14 @@
+/* PR tree-optimization/93744 */
+
+typedef int I;
+
+int
+main ()
+{
+ int a = 0;
+ I b = 0;
+ (a > 0) * (b |= 2);
+ if (b != 2)
+ __builtin_abort ();
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr93744-2.c b/gcc/testsuite/gcc.c-torture/execute/pr93744-2.c
new file mode 100644
index 00000000000..0c1baaac77b
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr93744-2.c
@@ -0,0 +1,21 @@
+/* PR tree-optimization/93744 */
+
+int w;
+
+int
+foo (int x, int y, int z)
+{
+ int r = z - ((z - w++) & -(x < y));
+ return r;
+}
+
+int
+main ()
+{
+ w = 4;
+ if (foo (5, 7, 12) != 4 || w != 5)
+ __builtin_abort ();
+ if (foo (7, 5, 12) != 12 || w != 6)
+ __builtin_abort ();
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr93744-3.c b/gcc/testsuite/gcc.c-torture/execute/pr93744-3.c
new file mode 100644
index 00000000000..8542c7c53ba
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr93744-3.c
@@ -0,0 +1,21 @@
+/* PR tree-optimization/93744 */
+
+int w;
+
+int
+foo (int x, int y, int z)
+{
+ int r = z + ((w++ - z) & -(x < y));
+ return r;
+}
+
+int
+main ()
+{
+ w = 4;
+ if (foo (5, 7, 12) != 4 || w != 5)
+ __builtin_abort ();
+ if (foo (7, 5, 12) != 12 || w != 6)
+ __builtin_abort ();
+ return 0;
+}
More information about the Gcc-cvs
mailing list