From: Richard Biener Date: Fri, 30 Jan 2026 18:30:40 +0000 (+0100) Subject: middle-end/123887 - fix another missing side-effect check X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cd6c3d19f6370810a20a2b84dad639200affa4fa;p=thirdparty%2Fgcc.git middle-end/123887 - fix another missing side-effect check The following fixes up another pattern lacking a check for side-effects on operands made evaluated unconditional. PR middle-end/123887 * match.pd ((a ? x : y) !=/== (b ? x : y)): Make sure x and y have no side-effects before evaluating them unconditionally. * gcc.dg/torture/pr123887-2.c: New testcase. --- diff --git a/gcc/match.pd b/gcc/match.pd index 9b2da2be4c5..f4732d39c51 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -6470,7 +6470,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (eqne (cnd @0 @1 @2) (cnd @3 @1 @2)) (if (!HONOR_NANS (@1) && types_match (TREE_TYPE (@0), TREE_TYPE (@3)) - && types_match (type, TREE_TYPE (@0))) + && types_match (type, TREE_TYPE (@0)) + && expr_no_side_effects_p (@1) + && expr_no_side_effects_p (@2)) (cnd (bit_and (bit_xor @0 @3) (ne:type @1 @2)) { constant_boolean_node (eqne == NE_EXPR, type); } { constant_boolean_node (eqne != NE_EXPR, type); }))) @@ -6478,7 +6480,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (eqne (cnd @0 @1 @2) (cnd @3 @2 @1)) (if (!HONOR_NANS (@1) && types_match (TREE_TYPE (@0), TREE_TYPE (@3)) - && types_match (type, TREE_TYPE (@0))) + && types_match (type, TREE_TYPE (@0)) + && expr_no_side_effects_p (@1) + && expr_no_side_effects_p (@2)) (cnd (bit_ior (bit_xor @0 @3) (eq:type @1 @2)) { constant_boolean_node (eqne != NE_EXPR, type); } { constant_boolean_node (eqne == NE_EXPR, type); }))))) diff --git a/gcc/testsuite/gcc.dg/torture/pr123887-2.c b/gcc/testsuite/gcc.dg/torture/pr123887-2.c new file mode 100644 index 00000000000..29c43369d6e --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr123887-2.c @@ -0,0 +1,12 @@ +/* { dg-do run } */ + +[[gnu::noipa]] +int f(int a, int b, int *x) +{ + return (a ? *x : 0) != (b ? *x : 0); +} +int main() +{ + f(0, 0, 0); + return 0; +}