https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117764
Bug ID: 117764 Summary: cddce should handle __builtin_unreachable guards Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: hubicka at gcc dot gnu.org Target Milestone: --- In the following testcase: #include <vector> void test (std::vector<int> v) { for (size_t i = 0; i < v.size (); i++) ; } we used to be able to optimize out the empty loop pre-inlining, however now after cddce2 we get: void test (struct vector & v) { ptrdiff_t __dif; size_t i; int * _4; int * _6; long int _7; long unsigned int _9; <bb 2> [local count: 118111600]: goto <bb 4>; [100.00%] <bb 3> [local count: 955630224]: i_5 = i_1 + 1; <bb 4> [local count: 1073741824]: # i_1 = PHI <0(2), i_5(3)> _4 = MEM[(const struct vector *)v_3(D)].D.25542._M_impl.D.24853._M_finish; _6 = MEM[(const struct vector *)v_3(D)].D.25542._M_impl.D.24853._M_start; _7 = _4 - _6; __dif_8 = _7 /[ex] 4; if (_7 < 0) goto <bb 5>; [0.00%] else goto <bb 6>; [100.00%] <bb 5> [count: 0]: __builtin_unreachable (); <bb 6> [local count: 1073741824]: _9 = (long unsigned int) __dif_8; if (i_1 < _9) goto <bb 3>; [89.00%] else goto <bb 7>; [11.00%] <bb 7> [local count: 118111600]: return; } The mini-dce of fnsummary is able to figure out that if (_7 < 0) is unnecesary, but rest is held together by the empty loop. I think cddce needs to understand __builtin_unreachable guards, too. However what is not clear to me is how to decide what guards are potentially useful for later optimization...