aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorKaveh R. Ghazi <ghazi@caip.rutgers.edu>2009-11-10 16:16:57 +0000
committerKaveh Ghazi <ghazi@gcc.gnu.org>2009-11-10 16:16:57 +0000
commit08d198890e548cc9d551d4dfdfef257893a21ed3 (patch)
tree1e6767691811d80f2fa58e920b8a005d425ec3a7 /gcc
parent2c5721d9f36a114809e296686ff39b1324b0cc5b (diff)
downloadgcc-08d198890e548cc9d551d4dfdfef257893a21ed3.zip
gcc-08d198890e548cc9d551d4dfdfef257893a21ed3.tar.gz
gcc-08d198890e548cc9d551d4dfdfef257893a21ed3.tar.bz2
re PR tree-optimization/41987 (expected class ‘constant’, have ‘binary’ (rdiv_expr) in build_complex, at tree.c:1485)
PR tree-optimization/41987 * fold-const.c (const_binop): Avoid using fold_buildN(). testsuite: * gcc.c-torture/compile/pr41987.c: New. From-SVN: r154065
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/fold-const.c56
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.c-torture/compile/pr41987.c22
4 files changed, 60 insertions, 27 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 7bcc946..93c86bb 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2009-11-10 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
+
+ PR tree-optimization/41987
+ * fold-const.c (const_binop): Avoid using fold_buildN().
+
2009-11-10 Martin Jambor <mjambor@suse.cz>
* tree-pass.h (struct ipa_opt_pass_d): Added stmt_fixup field.
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;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index a37b0b1..2f0e9aa 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2009-11-10 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
+
+ * gcc.c-torture/compile/pr41987.c: New.
+
2009-11-09 Jakub Jelinek <jakub@redhat.com>
PR middle-end/40946
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr41987.c b/gcc/testsuite/gcc.c-torture/compile/pr41987.c
new file mode 100644
index 0000000..7bb4919
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr41987.c
@@ -0,0 +1,22 @@
+/* PR tree-optimization/41987 */
+
+#define TESTIT(TYPE) do { \
+ _Complex TYPE ylm; \
+ TYPE nbond; \
+ ylm = 0; \
+ nbond = 0; \
+ ylm = ylm / nbond; \
+} while (0)
+
+void qparm_colvar(void)
+{
+ TESTIT (float);
+ TESTIT (double);
+ TESTIT (long double);
+
+ TESTIT (char);
+ TESTIT (short);
+ TESTIT (int);
+ TESTIT (long);
+ TESTIT (long long);
+}