<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span>I am looking for feedback to add support for a new loop pragma to Clang/LLVM.<br>
</span>
<div>With "#pragma tail_predicate" the idea would be to indicate that a loop<br>
</div>
<div>epilogue/tail can, or should be, folded into the main loop. I see two use<br>
</div>
<div>cases for this pragma.<br>
</div>
<div><br>
</div>
<div>First, this could be interesting for the vectorizer. It currently supports tail<br>
</div>
<div>folding by masking all loop instructions/blocks, but does this only when<br>
</div>
<div>optimising for size is enabled. This pragma could override the cost-model/opt-level.<br>
</div>
<div><br>
</div>
<div>Second use case would be the Armv8.1-M MVE vector extension, which supports<br>
</div>
<div>tail-predicated hardware loops. This version of hardware loops sets the vector<br>
</div>
<div>lanes to be masked, and is thus a nice optimisation that avoids generating a<br>
</div>
<div>tail loop when the number of elements processed is not a multiple of the vector<br>
</div>
<div>length.<br>
</div>
<div><br>
</div>
<div>For this use case, the tail predicate pragma could be good user experience<br>
</div>
<div>improvement, as it would for example allow this more compact form without<br>
</div>
<div>any predicated intrinsics:<br>
</div>
<div><br>
</div>
<div>  #pragma tail_predicate<br>
</div>
<div>  do {<br>
</div>
<div>    VLD(..);   // some vector load intrinsic<br>
</div>
<div>    VST(..);   // some vector store intrinsic<br>
</div>
<div>    ..<br>
</div>
<div>  } while (N);<br>
</div>
<div><br>
</div>
<div>which can then be transformed and predication made explicit through data<br>
</div>
<div>dependencies like so:<br>
</div>
<div><br>
</div>
<div>  do {<br>
</div>
<div>    mask = vctp(N);   // intrinsic that generates the mask of active lanes<br>
</div>
<div>    VLD(.., mask);<br>
</div>
<div>    VST(.., mask);<br>
</div>
<div>    ..<br>
</div>
<div>  } while (N);<br>
</div>
<div><br>
</div>
<div>A vector loop in this form can easily be picked up the new hardware loop pass,<br>
</div>
<div>and the corresponding tail-predicated hardware loop can be generated. This is<br>
</div>
<div>only a small example, but we think for more complicated examples we think<br>
</div>
<div>the benefit could be substantial.<br>
</div>
<div><br>
</div>
<div>I have uploaded a patch for the initial Clang plumbing exercise here:<br>
</div>
<span><a href="https://reviews.llvm.org/D64744" id="LPlnk553447">https://reviews.llvm.org/D64744</a></span><br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Cheers,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Sjoerd.</div>
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose,
 or store or copy the information in any medium. Thank you.
</body>
</html>