The current translation of GIMPLE to ISL only handles do-while loops correctly so we have to reject others.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk, queued for backporting. Richard. 2019-01-25 Richard Biener <rguent...@suse.de> PR tree-optimization/86865 * graphite-scop-detection.c (scop_detection::can_represent_loop): Reject non-do-while loops. * gcc.dg/graphite/pr86865.c: New testcase. Index: gcc/graphite-scop-detection.c =================================================================== --- gcc/graphite-scop-detection.c (revision 268010) +++ gcc/graphite-scop-detection.c (working copy) @@ -555,8 +555,15 @@ scop_detection::can_represent_loop (loop tree niter; struct tree_niter_desc niter_desc; - return single_exit (loop) - && !(loop_preheader_edge (loop)->flags & EDGE_IRREDUCIBLE_LOOP) + /* We can only handle do {} while () style loops correctly. */ + edge exit = single_exit (loop); + if (!exit + || !single_pred_p (loop->latch) + || exit->src != single_pred (loop->latch) + || !empty_block_p (loop->latch)) + return false; + + return !(loop_preheader_edge (loop)->flags & EDGE_IRREDUCIBLE_LOOP) && number_of_iterations_exit (loop, single_exit (loop), &niter_desc, false) && niter_desc.control.no_overflow && (niter = number_of_latch_executions (loop)) Index: gcc/testsuite/gcc.dg/graphite/pr86865.c =================================================================== --- gcc/testsuite/gcc.dg/graphite/pr86865.c (nonexistent) +++ gcc/testsuite/gcc.dg/graphite/pr86865.c (working copy) @@ -0,0 +1,35 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -fgraphite-identity -fstack-reuse=none -fwrapv -fno-tree-ch -fno-tree-dce -fno-tree-dominator-opts -fno-tree-loop-ivcanon" } */ + +int xy, tb; + +void +bt (void) +{ + for (xy = 0; xy >= 0; --xy) + { + int yt[8] = { 0 }; + int pz[2] = { 0 }; + int sa[32] = { 0 }; + int us; + + for (us = 0; us < 8; ++us) + yt[us] = 0; + + (void) yt; + (void) pz; + (void) sa; + } + + tb = 1; +} + +int +main (void) +{ + bt (); + if (xy != -1) + __builtin_abort (); + + return 0; +} Index: gcc/testsuite/gcc.dg/graphite/pr69728.c =================================================================== --- gcc/testsuite/gcc.dg/graphite/pr69728.c (revision 268010) +++ gcc/testsuite/gcc.dg/graphite/pr69728.c (working copy) @@ -24,4 +24,6 @@ fn1 () run into scheduling issues before here, not being able to handle empty domains. */ -/* { dg-final { scan-tree-dump "loop nest optimized" "graphite" } } */ +/* XFAILed by fix for PR86865. */ + +/* { dg-final { scan-tree-dump "loop nest optimized" "graphite" { xfail *-*-* } } } */ Index: gcc/testsuite/gcc.dg/graphite/scop-21.c =================================================================== --- gcc/testsuite/gcc.dg/graphite/scop-21.c (revision 268010) +++ gcc/testsuite/gcc.dg/graphite/scop-21.c (working copy) @@ -30,4 +30,5 @@ int test () return a[20]; } -/* { dg-final { scan-tree-dump-times "number of SCoPs: 1" 1 "graphite"} } */ +/* XFAILed by the fix for PR86865. */ +/* { dg-final { scan-tree-dump-times "number of SCoPs: 1" 1 "graphite" { xfail *-*-* } } } */