<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=us-ascii">
<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;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@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="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Hi,<o:p></o:p></p>
<p class="MsoNormal">I would like to understand better the implications of using loads and stores with struct types in LLVM IR.<o:p></o:p></p>
<p class="MsoNormal">It seems that using loads and stores on struct types leads to troubles as the struct size grows (detailed observations below).<o:p></o:p></p>
<p class="MsoNormal">Hence my questions:<o:p></o:p></p>
<p class="MsoNormal">- Is it reasonable/better to use stores and loads with some struct types or should llvm.memcpy always be preferred ?<o:p></o:p></p>
<p class="MsoNormal">- Is there an official limitation on the size of struct types that can be used in load and store operations ?
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks in advance for the guidance,<o:p></o:p></p>
<p class="MsoNormal">Jean Perier<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Here are more details about what I have observed with struct type loads and stores. Take the example:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><i>  </i><i><span lang="FR">%t = type { [N x i8] }<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span lang="FR">  define void @foo(%t* %0, %t* %1)  {<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span lang="FR">  %3 = load %t, %t* %1<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span lang="FR">   store %t %3, %t* %0<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span lang="FR">   ret void<o:p></o:p></span></i></p>
<p class="MsoNormal"><i>  }<o:p></o:p></i></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I noticed that:<o:p></o:p></p>
<p class="MsoNormal">- llc compile times are not linear at all with `N` (with a debug build on a powerful machine, N=100 -> 0.05s, N=500 -> 1.4s, N = 1000 -> 2.25s, N = 2000 : 12.5s. … N= 65535 : more than 22 minutes, I did not wait).<o:p></o:p></p>
<p class="MsoNormal">- llc hits a first assert when `N` >= 65536 (at [1] in the code, reported 10 years ago in bug [2]).<o:p></o:p></p>
<p class="MsoNormal">- llc hits a different assert when `N` >= 2097153 (at [3] in the code, reported  a year ago in bugs [4])<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">All this leads me to question if I should produce LLVM IR that loads/stores struct types, or just always use llvm.memcpy for them. Why is it allowed to load/store them if it can lead to trouble ?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">[1] <a href="https://github.com/llvm/llvm-project/blob/4c484f11d355e4293f7b245a9330f0a1e89630ac/llvm/include/llvm/CodeGen/SelectionDAGNodes.h#L1069">
https://github.com/llvm/llvm-project/blob/4c484f11d355e4293f7b245a9330f0a1e89630ac/llvm/include/llvm/CodeGen/SelectionDAGNodes.h#L1069</a><o:p></o:p></p>
<p class="MsoNormal">[2] <a href="https://bugs.llvm.org/show_bug.cgi?id=7250">https://bugs.llvm.org/show_bug.cgi?id=7250</a> and more recently duplicated in
<a href="https://bugs.llvm.org/show_bug.cgi?id=37000">https://bugs.llvm.org/show_bug.cgi?id=37000</a><o:p></o:p></p>
<p class="MsoNormal">[3] <a href="https://github.com/llvm/llvm-project/blob/4c484f11d355e4293f7b245a9330f0a1e89630ac/llvm/lib/IR/Type.cpp#L315">
https://github.com/llvm/llvm-project/blob/4c484f11d355e4293f7b245a9330f0a1e89630ac/llvm/lib/IR/Type.cpp#L315</a><o:p></o:p></p>
<p class="MsoNormal">[4] <a href="https://bugs.llvm.org/show_bug.cgi?id=48615">https://bugs.llvm.org/show_bug.cgi?id=48615</a> and
<a href="https://bugs.llvm.org/show_bug.cgi?id=50913">https://bugs.llvm.org/show_bug.cgi?id=50913</a><o:p></o:p></p>
</div>
</body>
</html>