[LLVMdev] induction variables

David Crowe dcrowe at crhc.uiuc.edu
Tue Sep 9 20:53:00 PDT 2003

Hello LLVM,

Can you suggest a good way to use the loops and induction variable
passes to map loop exiting BasicBlocks to InductionVariables.  That is,
can we use these tools to identify the loop condition.

What i have tried
Function Pass:
  foreach BB
    if(terminal is loop exit of containing loop)
      trace back to instruction producing the cond that the 
      branch branches on - condProducer
      foreach(inst in loop header)
        if(isa PHI )
	  if(PHI uses condProducer)
            Run InductionVariables on this PHI Loop pair, 
            save result

Problems I have encountered:
Often the induction variable is stored in memory,
--basicaa --ds-aa --steens-aa -aa-eval --licm --indvars doesn't seems to
help much.  in fact it worsens the rates at which induction variables
are found because of the new code inserted.
Often the branch instruction uses a value where we must go backward
through several instructions to find the "true" induction variable

I guess the basis of my problem is my mapping loop exit block to PHI
nodes is too fragile for the general case.  Perhaps I am doing this the
wrong way.  Should I simply examine every PHI node in the loop header
and then determine if the value is eventually used in an exit block's
branch?  Any help on this, or further suggestions on the memory issue
would be appreciated.


More information about the llvm-dev mailing list