The problem with these patterns is they will do a copy of the comparison
so for non-call exceptions (and trapping math), we could copy a statement
that can throw internally and then remove the landing pad information.
Or in the case of throwing externally, always create a copy from GIMPLE_COND.
That is if we have:
```
_2 = _1 < 0.0;
if (_2 != 0)
```
this pattern will cause a copy to be produced:
```
_2 = _1 < 0.0;
_3 = _1 < 0.0;
if (_3 != 0)
```
So let's restrict these pattern to only non-call exception throwing comparisons.
There is a pattern below that already handles `bool_name != 0` into `bool_name`
which will be used in the case of the non-call exceptions throwing comparisons.
Bootstrapped and tested on x86_64-linux-gnu.
gcc/ChangeLog:
* match.pd (`(ne (cmp) 0)`, `(eq (cmp) 1)`): Restrict to comparisons
that don't throw.
Signed-off-by: Andrew Pinski <[email protected]>
---
gcc/match.pd | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/gcc/match.pd b/gcc/match.pd
index ab496d923cc..e99ed40fbd1 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -6900,12 +6900,22 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
/* The following bits are handled by fold_binary_op_with_conditional_arg. */
(simplify
(ne (cmp@2 @0 @1) integer_zerop)
- (if (types_match (type, TREE_TYPE (@2)))
- (cmp @0 @1)))
+ /* For non-call exceptions, don't copy stmts that might throw (trap). */
+ (if (!flag_exceptions
+ || !(cfun && cfun->can_throw_non_call_exceptions)
+ || !operation_could_trap_p (cmp, FLOAT_TYPE_P (TREE_TYPE (@0)),
+ false, NULL_TREE))
+ (if (types_match (type, TREE_TYPE (@2)))
+ (cmp @0 @1))))
(simplify
(eq (cmp@2 @0 @1) integer_truep)
- (if (types_match (type, TREE_TYPE (@2)))
- (cmp @0 @1)))
+ /* For non-call exceptions, don't copy stmts that might throw (trap). */
+ (if (!flag_exceptions
+ || !(cfun && cfun->can_throw_non_call_exceptions)
+ || !operation_could_trap_p (cmp, FLOAT_TYPE_P (TREE_TYPE (@0)),
+ false, NULL_TREE))
+ (if (types_match (type, TREE_TYPE (@2)))
+ (cmp @0 @1))))
(simplify
(ne (cmp@2 @0 @1) integer_truep)
(if (types_match (type, TREE_TYPE (@2)))
--
2.43.0