<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p><br>
</p>
<div class="moz-cite-prefix">On 10/4/19 5:46 AM, Joan Lluch via llvm-dev wrote:<br>
</div>
<blockquote type="cite" cite="mid:01C51DE9-24BB-43EF-BADC-C2384AA4DBBD@icloud.com">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space;
        -webkit-line-break: after-white-space;" class="">
Hi all,
<div class=""><br class="">
</div>
<div class="">As a continuation of this thread, I was about to fill a bug report requesting the modification of <font class="" size="3"><span style="white-space: pre-wrap;" class="">DAGTypeLegalizer::ExpandIntRes_SIGN_EXTEND, in order to avoid the creation
 of Shifts for targets with no native support. For example by generating a ‘select' equivalent to  a<0 ? -1 : 0
</span></font>instead of an arithmetic shift right. For targets with no multiple shifts or word extension instructions, the select is much cheaper.</div>
<div class=""><br class="">
</div>
<div class="">However, I found that the early InstCombine pass spoils such optimisation by creating shifts on their own as a transform of (supposedly) equivalent code. </div>
<div class=""><br class="">
</div>
...
<div class="">
<div class=""><br class="">
</div>
<div class=""><span style="background-color: rgb(255, 255,
              255);" class="">I strongly suggest the above gets fixed. HOWEVER, even after the DAG combiner is fixed, the issues will remain due to InstCombine doing essentially the same thing </span><span style="background-color: rgb(255, 255,
              255);" class="">much
 earlier. Consider code like this:</span></div>
<div class=""><span style="background-color: rgb(255, 255,
              255);" class=""><br class="">
</span></div>
<div class="">
<div style="margin: 0px; font-size: 11px; line-height:
              normal; font-family: Monaco; background-color: rgb(255,
              255, 255);" class="">
<span style="color: rgb(186, 45,
                162);" class="">int</span> test0( <span style="color:
                rgb(186, 45, 162);" class="">int</span> a )</div>
<div style="margin: 0px; font-size: 11px; line-height:
              normal; font-family: Monaco; background-color: rgb(255,
              255, 255);" class="">
{</div>
<div style="margin: 0px; font-size: 11px; line-height:
              normal; font-family: Monaco; background-color: rgb(255,
              255, 255);" class="">
  <span style="color: rgb(186, 45,
                162);" class="">return</span> a<<span style="color:
                rgb(39, 42, 216);" class="">0</span> ? -<span style="color: rgb(39, 42, 216);" class="">1</span> : <span style="color: rgb(39, 42, 216);" class="">0</span>;</div>
<div style="margin: 0px; font-size: 11px; line-height:
              normal; font-family: Monaco; background-color: rgb(255,
              255, 255);" class="">
}</div>
</div>
<div style="margin: 0px; font-size: 11px; line-height: normal;
            font-family: Monaco; background-color: rgb(255, 255, 255);" class="">
<br class="">
</div>
<div style="margin: 0px; font-size: 11px; line-height: normal;
            font-family: Monaco; background-color: rgb(255, 255, 255);" class="">
<div style="margin: 0px; line-height: normal;" class=""><span style="color: rgb(186, 45, 162);" class="">int</span> test1( <span style="color: rgb(186, 45, 162);" class="">int</span> a )</div>
<div style="margin: 0px; line-height: normal;" class="">{</div>
<div style="margin: 0px; line-height: normal;" class="">  <span style="color: rgb(186, 45, 162);" class="">return</span> a<<span style="color: rgb(39, 42, 216);" class="">0</span> ?
<span style="color: rgb(39, 42, 216);" class="">1</span> : <span style="color: rgb(39, 42, 216);" class="">0</span>;</div>
<div style="margin: 0px; line-height: normal;" class="">}</div>
<div style="margin: 0px; line-height: normal;" class=""><br class="">
</div>
<div style="margin: 0px; line-height: normal;" class="">
<div style="margin: 0px; line-height: normal;" class=""><span style="color: rgb(186, 45, 162);" class="">int</span> test2( <span style="color: rgb(186, 45, 162);" class="">int</span> a )</div>
<div style="margin: 0px; line-height: normal;" class="">{</div>
<div style="margin: 0px; line-height: normal;" class="">  <span style="color: rgb(186, 45, 162);" class="">return</span> a<<span style="color: rgb(39, 42, 216);" class="">0</span> ? <font class="" color="#272ad8">2</font> : <span style="color: rgb(39, 42, 216);" class="">0</span>;</div>
<div style="margin: 0px; line-height: normal;" class="">}</div>
<div style="margin: 0px; line-height: normal;" class=""><br class="">
</div>
<div style="margin: 0px; line-height: normal;" class="">
<div style="margin: 0px; line-height: normal;" class=""><span style="color: rgb(186, 45, 162);" class="">int</span> test3( <span style="color: rgb(186, 45, 162);" class="">int</span> a )</div>
<div style="margin: 0px; line-height: normal;" class="">{</div>
<div style="margin: 0px; line-height: normal;" class="">  <span style="color: rgb(186, 45, 162);" class="">return</span> a<<span style="color: rgb(39, 42, 216);" class="">0</span> ?
<font class="" color="#272ad8">3</font> : <span style="color: rgb(39, 42, 216);" class="">0</span>;</div>
<div style="margin: 0px; line-height: normal;" class="">}</div>
</div>
</div>
</div>
<div class=""><span style="background-color: rgb(255, 255,
              255);" class=""><br class="">
</span></div>
<div class=""><span style="background-color: rgb(255, 255,
              255);" class="">In all cases, InstCombine converts the above into Shifts, right into the IR, which the backend can’t do anything about.</span></div>
</div>
</div>
</blockquote>
<p><br>
</p>
<p>Why not? It seems like we could pattern match the shifts back into selects/branches?</p>
<p> -Hal<br>
</p>
<p><br>
</p>
<blockquote type="cite" cite="mid:01C51DE9-24BB-43EF-BADC-C2384AA4DBBD@icloud.com">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space;
        -webkit-line-break: after-white-space;" class="">
<div class="">...
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px
              0.8ex;border-left:1px solid
              rgb(204,204,204);padding-left:1ex">
<div style="overflow-wrap: break-word;" class="">
<div class=""><br class="">
</div>
</div>
</blockquote>
</div>
<div class="">
<div class="">
<blockquote type="cite" class="">
<div class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode:
                    space; -webkit-line-break: after-white-space;" class="">
<div class="">
<div class="">
<div class="">
<div class="">
<blockquote type="cite" class="">
<div class=""></div>
</blockquote>
</div>
<br class="">
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
</blockquote>
<pre class="moz-signature" cols="72">-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory</pre>
</body>
</html>