<div>Dear LLVM,</div><div><br></div><div> Consider two loops with one interation - </div><div> First with constant lower bound, second with usual non-constant lower bound:</div><div> </div><div> int main(int argc, char ** argv)</div>
<div> {</div><div> int numOfIterations= 1;</div><div> int stride=1; </div><div> int lowerBound = 1000; - 1st | int lowerBound = argc; - 2nd</div><div> int upperBound = lowerBound + (numOfIterations - 1)*stride;</div>
<div><br></div><div> int i = lowerBound;</div><div><br></div><div> int s = 0;</div><div> while(i <= upperBound)</div><div> {</div><div> s += i;</div><div> i++;</div><div>
}</div><div> return s;</div><div> }</div><div> After the application of -O3 optimization:</div><div><br></div><div> The first loop was unrolled:</div><div> </div><div> define i32 @main(i32 %argc, i8** nocapture %argv) nounwind uwtable readnone {</div>
<div> entry:</div><div> ret i32 1000</div><div> }</div><div> </div><div> But the second was not:</div><div> </div><div> define i32 @main(i32 %argc, i8** nocapture %argv) nounwind uwtable readnone {</div>
<div> entry:</div><div> br label %"3"</div><div><br></div><div> "3": ; preds = %entry, %"3"</div><div> %0 = phi i32 [ 0, %entry ], [ %2, %"3" ]</div>
<div> %1 = phi i32 [ %argc, %entry ], [ %3, %"3" ]</div><div> %2 = add i32 %0, %1</div><div> %3 = add i32 %1, 1</div><div> %4 = icmp sgt i32 %3, %argc</div><div> br i1 %4, label %"5", label %"3"</div>
<div><br></div><div> "5": ; preds = %"3"</div><div> ret i32 %2</div><div> }</div><div> </div><div> The questions: </div><div> Is it possible to unroll loop with non-constant boundary using standard LLVM 3.1 facilities, and, if it is, how I can do that?</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div>Best regards,</div><div> Nicolas</div>