<div dir="ltr"><div>Hi!</div><div><br></div><div>FWIW, my understanding is that the domtree isn't used in or after CGP, so invalidating it isn't really a problem with the standard pass ordering. I'm not super familiar with the pass manager/CGP though, so I could definitely be wrong.</div><div><br></div>> <span style="font-size:12.8px">Would it be easy to teach CGP how to update it?</span><br style="font-size:12.8px"><br style="font-size:12.8px"><div>I have no clue. Like said, not super familiar with these parts of LLVM :)</div><div><br></div><div>> <span style="font-size:12.8px">We have the availableIf idiom or something for such cases and that would avoid invalidating the whole thing</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">But that's the new pass manager only, yeah? I added a FIXME to make it selectively preserved in the future. If we can do that now, I'd be happy to swap to selectively preserving it (since it seems we already track whether or not we may have invalidated the domtree).</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">></span><span style="font-size:12.8px"> </span><span style="font-size:12.8px">I don’t actually what in CGP invalidates the DomTree</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">A number of places seem to do so; grep for `ModifiedDT` :)</span></div><div><br></div><div>The example I ran into was:</div><div><br></div><div>$ opt test/Transforms/CodeGenPrepare/dom-tree.ll -S -loop-unroll -codegenprepare -domtree -analyze -print-after-all</div><div>#### Snip ####</div><div><div><span style="font-size:12.8px">*** IR Dump After Loop-Closed SSA Form Pass ***</span></div><div><span style="font-size:12.8px">; Function Attrs: norecurse nounwind readnone</span></div><div><span style="font-size:12.8px">define i32 @f(i32 %a) #0 {</span></div><div><span style="font-size:12.8px">entry:</span></div><div><span style="font-size:12.8px">  br label %for.body</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">for.cond.cleanup:                                 ; preds = %for.body</span></div><div><span style="font-size:12.8px">  %or.lcssa = phi i32 [ %or, %for.body ]</span></div><div><span style="font-size:12.8px">  ret i32 %or.lcssa</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">for.body:                                         ; preds = %for.body, %entry</span></div><div><span style="font-size:12.8px">  %i.08 = phi i32 [ 0, %entry ], [ %inc, %for.body ]</span></div><div><span style="font-size:12.8px">  %b.07 = phi i32 [ 0, %entry ], [ %or, %for.body ]</span></div><div><span style="font-size:12.8px">  %shr = lshr i32 %a, %i.08</span></div><div><span style="font-size:12.8px">  %and = and i32 %shr, 1</span></div><div><span style="font-size:12.8px">  %sub = sub nuw nsw i32 31, %i.08</span></div><div><span style="font-size:12.8px">  %shl = shl i32 %and, %sub</span></div><div><span style="font-size:12.8px">  %or = or i32 %shl, %b.07</span></div><div><span style="font-size:12.8px">  %inc = add nuw nsw i32 %i.08, 1</span></div><div><span style="font-size:12.8px">  %exitcond = icmp eq i32 %inc, 32</span></div><div><span style="font-size:12.8px">  br i1 %exitcond, label %for.cond.cleanup, label %for.body, !llvm.loop !3</span></div><div><span style="font-size:12.8px">}</span></div><div><span style="font-size:12.8px">*** IR Dump After CodeGen Prepare ***</span></div><div><span style="font-size:12.8px">; Function Attrs: norecurse nounwind readnone</span></div><div><span style="font-size:12.8px">define i32 @f(i32 %a) #0 {</span></div><div><span style="font-size:12.8px">for.body:</span></div><div><span style="font-size:12.8px">  %rev = call i32 @llvm.bitreverse.i32(i32 %a)</span></div><div><span style="font-size:12.8px">  ret i32 %rev</span></div><div><span style="font-size:12.8px">}</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 22, 2016 at 3:59 PM, Quentin Colombet <span dir="ltr"><<a href="mailto:qcolombet@apple.com" target="_blank">qcolombet@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi George,<br>
<br>
Would it be easy to teach CGP how to update it?<br>
<br>
We have the availableIf idiom or something for such cases and that would avoid invalidating the whole thing.<br>
<br>
(Just asking, I don’t actually what in CGP invalidates the DomTree.)<br>
<br>
Cheers,<br>
-Quentin<br>
<div><div>> On Mar 22, 2016, at 2:25 PM, George Burgess IV via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br>
><br>
> Author: gbiv<br>
> Date: Tue Mar 22 16:25:08 2016<br>
> New Revision: 264099<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=264099&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=264099&view=rev</a><br>
> Log:<br>
> Keep CodeGenPrepare from preserving the domtree.<br>
><br>
> CGP modifies the domtree in some cases, so saying that it preserves the<br>
> domtree is a lie. We'll be able to selectively preserve it with the new<br>
> pass manager.<br>
><br>
> Differential Revision: <a href="http://reviews.llvm.org/D16893" rel="noreferrer" target="_blank">http://reviews.llvm.org/D16893</a><br>
><br>
> Added:<br>
>    llvm/trunk/test/Transforms/CodeGenPrepare/dom-tree.ll<br>
> Modified:<br>
>    llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp<br>
><br>
> Modified: llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp?rev=264099&r1=264098&r2=264099&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp?rev=264099&r1=264098&r2=264099&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp (original)<br>
> +++ llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp Tue Mar 22 16:25:08 2016<br>
> @@ -158,7 +158,7 @@ class TypePromotionTransaction;<br>
>     const char *getPassName() const override { return "CodeGen Prepare"; }<br>
><br>
>     void getAnalysisUsage(AnalysisUsage &AU) const override {<br>
> -      AU.addPreserved<DominatorTreeWrapperPass>();<br>
> +      // FIXME: When we can selectively preserve passes, preserve the domtree.<br>
>       AU.addRequired<TargetLibraryInfoWrapperPass>();<br>
>       AU.addRequired<TargetTransformInfoWrapperPass>();<br>
>     }<br>
> @@ -5277,6 +5277,7 @@ bool CodeGenPrepare::optimizeBlock(Basic<br>
>     for (auto &I : reverse(BB)) {<br>
>       if (makeBitReverse(I, *DL, *TLI)) {<br>
>         MadeBitReverse = MadeChange = true;<br>
> +        ModifiedDT = true;<br>
>         break;<br>
>       }<br>
>     }<br>
><br>
> Added: llvm/trunk/test/Transforms/CodeGenPrepare/dom-tree.ll<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/CodeGenPrepare/dom-tree.ll?rev=264099&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/CodeGenPrepare/dom-tree.ll?rev=264099&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/test/Transforms/CodeGenPrepare/dom-tree.ll (added)<br>
> +++ llvm/trunk/test/Transforms/CodeGenPrepare/dom-tree.ll Tue Mar 22 16:25:08 2016<br>
> @@ -0,0 +1,41 @@<br>
> +; RUN: opt -S -loop-unroll -codegenprepare < %s -domtree -analyze | FileCheck %s<br>
> +;<br>
> +; Checks that the dom tree is properly invalidated after an operation that will<br>
> +; invalidate it in CodeGenPrepare. If the domtree isn't properly invalidated,<br>
> +; this will likely segfault, or print badref.<br>
> +<br>
> +; CHECK-NOT: <badref><br>
> +<br>
> +target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"<br>
> +target triple = "armv7--linux-gnueabihf"<br>
> +<br>
> +define i32 @f(i32 %a) #0 {<br>
> +entry:<br>
> +  br label %for.body<br>
> +<br>
> +for.cond.cleanup:<br>
> +  ret i32 %or<br>
> +<br>
> +for.body:<br>
> +  %i.08 = phi i32 [ 0, %entry ], [ %inc, %for.body ]<br>
> +  %b.07 = phi i32 [ 0, %entry ], [ %or, %for.body ]<br>
> +  %shr = lshr i32 %a, %i.08<br>
> +  %and = and i32 %shr, 1<br>
> +  %sub = sub nuw nsw i32 31, %i.08<br>
> +  %shl = shl i32 %and, %sub<br>
> +  %or = or i32 %shl, %b.07<br>
> +  %inc = add nuw nsw i32 %i.08, 1<br>
> +  %exitcond = icmp eq i32 %inc, 32<br>
> +  br i1 %exitcond, label %for.cond.cleanup, label %for.body, !llvm.loop !3<br>
> +}<br>
> +<br>
> +attributes #0 = { norecurse nounwind readnone "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="cortex-a8" "target-features"="+dsp,+neon,+vfp3" "unsafe-fp-math"="false" "use-soft-float"="false" }<br>
> +<br>
> +!llvm.module.flags = !{!0, !1}<br>
> +!llvm.ident = !{!2}<br>
> +<br>
> +!0 = !{i32 1, !"wchar_size", i32 4}<br>
> +!1 = !{i32 1, !"min_enum_size", i32 4}<br>
> +!2 = !{!"clang version 3.8.0 (<a href="http://llvm.org/git/clang.git" rel="noreferrer" target="_blank">http://llvm.org/git/clang.git</a> b7441a0f42c43a8eea9e3e706be187252db747fa)"}<br>
> +!3 = distinct !{!3, !4}<br>
> +!4 = !{!"llvm.loop.unroll.full"}<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>
</div></div></blockquote></div><br></div></div>