<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 12, 2017 at 11:06 AM, Friedman, Eli <span dir="ltr"><<a href="mailto:efriedma@codeaurora.org" target="_blank">efriedma@codeaurora.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"><div><div class="h5">
<div class="m_-5042466709717109602moz-cite-prefix">On 1/12/2017 9:04 AM, Sanjay Patel via
llvm-dev wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div>It's time for another round of "What is the canonical IR?"<br>
<br>
Credit for this episode to Zvi and PR31551. :)<br>
<a href="https://llvm.org/bugs/show_bug.cgi?id=31551" target="_blank">https://llvm.org/bugs/show_<wbr>bug.cgi?id=31551</a>
<pre class="m_-5042466709717109602gmail-bz_comment_text" id="m_-5042466709717109602gmail-comment_text_2">define <4 x i16> @shuffle(<16 x i16> %x) {
%shuf = shufflevector <16 x i16> %x, <16 x i16> undef, <4 x i32> <i32 0, i32 4, i32 8, i32 12>
ret <4 x i16> %shuf
}
define <4 x i16> @trunc(<16 x i16> %x) {
%bc = bitcast <16 x i16> %x to <4 x i64>
%tr = trunc <4 x i64> %bc to <4 x i16>
ret <4 x i16> %tr
}
</pre>
Potential reasons to prefer one or the other:<br>
1. Shuffle is the most compact.<br>
2. Trunc is easier to read.<br>
3. One of these is easier for value tracking.<br>
4. Compatibility with existing IR transforms (eg,
InterleavedAccess recognizes the shuffle form).<br>
</div>
5. We don't create arbitrary shuffle masks in IR because that's
bad for a lot of targets (but maybe this mask pattern should
always be recognized as special?).<br>
</div>
</blockquote>
<br></div></div>
Hmm... not sure what the right answer is, but a couple more
observations:<br>
1. If we're going to canonicalize, we should probably canonicalize
the same way independent of the original argument type (so we would
introduce bitcasts either way).<br></div></blockquote><div><br></div><div>Ah, right - kill #1 in my list.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div bgcolor="#FFFFFF" text="#000000">
2. Those two functions are only equivalent on little-endian
platforms.</div></blockquote><div><br></div><div>I was wondering about that. So yes, if we do want to canonicalize (until the recent compile-time complaints, I always thought this was the objective of InstCombine...maybe it still is), then the masks we're matching or generating will differ based on endianness.<br></div><div> <br></div></div></div></div>