<div dir="ltr">I'm almost positive it's because of this code:<div><div><br></div><div>  Value *Val = nullptr;</div><div>  if (DT->dominates(Vals.BB, BB)) {</div><div>    Val = Vals.Val;</div><div>    if (isa<Constant>(Val)) return Val;</div><div>  }</div><div><br></div><div>  LeaderTableEntry* Next = Vals.Next;</div><div>  while (Next) {</div><div>    if (DT->dominates(Next->BB, BB)) {</div><div>      if (isa<Constant>(Next->Val)) return Next->Val;</div><div>      if (!Val) Val = Next->Val;</div><div>    }</div><div><br></div><div>    Next = Next->Next;</div><div>  }</div><div><br></div><div><br></div><div><br></div><div>IE If it's in the same block as anything in the leader table, it assumes they are ordered from first to last. but they may not be once you insert new instructions.</div><div><br></div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Nov 13, 2015 at 9:26 PM,  <span dir="ltr"><<a href="mailto:weimingz@codeaurora.org" target="_blank">weimingz@codeaurora.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hmmm. That's interesting.<br>
I will dig more and try to find out why.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
> Err, then the algorithm is broken somewhere.<br>
><br>
> This is definitely not the right fix from what i've seen so far.<br>
> Can you see what decides to insert this?<br>
><br>
> I suspect, based on your failure mode, that the leader table is not<br>
> ordered<br>
> locally by dominance, only by bb, and so when it calls findLeader, it<br>
> grabs<br>
> the first thing it finds, and does a broken thing.<br>
><br>
> It would only work in the processInstruction case because<br>
> processInstrucion<br>
> goes in dominance order.<br>
><br>
> If so, that would be bad (and hard to fix well without serious surgery),<br>
> and we should probably declare it broken, revert your set of patches, and<br>
> just abort PRE  (IE the other option i suggested where we set<br>
> success=false<br>
> and bailing)<br>
><br>
><br>
><br>
> On Fri, Nov 13, 2015 at 5:30 PM, Weiming Zhao <<a href="mailto:weimingz@codeaurora.org">weimingz@codeaurora.org</a>><br>
> wrote:<br>
><br>
>> weimingz added a comment.<br>
>><br>
>> This patch adds a reduced test from SPASS.<br>
>><br>
>> we need the check:<br>
>><br>
>>   if (Num >= NextNum)<br>
>>           addToLeaderTable(Num, I, I->getParent());<br>
>><br>
>> Otherwise, BB %wile.end (see line 91) will become :<br>
>><br>
>> while.end:                                        ; preds =<br>
>> %while.cond.16<br>
>><br>
>>   %add.ptr = getelementptr inbounds i8, i8* %v2, i32 undef<br>
>>   store i8* %add.ptr, i8** @dfg_text, align 4<br>
>>   %sub.ptr.sub26 = sub i32 0, %0  ==> use here<br>
>>   %0 = ptrtoint i8* %add.ptr to i32  ==> def here<br>
>>   switch i32 undef, label %sw.default [<br>
>>     i32 65, label %while.bodythread-pre-split<br>
>><br>
>><br>
>> <a href="http://reviews.llvm.org/D14670" rel="noreferrer" target="_blank">http://reviews.llvm.org/D14670</a><br>
>><br>
>><br>
>><br>
>><br>
><br>
<br>
<br>
</div></div></blockquote></div><br></div>