This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71423

Richard Biener <rguenth at gcc dot gnu.org> 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 <rguenth at gcc dot gnu.org> ---
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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]