<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Jul 27, 2011, at 7:11 AM, Jimborean Alexandra wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><div style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-family: arial, helvetica, sans-serif; font-size: 10pt; position: static; z-index: auto; "><div>Hello,</div><div><br></div><div>How can I compute the functions on the loop iterators used as array indices? </div><div><br></div><div>For example:</div><div><br></div><div>for i = 0, N</div><div>      for j = 0, M</div><div><span class="tab">    </span><span class="tab">    </span><span class="tab">    A[2*i + j - 10] = ... </span></div><div><br><span class="tab"></span></div><div><span class="tab">Can I obtain that this instruction </span><span class="tab">A[2*i + j - 10]= .. always accesses memory using a function       f(i,j)   =   2*i + j - 10 + base_address_of_A</span></div><div><br><span class="tab"></span></div><div><span class="tab">If I run the scalar evolution pass on this code I obtain:</span></div><div><span class="tab"><br></span></div><div><span class="tab">%arrayidx = getelementptr inbounds [200 x i32]* @main.A, i32 0, i64 %idxprom</span></div><div><span class="tab"><br></span></div><div><span class="tab">  -->  ((4 * (sext i32 (-10 + (2 * %tmp6) + %tmp7) to i64)) + @main.A)        </span></div><div><br><span class="tab"></span></div><div><span class="tab">Could you please offer an insight on how can I obtain the function from the internals of the scalar evolution pass? </span></div><div><span class="tab">Thank you.<br></span></div><div><br><span class="tab"></span></div><div><span class="tab">Alexandra<br></span></div></div></div></blockquote><br></div><div>Hello Alexandra,</div><div><br></div><div>The scalar evolution pass doesn't to anything when it runs except initialize some empty maps. The important one is the Value->SCEV map. SCEV is the class that holds an expression tree. Scalar evolution populates this map on-demand when the client asks for an expression via ScalarEvolution::getSCEV(Value).</div><br><div>IndVarSimplify and LoopStrengthReduce are example SCEV clients.</div><div><br></div><div>Just be careful to invalidate SCEV entries when you mutate the IR.</div><div><br></div><div>-Andy</div></body></html>