<div dir="ltr">I tried both to no avail. But I think I have the missing pieces of the<br>puzzle now:<br><br><ul><li>We run LICM after JumpThreading and CorrelatedValuePropagation<br></li><li>LICM depends on the order of children of a DomTreeNode<br></li><li>When doing DDT inserts within one bulk edit the children are stored in a SmallDenseSet</li><li>SmallDenseSet iteration order is unspecified<br></li></ul><br>I'm afraid I wont be able to find a test case for this (my example is<br>a 240M .ll file), but I'll take a stab at fixing DDT. Thanks for<br>rubber ducking :)</div><br><br><div class="gmail_quote"><div dir="ltr">On Wed, Jun 20, 2018 at 8:43 PM Mikhail Zolotukhin <<a href="mailto:mzolotukhin@apple.com">mzolotukhin@apple.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I see. When you tried verification, did you use “-verify-dom-tree”, or did you put explicit "assert(DT->verify(…))" call into the code? If the former, then the latter approach might still catch the issue (if you insert this assert into the suspicious place, e.g. after a block deletion). If there is DDT involved, you’ll also need to run DDT->flush() before that.<br>
<br>
Michael<br>
<br>
> On Jun 20, 2018, at 9:04 AM, Benjamin Kramer <<a href="mailto:benny.kra@gmail.com" target="_blank">benny.kra@gmail.com</a>> wrote:<br>
> <br>
> In JumpThreading. I don't think CVT is the problem here, it just<br>
> doesn't trigger a dominator recompute anymore.<br>
> On Wed, Jun 20, 2018 at 6:00 PM Michael Zolotukhin<br>
> <<a href="mailto:mzolotukhin@apple.com" target="_blank">mzolotukhin@apple.com</a>> wrote:<br>
>> <br>
>> Are you talking about flushing DDT in JT or in CVT?<br>
>> <br>
>>> On Jun 20, 2018, at 8:31 AM, Benjamin Kramer <<a href="mailto:benny.kra@gmail.com" target="_blank">benny.kra@gmail.com</a>> wrote:<br>
>>> <br>
>>> Sadly I can't share it and I don't know how to reduce it. Verification<br>
>>> doesn't catch it either. What works is flushing DeferredDominators<br>
>>> after we delete a block, which makes me think that there's something<br>
>>> wrong with the way we handle dead blocks.<br>
>>> On Wed, Jun 20, 2018 at 5:00 PM Michael Zolotukhin<br>
>>> <<a href="mailto:mzolotukhin@apple.com" target="_blank">mzolotukhin@apple.com</a>> wrote:<br>
>>>> <br>
>>>> Hmm, that’s interesting. Could you please share your test-case so that I can poke at it too? Another thing to try would be to add explicit DT verification after JT - if recomputation helps, then the existing DT should be incorrect at that point.<br>
>>>> <br>
>>>> Michael<br>
>>>> <br>
>>>>> On Jun 20, 2018, at 6:11 AM, Benjamin Kramer <<a href="mailto:benny.kra@gmail.com" target="_blank">benny.kra@gmail.com</a>> wrote:<br>
>>>>> <br>
>>>>> I'm seeing non-determinism after this change. Since this change is<br>
>>>>> fairly simple it's probably coming from earlier in the pipeline,<br>
>>>>> likely candidate being JumpThreading. Recalculating DT before<br>
>>>>> JumpThreading doesn't fix it, but recalculating after JumpThreading<br>
>>>>> removes the non-determinism.<br>
>>>>> <br>
>>>>> My test case is coming out of tfcompile and is huge and scary, any<br>
>>>>> ideas on how to track this down?<br>
>>>>> On Sat, Jun 16, 2018 at 9:01 PM Michael Zolotukhin via llvm-commits<br>
>>>>> <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br>
>>>>>> <br>
>>>>>> Author: mzolotukhin<br>
>>>>>> Date: Sat Jun 16 11:57:31 2018<br>
>>>>>> New Revision: 334895<br>
>>>>>> <br>
>>>>>> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=334895&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=334895&view=rev</a><br>
>>>>>> Log:<br>
>>>>>> CorrelatedValuePropagation: Preserve DT.<br>
>>>>>> <br>
>>>>>> Summary:<br>
>>>>>> We only modify CFG in a couple of places, and we can preserve DT there<br>
>>>>>> with a little effort.<br>
>>>>>> <br>
>>>>>> Reviewers: davide, vsk<br>
>>>>>> <br>
>>>>>> Subscribers: hiraditya, llvm-commits<br>
>>>>>> <br>
>>>>>> Differential Revision: <a href="https://reviews.llvm.org/D48059" rel="noreferrer" target="_blank">https://reviews.llvm.org/D48059</a><br>
>>>>>> <br>
>>>>>> Modified:<br>
>>>>>>  llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp<br>
>>>>>>  llvm/trunk/test/Other/opt-O2-pipeline.ll<br>
>>>>>>  llvm/trunk/test/Other/opt-O3-pipeline.ll<br>
>>>>>>  llvm/trunk/test/Other/opt-Os-pipeline.ll<br>
>>>>>> <br>
>>>>>> Modified: llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp<br>
>>>>>> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp?rev=334895&r1=334894&r2=334895&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp?rev=334895&r1=334894&r2=334895&view=diff</a><br>
>>>>>> ==============================================================================<br>
>>>>>> --- llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp (original)<br>
>>>>>> +++ llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp Sat Jun 16 11:57:31 2018<br>
>>>>>> @@ -82,6 +82,7 @@ namespace {<br>
>>>>>>     AU.addRequired<DominatorTreeWrapperPass>();<br>
>>>>>>     AU.addRequired<LazyValueInfoWrapperPass>();<br>
>>>>>>     AU.addPreserved<GlobalsAAWrapperPass>();<br>
>>>>>> +      AU.addPreserved<DominatorTreeWrapperPass>();<br>
>>>>>>   }<br>
>>>>>> };<br>
>>>>>> <br>
>>>>>> @@ -306,7 +307,7 @@ static bool processCmp(CmpInst *C, LazyV<br>
>>>>>> /// that cannot fire no matter what the incoming edge can safely be removed. If<br>
>>>>>> /// a case fires on every incoming edge then the entire switch can be removed<br>
>>>>>> /// and replaced with a branch to the case destination.<br>
>>>>>> -static bool processSwitch(SwitchInst *SI, LazyValueInfo *LVI) {<br>
>>>>>> +static bool processSwitch(SwitchInst *SI, LazyValueInfo *LVI, DominatorTree *DT) {<br>
>>>>>> Value *Cond = SI->getCondition();<br>
>>>>>> BasicBlock *BB = SI->getParent();<br>
>>>>>> <br>
>>>>>> @@ -321,6 +322,10 @@ static bool processSwitch(SwitchInst *SI<br>
>>>>>> <br>
>>>>>> // Analyse each switch case in turn.<br>
>>>>>> bool Changed = false;<br>
>>>>>> +  DenseMap<BasicBlock*, int> SuccessorsCount;<br>
>>>>>> +  for (auto *Succ : successors(BB))<br>
>>>>>> +    SuccessorsCount[Succ]++;<br>
>>>>>> +<br>
>>>>>> for (auto CI = SI->case_begin(), CE = SI->case_end(); CI != CE;) {<br>
>>>>>>   ConstantInt *Case = CI->getCaseValue();<br>
>>>>>> <br>
>>>>>> @@ -355,7 +360,8 @@ static bool processSwitch(SwitchInst *SI<br>
>>>>>> <br>
>>>>>>   if (State == LazyValueInfo::False) {<br>
>>>>>>     // This case never fires - remove it.<br>
>>>>>> -      CI->getCaseSuccessor()->removePredecessor(BB);<br>
>>>>>> +      BasicBlock *Succ = CI->getCaseSuccessor();<br>
>>>>>> +      Succ->removePredecessor(BB);<br>
>>>>>>     CI = SI->removeCase(CI);<br>
>>>>>>     CE = SI->case_end();<br>
>>>>>> <br>
>>>>>> @@ -365,6 +371,8 @@ static bool processSwitch(SwitchInst *SI<br>
>>>>>> <br>
>>>>>>     ++NumDeadCases;<br>
>>>>>>     Changed = true;<br>
>>>>>> +      if (--SuccessorsCount[Succ] == 0)<br>
>>>>>> +        DT->deleteEdge(BB, Succ);<br>
>>>>>>     continue;<br>
>>>>>>   }<br>
>>>>>>   if (State == LazyValueInfo::True) {<br>
>>>>>> @@ -381,10 +389,14 @@ static bool processSwitch(SwitchInst *SI<br>
>>>>>>   ++CI;<br>
>>>>>> }<br>
>>>>>> <br>
>>>>>> -  if (Changed)<br>
>>>>>> +  if (Changed) {<br>
>>>>>>   // If the switch has been simplified to the point where it can be replaced<br>
>>>>>>   // by a branch then do so now.<br>
>>>>>> -    ConstantFoldTerminator(BB);<br>
>>>>>> +    DeferredDominance DDT(*DT);<br>
>>>>>> +    ConstantFoldTerminator(BB, /*DeleteDeadConditions = */ false,<br>
>>>>>> +                           /*TLI = */ nullptr, &DDT);<br>
>>>>>> +    DDT.flush();<br>
>>>>>> +  }<br>
>>>>>> <br>
>>>>>> return Changed;<br>
>>>>>> }<br>
>>>>>> @@ -722,7 +734,7 @@ static bool runImpl(Function &F, LazyVal<br>
>>>>>>   Instruction *Term = BB->getTerminator();<br>
>>>>>>   switch (Term->getOpcode()) {<br>
>>>>>>   case Instruction::Switch:<br>
>>>>>> -      BBChanged |= processSwitch(cast<SwitchInst>(Term), LVI);<br>
>>>>>> +      BBChanged |= processSwitch(cast<SwitchInst>(Term), LVI, DT);<br>
>>>>>>     break;<br>
>>>>>>   case Instruction::Ret: {<br>
>>>>>>     auto *RI = cast<ReturnInst>(Term);<br>
>>>>>> @@ -767,5 +779,6 @@ CorrelatedValuePropagationPass::run(Func<br>
>>>>>>   return PreservedAnalyses::all();<br>
>>>>>> PreservedAnalyses PA;<br>
>>>>>> PA.preserve<GlobalsAA>();<br>
>>>>>> +  PA.preserve<DominatorTreeAnalysis>();<br>
>>>>>> return PA;<br>
>>>>>> }<br>
>>>>>> <br>
>>>>>> Modified: llvm/trunk/test/Other/opt-O2-pipeline.ll<br>
>>>>>> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/opt-O2-pipeline.ll?rev=334895&r1=334894&r2=334895&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/opt-O2-pipeline.ll?rev=334895&r1=334894&r2=334895&view=diff</a><br>
>>>>>> ==============================================================================<br>
>>>>>> --- llvm/trunk/test/Other/opt-O2-pipeline.ll (original)<br>
>>>>>> +++ llvm/trunk/test/Other/opt-O2-pipeline.ll Sat Jun 16 11:57:31 2018<br>
>>>>>> @@ -145,7 +145,6 @@<br>
>>>>>> ; CHECK-NEXT:         Lazy Value Information Analysis<br>
>>>>>> ; CHECK-NEXT:         Jump Threading<br>
>>>>>> ; CHECK-NEXT:         Value Propagation<br>
>>>>>> -; CHECK-NEXT:         Dominator Tree Construction<br>
>>>>>> ; CHECK-NEXT:         Basic Alias Analysis (stateless AA impl)<br>
>>>>>> ; CHECK-NEXT:         Function Alias Analysis Results<br>
>>>>>> ; CHECK-NEXT:         Memory Dependence Analysis<br>
>>>>>> <br>
>>>>>> Modified: llvm/trunk/test/Other/opt-O3-pipeline.ll<br>
>>>>>> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/opt-O3-pipeline.ll?rev=334895&r1=334894&r2=334895&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/opt-O3-pipeline.ll?rev=334895&r1=334894&r2=334895&view=diff</a><br>
>>>>>> ==============================================================================<br>
>>>>>> --- llvm/trunk/test/Other/opt-O3-pipeline.ll (original)<br>
>>>>>> +++ llvm/trunk/test/Other/opt-O3-pipeline.ll Sat Jun 16 11:57:31 2018<br>
>>>>>> @@ -149,7 +149,6 @@<br>
>>>>>> ; CHECK-NEXT:         Lazy Value Information Analysis<br>
>>>>>> ; CHECK-NEXT:         Jump Threading<br>
>>>>>> ; CHECK-NEXT:         Value Propagation<br>
>>>>>> -; CHECK-NEXT:         Dominator Tree Construction<br>
>>>>>> ; CHECK-NEXT:         Basic Alias Analysis (stateless AA impl)<br>
>>>>>> ; CHECK-NEXT:         Function Alias Analysis Results<br>
>>>>>> ; CHECK-NEXT:         Memory Dependence Analysis<br>
>>>>>> <br>
>>>>>> Modified: llvm/trunk/test/Other/opt-Os-pipeline.ll<br>
>>>>>> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/opt-Os-pipeline.ll?rev=334895&r1=334894&r2=334895&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/opt-Os-pipeline.ll?rev=334895&r1=334894&r2=334895&view=diff</a><br>
>>>>>> ==============================================================================<br>
>>>>>> --- llvm/trunk/test/Other/opt-Os-pipeline.ll (original)<br>
>>>>>> +++ llvm/trunk/test/Other/opt-Os-pipeline.ll Sat Jun 16 11:57:31 2018<br>
>>>>>> @@ -131,7 +131,6 @@<br>
>>>>>> ; CHECK-NEXT:         Lazy Value Information Analysis<br>
>>>>>> ; CHECK-NEXT:         Jump Threading<br>
>>>>>> ; CHECK-NEXT:         Value Propagation<br>
>>>>>> -; CHECK-NEXT:         Dominator Tree Construction<br>
>>>>>> ; CHECK-NEXT:         Basic Alias Analysis (stateless AA impl)<br>
>>>>>> ; CHECK-NEXT:         Function Alias Analysis Results<br>
>>>>>> ; CHECK-NEXT:         Memory Dependence Analysis<br>
>>>>>> <br>
>>>>>> <br>
>>>>>> _______________________________________________<br>
>>>>>> llvm-commits mailing list<br>
>>>>>> <a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
>>>>>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
>>>> <br>
>> <br>
<br>
</blockquote></div>