help using indvars pass

I am trying to use the indvars pass on a simple loop but it does not seem to have any effect
The sample code i am using is

#include <stdio.h>
int test (int p);
int main(){
int a,b=3;
if(b >3)

return 1;
int test(int p){
return p;

According to documentation the loop should get converted to something like

for (a = 0; a != 25; ++a)
 but the generated IR does not reflect this.the loop still goes from 7 to 99. Neither is there a Phinode for a
I am using the following commands

llvm-gcc -emit-llvm -c hello.c

opt -indvars hello.o >hello.bc
llvm-dis hello.bc

Is there something  I am missing?


Maybe you need to run mem2reg first?


You need more than mem2reg, but -O1 will do it for sure.


Thanks Eli. It worked. :slight_smile: