[llvm-dev] Handling case when getCanonicalInductionVariable() returns NULL

Friedman, Eli via llvm-dev llvm-dev at lists.llvm.org
Mon Mar 20 10:25:35 PDT 2017


On 3/18/2017 10:06 AM, Alex Susu via llvm-dev wrote:
>   Hello.
>      Is there a way to obtain an llvm::Loop induction variable when 
> getCanonicalInductionVariable() returns NULL? This happens, for 
> example, when we have induction variables with non-unit step for loops 
> like:
>        for (row = 0; row < size; row += 2).
>     It seems that using parameters for opt like -indvars (I also 
> disabled it some time ago in PassManagerBuilder, but I made sure I 
> re-enabled it), -mem2reg, -loop-simplify do not help. (I got inspired 
> from other mail threads like 
> https://groups.google.com/forum/#!topic/llvm-dev/2xZAuiY9s_o OR 
> http://stackoverflow.com/questions/13831678/using-indvars-optimization-pass-for-finding-canonical-induction-variable-in-llvm 
> ).
>
>     I'm thinking to create my own method similar to 
> Loop::getCanonicalInductionVariable() (from 
> http://llvm.org/docs/doxygen/html/LoopInfo_8cpp_source.html#l00112 ).
>     But otherwise am I missing something? 

In general, the only way to obtain an induction variable for a loop is 
to generate it yourself; there is no general guarantee that a loop has 
an induction variable, and there is no optimization which produces them 
(except for LSR).  If you have a SCEV expression, you can use 
ScalarEvolutionExpander to get a Value* for a SCEV expression.

What are you trying to do?

-Eli

-- 
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project



More information about the llvm-dev mailing list