From: Richard Biener Date: Tue, 29 Nov 2016 07:48:43 +0000 (+0000) Subject: re PR rtl-optimization/78546 (wrong code at -O2 and above) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b302f2e058a37b462e8c78216a65ff7341a58bf1;p=gcc.git re PR rtl-optimization/78546 (wrong code at -O2 and above) 2016-11-29 Richard Biener PR middle-end/78546 * match.pd: Add CST1 - (CST2 - A) -> CST3 + A missing case. * gcc.dg/tree-ssa/forwprop-36.c: New testcase. From-SVN: r242953 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index fb25f75f23b..c1dd877bd3d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2016-11-29 Richard Biener + + PR middle-end/78546 + * match.pd: Add CST1 - (CST2 - A) -> CST3 + A missing case. + 2016-11-29 Janus Weil * doc/contrib.texi: Add a few missing gfortran contributors. diff --git a/gcc/match.pd b/gcc/match.pd index 2d4e0197c19..bc8a5e74d2d 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1195,7 +1195,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (minus @0 (minus @0 @1)) @1) - /* (A +- CST) +- CST -> A + CST */ + /* (A +- CST1) +- CST2 -> A + CST3 */ (for outer_op (plus minus) (for inner_op (plus minus) (simplify @@ -1208,7 +1208,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (cst && !TREE_OVERFLOW (cst)) (inner_op @0 { cst; } )))))) - /* (CST - A) +- CST -> CST - A */ + /* (CST1 - A) +- CST2 -> CST3 - A */ (for outer_op (plus minus) (simplify (outer_op (minus CONSTANT_CLASS_P@1 @0) CONSTANT_CLASS_P@2) @@ -1216,6 +1216,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (cst && !TREE_OVERFLOW (cst)) (minus { cst; } @0))))) + /* CST1 - (CST2 - A) -> CST3 + A */ + (simplify + (minus CONSTANT_CLASS_P@1 (minus CONSTANT_CLASS_P@2 @0)) + (with { tree cst = const_binop (MINUS_EXPR, type, @1, @2); } + (if (cst && !TREE_OVERFLOW (cst)) + (plus { cst; } @0)))) + /* ~A + A -> -1 */ (simplify (plus:c (bit_not @0) @0) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b325e2c9d58..d209fcbbce8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-11-29 Richard Biener + + PR middle-end/78546 + * gcc.dg/tree-ssa/forwprop-36.c: New testcase. + 2016-11-29 Segher Boessenkool * gcc.target/powerpc/rldic-0.c: New testcase. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/forwprop-36.c b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-36.c new file mode 100644 index 00000000000..9de73ff947f --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-36.c @@ -0,0 +1,24 @@ +/* { dg-do compile { target int128 } } */ +/* { dg-options "-O -fdump-tree-cddce1" } */ + +typedef unsigned __int128 u128; + +u128 a, b; + +static inline u128 +foo (u128 p1) +{ + p1 += ~b; + return -p1; +} + +int +main () +{ + u128 x = foo (~0x7fffffffffffffff); + if (x != 0x8000000000000001) + __builtin_abort(); + return 0; +} + +/* { dg-final { scan-tree-dump "if \\(b.0_\[0-9\]+ != 0\\)" "cddce1" } } */