public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-7048] Disable new 1/X optimization with -fnon-call-exceptions
@ 2022-02-04 11:10 Eric Botcazou
0 siblings, 0 replies; only message in thread
From: Eric Botcazou @ 2022-02-04 11:10 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:bd14cdceb9c6f4800e25a9fbca635a1d4c06fd32
commit r12-7048-gbd14cdceb9c6f4800e25a9fbca635a1d4c06fd32
Author: Eric Botcazou <ebotcazou@adacore.com>
Date: Fri Feb 4 12:03:49 2022 +0100
Disable new 1/X optimization with -fnon-call-exceptions
The trapping behavior of the operation needs to be preserved when the
-fnon-call-exceptions switch is in effect. This also adds the same
guards to similar optimizations.
gcc/
PR tree-optimization/104356
* match.pd (X / bool_range_Y is X): Add guard.
(X / X is one): Likewise.
(X / abs (X) is X < 0 ? -1 : 1): Likewise.
(X / -X is -1): Likewise.
(1 / X -> X == 1): Likewise.
Diff:
---
gcc/match.pd | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/gcc/match.pd b/gcc/match.pd
index b942cb2930a..10ff867e854 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -401,27 +401,35 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
/* X / bool_range_Y is X. */
(simplify
(div @0 SSA_NAME@1)
- (if (INTEGRAL_TYPE_P (type) && ssa_name_has_boolean_range (@1))
+ (if (INTEGRAL_TYPE_P (type)
+ && ssa_name_has_boolean_range (@1)
+ && !flag_non_call_exceptions)
@0))
/* X / X is one. */
(simplify
(div @0 @0)
/* But not for 0 / 0 so that we can get the proper warnings and errors.
And not for _Fract types where we can't build 1. */
- (if (!integer_zerop (@0) && !ALL_FRACT_MODE_P (TYPE_MODE (type)))
+ (if (!ALL_FRACT_MODE_P (TYPE_MODE (type))
+ && !integer_zerop (@0)
+ && (!flag_non_call_exceptions || tree_expr_nonzero_p (@0)))
{ build_one_cst (type); }))
/* X / abs (X) is X < 0 ? -1 : 1. */
(simplify
(div:C @0 (abs @0))
(if (INTEGRAL_TYPE_P (type)
- && TYPE_OVERFLOW_UNDEFINED (type))
+ && TYPE_OVERFLOW_UNDEFINED (type)
+ && !integer_zerop (@0)
+ && (!flag_non_call_exceptions || tree_expr_nonzero_p (@0)))
(cond (lt @0 { build_zero_cst (type); })
{ build_minus_one_cst (type); } { build_one_cst (type); })))
/* X / -X is -1. */
(simplify
(div:C @0 (negate @0))
(if ((INTEGRAL_TYPE_P (type) || VECTOR_INTEGER_TYPE_P (type))
- && TYPE_OVERFLOW_UNDEFINED (type))
+ && TYPE_OVERFLOW_UNDEFINED (type)
+ && !integer_zerop (@0)
+ && (!flag_non_call_exceptions || tree_expr_nonzero_p (@0)))
{ build_minus_one_cst (type); })))
/* For unsigned integral types, FLOOR_DIV_EXPR is the same as
@@ -443,8 +451,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(simplify
(trunc_div integer_onep@0 @1)
(if (INTEGRAL_TYPE_P (type)
+ && TYPE_PRECISION (type) > 1
&& !integer_zerop (@1)
- && TYPE_PRECISION (type) > 1)
+ && (!flag_non_call_exceptions || tree_expr_nonzero_p (@1)))
(if (TYPE_UNSIGNED (type))
(convert (eq:boolean_type_node @1 { build_one_cst (type); }))
(with { tree utype = unsigned_type_for (type); }
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-02-04 11:10 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-04 11:10 [gcc r12-7048] Disable new 1/X optimization with -fnon-call-exceptions Eric Botcazou
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).