From: Andrew Stubbs Date: Tue, 18 Oct 2011 19:57:15 +0000 (+0000) Subject: re PR tree-optimization/50717 (Silent code gen fault with incorrect widening of multiply) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3d71881d2d0380a58370694a053cedf721c3e05f;p=gcc.git re PR tree-optimization/50717 (Silent code gen fault with incorrect widening of multiply) 2011-10-18 Andrew Stubbs PR tree-optimization/50717 gcc/ * tree-ssa-math-opts.c (is_widening_mult_p): Remove the 'type' parameter. Calculate 'type' from stmt. (convert_mult_to_widen): Update call the is_widening_mult_p. (convert_plusminus_to_widen): Likewise. gcc/testsuite/ * gcc.dg/pr50717-1.c: New file. * gcc.target/arm/wmul-12.c: Correct types. * gcc.target/arm/wmul-8.c: Correct types. From-SVN: r180164 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 40e2998f481..365eb94f031 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2011-10-18 Andrew Stubbs + + PR tree-optimization/50717 + + * tree-ssa-math-opts.c (is_widening_mult_p): Remove the 'type' + parameter. Calculate 'type' from stmt. + (convert_mult_to_widen): Update call the is_widening_mult_p. + (convert_plusminus_to_widen): Likewise. + 2011-10-18 Ulrich Weigand * config/spu/spu.c (struct machine_function): New data structure. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ed9a8e61640..2ed54293ab4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2011-10-18 Andrew Stubbs + + PR tree-optimization/50717 + + * gcc.dg/pr50717-1.c: New file. + * gcc.target/arm/wmul-12.c: Correct types. + * gcc.target/arm/wmul-8.c: Correct types. + 2011-10-18 Jason Merrill PR c++/50531 diff --git a/gcc/testsuite/gcc.dg/pr50717-1.c b/gcc/testsuite/gcc.dg/pr50717-1.c new file mode 100644 index 00000000000..afbe542a2be --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr50717-1.c @@ -0,0 +1,26 @@ +/* PR tree-optimization/50717 */ +/* Ensure that widening multiply-and-accumulate is not used where integer + type promotion or users' casts should prevent it. */ + +/* { dg-options "-O2 -fdump-tree-widening_mul" } */ + +long long +f (unsigned int a, char b, long long c) +{ + return (a * b) + c; +} + +int +g (short a, short b, int c) +{ + return (short)(a * b) + c; +} + +int +h (char a, char b, int c) +{ + return (char)(a * b) + c; +} + +/* { dg-final { scan-tree-dump-times "WIDEN_MULT_PLUS_EXPR" 0 "widening_mul" } } */ +/* { dg-final { cleanup-tree-dump "widening_mul" } } */ diff --git a/gcc/testsuite/gcc.target/arm/wmul-12.c b/gcc/testsuite/gcc.target/arm/wmul-12.c index 556e53f8e44..5c6b5b9882c 100644 --- a/gcc/testsuite/gcc.target/arm/wmul-12.c +++ b/gcc/testsuite/gcc.target/arm/wmul-12.c @@ -5,8 +5,8 @@ long long foo (int *b, int *c) { - int tmp = *b * *c; - return 10 + (long long)tmp; + long long tmp = (long long)*b * *c; + return 10 + tmp; } /* { dg-final { scan-assembler "smlal" } } */ diff --git a/gcc/testsuite/gcc.target/arm/wmul-8.c b/gcc/testsuite/gcc.target/arm/wmul-8.c index 3de065d0a62..5ae110d3c49 100644 --- a/gcc/testsuite/gcc.target/arm/wmul-8.c +++ b/gcc/testsuite/gcc.target/arm/wmul-8.c @@ -5,7 +5,7 @@ long long foo (long long a, int *b, int *c) { - return a + *b * *c; + return a + (long long)*b * *c; } /* { dg-final { scan-assembler "smlal" } } */ diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c index 02d91ca8bbd..75abb3369a1 100644 --- a/gcc/tree-ssa-math-opts.c +++ b/gcc/tree-ssa-math-opts.c @@ -2039,10 +2039,12 @@ is_widening_mult_rhs_p (tree type, tree rhs, tree *type_out, and *TYPE2_OUT would give the operands of the multiplication. */ static bool -is_widening_mult_p (tree type, gimple stmt, +is_widening_mult_p (gimple stmt, tree *type1_out, tree *rhs1_out, tree *type2_out, tree *rhs2_out) { + tree type = TREE_TYPE (gimple_assign_lhs (stmt)); + if (TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != FIXED_POINT_TYPE) return false; @@ -2104,7 +2106,7 @@ convert_mult_to_widen (gimple stmt, gimple_stmt_iterator *gsi) if (TREE_CODE (type) != INTEGER_TYPE) return false; - if (!is_widening_mult_p (type, stmt, &type1, &rhs1, &type2, &rhs2)) + if (!is_widening_mult_p (stmt, &type1, &rhs1, &type2, &rhs2)) return false; to_mode = TYPE_MODE (type); @@ -2281,7 +2283,7 @@ convert_plusminus_to_widen (gimple_stmt_iterator *gsi, gimple stmt, if (code == PLUS_EXPR && (rhs1_code == MULT_EXPR || rhs1_code == WIDEN_MULT_EXPR)) { - if (!is_widening_mult_p (type, rhs1_stmt, &type1, &mult_rhs1, + if (!is_widening_mult_p (rhs1_stmt, &type1, &mult_rhs1, &type2, &mult_rhs2)) return false; add_rhs = rhs2; @@ -2289,7 +2291,7 @@ convert_plusminus_to_widen (gimple_stmt_iterator *gsi, gimple stmt, } else if (rhs2_code == MULT_EXPR || rhs2_code == WIDEN_MULT_EXPR) { - if (!is_widening_mult_p (type, rhs2_stmt, &type1, &mult_rhs1, + if (!is_widening_mult_p (rhs2_stmt, &type1, &mult_rhs1, &type2, &mult_rhs2)) return false; add_rhs = rhs1;