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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Well, genmatch has some code to add TREE_SIDE_EFFECTS checks on its own, but
apparently it doesn't trigger in this case, perhaps it needs be conditional in
the matching pattern rather than replacement or it needs to be matched more
than once.
--- gcc/match.pd.jj     2020-02-05 11:12:33.679383217 +0100
+++ gcc/match.pd        2020-02-14 22:31:46.416421704 +0100
@@ -1472,7 +1472,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 (for cmp (gt lt ge le)
 (simplify
  (mult (convert (cmp @0 @1)) @2)
-  (cond (cmp @0 @1) @2 { build_zero_cst (type); })))
+  (if (GIMPLE || !TREE_SIDE_EFFECTS (@2))
+   (cond (cmp @0 @1) @2 { build_zero_cst (type); }))))

 /* For integral types with undefined overflow and C != 0 fold
    x * C EQ/NE y * C into x EQ/NE y.  */
of course fixes it, will bootstrap/regtest it with the testcase and let's see
what Richi will say ;).

Reply via email to