constructing 'for' statement from LLVM bitcode

Dear Wojciech Matyjewicz:

Thank you for your advice.
I could follow what you had suggested upto
  opt -analyze -loops bsloop-opt.bc

Therefore, I could get the prints you had showed me as follows:


Seung Jae Lee wrote:

In your reply, you could re-construct the simple 'for' from the info above like this:
FOR %i.0 = 0 TO %n - 1 STEP 1:
   %tmp4 = call i32 (...)* @norm( i32 0, i32 1 )
   // is no longer needed

I'd just like to make it sure whether you did this manually.
(LLVM doesn't support any pass doing this automatically for us. Am I right?)

You're right - there is no pass that automatically reconstructs 'for'
loops. I might have gone too far with the above example, because my
algorithm doesn't represent loops literally this way. It was only a
high-level view of information gathered about the loop.

By writing "simple for loop", I mean a loop which in C would have this form:
for (int i = low; i < up; i += step)
   // loop body

If it doesn't contain 'break', 'goto' nor 'continue' statements it is
generally translated to something like this (only -mem2reg and
-instcombine passes used):