[Bug tree-optimization/71423] [5/6/7 Regression] wrong code at -Os and above on x86_64-linux-gnu

2016-06-07 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71423

--- Comment #4 from Richard Biener  ---
Author: rguenth
Date: Tue Jun  7 07:30:47 2016
New Revision: 237166

URL: https://gcc.gnu.org/viewcvs?rev=237166=gcc=rev
Log:
2016-06-07  Richard Biener  

PR middle-end/71423
* match.pd ((X | ~Y) -> Y <= X): Properly invert the comparison
for signed ops.

* gcc.dg/torture/pr71423.c: New testcase.

Added:
trunk/gcc/testsuite/gcc.dg/torture/pr71423.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/match.pd
trunk/gcc/testsuite/ChangeLog

[Bug tree-optimization/71423] [5/6/7 Regression] wrong code at -Os and above on x86_64-linux-gnu

2016-06-06 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71423

Richard Biener  changed:

   What|Removed |Added

   Keywords||wrong-code
 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |rguenth at gcc dot 
gnu.org
   Target Milestone|--- |5.5
Summary|[6/7 Regression] wrong code |[5/6/7 Regression] wrong
   |at -Os and above on |code at -Os and above on
   |x86_64-linux-gnu|x86_64-linux-gnu

--- Comment #3 from Richard Biener  ---
Those transforms were carried over from tree-ssa-forwprop.c IIRC.  On the
gcc-4_9-branch this was done in simplify_bitwise_binary thus the issue is
latent on the gcc-5-branch as well.  In its transform phase it did the
proper comparison swapping:

static bool
simplify_bitwise_binary_boolean (gimple_stmt_iterator *gsi,
 enum tree_code code,
 tree op0, tree op1)
{
...
  if (code == BIT_AND_EXPR)
newcode = TYPE_UNSIGNED (TREE_TYPE (x)) ? LT_EXPR : GT_EXPR;
  else
newcode = TYPE_UNSIGNED (TREE_TYPE (x)) ? LE_EXPR : GE_EXPR;

The following fixes it.

Index: gcc/match.pd
===
--- gcc/match.pd(revision 237117)
+++ gcc/match.pd(working copy)
@@ -900,12 +900,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (ne (bit_and:c (bit_not @0) @1) integer_zerop)
   (if (INTEGRAL_TYPE_P (TREE_TYPE (@1))
&& TYPE_PRECISION (TREE_TYPE (@1)) == 1)
-   (lt @0 @1)))
+   (if (TYPE_UNSIGNED (TREE_TYPE (@1)))
+(lt @0 @1)
+(gt @0 @1
 (simplify
   (ne (bit_ior:c (bit_not @0) @1) integer_zerop)
   (if (INTEGRAL_TYPE_P (TREE_TYPE (@1))
&& TYPE_PRECISION (TREE_TYPE (@1)) == 1)
-   (le @0 @1)))
+   (if (TYPE_UNSIGNED (TREE_TYPE (@1)))
+(le @0 @1)
+(ge @0 @1

 /* ~~x -> x */
 (simplify