Hello,

I hadn't implemented this simplification because I think it is invalid code, but apparently people do write it, so we might as well handle it sensibly. This also happens to work around PR 83104 (already fixed).

bootstrap+regtest on powerpc64le-unknown-linux-gnu.

2017-11-22  Marc Glisse  <marc.gli...@inria.fr>

        * match.pd (ptr-0): New transformation.

--
Marc Glisse
Index: gcc/match.pd
===================================================================
--- gcc/match.pd	(revision 255052)
+++ gcc/match.pd	(working copy)
@@ -95,20 +95,25 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 (for op (plus pointer_plus minus bit_ior bit_xor)
   (simplify
     (op @0 integer_zerop)
     (non_lvalue @0)))
 
 /* 0 +p index -> (type)index */
 (simplify
  (pointer_plus integer_zerop @1)
  (non_lvalue (convert @1)))
 
+/* ptr - 0 -> (type)ptr */
+(simplify
+ (pointer_diff @0 integer_zerop)
+ (convert @0))
+
 /* See if ARG1 is zero and X + ARG1 reduces to X.
    Likewise if the operands are reversed.  */
 (simplify
  (plus:c @0 real_zerop@1)
  (if (fold_real_zero_addition_p (type, @1, 0))
   (non_lvalue @0)))
 
 /* See if ARG1 is zero and X - ARG1 reduces to X.  */
 (simplify
  (minus @0 real_zerop@1)

Reply via email to