Commit 8f085166 by Richard Henderson Committed by Jeff Law

re PR middle-end/69845 (Expression getting incorrectly optimized after being rewritten by compiler)

2016-03-24  Richard Henderson  <rth@redhat.com>

	PR middle-end/69845
	* fold-const.c (extract_muldiv_1): Correct test for multiplication
	overflow.

	PR middle-end/69845
	* gcc.dg/tree-ssa/pr69845-1.c: New test.
	* gcc.dg/tree-ssa/pr69845-2.c: New test.

From-SVN: r234462
parent 011e5ec3
2016-03-24 Richard Henderson <rth@redhat.com>
PR middle-end/69845
* fold-const.c (extract_muldiv_1): Correct test for multiplication
overflow.
2016-03-24 Uros Bizjak <ubizjak@gmail.com> 2016-03-24 Uros Bizjak <ubizjak@gmail.com>
* config/i386/i386.md (*anddi3_doubleword): Generate AND insn * config/i386/i386.md (*anddi3_doubleword): Generate AND insn
......
...@@ -6116,11 +6116,9 @@ extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type, ...@@ -6116,11 +6116,9 @@ extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type,
{ {
tree tem = const_binop (code, fold_convert (ctype, t), tree tem = const_binop (code, fold_convert (ctype, t),
fold_convert (ctype, c)); fold_convert (ctype, c));
/* If the multiplication overflowed to INT_MIN then we lost sign /* If the multiplication overflowed, we lost information on it.
information on it and a subsequent multiplication might See PR68142 and PR69845. */
spuriously overflow. See PR68142. */ if (TREE_OVERFLOW (tem))
if (TREE_OVERFLOW (tem)
&& wi::eq_p (tem, wi::min_value (TYPE_PRECISION (ctype), SIGNED)))
return NULL_TREE; return NULL_TREE;
return tem; return tem;
} }
......
2016-03-24 Richard Henderson <rth@redhat.com>
PR middle-end/69845
* gcc.dg/tree-ssa/pr69845-1.c: New test.
* gcc.dg/tree-ssa/pr69845-2.c: New test.
2016-03-24 Tom de Vries <tom@codesourcery.com> 2016-03-24 Tom de Vries <tom@codesourcery.com>
* gfortran.dg/goacc/host_data-tree.f95: Add missing initialization. * gfortran.dg/goacc/host_data-tree.f95: Add missing initialization.
......
/* { dg-do compile } */
/* { dg-require-effective-target int32 } */
/* { dg-options "-O -fdump-tree-gimple -fdump-tree-optimized" } */
int
main ()
{
struct S { char s; } v;
v.s = 47;
int a = (int) v.s;
int b = (27005061 + (a + 680455));
int c = ((1207142401 * (((8 * b) + 9483541) - 230968044)) + 469069442);
if (c != 1676211843)
__builtin_abort ();
return 0;
}
/* { dg-final { scan-tree-dump-times "b \\\* 8" 1 "gimple" } } */
/* { dg-final { scan-tree-dump-not "abort" "optimized" } } */
/* { dg-do compile } */
/* { dg-require-effective-target int32 } */
/* { dg-options "-O -fdump-tree-gimple -fdump-tree-optimized" } */
int
main ()
{
struct S { char s; } v;
v.s = 47;
unsigned int a = (unsigned int) v.s;
unsigned int b = (27005061 + (a + 680455));
unsigned int c
= ((1207142401u * (((8u * b) + 9483541u) - 230968044u)) + 469069442u);
if (c != 1676211843u)
__builtin_abort ();
return 0;
}
/* { dg-final { scan-tree-dump-times "b \\\* 1067204616" 1 "gimple" } } */
/* { dg-final { scan-tree-dump-not "abort" "optimized" } } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment