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

--- Comment #9 from Qi Feng <ffengqi at gcc dot gnu.org> ---
And there's another problem. Take `x >  y  &&  x != 0   -->   x > y' for
example, I would also like to do

   x <  y  &&  y != 0  -->  x < y
   x != 0  &&  x >  y  -->  x > y
   y != 0  &&  x <  y  -->  x < y

If the constant always comes in as the second operand is incorrect, these would
have to be doubled.

I tried to add :c to truth_andif, but got the `operation is not commutative'
error.  I also tried to make truth_andif commutative by modifying genmatch.c,
but again, I don't know it well, afraid that I would break something.

The patterns I wrote looks like:

    /* x >  y  &&  x != 0     -->     x > y
       Only for unsigned x and y.  */
    (simplify
     (truth_andif:c (gt@2 @0 @1) (ne @0 integer_zerop))
     (if (INTEGRAL_TYPE_P (TREE_TYPE(@0)) && TYPE_UNSIGNED (TREE_TYPE(@0))
          && INTEGRAL_TYPE_P (TREE_TYPE(@1)) && TYPE_UNSIGNED (TREE_TYPE(@1)))
       @2))

I have to wrote 4 of this with minor modification for a single transformation.
If there's better way to do it, please do leave a comment.

Reply via email to