<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<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);">
In general, I don't like to see features supported by not-ext-vector types that are not supported by ext-vector types.</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);">
That having been said, is this related to our discussion on bool vectors:</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);">
<a href="http://lists.llvm.org/pipermail/cfe-dev/2020-May/065434.html" id="LPlnk214154">http://lists.llvm.org/pipermail/cfe-dev/2020-May/065434.html</a></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);">
-Hal</div>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id="Signature">
<div class="BodyFragment"><font size="2"><span style="font-size:10pt;">
<div class="PlainText">Hal Finkel<br>
Lead, Compiler Technology and Programming Languages<br>
Leadership Computing Facility<br>
Argonne National Laboratory</div>
</span></font></div>
</div>
</div>
<div>
<div id="appendonsend"></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> cfe-dev <cfe-dev-bounces@lists.llvm.org> on behalf of Min-Yih Hsu via cfe-dev <cfe-dev@lists.llvm.org><br>
<b>Sent:</b> Friday, May 8, 2020 1:17 PM<br>
<b>To:</b> Keane, Erich <erich.keane@intel.com><br>
<b>Cc:</b> cfe-dev@lists.llvm.org <cfe-dev@lists.llvm.org><br>
<b>Subject:</b> Re: [cfe-dev] [RFC] Ternary operator with vector type predicate</font>
<div> </div>
</div>
<div class="" style="word-wrap:break-word; line-break:after-white-space">Interesting….then I think the question simply becomes whether we should support it in ext_vector_type as well.
<div class=""><br class="">
</div>
<div class="">Thanks for the pointer</div>
<div class=""><br class="">
</div>
<div class="">-Min<br class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On May 8, 2020, at 11:04 AM, Keane, Erich <<a href="mailto:erich.keane@intel.com" class="">erich.keane@intel.com</a>> wrote:</div>
<br class="x_Apple-interchange-newline">
<div class="">
<div class="x_WordSection1" style="font-family:Helvetica; font-size:16px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
Note that this was implemented for non-ext-vector types here:</div>
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
<a href="https://github.com/llvm/llvm-project/commit/349636d2bfc39a5c81a835a95d203a42d9f9301a" class="" style="color:purple; text-decoration:underline">https://github.com/llvm/llvm-project/commit/349636d2bfc39a5c81a835a95d203a42d9f9301a</a></div>
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
</div>
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
Which matches the GCC version. <span class="x_Apple-converted-space"> </span></div>
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
The attribute is vector_size, not ext_vector_type however.</div>
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
</div>
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
Otherwise, it does everything you’re proposing (like I said, just with a more portable vector-type definition).</div>
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
</div>
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
</div>
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
</div>
<div class="">
<div class="" style="border-style:solid none none; border-top-width:1pt; border-top-color:rgb(225,225,225); padding:3pt 0in 0in">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
<b class="">From:</b><span class="x_Apple-converted-space"> </span>cfe-dev <<a href="mailto:cfe-dev-bounces@lists.llvm.org" class="">cfe-dev-bounces@lists.llvm.org</a>><span class="x_Apple-converted-space"> </span><b class="">On Behalf Of<span class="x_Apple-converted-space"> </span></b>Min-Yih
Hsu via cfe-dev<br class="">
<b class="">Sent:</b><span class="x_Apple-converted-space"> </span>Friday, May 8, 2020 10:58 AM<br class="">
<b class="">To:</b><span class="x_Apple-converted-space"> </span><a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a><br class="">
<b class="">Subject:</b><span class="x_Apple-converted-space"> </span>[cfe-dev] [RFC] Ternary operator with vector type predicate</div>
</div>
</div>
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
</div>
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
Hi folks,</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
In clang’s vector extension, the ternary operator (?:) is able to select from two vector type values based on the boolean type predicate. For example:</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
```</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
typedef float float4 __attribute__((ext_vector_type(4)));</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
float4 foo(bool cond, float4 a, float4 b) {</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
return cond? a : b;</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
}</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
```</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
However, clang currently doesn’t support vector type values as the predicates. So code shown below won’t compile:</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
```</div>
</div>
<div class="">
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
<span class="" style="">float4 foo(float4 a, float4 b) {</span></div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
<span class="" style=""> return a > b? a : b;</span></div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
<span class="" style="">}</span></div>
</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
```</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
Which is essentially just a max function that can be implemented by hardware instructions (vmaxps in Intel AVX for example) efficiently.</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
I’m proposing to support vector type values as predicates in the ternary operator: If the predicate value has vector type, each of its element would be converted to bool before being used to select corresponding elements from the second or third operands. Note
that this is exactly what GCC is doing right now [1] in their vector extensions.</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
On the (IR) codegen side, since the IR `select`, `icmp`, and `fcmp` instruction all support vector type values as the operands, I don’t think there are much trouble in it.</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
Here are the reasons and some advantages:</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
1. It provides more flexibility for programmers to do conditional selections on vectors. Especially for cases that can be optimized by hardware instructions like the motivated example above.</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
2. It will not break the current usages of ternary operator: If the predicate is a scalar value, it’s still sticking to the current model.</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
3. If the goal of our extensions is aiming to “support a broad range of GCC extensions”. Then the behavior should also be as consistent as possible.</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
I’ll try to come up with a patch for preview as soon as possible.</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
Also a slightly off-topic thing: In our document [2], the ternary operator has always been mis-typed as ‘:?’ Maybe we should fix it some times.</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
Thanks for the feedbacks in advance.</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
-Min</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
</div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
[1]: <a href="https://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html" class="" style="color:purple; text-decoration:underline">https://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html</a></div>
</div>
<div class="">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
[2]: <a href="https://clang.llvm.org/docs/LanguageExtensions.html#vectors-and-extended-vectors" class="" style="color:purple; text-decoration:underline">https://clang.llvm.org/docs/LanguageExtensions.html#vectors-and-extended-vectors</a></div>
</div>
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</div>
</div>
</body>
</html>