]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
middle-end/123887 - fix another missing side-effect check
authorRichard Biener <rguenther@suse.de>
Fri, 30 Jan 2026 18:30:40 +0000 (19:30 +0100)
committerRichard Biener <rguenther@suse.de>
Sat, 31 Jan 2026 12:05:22 +0000 (13:05 +0100)
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.

gcc/match.pd
gcc/testsuite/gcc.dg/torture/pr123887-2.c [new file with mode: 0644]

index 9b2da2be4c545687d2293f36b2599522c7ebdef6..f4732d39c517a8cc9ff41c9b1d18e3756dbec72e 100644 (file)
@@ -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 (file)
index 0000000..29c4336
--- /dev/null
@@ -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;
+}