<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
        {font-family:"Hack Nerd Font Mono";
        panose-1:0 0 0 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;}
span.EmailStyle21
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.EmailStyle22
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Hi Bandhav,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<pre>> It's given that pointer a, in each object of the class RemotePtr, is the<o:p></o:p></pre>
<pre>> only pointer that can access the array pointed by it. So, I tried __remote<o:p></o:p></pre>
<pre>> int* __restrict a; (line 9) construct to tell Clang the same. This doesn't<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<p class="MsoNormal">This is indeed the correct way to interpret the restrict annotation.<o:p></o:p></p>
<p class="MsoNormal">With the full restrict patches, this code is vectorized to:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New"">; Function Attrs: norecurse nounwind uwtable<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New"">define dso_local i32 @main(i32 %argc, i8** nocapture readnone %argv) local_unnamed_addr #0 !noalias !2 {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New"">entry:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New"">  %0 = load i32 addrspace(1)*, i32 addrspace(1)** @A, align 8, !tbaa !5, !noalias !9<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New"">  %1 = load <4 x i32> addrspace(1)*, <4 x i32> addrspace(1)** bitcast (i32 addrspace(1)** @B to <4 x i32> addrspace(1)**), align 8, !tbaa !5, !noalias !9<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New"">  %2 = load <4 x i32>, <4 x i32> addrspace(1)* %1, align 4, !tbaa !13<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New"">  %3 = bitcast i32 addrspace(1)* %0 to <4 x i32> addrspace(1)*<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New"">  %4 = load <4 x i32>, <4 x i32> addrspace(1)* %3, align 4, !tbaa !13<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New"">  %5 = add nsw <4 x i32> %4, %2<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New"">  %6 = bitcast i32 addrspace(1)* %0 to <4 x i32> addrspace(1)*<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New"">  store <4 x i32> %5, <4 x i32> addrspace(1)* %6, align 4, !tbaa !13<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New"">  ret i32 0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New"">}<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Greetings,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Jeroen Dobbelaere<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> Johannes Doerfert <johannesdoerfert@gmail.com> <br>
<b>Sent:</b> Sunday, June 21, 2020 19:22<br>
<b>To:</b> Bandhav Veluri <bandhav.veluri00@gmail.com>; llvm-dev <llvm-dev@lists.llvm.org><br>
<b>Cc:</b> Jeroen Dobbelaere <dobbel@synopsys.com>; Kruse, Michael <michael.kruse@anl.gov><br>
<b>Subject:</b> Re: [llvm-dev] Restrict qualifier on class members<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p><span style="font-family:"Hack Nerd Font Mono",serif">Hi Bandhav,</span><o:p></o:p></p>
<p><o:p> </o:p></p>
<p><span style="font-family:"Hack Nerd Font Mono",serif">Jeroen Dobbelaere (CC'ed) is currently working on support for restrict qualified local variables and struct members.</span><o:p></o:p></p>
<p><span style="font-family:"Hack Nerd Font Mono",serif">The patches exist but are not merged yet. If you want to give it a try apply
<a href="https://urldefense.com/v3/__https:/reviews.llvm.org/D69542__;!!A4F2R9G_pg!Pjti9CWiUzKTT2q0q845iVs3V_xoVOwy0jfjcORjShtA3AY2yyxst36qT7R2WV_qjrJfjPOL$">
https://reviews.llvm.org/D69542</a>.</span><o:p></o:p></p>
<p><o:p> </o:p></p>
<p><span style="font-family:"Hack Nerd Font Mono",serif">Initially I could only think of this solution for your problem:
<a href="https://urldefense.com/v3/__https:/godbolt.org/z/6WtPXJ__;!!A4F2R9G_pg!Pjti9CWiUzKTT2q0q845iVs3V_xoVOwy0jfjcORjShtA3AY2yyxst36qT7R2WV_qjiZydN-O$">
https://godbolt.org/z/6WtPXJ</a></span><o:p></o:p></p>
<p><span style="font-family:"Hack Nerd Font Mono",serif">Michael (CC'ed) might now another annotation to get `llvm.access` metadata for the loop, which should do what you intend.</span><o:p></o:p></p>
<p><o:p> </o:p></p>
<p><span style="font-family:"Hack Nerd Font Mono",serif">Cheers,</span><o:p></o:p></p>
<p><span style="font-family:"Hack Nerd Font Mono",serif">  Johannes</span><o:p></o:p></p>
<p><o:p> </o:p></p>
<div>
<p class="MsoNormal">On 6/21/20 11:56 AM, Bandhav Veluri via llvm-dev wrote:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre>Hi,<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>I'm trying to abstract some special pointers with a class, like in the<o:p></o:p></pre>
<pre>example program below:<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>  1 #define __remote __attribute__((address_space(1)))<o:p></o:p></pre>
<pre>  2 #include <stdint.h><o:p></o:p></pre>
<pre>  3<o:p></o:p></pre>
<pre>  4 __remote int* A;<o:p></o:p></pre>
<pre>  5 __remote int* B;<o:p></o:p></pre>
<pre>  6<o:p></o:p></pre>
<pre>  7 class RemotePtr {<o:p></o:p></pre>
<pre>  8   private:<o:p></o:p></pre>
<pre>  9     __remote int* __restrict a;<o:p></o:p></pre>
<pre> 10<o:p></o:p></pre>
<pre> 11   public:<o:p></o:p></pre>
<pre> 12     RemotePtr(__remote int* a) : a(a) {}<o:p></o:p></pre>
<pre> 13<o:p></o:p></pre>
<pre> 14     __remote int& at(int n) {<o:p></o:p></pre>
<pre> 15       return a[n];<o:p></o:p></pre>
<pre> 16     }<o:p></o:p></pre>
<pre> 17 };<o:p></o:p></pre>
<pre> 18<o:p></o:p></pre>
<pre> 19 int main(int argc, char** argv) {<o:p></o:p></pre>
<pre> 20   RemotePtr a(A);<o:p></o:p></pre>
<pre> 21   RemotePtr b(B);<o:p></o:p></pre>
<pre> 22<o:p></o:p></pre>
<pre> 23   #pragma unroll 4<o:p></o:p></pre>
<pre> 24   for(int i=0; i<4; ++i) {<o:p></o:p></pre>
<pre> 25     a.at(i) += b.at(i);<o:p></o:p></pre>
<pre> 26   }<o:p></o:p></pre>
<pre> 27<o:p></o:p></pre>
<pre> 28   return 0;<o:p></o:p></pre>
<pre> 29 }<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>It's given that pointer a, in each object of the class RemotePtr, is the<o:p></o:p></pre>
<pre>only pointer that can access the array pointed by it. So, I tried __remote<o:p></o:p></pre>
<pre>int* __restrict a; (line 9) construct to tell Clang the same. This doesn't<o:p></o:p></pre>
<pre>seem to work and I see no noliass in the generated IR. Specifically, I want<o:p></o:p></pre>
<pre>lines 23-26 optimized assuming no aliasing between A and B. Any reason why<o:p></o:p></pre>
<pre>Clang shouldn't annotate memory accesses in lines 23-26 with noaliass<o:p></o:p></pre>
<pre>taking line 9 into account?<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>The higher level problem is this: is there a way to compile lines 23-26<o:p></o:p></pre>
<pre>assuming no aliasing between A and B, by just doing something in the<o:p></o:p></pre>
<pre>RemotePtr class (so that main is clear of ugly code)? If that's not<o:p></o:p></pre>
<pre>possible, is there a way to tell Clang that lines 23-26 should assume no<o:p></o:p></pre>
<pre>aliasing at all, by some pragma?<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>Thank you,<o:p></o:p></pre>
<pre>Bandhav<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
<pre>_______________________________________________<o:p></o:p></pre>
<pre>LLVM Developers mailing list<o:p></o:p></pre>
<pre><a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><o:p></o:p></pre>
<pre><a href="https://urldefense.com/v3/__https:/lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev__;!!A4F2R9G_pg!Pjti9CWiUzKTT2q0q845iVs3V_xoVOwy0jfjcORjShtA3AY2yyxst36qT7R2WV_qjlOsJRhJ$">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><o:p></o:p></pre>
</blockquote>
</div>
</div>
</body>
</html>