https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123887
--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
A more localized fix would be
diff --git a/gcc/match.pd b/gcc/match.pd
index 05e8ea7a229..9b2da2be4c5 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -5178,7 +5178,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(op:c @2 @1))
(if (INTEGRAL_TYPE_P (type)
&& TYPE_PRECISION (type) > 1
- && (INTEGRAL_TYPE_P (TREE_TYPE (@0))))
+ && INTEGRAL_TYPE_P (TREE_TYPE (@0))
+ && expr_no_side_effects_p (@2))
(op (mult (convert:type @0) @2) @1))))
/* (zero_one != 0) ? z <op> y : y -> ((typeof(y))zero_one * z) <op> y */
@@ -5190,7 +5191,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
@1)
(if (INTEGRAL_TYPE_P (type)
&& TYPE_PRECISION (type) > 1
- && (INTEGRAL_TYPE_P (TREE_TYPE (@0))))
+ && INTEGRAL_TYPE_P (TREE_TYPE (@0))
+ && expr_no_side_effects_p (@2))
(op (mult (convert:type @0) @2) @1))))
/* ?: Value replacement. */