<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jun 5, 2013 at 1:54 PM, Tobias Grosser <span dir="ltr"><<a href="mailto:tobias@grosser.es" target="_blank">tobias@grosser.es</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class=""><div class="h5">On 06/03/2013 09:22 AM, Sebastian Pop wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Hi,<br>
<br>
I see that we call hasScalarDependency over every instruction in a region, and<br>
that iterates over all the uses of the instruction.  Here is the code of that<br>
function, with a nice "dirty hack" comment in it:<br>
<br>
bool ScopDetection::<u></u>hasScalarDependency(<u></u>Instruction &Inst,<br>
                                         Region &RefRegion) const {<br>
   for (Instruction::use_iterator UI = Inst.use_begin(), UE = Inst.use_end();<br>
        UI != UE; ++UI)<br>
     if (Instruction *Use = dyn_cast<Instruction>(*UI))<br>
       if (!RefRegion.contains(Use-><u></u>getParent())) {<br>
         // DirtyHack 1: PHINode user outside the Scop is not allow, if this<br>
         // PHINode is induction variable, the scalar to array transform may<br>
         // break it and introduce a non-indvar PHINode, which is not allow in<br>
         // Scop.<br>
         // This can be fix by:<br>
         // Introduce a IndependentBlockPrepare pass, which translate all<br>
         // PHINodes not in Scop to array.<br>
         // The IndependentBlockPrepare pass can also split the entry block of<br>
         // the function to hold the alloca instruction created by scalar to<br>
         // array.  and split the exit block of the Scop so the new create load<br>
         // instruction for escape users will not break other Scops.<br>
         if (isa<PHINode>(Use))<br>
           return true;<br>
       }<br>
<br>
   return false;<br>
}<br>
<br>
My question is how do we remove all this code: it is very expensive!<br>
</blockquote>
<br></div></div>
I just checked and there is no test case in the polly test cases that would fail if we remove this function. However, I was able to create a test case that is similar to the description in the comment.<br>
<br>
>From a first view I do not really see why PHI nodes need to be handled in a special way. In fact, when removing this function as well as the<br>
two asserts in the IndependentBlocks pass, the attached test case is correctly code generated. I can see that there may be some problems with invalidating later scops when translating out of SSA, but I do not see how this is specific to PHI nodes. So from my point of view, I would<br>

be OK with removing this code (and add the relevant test cases to ensure we do the right thing) given such a patch passes the LLVM test suite without regressions.<br>
<br>
However, maybe ether has some more insights. I remember he was the one adding this code in, but I don't remember the exact reasoning behind this.<br></blockquote><div style><br></div><div style>What I remember is there are some fail cases when we running polly on the testsuite without this function...</div>
<div style><br></div><div style>At that time If an instruction is used in another SCoP, the independent blocks pass will generate some mess to make the  induction variable become a non- induction variable, and this non- induction variable PHINode will confuse the later passes.</div>
<div style>I think the commit "Remove dependence on canonical induction variable" which introduce canSynthesize in line 310 of the IndependentBlocks.cpp implicitly fix this.</div><div style><span style="color:rgb(0,0,0);white-space:pre-wrap"><br>
</span></div><div style><span style="color:rgb(0,0,0);white-space:pre-wrap">Thanks</span></div><div style><span style="color:rgb(0,0,0);white-space:pre-wrap">Hongbin</span></div><div style><span style="color:rgb(0,0,0);white-space:pre-wrap"><br>
</span></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
Cheers,<br>
Tobi<br>
</blockquote></div><br></div></div>