aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Earnshaw <rearnsha@arm.com>2012-08-20 12:49:47 +0000
committerRichard Earnshaw <rearnsha@gcc.gnu.org>2012-08-20 12:49:47 +0000
commit7ab6a8280170732268c190fffb7f522c73f7b800 (patch)
tree974542ce1cddb8b6e57104203aaa61a2f96f6fcb /gcc
parent19f757838959f060042c2db6c6dee79a930dfa5c (diff)
downloadgcc-7ab6a8280170732268c190fffb7f522c73f7b800.zip
gcc-7ab6a8280170732268c190fffb7f522c73f7b800.tar.gz
gcc-7ab6a8280170732268c190fffb7f522c73f7b800.tar.bz2
re PR tree-optimization/54295 (Widening multiply-accumulate operation uses wrong value extension)
PR tree-ssa/54295 * tree-ssa-math-opts.c (widening_mult_conversion_strippable_p): New function. (is_widening_mult_rhs_p): Use it. * gcc.c-torture/execute/20120817-1.c: New test. From-SVN: r190533
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/20120817-1.c14
-rw-r--r--gcc/tree-ssa-math-opts.c41
4 files changed, 64 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index f892f00..13e2b4c 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2012-08-20 Richard Earnshaw <rearnsha@arm.com>
+
+ PR tree-ssa/54295
+ * tree-ssa-math-opts.c (widening_mult_conversion_strippable_p):
+ New function.
+ (is_widening_mult_rhs_p): Use it.
+
2012-08-20 Joseph Myers <joseph@codesourcery.com>
* configure.ac (ffs): Check for declaration.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index e9aaf24..f33149a 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,10 @@
2012-08-20 Richard Earnshaw <rearnsha@arm.com>
+ PR tree-ssa/54295
+ * gcc.c-torture/execute/20120817-1.c: New test.
+
+2012-08-20 Richard Earnshaw <rearnsha@arm.com>
+
* gcc.target/arm/thumb-16bit-ops.c (f): This test uses a 16-bit
add instruction.
(f2): New test that really does need adds.
diff --git a/gcc/testsuite/gcc.c-torture/execute/20120817-1.c b/gcc/testsuite/gcc.c-torture/execute/20120817-1.c
new file mode 100644
index 0000000..8fb2820
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/20120817-1.c
@@ -0,0 +1,14 @@
+typedef unsigned long long u64;
+unsigned long foo = 0;
+u64 f() __attribute__((noinline));
+
+u64 f() {
+ return ((u64)40) + ((u64) 24) * (int)(foo - 1);
+}
+
+int main ()
+{
+ if (f () != 16)
+ abort ();
+ exit (0);
+}
diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c
index 0d6eeb6..748bf2f 100644
--- a/gcc/tree-ssa-math-opts.c
+++ b/gcc/tree-ssa-math-opts.c
@@ -1958,6 +1958,43 @@ struct gimple_opt_pass pass_optimize_bswap =
}
};
+/* Return true if stmt is a type conversion operation that can be stripped
+ when used in a widening multiply operation. */
+static bool
+widening_mult_conversion_strippable_p (tree result_type, gimple stmt)
+{
+ enum tree_code rhs_code = gimple_assign_rhs_code (stmt);
+
+ if (TREE_CODE (result_type) == INTEGER_TYPE)
+ {
+ tree op_type;
+ tree inner_op_type;
+
+ if (!CONVERT_EXPR_CODE_P (rhs_code))
+ return false;
+
+ op_type = TREE_TYPE (gimple_assign_lhs (stmt));
+
+ /* If the type of OP has the same precision as the result, then
+ we can strip this conversion. The multiply operation will be
+ selected to create the correct extension as a by-product. */
+ if (TYPE_PRECISION (result_type) == TYPE_PRECISION (op_type))
+ return true;
+
+ /* We can also strip a conversion if it preserves the signed-ness of
+ the operation and doesn't narrow the range. */
+ inner_op_type = TREE_TYPE (gimple_assign_rhs1 (stmt));
+
+ if (TYPE_UNSIGNED (op_type) == TYPE_UNSIGNED (inner_op_type)
+ && TYPE_PRECISION (op_type) > TYPE_PRECISION (inner_op_type))
+ return true;
+
+ return false;
+ }
+
+ return rhs_code == FIXED_CONVERT_EXPR;
+}
+
/* Return true if RHS is a suitable operand for a widening multiplication,
assuming a target type of TYPE.
There are two cases:
@@ -1982,9 +2019,7 @@ is_widening_mult_rhs_p (tree type, tree rhs, tree *type_out,
if (is_gimple_assign (stmt))
{
rhs_code = gimple_assign_rhs_code (stmt);
- if (TREE_CODE (type) == INTEGER_TYPE
- ? !CONVERT_EXPR_CODE_P (rhs_code)
- : rhs_code != FIXED_CONVERT_EXPR)
+ if (! widening_mult_conversion_strippable_p (type, stmt))
rhs1 = rhs;
else
{