]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
middle-end/106617 - fix fold_binary_op_with_conditional_arg pattern issue
authorRichard Biener <rguenther@suse.de>
Thu, 18 Aug 2022 09:10:30 +0000 (11:10 +0200)
committerRichard Biener <rguenther@suse.de>
Thu, 18 Aug 2022 14:03:58 +0000 (16:03 +0200)
Now that we have parts of fold_binary_op_with_conditional_arg duplicated
in match.pd and are using ! to take or throw away the result we have to
be careful to not have both implementations play games which each other,
causing quadratic behavior.  In particular the match.pd implementation
requires both arms to simplify while the fold-const.cc is happy with
just one arm simplifying (something we cannot express in match.pd).

The fix is to simply not enable the match.pd pattern for GENERIC.

PR middle-end/106617
* match.pd ((a ? b : c) > d -> a ? (b > d) : (c > d)): Fix
guard, disable on GENERIC to not cause quadratic behavior
with the fold-const.cc implementation and the use of !

* gcc.dg/pr106617.c: New testcase.

gcc/match.pd
gcc/testsuite/gcc.dg/pr106617.c [new file with mode: 0644]

index 07d0a61fc3a72e16af32802b2f22d3efa9872261..1bb936fc4010f98f24bb97671350e8432c55b347 100644 (file)
@@ -5796,6 +5796,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (cmp (bit_and@2 @0 integer_pow2p@1) @1)
   (icmp @2 { build_zero_cst (TREE_TYPE (@0)); })))
 
+#if GIMPLE
 /* From fold_binary_op_with_conditional_arg handle the case of
    rewriting (a ? b : c) > d to a ? (b > d) : (c > d) when the
    compares simplify.  */
@@ -5805,8 +5806,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   /* Do not move possibly trapping operations into the conditional as this
      pessimizes code and causes gimplification issues when applied late.  */
   (if (!FLOAT_TYPE_P (TREE_TYPE (@3))
-       || operation_could_trap_p (cmp, true, false, @3))
+       || !operation_could_trap_p (cmp, true, false, @3))
    (cond @0 (cmp! @1 @3) (cmp! @2 @3)))))
+#endif
 
 (for cmp (ge lt)
 /* x < 0 ? ~y : y into (x >> (prec-1)) ^ y. */
diff --git a/gcc/testsuite/gcc.dg/pr106617.c b/gcc/testsuite/gcc.dg/pr106617.c
new file mode 100644 (file)
index 0000000..4274b55
--- /dev/null
@@ -0,0 +1,36 @@
+/* { dg-do compile } */
+
+int nr_cpu_ids;
+void fc_setup_exch_mgr() {
+  (((((((1UL << (((0, 0)
+                            ? ((1)
+                                   ? (((nr_cpu_ids)) ? 0
+                                      : ((nr_cpu_ids)) & (21) ? 21
+                                      : ((nr_cpu_ids)) ? 20
+                                      : ((nr_cpu_ids)) & (19) ? 19
+                                      : ((nr_cpu_ids)) ? 18
+                                      : ((nr_cpu_ids)) & (17) ? 17
+                                      : ((nr_cpu_ids)) ? 16
+                                      : ((nr_cpu_ids)) & (15) ? 15
+                                      : ((nr_cpu_ids)) ? 14
+                                      : ((nr_cpu_ids)) & (13) ? 13
+                                      : ((nr_cpu_ids)) ? 12
+                                      : ((nr_cpu_ids)) & (11) ? 11
+                                      : ((nr_cpu_ids)) ? 10
+                                      : ((nr_cpu_ids)) & (9)  ? 9
+                                      : ((nr_cpu_ids))  ? 8
+                                      : ((nr_cpu_ids)) & (7)  ? 7
+                                      : ((nr_cpu_ids))  ? 6
+                                      : ((nr_cpu_ids)) & (5)  ? 5
+                                      : ((nr_cpu_ids))  ? 4
+                                      : ((nr_cpu_ids)) & (3)
+                                          ? 3
+                                          : ((nr_cpu_ids)-1) & 1)
+                                   : 1)
+                            : 0) +
+                       1))))) &
+                 (1UL << 2)
+             ? 2
+             : 1))
+           );
+}