middle-end/106617 - fix fold_binary_op_with_conditional_arg pattern issue

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.
This commit is contained in:
Richard Biener 2022-08-18 11:10:30 +02:00
parent 03119249b9
commit ac68f904fe
2 changed files with 39 additions and 1 deletions

View 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. */

View file

@ -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))
);
}