aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog15
-rw-r--r--gcc/fold-const.c14
-rw-r--r--gcc/testsuite/ChangeLog9
-rw-r--r--gcc/testsuite/g++.dg/tree-ssa/pr19807.C2
-rw-r--r--gcc/testsuite/gcc.dg/pr23295.c10
-rw-r--r--gcc/testsuite/gcc.dg/pr27132.c10
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/pr23294.c5
7 files changed, 58 insertions, 7 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 655596d..568ba2e 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,20 @@
2006-10-23 Richard Guenther <rguenther@suse.de>
+ PR middle-end/27132
+ PR middle-end/23295
+ * builtins.c (fold_binary): Remove checks for flag_wrapv
+ and flag_trapv where negate_expr_p covers these cases.
+
+2006-10-23 Richard Guenther <rguenther@suse.de>
+
+ PR middle-end/29548
+ * fold-const.c (fold_plusminus_mult_expr): Check exact power
+ of two on the absolute value.
+ (fold_binary): Fold x * -C to -x * C if x is easily negatable
+ and negating -C does not overflow.
+
+2006-10-23 Richard Guenther <rguenther@suse.de>
+
PR middle-end/21032
* convert.c (convert_to_real): Fold (float)-x to -(float)x
only if not flag_rounding_math.
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index b04022e..571a7e8 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -6787,7 +6787,7 @@ fold_plusminus_mult_expr (enum tree_code code, tree type, tree arg0, tree arg1)
else
maybe_same = arg11;
- if (exact_log2 (int11) > 0 && int01 % int11 == 0)
+ if (exact_log2 (abs (int11)) > 0 && int01 % int11 == 0)
{
alt0 = fold_build2 (MULT_EXPR, TREE_TYPE (arg00), arg00,
build_int_cst (TREE_TYPE (arg00),
@@ -8752,7 +8752,7 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
/* (-A) - B -> (-B) - A where B is easily negated and we can swap. */
if (TREE_CODE (arg0) == NEGATE_EXPR
&& (FLOAT_TYPE_P (type)
- || (INTEGRAL_TYPE_P (type) && flag_wrapv && !flag_trapv))
+ || INTEGRAL_TYPE_P (type))
&& negate_expr_p (arg1)
&& reorder_operands_p (arg0, arg1))
return fold_build2 (MINUS_EXPR, type, negate_expr (arg1),
@@ -8838,7 +8838,7 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
/* Avoid this transformation if B is a positive REAL_CST. */
&& (TREE_CODE (arg1) != REAL_CST
|| REAL_VALUE_NEGATIVE (TREE_REAL_CST (arg1))))
- || (INTEGRAL_TYPE_P (type) && flag_wrapv && !flag_trapv)))
+ || INTEGRAL_TYPE_P (type)))
return fold_build2 (PLUS_EXPR, type,
fold_convert (type, arg0),
fold_convert (type, negate_expr (arg1)));
@@ -8923,6 +8923,14 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
/* Transform x * -1 into -x. */
if (integer_all_onesp (arg1))
return fold_convert (type, negate_expr (arg0));
+ /* Transform x * -C into -x * C if x is easily negatable. */
+ if (TREE_CODE (arg1) == INTEGER_CST
+ && tree_int_cst_sgn (arg1) == -1
+ && negate_expr_p (arg0)
+ && (tem = negate_expr (arg1)) != arg1
+ && !TREE_OVERFLOW (tem))
+ return fold_build2 (MULT_EXPR, type,
+ negate_expr (arg0), tem);
/* (a * (1 << b)) is (a << b) */
if (TREE_CODE (arg1) == LSHIFT_EXPR
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 06d1abc..b8b1c52 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,14 @@
2006-10-23 Richard Guenther <rguenther@suse.de>
+ PR middle-end/27132
+ PR middle-end/23295
+ * gcc.dg/pr27132.c: New testcase.
+ * gcc.dg/pr23295.c: Likewise.
+ * gcc.dg/tree-ssa/pr23294.c: Adjust patterns.
+ * g++.dg/tree-ssa/pr19807.C: Likewise.
+
+2006-10-23 Richard Guenther <rguenther@suse.de>
+
PR middle-end/21032
* gcc.dg/pr21032.c: New testcase.
diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr19807.C b/gcc/testsuite/g++.dg/tree-ssa/pr19807.C
index 0ff10db..d85b8ad 100644
--- a/gcc/testsuite/g++.dg/tree-ssa/pr19807.C
+++ b/gcc/testsuite/g++.dg/tree-ssa/pr19807.C
@@ -19,6 +19,6 @@ void bar(int i)
}
/* { dg-final { scan-tree-dump-times "&a\\\[2\\\]" 3 "optimized" } } */
-/* { dg-final { scan-tree-dump-times "&a\\\[.* - 1\\\]" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "&a\\\[.* \\+ -1\\\]" 1 "optimized" } } */
/* { dg-final { scan-tree-dump-times "&a\\\[.* \\+ 1\\\]" 1 "optimized" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/pr23295.c b/gcc/testsuite/gcc.dg/pr23295.c
new file mode 100644
index 0000000..0418964
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr23295.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-fdump-tree-gimple" } */
+
+int foo(int i)
+{
+ return -i - 5;
+}
+
+/* { dg-final { scan-tree-dump "-5 - i" "gimple" } } */
+/* { dg-final { cleanup-tree-dump "gimple" } } */
diff --git a/gcc/testsuite/gcc.dg/pr27132.c b/gcc/testsuite/gcc.dg/pr27132.c
new file mode 100644
index 0000000..272862a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr27132.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-fdump-tree-gimple" } */
+
+int foo(int i)
+{
+ return i - -1;
+}
+
+/* { dg-final { scan-tree-dump "i \\+ 1" "gimple" } } */
+/* { dg-final { cleanup-tree-dump "gimple" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr23294.c b/gcc/testsuite/gcc.dg/tree-ssa/pr23294.c
index 35ab578..d73512d 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr23294.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr23294.c
@@ -32,7 +32,6 @@ int f6(int a, int b)
}
/* { dg-final { scan-tree-dump-times "a \\\* 5" 3 "optimized" } } */
-/* { dg-final { scan-tree-dump "\\\(b \\\* 3 \\\+ a\\\) \\\* 2" "optimized" } } */
-/* { dg-final { scan-tree-dump "\\\(a - b \\\* 3\\\) \\\* 2" "optimized" } } */
-/* { dg-final { scan-tree-dump "\\\(a \\\* 3 - b\\\) \\\* 2" "optimized" } } */
+/* { dg-final { scan-tree-dump-times "\\\) \\\* 2" 3 "optimized" } } */
+/* { dg-final { scan-tree-dump-not "\\\* 6" "optimized" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */