<html><body><div style="color:#000; background-color:#fff; font-family:arial, helvetica, sans-serif;font-size:10pt"><div><span>Hello Tobi,</span></div><div><br><span></span></div><div><span>You are right, we need to run some other passes before running the scalar evolution pass. The sequence that I run for this example is -O3 -loop-simplify -reg2mem. This is why I did not obtain the expressions depending on the loop indices. So I removed the reg2mem pass and scalar evolution computes the correct functions. <br></span></div><div><br><span></span></div><div><span>However, I need to run the reg2mem pass (or any other that would eliminate the phi nodes) before calling my own passes. So probably we are going to run the scalar evolution on the code containing the phi nodes, run reg2mem and try to identify the original variables in the new code built after reg2mem.</span></div><div><br><span></span></div><div><span>Thanks for your
advice,</span></div><div><span>Alexandra</span></div><div><br></div><div style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"><font face="Arial" size="2"><hr size="1"><b><span style="font-weight:bold;">From:</span></b> Tobias Grosser <tobias@grosser.es><br><b><span style="font-weight: bold;">To:</span></b> Jimborean Alexandra <xinfinity_a@yahoo.com><br><b><span style="font-weight: bold;">Cc:</span></b> "llvmdev@cs.uiuc.edu" <llvmdev@cs.uiuc.edu>; "luismastrangelo@gmail.com" <luismastrangelo@gmail.com><br><b><span style="font-weight: bold;">Sent:</span></b> Wednesday, August 3, 2011 2:21 AM<br><b><span style="font-weight: bold;">Subject:</span></b> Re: [LLVMdev] scalar evolution to determine access functions in arays<br></font><br>On 07/27/2011 03:11 PM, Jimborean Alexandra wrote:<br>> Hello,<br>> <br>> How can I compute the
functions on the loop iterators used as array<br>> indices?<br>> <br>> For example:<br>> <br>> for i = 0, N<br>> for j = 0, M<br>> A[2*i + j - 10] = ...<br>> <br>> Can I obtain that this instruction A[2*i + j - 10]= .. always accesses<br>> memory using a function f(i,j) = 2*i + j - 10 + base_address_of_A<br>> <br>> If I run the scalar evolution pass on this code I obtain:<br>> <br>> %arrayidx = getelementptr inbounds [200 x i32]* @main.A, i32 0, i64 %idxprom<br>> <br>> --> ((4 * (sext i32 (-10 + (2 * %tmp6) + %tmp7) to i64)) + @main.A)<br>> <br>> Could you please offer an insight on how can I obtain the function from<br>> the internals of the scalar evolution pass?<br><br><br>Hi Alexandra,<br><br>sorry for the delay, I was a little bit busy.<br><br>In general your approach is correct, but scalar evolution is in your case not able to derive an access function that is defined in terms of loop
iterators. (If it would you would have something like {0, + 1}<loop_1> in your scev expression).<br><br>What I suspect is that you need to run some canonicalization passes before you actually run the scalar evolution pass. Most of the time these passes should be sufficient:<br>-correlated-propagation -mem2reg -instcombine -loop-simplify -indvars<br><br>But in Polly we use e.g.:<br>-basicaa -mem2reg -simplify-libcalls -simplifycfg -instcombine -tailcallelim -loop-simplify -lcssa -loop-rotate -lcssa -loop-unswitch -instcombine -loop-simplify -lcssa -indvars -loop-deletion -instcombine -polly-prepare -polly-region-simplify -indvars<br><br>If you send me the .ll file you run your tool on, I could take a closer look.<br><br>Cheers and all the best<br>Tobi<br><br><br><br><br></div></div></div></body></html>