<div dir="ltr"><div><div><div>Hi,<br><br></div>I'm attempting to understand why in the following C++ code LLVM produes cycles in the IR (for `cycle1` and `cycle2`, that do not have data-dependent cycles), but `nocycle` is not. In the first two cases, `Count` has an undefined value when `Count + 1` is evaluated and the value is scoped to the body of the loop so can't (or shouldn't) hold values from one iteration to the next, but in `clang++ -std=c++11 sample.cpp -S -emit-llvm -OX -o sample.ll` where X = any of 0,1,2,3,s,z, a data-dependent cycle is created - like below:<br><br></div><div style="margin-left:40px">%for.body:<br></div><div><div style="margin-left:40px">  Count.012 = phi i32 [ undef, %entry ], [ %cond.i, %for.body ]<br>  %add = add nsw i32 %Count.012, 1<br>  %cond.i = select i1 %call, i32 %0, i32 %add<br></div><br></div>Thanks,<br></div>Matt<br><div><div><br><div style="margin-left:40px">int select(bool P, int True, int False) { return P ? True : False; }<br><br>bool random(void);<br><br>void cycle1(int (&Input)[100], int (&Output)[100]) {<br>  for (int I = 0, N = 100; I < N; ++I) {<br>    int Count;<br><br>    Count = select(random(), Input[I], Count + 1);<br><br>    Output[I] = Count;<br>  }<br>}<br><br>void cycle2(int (&Input)[100], int (&Output)[100]) {<br>  for (int I = 0, N = 100; I < N; ++I) {<br>    int Count = select(random(), Input[I], Count + 1);<br><br>    Output[I] = Count;<br>  }<br>}<br><br>void nocycle1(int (&Input)[100], int (&Output)[100]) {<br>  for (int I = 0, N = 100; I < N; ++I) {<br>    int Count = 0;<br><br>    Count = select(random(), Input[I], Count + 1);<br><br>    Output[I] = Count;<br>  }<br>}<br></div><br></div></div></div>