public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/100817] New: ICE with -O2: in compute_antic, at tree-ssa-pre.c:2513
@ 2021-05-28 17:24 cnsun at uwaterloo dot ca
  2021-05-28 19:24 ` [Bug tree-optimization/100817] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: cnsun at uwaterloo dot ca @ 2021-05-28 17:24 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100817
           Summary: ICE with -O2: in compute_antic, at tree-ssa-pre.c:2513
           Product: gcc
           Version: tree-ssa
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cnsun at uwaterloo dot ca
  Target Milestone: ---

$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/scratch/software/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/12.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /tmp/tmp.EknlexSzGF-gcc-builder/gcc/configure
--enable-languages=c,c++,lto --enable-checking-yes --enable-multiarch
--prefix=/scratch/software/gcc-trunk --disable-bootstrap
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.0.0 20210528 (experimental) [master revision
:0e2d976f7:cd62d089f6021fd1ad4537b8182836d15b14514f] (GCC)

$ cat mutant.c
a;
__attribute__((cold)) b ()
{
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a >= 0;)
for (; a;)
for (; a; a += 2)
;
}

$ gcc-trunk -O2 mutant.c
mutant.c:1:1: warning: data definition has no type or storage class
    1 | a;
      | ^
mutant.c:1:1: warning: type defaults to ‘int’ in declaration of ‘a’
[-Wimplicit-int]
mutant.c:2:23: warning: return type defaults to ‘int’ [-Wimplicit-int]
    2 | __attribute__((cold)) b ()
      |                       ^
during GIMPLE pass: pre
mutant.c: In function ‘b’:
mutant.c:2:23: internal compiler error: in compute_antic, at
tree-ssa-pre.c:2513
0x7920a1 compute_antic
        /tmp/tmp.EknlexSzGF-gcc-builder/gcc/gcc/tree-ssa-pre.c:2513
0x7920a1 execute
        /tmp/tmp.EknlexSzGF-gcc-builder/gcc/gcc/tree-ssa-pre.c:4384
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/100817] ICE with -O2: in compute_antic, at tree-ssa-pre.c:2513
  2021-05-28 17:24 [Bug c/100817] New: ICE with -O2: in compute_antic, at tree-ssa-pre.c:2513 cnsun at uwaterloo dot ca
@ 2021-05-28 19:24 ` pinskia at gcc dot gnu.org
  2021-05-31  6:53 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-05-28 19:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
      /* Theoretically possible, but *highly* unlikely.  */
      gcc_checking_assert (num_iterations < 500);

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/100817] ICE with -O2: in compute_antic, at tree-ssa-pre.c:2513
  2021-05-28 17:24 [Bug c/100817] New: ICE with -O2: in compute_antic, at tree-ssa-pre.c:2513 cnsun at uwaterloo dot ca
  2021-05-28 19:24 ` [Bug tree-optimization/100817] " pinskia at gcc dot gnu.org
@ 2021-05-31  6:53 ` rguenth at gcc dot gnu.org
  2021-05-31  8:35 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-05-31  6:53 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org
   Last reconfirmed|                            |2021-05-31

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Eh, interesting you managed to construct that worst-case CFG - I'm interested.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/100817] ICE with -O2: in compute_antic, at tree-ssa-pre.c:2513
  2021-05-28 17:24 [Bug c/100817] New: ICE with -O2: in compute_antic, at tree-ssa-pre.c:2513 cnsun at uwaterloo dot ca
  2021-05-28 19:24 ` [Bug tree-optimization/100817] " pinskia at gcc dot gnu.org
  2021-05-31  6:53 ` rguenth at gcc dot gnu.org
@ 2021-05-31  8:35 ` rguenth at gcc dot gnu.org
  2021-05-31  9:32 ` rguenth at gcc dot gnu.org
  2021-06-01  6:34 ` rguenth at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-05-31  8:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
The number of iterations grows linear with loop depth, starting with 6 for

for (; a;)
 for (; a >= 0;)
  for (; a;)
   for (; a; a += 2)
    ;

adding 2 for every

 for (; a;)
  for (; a >= 0;)

added.  The issue is that the postorder on the inverted graph chosen for
iteration is "worst" in how it iterates over the loop nest.  Adding an
exit to the innermost loop makes antic iteration iterate two times independent
on loop depth.  For anti iteration it's important to minimize the number of
blocks that are visited before all sucessors are visited, but here the whole
loop nest is only backwards reachable via backedges but there walking the
nest outer-to-inner producing N such blocks.

Now, doing reverse program order iteration after the initial postorder
traversal would fix this, so I'm going to explore this idea.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/100817] ICE with -O2: in compute_antic, at tree-ssa-pre.c:2513
  2021-05-28 17:24 [Bug c/100817] New: ICE with -O2: in compute_antic, at tree-ssa-pre.c:2513 cnsun at uwaterloo dot ca
                   ` (2 preceding siblings ...)
  2021-05-31  8:35 ` rguenth at gcc dot gnu.org
@ 2021-05-31  9:32 ` rguenth at gcc dot gnu.org
  2021-06-01  6:34 ` rguenth at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-05-31  9:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
Created attachment 50897
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50897&action=edit
patch

(In reply to Richard Biener from comment #3)
> The number of iterations grows linear with loop depth, starting with 6 for
> 
> for (; a;)
>  for (; a >= 0;)
>   for (; a;)
>    for (; a; a += 2)
>     ;
> 
> adding 2 for every
> 
>  for (; a;)
>   for (; a >= 0;)
> 
> added.  The issue is that the postorder on the inverted graph chosen for
> iteration is "worst" in how it iterates over the loop nest.  Adding an
> exit to the innermost loop makes antic iteration iterate two times
> independent
> on loop depth.  For anti iteration it's important to minimize the number of
> blocks that are visited before all sucessors are visited, but here the whole
> loop nest is only backwards reachable via backedges but there walking the
> nest outer-to-inner producing N such blocks.
> 
> Now, doing reverse program order iteration after the initial postorder
> traversal would fix this, so I'm going to explore this idea.

It's measurably worse for regular CFGs (gcc/*.c), just as example:

 attribs.c.334t.statistics:146 pre "compute_antic iterations == 2" 39
-attribs.c.334t.statistics:146 pre "compute_antic iterations == 3" 27
+attribs.c.334t.statistics:146 pre "compute_antic iterations == 3" 17
+attribs.c.334t.statistics:146 pre "compute_antic iterations == 4" 9
+attribs.c.334t.statistics:146 pre "compute_antic iterations == 5" 1

still only the very first "iteration" technically requires the
postorder on the inverted graph iteration order.  I've attached the patch
I've used for the measurement.

The immediate "fix" would be to remove the assert replacing it with a comment
refering to this PR.  But not sure if action is really required.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/100817] ICE with -O2: in compute_antic, at tree-ssa-pre.c:2513
  2021-05-28 17:24 [Bug c/100817] New: ICE with -O2: in compute_antic, at tree-ssa-pre.c:2513 cnsun at uwaterloo dot ca
                   ` (3 preceding siblings ...)
  2021-05-31  9:32 ` rguenth at gcc dot gnu.org
@ 2021-06-01  6:34 ` rguenth at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-06-01  6:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
int a;
int bar();
void __attribute__((cold)) b ()
{
#define FOO \
for (; a;) \
for (; a >= 0;)
#define FOO1 FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO
#define FOO2 FOO1 FOO1 FOO1 FOO1 FOO1 FOO1 FOO1 FOO1 FOO1 FOO1
  FOO2 FOO2 FOO2 FOO2 FOO2 FOO2
  for (; a;)
    for (; a; a += 2)
      if (bar()) return;
}

btw, for a shorter way to write

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-06-01  6:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-28 17:24 [Bug c/100817] New: ICE with -O2: in compute_antic, at tree-ssa-pre.c:2513 cnsun at uwaterloo dot ca
2021-05-28 19:24 ` [Bug tree-optimization/100817] " pinskia at gcc dot gnu.org
2021-05-31  6:53 ` rguenth at gcc dot gnu.org
2021-05-31  8:35 ` rguenth at gcc dot gnu.org
2021-05-31  9:32 ` rguenth at gcc dot gnu.org
2021-06-01  6:34 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).