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
Confirmed. We seem to end up with a reduction partition not in the last position thus miss some required partition merging.
(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.
(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; } }
Started with r11-1565-g2c0069fafb53ccb7. I see it failing in blender SPEC benchmark.
@Bin: Any news about this?
(In reply to Martin Liška from comment #5) > @Bin: Any news about this? Patch is approved, will apply soon. Thanks
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.
Fixed - note it needs to be backported when the PR95638 fix is backported.
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)
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)
(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.