aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 4e05368..9ea3232 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -8902,8 +8902,10 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
return NULL_TREE;
/* Optimize A / A to 1.0 if we don't care about
- NaNs or Infinities. */
- if (! HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0)))
+ NaNs or Infinities. Skip the transformation
+ for non-real operands. */
+ if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (arg0))
+ && ! HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0)))
&& ! HONOR_INFINITIES (TYPE_MODE (TREE_TYPE (arg0)))
&& operand_equal_p (arg0, arg1, 0))
{
@@ -8912,6 +8914,20 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
return omit_two_operands (type, r, arg0, arg1);
}
+ /* The complex version of the above A / A optimization. */
+ if (COMPLEX_FLOAT_TYPE_P (TREE_TYPE (arg0))
+ && operand_equal_p (arg0, arg1, 0))
+ {
+ tree elem_type = TREE_TYPE (TREE_TYPE (arg0));
+ if (! HONOR_NANS (TYPE_MODE (elem_type))
+ && ! HONOR_INFINITIES (TYPE_MODE (elem_type)))
+ {
+ tree r = build_real (elem_type, dconst1);
+ /* omit_two_operands will call fold_convert for us. */
+ return omit_two_operands (type, r, arg0, arg1);
+ }
+ }
+
/* (-A) / (-B) -> A / B */
if (TREE_CODE (arg0) == NEGATE_EXPR && negate_expr_p (arg1))
return fold_build2 (RDIV_EXPR, type,