On Sun, Apr 18, 2021 at 08:11:21PM -0400, Andrew MacLeod via Gcc-patches wrote:
> --- a/gcc/gimple-range-gori.cc
> +++ b/gcc/gimple-range-gori.cc
> @@ -29,6 +29,36 @@ along with GCC; see the file COPYING3.  If not see
>  #include "gimple-pretty-print.h"
>  #include "gimple-range.h"
>  
> +// Limit the nested depth thru logical expressions which GORI will build
> +// def chains.
> +#define LOGICAL_LIMIT        6

Such limits should be in params.def so that users can override them.

> +// Return TRUE if GS is a logical && or || expression.
> +
> +static inline bool
> +is_gimple_logical_p (const gimple *gs)
> +{
> +  // Look for boolean and/or condition.
> +  if (gimple_code (gs) == GIMPLE_ASSIGN)

  if (is_gimple_assign (gs))

is the normal spelling of this check.

But more importantly, isn't 6 too low for logicals, and wouldn't it be
better to put a cap not on the number of seen logicals, but on how many
SSA_NAMEs are handled in a query?  Because it is easy to construct
testcases where the logical limit would not trigger but the operands
of comparisons used in logicals would be thousands of arithmetic/bitwise
statements etc.  And it isn't just artificial, we have various examples
of generated tests in bugzilla that typically can't be compiled in
reasonable time at -O2 and need to use -O1 and have huge basic blocks with
very deep chains.

One thing is evrp/vrp passes where we want to compute ranges of all
SSA_NAMEs and if caching is done, compute range of everything at most once
(or with some bounded iteration counts for loops or whatever ranger uses).

And another thing is where passes ask for ranges, perhaps just those should
use the limit or should use lower limit.

        Jakub

Reply via email to