[PATCH] Simplify (view_convert ~a) < 0 to (view_convert a) >= 0 [PR middle-end/100738]

Marc Glisse marc.glisse@inria.fr
Tue Jun 1 10:17:48 GMT 2021


On Tue, 1 Jun 2021, Hongtao Liu via Gcc-patches wrote:

> Hi:
>  This patch is about to simplify (view_convert:type ~a) < 0 to
> (view_convert:type a) >= 0 when type is signed integer. Similar for
> (view_convert:type ~a) >= 0.
>  Bootstrapped and regtested on x86_64-linux-gnu{-m32,}.
>  Ok for the trunk?
>
> gcc/ChangeLog:
>
>        PR middle-end/100738
>        * match.pd ((view_convert ~a) < 0 --> (view_convert a) >= 0,
>        (view_convert ~a) >= 0 --> (view_convert a) < 0): New GIMPLE
>        simplification.

We already have

/* Fold ~X op C as X op' ~C, where op' is the swapped comparison.  */
(for cmp (simple_comparison)
      scmp (swapped_simple_comparison)
  (simplify
   (cmp (bit_not@2 @0) CONSTANT_CLASS_P@1)
   (if (single_use (@2)
        && (TREE_CODE (@1) == INTEGER_CST || TREE_CODE (@1) == VECTOR_CST))
    (scmp @0 (bit_not @1)))))

Would it make sense to try and generalize it a bit, say with

(cmp (nop_convert1? (bit_not @0)) CONSTANT_CLASS_P)

(scmp (view_convert:XXX @0) (bit_not @1))

(I still believe that it is a bad idea that SSA_NAMEs are strongly typed, 
encoding the type in operations would be more convenient, but I think the 
time for that choice has long gone)

-- 
Marc Glisse


More information about the Gcc-patches mailing list