<div dir="ltr"><div>Hey JinGu-nim,</div><div><br></div><div>Now I've looked at that example - isn't the problem that TBAA isn't doing its job here? `unsigned*` should be distinct from `unsigned**` and TBAA should say that the pointers can't alias?</div><div><br></div><div>We don't have TBAA in Burst, so that's why we had to roll our own alias analysis with our specific characteristics!</div><div><br></div><div>Cheers,</div><div>-Neil.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Nov 1, 2021 at 8:39 AM Jingu Kang <<a href="mailto:Jingu.Kang@arm.com">Jingu.Kang@arm.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div style="overflow-wrap: break-word;" lang="EN-US">
<div class="gmail-m_-7247147800722513975WordSection1">
<p class="MsoNormal">Hello Neil-nim,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Thanks for kind reply.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I am fixing <a href="https://bugs.llvm.org/show_bug.cgi?id=52143" target="_blank">
https://bugs.llvm.org/show_bug.cgi?id=52143</a>. If we can fix the case with AliasAnalysis, it would be a fundamental solution. If possible, can I ask you how you fixed it like adding a pattern in BasicAA, running other existing AA or your own one and etc please?
If Neil-nim pushes the solution to upstream, it will be best. <span style="font-family:"Segoe UI Emoji",sans-serif">
😊</span><u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Cheers,<u></u><u></u></p>
<p class="MsoNormal">JinGu Kang<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div style="border-color:currentcolor currentcolor currentcolor blue;border-style:none none none solid;border-width:medium medium medium 1.5pt;padding:0cm 0cm 0cm 4pt">
<div>
<div style="border-color:rgb(225,225,225) currentcolor currentcolor;border-style:solid none none;border-width:1pt medium medium;padding:3pt 0cm 0cm">
<p class="MsoNormal"><b>From:</b> Neil Henning <<a href="mailto:neil.henning@unity3d.com" target="_blank">neil.henning@unity3d.com</a>> <br>
<b>Sent:</b> 01 November 2021 07:47<br>
<b>To:</b> Jingu Kang <<a href="mailto:Jingu.Kang@arm.com" target="_blank">Jingu.Kang@arm.com</a>><br>
<b>Cc:</b> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<b>Subject:</b> Re: [llvm-dev] Question about hoisting LoadInst in LICM pass using MemorySSA/AliasAnalysis<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">Hey JinGu!<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I don't know the answer to this from a MemorySSA / LICM perspective (I'm not deeply aware of their internals) - but I do remember having to fix this exact kind of issue with our Burst HPC# compiler with our own custom alias analysis. From
our perspective it was safe to assume that any pointer deriving from @a couldn't alias with it, and we could make this optimization (this was really important in LLVM 6/7 timeframe if I'm remembering it right because we had a lot of cases where these kind
of things would disable vectorization).<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Cheers,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">-Neil.<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Fri, Oct 29, 2021 at 7:27 PM Jingu Kang via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-color:currentcolor currentcolor currentcolor rgb(204,204,204);border-style:none none none solid;border-width:medium medium medium 1pt;padding:0cm 0cm 0cm 6pt;margin:5pt 0cm 5pt 4.8pt">
<div>
<div>
<p class="MsoNormal">Ping<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<div style="border-style:none none none solid;border-width:medium medium medium 1.5pt;padding:0cm 0cm 0cm 4pt;border-color:currentcolor currentcolor currentcolor blue">
<div>
<div style="border-style:solid none none;border-width:1pt medium medium;padding:3pt 0cm 0cm;border-color:currentcolor">
<p class="MsoNormal"><b>From:</b> llvm-dev <<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a>>
<b>On Behalf Of </b>Jingu Kang via llvm-dev<br>
<b>Sent:</b> 27 October 2021 15:15<br>
<b>To:</b> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<b>Subject:</b> [llvm-dev] Question about hoisting LoadInst in LICM pass using MemorySSA/AliasAnalysis<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Hi All,<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">I have a question about hoisting LoadInst in LICM pass. I am looking at below IR code.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">@a = dso_local local_unnamed_addr global i32** null, align 8<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">define dso_local void @foo(i32 %max) {<u></u><u></u></p>
<p class="MsoNormal">entry:<u></u><u></u></p>
<p class="MsoNormal"> br label %for.cond<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">for.cond: ; preds = %for.body, %entry<u></u><u></u></p>
<p class="MsoNormal"> %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]<u></u><u></u></p>
<p class="MsoNormal"> %cmp.not = icmp sgt i32 %i.0, %max<u></u><u></u></p>
<p class="MsoNormal"> br i1 %cmp.not, label %for.cond.cleanup, label %for.body<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">for.cond.cleanup: ; preds = %for.cond<u></u><u></u></p>
<p class="MsoNormal"> ret void<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">for.body: ; preds = %for.cond<u></u><u></u></p>
<p class="MsoNormal"> %0 = load i32**, i32*** @a, align 8, !tbaa !8<u></u><u></u></p>
<p class="MsoNormal"> %idxprom = zext i32 %i.0 to i64<u></u><u></u></p>
<p class="MsoNormal"> %arrayidx = getelementptr inbounds i32*, i32** %0, i64 %idxprom<u></u><u></u></p>
<p class="MsoNormal"> store i32* null, i32** %arrayidx, align 8, !tbaa !8<u></u><u></u></p>
<p class="MsoNormal"> %inc = add nuw nsw i32 %i.0, 1<u></u><u></u></p>
<p class="MsoNormal"> br label %for.cond, !llvm.loop !12<u></u><u></u></p>
<p class="MsoNormal">}<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">I have expected the `%0 = load` is hoisted to entry block because I think it is loop invariant. However, LICM pass fails to hoist it because the MemorySSA is as below.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">define dso_local void @foo(i32 %max) local_unnamed_addr #0 {<u></u><u></u></p>
<p class="MsoNormal">entry:<u></u><u></u></p>
<p class="MsoNormal"> br label %for.cond<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">for.cond: ; preds = %for.body, %entry<u></u><u></u></p>
<p class="MsoNormal">; 2 = MemoryPhi({entry,liveOnEntry},{for.body,1})<u></u><u></u></p>
<p class="MsoNormal"> %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]<u></u><u></u></p>
<p class="MsoNormal"> %cmp.not = icmp sgt i32 %i.0, %max<u></u><u></u></p>
<p class="MsoNormal"> br i1 %cmp.not, label %for.cond.cleanup, label %for.body<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">for.cond.cleanup: ; preds = %for.cond<u></u><u></u></p>
<p class="MsoNormal"> ret void<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">for.body: ; preds = %for.cond<u></u><u></u></p>
<p class="MsoNormal">; MemoryUse(2) MayAlias<u></u><u></u></p>
<p class="MsoNormal"> %0 = load i32**, i32*** @a, align 8, !tbaa !8<u></u><u></u></p>
<p class="MsoNormal"> %idxprom = zext i32 %i.0 to i64<u></u><u></u></p>
<p class="MsoNormal"> %arrayidx = getelementptr inbounds i32*, i32** %0, i64 %idxprom<u></u><u></u></p>
<p class="MsoNormal">; 1 = MemoryDef(2)<u></u><u></u></p>
<p class="MsoNormal"> store i32* null, i32** %arrayidx, align 8, !tbaa !8<u></u><u></u></p>
<p class="MsoNormal"> %inc = add nuw nsw i32 %i.0, 1<u></u><u></u></p>
<p class="MsoNormal"> br label %for.cond, !llvm.loop !12<u></u><u></u></p>
<p class="MsoNormal">}<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">As we can see there is `MemoryUse(2) MayAlias` above the `%0 = load` because AliasAnalysis returns MayAlias between the ‘%0 = load’ and ‘store i32* null’. I think it could be `MemoryUse(liveOnEntry)`.
How do you think about it? If I missed something, please let me know.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Thanks,<u></u><u></u></p>
<p class="MsoNormal">JinGu Kang<u></u><u></u></p>
</div>
</div>
</div>
<p class="MsoNormal">_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><u></u><u></u></p>
</blockquote>
</div>
<p class="MsoNormal"><br clear="all">
<br>
-- <u></u><u></u></p>
<div>
<div>
<table style="width:100%;border-collapse:collapse;border-spacing:0px" width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td style="padding:0cm 0cm 15pt" valign="top">
<table style="border-collapse:collapse;border-spacing:0px" cellspacing="0" cellpadding="0" border="0" align="left">
<tbody>
<tr>
<td style="width:48pt;padding:0cm" width="64" valign="top">
<p class="MsoNormal" style="line-height:18pt"><span style="font-size:12.5pt;border:1pt solid windowtext;padding:0cm"><img style="width: 0.6666in; height: 0.6666in;" id="gmail-m_-7247147800722513975Picture_x0020_1" src="cid:17cdab82580bee2ed7e1" alt="Image removed by sender." width="64" height="64" border="0"></span><span style="font-size:12.5pt"><u></u><u></u></span></p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td style="padding:0cm" valign="top">
<div>
<p class="MsoNormal" style="line-height:11.25pt"><b><span style="font-size:10.5pt;font-family:"Arial",sans-serif;color:black">Neil Henning<u></u><u></u></span></b></p>
</div>
</td>
</tr>
<tr>
<td style="padding:0cm" valign="top">
<div>
<p class="MsoNormal" style="line-height:11.25pt"><span style="font-size:10.5pt;font-family:"Arial",sans-serif;color:black">Senior Software Engineer Compiler<u></u><u></u></span></p>
</div>
</td>
</tr>
<tr>
<td style="padding:0cm" valign="top">
<div>
<p class="MsoNormal" style="line-height:11.25pt"><a href="http://unity.com" target="_blank"><span style="font-size:9pt;font-family:"Arial",sans-serif">unity.com</span></a><span style="font-size:9pt;font-family:"Arial",sans-serif;color:black"><u></u><u></u></span></p>
</div>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
</div>
</div>
</div>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><table style="border-collapse:collapse;border-spacing:0px;color:rgb(90,90,91);font-size:13px;margin:0px 0px 20px;padding:0px" width="100%" cellspacing="0" cellpadding="0" border="0"><tbody style="margin:0px;padding:0px"><tr style="margin:0px;padding:0px"><td style="border-collapse:collapse;font-size:0px;line-height:1.5em;padding:0px 0px 20px;vertical-align:top" align="left"><table style="border-collapse:collapse;border-spacing:0px;margin:0px;padding:0px" cellspacing="0" cellpadding="0" border="0" align="left"><tbody style="margin:0px;padding:0px"><tr style="margin:0px;padding:0px"><td style="border-collapse:collapse;font-size:1.12em;line-height:1.5em;padding:0px;vertical-align:top;width:64px"><img style="border: medium none; border-radius: 0px; display: block; font-size: 13px; height: auto; line-height: 100%; margin: 0px; max-width: 100%; outline-style: none; outline-width: medium; padding: 20px 0px 0px; width: 100%;" alt="" src="https://unity3d.com/profiles/unity3d/themes/unity/images/ui/other/unity-logo-dark-email.png" width="64" height="auto"></td></tr></tbody></table></td></tr><tr style="margin:0px;padding:0px"><td style="border-collapse:collapse;font-size:0px;line-height:1.5em;padding:0px;vertical-align:top" align="left"><div style="color:rgb(0,0,0);font-family:Roboto,Arial;font-size:14px;font-weight:600;line-height:15px;margin:0px;padding:0px">Neil Henning</div></td></tr><tr style="margin:0px;padding:0px"><td style="border-collapse:collapse;font-size:0px;line-height:1.5em;padding:0px;vertical-align:top" align="left"><div style="color:rgb(0,0,0);font-family:Roboto,Arial;font-size:14px;line-height:15px;margin:0px;padding:0px 0px 10px">Senior Software Engineer Compiler</div></td></tr><tr style="margin:0px;padding:0px"><td style="border-collapse:collapse;font-size:0px;line-height:1.5em;padding:0px;vertical-align:top" align="left"><div style="color:rgb(0,0,0);font-family:Roboto,Arial;font-size:12px;line-height:15px;margin:0px;padding:0px"><a href="http://unity.com" target="_blank">unity.com</a></div></td></tr></tbody></table></div></div>