Bug 95804 - [11 Regression] ICE in generate_code_for_partition, at tree-loop-distribution.c:1323 since r11-1565-g2c0069fafb53ccb7
Summary: [11 Regression] ICE in generate_code_for_partition, at tree-loop-distribution...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 11.0
: P3 normal
Target Milestone: 11.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks: spec 95638
  Show dependency treegraph
 
Reported: 2020-06-21 19:40 UTC by David Binderman
Modified: 2020-07-10 05:12 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-06-22 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Binderman 2020-06-21 19:40:48 UTC
This C source code:

int a, b, c, e;
int *d;
void f() {
  int g;
  int *h;
  for (; b; b++) {
    for (; c; c++)
      ;
    e = *d || *h;
    for (; a; a++)
      h = g;
  }
  for (; e;)
    ;
}

on recent gcc trunk with compiler flag -O3 on x86_64, does this:

$ /home/dcb/gcc/results/bin/gcc -c -w -O3 bug624.c
during GIMPLE pass: ldist
bug624.c: In function ‘f’:
bug624.c:3:6: internal compiler error: in generate_code_for_partition, at tree-loop-distribution.c:1323
    3 | void f() {
      |      ^
0x85d652 generate_code_for_partition
	../../trunk.git/gcc/tree-loop-distribution.c:1323
0x3343807 loop_distribution::distribute_loop(loop*, vec<gimple*, va_heap, vl_ptr>, control_dependences*, int*, bool*, bool)
	../../trunk.git/gcc/tree-loop-distribution.c:3114
0x334a754 loop_distribution::execute(function*)
	../../trunk.git/gcc/tree-loop-distribution.c:3303
0x334e075 execute
	../../trunk.git/gcc/tree-loop-distribution.c:3391
Comment 1 Richard Biener 2020-06-22 08:48:25 UTC
Confirmed.  We seem to end up with a reduction partition not in the last
position thus miss some required partition merging.
Comment 2 bin cheng 2020-06-22 09:06:16 UTC
(In reply to Richard Biener from comment #1)
> Confirmed.  We seem to end up with a reduction partition not in the last
> position thus miss some required partition merging.
Sorry for the breakage.

Whew, this part IS can of worms.  Will investigate it.
Comment 3 David Binderman 2020-06-22 15:26:38 UTC
(In reply to bin cheng from comment #2)
> Whew, this part IS can of worms.  Will investigate it.

Great. The testcase I provided came from a C source code generator
called ccg. 

Here is another C test case which produces the same compiler crash with -O3:

$ more bug625.c
int a, b, c, d, e, f;
void g() {
  short *h = d;
  char *i = &b;
  for (; e; e++) {
    for (; f; f++) {
      b = 3;
      if ((c = 8) >= *i)
        a = 5 ? *h : 0;
      h = g;
    }
    i = &c;
  }
}
Comment 4 Martin Liška 2020-06-25 06:07:38 UTC
Started with r11-1565-g2c0069fafb53ccb7. I see it failing in blender SPEC benchmark.
Comment 5 Martin Liška 2020-07-08 17:56:31 UTC
@Bin: Any news about this?
Comment 6 bin cheng 2020-07-09 01:50:29 UTC
(In reply to Martin Liška from comment #5)
> @Bin: Any news about this?

Patch is approved, will apply soon.  Thanks
Comment 7 GCC Commits 2020-07-09 10:29:04 UTC
The master branch has been updated by Bin Cheng <amker@gcc.gnu.org>:

https://gcc.gnu.org/g:dd21b03900085c4d60bf03207ad28bcbfbc86a4b

commit r11-1968-gdd21b03900085c4d60bf03207ad28bcbfbc86a4b
Author: Bin Cheng <bin.cheng@linux.alibaba.com>
Date:   Thu Jul 9 18:10:03 2020 +0800

    Schedule reduction partition in the last.
    
    If reduction partition's SCC is broken by runtime alias checks, force
    a negative post order to it so that it will be scheduled in the last.
    
    2020-07-09  Bin Cheng  <bin.cheng@linux.alibaba.com>
    
    gcc/
            PR tree-optimization/95804
            * tree-loop-distribution.c (break_alias_scc_partitions): Force
            negative post order to reduction partition.
    
    gcc/testsuite/
            PR tree-optimization/95804
            * gcc.dg/tree-ssa/pr95804.c: New test.
Comment 8 Richard Biener 2020-07-09 11:47:27 UTC
Fixed - note it needs to be backported when the PR95638 fix is backported.
Comment 9 GCC Commits 2020-07-10 04:03:25 UTC
The releases/gcc-10 branch has been updated by Bin Cheng <amker@gcc.gnu.org>:

https://gcc.gnu.org/g:c7247272375899af51726df8424e911f00374200

commit r10-8454-gc7247272375899af51726df8424e911f00374200
Author: Bin Cheng <bin.cheng@linux.alibaba.com>
Date:   Thu Jul 9 18:10:03 2020 +0800

    Schedule reduction partition in the last.
    
    If reduction partition's SCC is broken by runtime alias checks, force
    a negative post order to it so that it will be scheduled in the last.
    
    2020-07-09  Bin Cheng  <bin.cheng@linux.alibaba.com>
    
    gcc/
            PR tree-optimization/95804
            * tree-loop-distribution.c (break_alias_scc_partitions): Force
            negative post order to reduction partition.
    
    gcc/testsuite/
            PR tree-optimization/95804
            * gcc.dg/tree-ssa/pr95804.c: New test.
    
    (cherry picked from commit dd21b03900085c4d60bf03207ad28bcbfbc86a4b)
Comment 10 GCC Commits 2020-07-10 04:12:58 UTC
The releases/gcc-9 branch has been updated by Bin Cheng <amker@gcc.gnu.org>:

https://gcc.gnu.org/g:8c25c91b117d814cf5c1deffd8a79b03fce68621

commit r9-8731-g8c25c91b117d814cf5c1deffd8a79b03fce68621
Author: Bin Cheng <bin.cheng@linux.alibaba.com>
Date:   Thu Jul 9 18:10:03 2020 +0800

    Schedule reduction partition in the last.
    
    If reduction partition's SCC is broken by runtime alias checks, force
    a negative post order to it so that it will be scheduled in the last.
    
    2020-07-09  Bin Cheng  <bin.cheng@linux.alibaba.com>
    
    gcc/
            PR tree-optimization/95804
            * tree-loop-distribution.c (break_alias_scc_partitions): Force
            negative post order to reduction partition.
    
    gcc/testsuite/
            PR tree-optimization/95804
            * gcc.dg/tree-ssa/pr95804.c: New test.
    
    (cherry picked from commit dd21b03900085c4d60bf03207ad28bcbfbc86a4b)
Comment 11 bin cheng 2020-07-10 05:12:01 UTC
(In reply to Richard Biener from comment #8)
> Fixed - note it needs to be backported when the PR95638 fix is backported.

I backported PR95638/PR95804 to GCC-10/GCC-9 branches.  However, unnecessary to backport to GCC-8, because the starting issue (pr94125) is not exposed on it.