summaryrefslogtreecommitdiff
path: root/gcc/match.pd
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2020-02-15 12:53:44 +0100
committerJakub Jelinek <jakub@redhat.com>2020-02-15 12:53:44 +0100
commit187dd955dbee3939c3a2ca7b6839e7f709999125 (patch)
tree02a3d390dc575f8d7179eabef999a485306e9544 /gcc/match.pd
parent55b00d14f4daf671b865550c119dafdeb3139672 (diff)
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.
Diffstat (limited to 'gcc/match.pd')
-rw-r--r--gcc/match.pd9
1 files changed, 6 insertions, 3 deletions
diff --git a/gcc/match.pd b/gcc/match.pd
index 73834c25593..19df0c404a4 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1472,7 +1472,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. */
@@ -2709,7 +2710,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
&& TREE_CODE (TREE_TYPE (@4)) != BOOLEAN_TYPE
&& INTEGRAL_TYPE_P (TREE_TYPE (@5))
&& (TYPE_PRECISION (TREE_TYPE (@4)) >= TYPE_PRECISION (type)
- || !TYPE_UNSIGNED (TREE_TYPE (@4))))
+ || !TYPE_UNSIGNED (TREE_TYPE (@4)))
+ && (GIMPLE || !TREE_SIDE_EFFECTS (@1)))
(cond (cmp @2 @3) @1 @0)))
(simplify
(plus:c @0 (bit_and:c (minus @1 @0)
@@ -2719,7 +2721,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
&& TREE_CODE (TREE_TYPE (@4)) != BOOLEAN_TYPE
&& INTEGRAL_TYPE_P (TREE_TYPE (@5))
&& (TYPE_PRECISION (TREE_TYPE (@4)) >= TYPE_PRECISION (type)
- || !TYPE_UNSIGNED (TREE_TYPE (@4))))
+ || !TYPE_UNSIGNED (TREE_TYPE (@4)))
+ && (GIMPLE || !TREE_SIDE_EFFECTS (@1)))
(cond (cmp @2 @3) @1 @0))))
/* Simplifications of shift and rotates. */