https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129117

Paul Menzel <pmenzel+gcc at molgen dot mpg.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pmenzel+gcc at molgen dot 
mpg.de

--- Comment #3 from Paul Menzel <pmenzel+gcc at molgen dot mpg.de> ---
Analysis with help of claude-opus-5.5 of the compile time:

For a logical stmt, gori_compute::compute_operand_range calls
compute_logical_operands for both operands, which solves for NAME with the
operand being true and with it being false.  In this test case both operands of

  _21 = _5 | _6;      // _5 = (unsigned) _18 <= q, _6 = ~_18
  _22 = A_15 | _21;

depend on the previous link _18, but neither is in the def chain of the other,
so the existing "op1 in chain of op2" check does not apply.  The same (operand,
true/false) pair is therefore solved again along every path that reaches it:
exponential in the number of links.

ranger-logical-depth does not bound this reliably.  get_def_chain returns NULL
without caching when m_logical_depth reaches the limit, so a later query for
the same name from a shallower depth builds and caches the full chain. That
makes the effective depth depend on the order of the queries, which is probably
why only some --param=ranger-logical-depth values help in comment 0 (not
verified).                             

Memoizing the operand ranges per backward solve (keyed on operand SSA version
and true/false; valid while NAME and the fur_source are the same) makes the
work linear.  Measured on trunk 81b35e05d4b, release checking, one core of an
AMD EPYC 7763 (time in s; 120 s timeout):                                       

  links  -O1 before  -O1 after  -O2 before  -O2 after                           
     9      0.27       0.02        2.79       0.02                              
    10      1.15       0.02       12.63       0.03                              
    11      5.07       0.02       57.73       0.02                              
    12     22.90       0.02     >120          0.03                              
    20    >120         0.02     >120          0.03                              
   100    >120         0.04     >120          0.07                              

Assembly at -O1 and -O2 of the 14,478 C files in gcc.dg, gcc.dg/tree-ssa,
gcc.dg/vect and gcc.c-torture is unchanged by it.                               

On comment #2 (PR129118 alone): with x starting from an independent _Bool
instead of q,                                                                   

  int f(int a, unsigned q, _Bool b) { _Bool A = !a, x = b; S ... }              

the first link no longer folds, and trunk is as slow as with the original test
case (-O2, 11 links: 57.5 s; 12 links: >100 s).  With the memoization it takes
0.1 s for 100 links.  Code generation is identical either way: at -O2 the
11-link function from comment #0 is 85 instructions, although it is equivalent
to "return a;" (for an even number of links, to "return q ? a : 0;"), so
PR129118 and PR129127 remain worthwhile for code quality.

Reply via email to