http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55216
Bug #: 55216 Summary: Infinite loop generated on non-infinite code Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassig...@gcc.gnu.org ReportedBy: josh.m.con...@gmail.com Attempting to compile this code: int d[16]; int SATD (void) { int k, satd = 0, dd; for (dd=d[k=0]; k<16; dd=d[++k]) { satd += (dd < 0 ? -dd : dd); } return satd; } with -O2 generates an infinite loop: .L2: b .L2 I am using trunk gcc (sync'd to r193173) configured with: --target=arm-linux-gnueabi --with-cpu=cortex-a15 --with-gnu-as --with-gnu-ld --enable-__cxa_atexit --disable-libssp --disable-libmudflap --enable-languages=c,c++,fortran --disable-nls Although I am pretty sure this is a tree optimization issue and not a target issue because I see the transformation from a valid loop into an invalid loop during vrp1. Specifically, when visiting this PHI node for the last time: Visiting PHI node: k_1 = PHI <0(2), k_8(4)> Argument #0 (2 -> 3 executable) 0 Value: [0, 0] Argument #1 (4 -> 3 executable) k_8 Value: [1, 15] vrp_visit_phi_node determines that the range for k_1 is: k_1: [0,14] If I'm understanding this correctly, the union of these ranges should give us [0,15] instead (and would, except that adjust_range_with_scev() overrides it). This invalid range leads to the belief that the loop exit condition can never be met.