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.c56
1 files changed, 29 insertions, 27 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 3403938..c6b420b 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -2031,10 +2031,10 @@ const_binop (enum tree_code code, tree arg1, tree arg2, int notrunc)
Expand complex division to scalars, modified algorithm to minimize
overflow with wide input ranges. */
- tree inner_type = TREE_TYPE (type);
- tree absr2 = fold_build1 (ABS_EXPR, inner_type, r2);
- tree absi2 = fold_build1 (ABS_EXPR, inner_type, i2);
- tree compare = fold_build2 (LT_EXPR, boolean_type_node, absr2, absi2);
+ tree compare = fold_build2 (LT_EXPR, boolean_type_node,
+ fold_abs_const (r2, TREE_TYPE (type)),
+ fold_abs_const (i2, TREE_TYPE (type)));
+
if (integer_nonzerop (compare))
{
/* In the TRUE branch, we compute
@@ -2044,17 +2044,18 @@ const_binop (enum tree_code code, tree arg1, tree arg2, int notrunc)
ti = (ai * ratio) - ar;
tr = tr / div;
ti = ti / div; */
- tree ratio = fold_build2 (code, inner_type, r2, i2);
- tree div = fold_build2 (PLUS_EXPR, inner_type, i2,
- fold_build2 (MULT_EXPR, inner_type,
- r2, ratio));
- real = fold_build2 (MULT_EXPR, inner_type, r1, ratio);
- real = fold_build2 (PLUS_EXPR, inner_type, real, i1);
- real = fold_build2 (code, inner_type, real, div);
-
- imag = fold_build2 (MULT_EXPR, inner_type, i1, ratio);
- imag = fold_build2 (MINUS_EXPR, inner_type, imag, r1);
- imag = fold_build2 (code, inner_type, imag, div);
+ tree ratio = const_binop (code, r2, i2, notrunc);
+ tree div = const_binop (PLUS_EXPR, i2,
+ const_binop (MULT_EXPR, r2, ratio,
+ notrunc),
+ notrunc);
+ real = const_binop (MULT_EXPR, r1, ratio, notrunc);
+ real = const_binop (PLUS_EXPR, real, i1, notrunc);
+ real = const_binop (code, real, div, notrunc);
+
+ imag = const_binop (MULT_EXPR, i1, ratio, notrunc);
+ imag = const_binop (MINUS_EXPR, imag, r1, notrunc);
+ imag = const_binop (code, imag, div, notrunc);
}
else
{
@@ -2065,18 +2066,19 @@ const_binop (enum tree_code code, tree arg1, tree arg2, int notrunc)
ti = b - (a * ratio);
tr = tr / div;
ti = ti / div; */
- tree ratio = fold_build2 (code, inner_type, i2, r2);
- tree div = fold_build2 (PLUS_EXPR, inner_type, r2,
- fold_build2 (MULT_EXPR, inner_type,
- i2, ratio));
-
- real = fold_build2 (MULT_EXPR, inner_type, i1, ratio);
- real = fold_build2 (PLUS_EXPR, inner_type, real, r1);
- real = fold_build2 (code, inner_type, real, div);
-
- imag = fold_build2 (MULT_EXPR, inner_type, r1, ratio);
- imag = fold_build2 (MINUS_EXPR, inner_type, i1, imag);
- imag = fold_build2 (code, inner_type, imag, div);
+ tree ratio = const_binop (code, i2, r2, notrunc);
+ tree div = const_binop (PLUS_EXPR, r2,
+ const_binop (MULT_EXPR, i2, ratio,
+ notrunc),
+ notrunc);
+
+ real = const_binop (MULT_EXPR, i1, ratio, notrunc);
+ real = const_binop (PLUS_EXPR, real, r1, notrunc);
+ real = const_binop (code, real, div, notrunc);
+
+ imag = const_binop (MULT_EXPR, r1, ratio, notrunc);
+ imag = const_binop (MINUS_EXPR, i1, imag, notrunc);
+ imag = const_binop (code, imag, div, notrunc);
}
}
break;