<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi,<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 22, 2016, at 4:35 PM, George Burgess IV <<a href="mailto:george.burgess.iv@gmail.com" class="">george.burgess.iv@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">Hi!</div><div class=""><br class=""></div><div class="">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. </div></div></div></blockquote><div><br class=""></div><div><br class=""></div>Fair enough :).</div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">I'm not super familiar with the pass manager/CGP though, so I could definitely be wrong.</div><div class=""><br class=""></div>> <span style="font-size:12.8px" class="">Would it be easy to teach CGP how to update it?</span><br style="font-size:12.8px" class=""><br style="font-size:12.8px" class=""><div class="">I have no clue. Like said, not super familiar with these parts of LLVM :)</div><div class=""><br class=""></div><div class="">> <span style="font-size:12.8px" class="">We have the availableIf idiom or something for such cases and that would avoid invalidating the whole thing</span></div><div class=""><span style="font-size:12.8px" class=""><br class=""></span></div><div class=""><span style="font-size:12.8px" class="">But that's the new pass manager only, yeah?</span></div></div></div></blockquote><div><br class=""></div>I was thinking of this thing:<br class=""><div><br class=""></div><div><table class="memname" style="font-weight: bold; font-size: 14px; line-height: 22px; font-family: Roboto, sans-serif; margin-left: 6px; color: rgb(37, 53, 85); background-color: rgb(226, 232, 242);"><tbody class=""><tr class=""><td class="memname" style="margin-left: 6px; vertical-align: bottom;">AnalysisType * llvm::Pass::getAnalysisIfAvailable </td><td style="vertical-align: bottom;" class="">(</td><td class="paramname" style="color: rgb(96, 32, 32); white-space: nowrap; vertical-align: bottom;"></td><td style="vertical-align: bottom;" class="">)</td><td style="vertical-align: bottom;" class="">const</td></tr></tbody></table><div class=""><br class=""></div></div><div>I think it is also available with the legacy pass manager.</div><div><br class=""></div><div>Anyhow does not seem we need to bother ;).</div><div><br class=""></div><div>Thanks,</div><div>Q.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><span style="font-size:12.8px" class=""> 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 class=""><span style="font-size:12.8px" class=""><br class=""></span></div><div class=""><span style="font-size:12.8px" class="">></span><span style="font-size:12.8px" class=""> </span><span style="font-size:12.8px" class="">I don’t actually what in CGP invalidates the DomTree</span></div><div class=""><span style="font-size:12.8px" class=""><br class=""></span></div><div class=""><span style="font-size:12.8px" class="">A number of places seem to do so; grep for `ModifiedDT` :)</span></div><div class=""><br class=""></div><div class="">The example I ran into was:</div><div class=""><br class=""></div><div class="">$ opt test/Transforms/CodeGenPrepare/dom-tree.ll -S -loop-unroll -codegenprepare -domtree -analyze -print-after-all</div><div class="">#### Snip ####</div><div class=""><div class=""><span style="font-size:12.8px" class="">*** IR Dump After Loop-Closed SSA Form Pass ***</span></div><div class=""><span style="font-size:12.8px" class="">; Function Attrs: norecurse nounwind readnone</span></div><div class=""><span style="font-size:12.8px" class="">define i32 @f(i32 %a) #0 {</span></div><div class=""><span style="font-size:12.8px" class="">entry:</span></div><div class=""><span style="font-size:12.8px" class="">  br label %for.body</span></div><div class=""><span style="font-size:12.8px" class=""><br class=""></span></div><div class=""><span style="font-size:12.8px" class="">for.cond.cleanup:                                 ; preds = %for.body</span></div><div class=""><span style="font-size:12.8px" class="">  %or.lcssa = phi i32 [ %or, %for.body ]</span></div><div class=""><span style="font-size:12.8px" class="">  ret i32 %or.lcssa</span></div><div class=""><span style="font-size:12.8px" class=""><br class=""></span></div><div class=""><span style="font-size:12.8px" class="">for.body:                                         ; preds = %for.body, %entry</span></div><div class=""><span style="font-size:12.8px" class="">  %i.08 = phi i32 [ 0, %entry ], [ %inc, %for.body ]</span></div><div class=""><span style="font-size:12.8px" class="">  %b.07 = phi i32 [ 0, %entry ], [ %or, %for.body ]</span></div><div class=""><span style="font-size:12.8px" class="">  %shr = lshr i32 %a, %i.08</span></div><div class=""><span style="font-size:12.8px" class="">  %and = and i32 %shr, 1</span></div><div class=""><span style="font-size:12.8px" class="">  %sub = sub nuw nsw i32 31, %i.08</span></div><div class=""><span style="font-size:12.8px" class="">  %shl = shl i32 %and, %sub</span></div><div class=""><span style="font-size:12.8px" class="">  %or = or i32 %shl, %b.07</span></div><div class=""><span style="font-size:12.8px" class="">  %inc = add nuw nsw i32 %i.08, 1</span></div><div class=""><span style="font-size:12.8px" class="">  %exitcond = icmp eq i32 %inc, 32</span></div><div class=""><span style="font-size:12.8px" class="">  br i1 %exitcond, label %for.cond.cleanup, label %for.body, !llvm.loop !3</span></div><div class=""><span style="font-size:12.8px" class="">}</span></div><div class=""><span style="font-size:12.8px" class="">*** IR Dump After CodeGen Prepare ***</span></div><div class=""><span style="font-size:12.8px" class="">; Function Attrs: norecurse nounwind readnone</span></div><div class=""><span style="font-size:12.8px" class="">define i32 @f(i32 %a) #0 {</span></div><div class=""><span style="font-size:12.8px" class="">for.body:</span></div><div class=""><span style="font-size:12.8px" class="">  %rev = call i32 @llvm.bitreverse.i32(i32 %a)</span></div><div class=""><span style="font-size:12.8px" class="">  ret i32 %rev</span></div><div class=""><span style="font-size:12.8px" class="">}</span></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, Mar 22, 2016 at 3:59 PM, Quentin Colombet <span dir="ltr" class=""><<a href="mailto:qcolombet@apple.com" target="_blank" class="">qcolombet@apple.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi George,<br class="">
<br class="">
Would it be easy to teach CGP how to update it?<br class="">
<br class="">
We have the availableIf idiom or something for such cases and that would avoid invalidating the whole thing.<br class="">
<br class="">
(Just asking, I don’t actually what in CGP invalidates the DomTree.)<br class="">
<br class="">
Cheers,<br class="">
-Quentin<br class="">
<div class=""><div class="">> On Mar 22, 2016, at 2:25 PM, George Burgess IV via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank" class="">llvm-commits@lists.llvm.org</a>> wrote:<br class="">
><br class="">
> Author: gbiv<br class="">
> Date: Tue Mar 22 16:25:08 2016<br class="">
> New Revision: 264099<br class="">
><br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=264099&view=rev" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=264099&view=rev</a><br class="">
> Log:<br class="">
> Keep CodeGenPrepare from preserving the domtree.<br class="">
><br class="">
> CGP modifies the domtree in some cases, so saying that it preserves the<br class="">
> domtree is a lie. We'll be able to selectively preserve it with the new<br class="">
> pass manager.<br class="">
><br class="">
> Differential Revision: <a href="http://reviews.llvm.org/D16893" rel="noreferrer" target="_blank" class="">http://reviews.llvm.org/D16893</a><br class="">
><br class="">
> Added:<br class="">
>    llvm/trunk/test/Transforms/CodeGenPrepare/dom-tree.ll<br class="">
> Modified:<br class="">
>    llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp<br class="">
><br class="">
> Modified: llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp<br class="">
> 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" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp?rev=264099&r1=264098&r2=264099&view=diff</a><br class="">
> ==============================================================================<br class="">
> --- llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp (original)<br class="">
> +++ llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp Tue Mar 22 16:25:08 2016<br class="">
> @@ -158,7 +158,7 @@ class TypePromotionTransaction;<br class="">
>     const char *getPassName() const override { return "CodeGen Prepare"; }<br class="">
><br class="">
>     void getAnalysisUsage(AnalysisUsage &AU) const override {<br class="">
> -      AU.addPreserved<DominatorTreeWrapperPass>();<br class="">
> +      // FIXME: When we can selectively preserve passes, preserve the domtree.<br class="">
>       AU.addRequired<TargetLibraryInfoWrapperPass>();<br class="">
>       AU.addRequired<TargetTransformInfoWrapperPass>();<br class="">
>     }<br class="">
> @@ -5277,6 +5277,7 @@ bool CodeGenPrepare::optimizeBlock(Basic<br class="">
>     for (auto &I : reverse(BB)) {<br class="">
>       if (makeBitReverse(I, *DL, *TLI)) {<br class="">
>         MadeBitReverse = MadeChange = true;<br class="">
> +        ModifiedDT = true;<br class="">
>         break;<br class="">
>       }<br class="">
>     }<br class="">
><br class="">
> Added: llvm/trunk/test/Transforms/CodeGenPrepare/dom-tree.ll<br class="">
> 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" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/CodeGenPrepare/dom-tree.ll?rev=264099&view=auto</a><br class="">
> ==============================================================================<br class="">
> --- llvm/trunk/test/Transforms/CodeGenPrepare/dom-tree.ll (added)<br class="">
> +++ llvm/trunk/test/Transforms/CodeGenPrepare/dom-tree.ll Tue Mar 22 16:25:08 2016<br class="">
> @@ -0,0 +1,41 @@<br class="">
> +; RUN: opt -S -loop-unroll -codegenprepare < %s -domtree -analyze | FileCheck %s<br class="">
> +;<br class="">
> +; Checks that the dom tree is properly invalidated after an operation that will<br class="">
> +; invalidate it in CodeGenPrepare. If the domtree isn't properly invalidated,<br class="">
> +; this will likely segfault, or print badref.<br class="">
> +<br class="">
> +; CHECK-NOT: <badref><br class="">
> +<br class="">
> +target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"<br class="">
> +target triple = "armv7--linux-gnueabihf"<br class="">
> +<br class="">
> +define i32 @f(i32 %a) #0 {<br class="">
> +entry:<br class="">
> +  br label %for.body<br class="">
> +<br class="">
> +for.cond.cleanup:<br class="">
> +  ret i32 %or<br class="">
> +<br class="">
> +for.body:<br class="">
> +  %i.08 = phi i32 [ 0, %entry ], [ %inc, %for.body ]<br class="">
> +  %b.07 = phi i32 [ 0, %entry ], [ %or, %for.body ]<br class="">
> +  %shr = lshr i32 %a, %i.08<br class="">
> +  %and = and i32 %shr, 1<br class="">
> +  %sub = sub nuw nsw i32 31, %i.08<br class="">
> +  %shl = shl i32 %and, %sub<br class="">
> +  %or = or i32 %shl, %b.07<br class="">
> +  %inc = add nuw nsw i32 %i.08, 1<br class="">
> +  %exitcond = icmp eq i32 %inc, 32<br class="">
> +  br i1 %exitcond, label %for.cond.cleanup, label %for.body, !llvm.loop !3<br class="">
> +}<br class="">
> +<br class="">
> +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 class="">
> +<br class="">
> +!llvm.module.flags = !{!0, !1}<br class="">
> +!llvm.ident = !{!2}<br class="">
> +<br class="">
> +!0 = !{i32 1, !"wchar_size", i32 4}<br class="">
> +!1 = !{i32 1, !"min_enum_size", i32 4}<br class="">
> +!2 = !{!"clang version 3.8.0 (<a href="http://llvm.org/git/clang.git" rel="noreferrer" target="_blank" class="">http://llvm.org/git/clang.git</a> b7441a0f42c43a8eea9e3e706be187252db747fa)"}<br class="">
> +!3 = distinct !{!3, !4}<br class="">
> +!4 = !{!"llvm.loop.unroll.full"}<br class="">
><br class="">
><br class="">
> _______________________________________________<br class="">
> llvm-commits mailing list<br class="">
> <a href="mailto:llvm-commits@lists.llvm.org" target="_blank" class="">llvm-commits@lists.llvm.org</a><br class="">
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br class="">
<br class="">
</div></div></blockquote></div><br class=""></div></div>
</div></blockquote></div><br class=""></div></body></html>