<div dir="ltr"><div><div>Thanks, Eli!<br></div>Hopefully fixed with:<br><a target="_blank" rel="noreferrer" href="https://reviews.llvm.org/rL284268">https://reviews.llvm.org/<wbr>rL284268</a><br><br></div>Still looking for a test case.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Oct 14, 2016 at 12:04 PM, 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 class="HOEnZb"><div class="h5">On 10/14/2016 7:26 AM, Sanjay Patel via llvm-commits wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: spatel<br>
Date: Fri Oct 14 09:26:47 2016<br>
New Revision: 284239<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=284239&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject?rev=284239&view=rev</a><br>
Log:<br>
[DAG] add folds for negated shifted sign bit<br>
<br>
The same folds exist in InstCombine already.<br>
<br>
This came up as part of:<br>
<a href="https://reviews.llvm.org/D25485" rel="noreferrer" target="_blank">https://reviews.llvm.org/D2548<wbr>5</a><br>
<br>
<br>
Modified:<br>
     llvm/trunk/lib/CodeGen/Select<wbr>ionDAG/DAGCombiner.cpp<br>
     llvm/trunk/test/CodeGen/X86/n<wbr>egate-shift.ll<br>
<br>
Modified: llvm/trunk/lib/CodeGen/Selecti<wbr>onDAG/DAGCombiner.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=284239&r1=284238&r2=284239&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/lib/CodeGen/<wbr>SelectionDAG/DAGCombiner.cpp?<wbr>rev=284239&r1=284238&r2=<wbr>284239&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/lib/CodeGen/Selecti<wbr>onDAG/DAGCombiner.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/Selecti<wbr>onDAG/DAGCombiner.cpp Fri Oct 14 09:26:47 2016<br>
@@ -1954,6 +1954,19 @@ SDValue DAGCombiner::visitSUB(SDNode *N)<br>
                         DAG.getConstant(-N1C->getAPIn<wbr>tValue(), DL, VT));<br>
    }<br>
  +  // Right-shifting everything out but the sign bit followed by negation is the<br>
+  // same as flipping arithmetic/logical shift type without the negation:<br>
+  // -(X >>u 31) -> (X >>s 31)<br>
+  // -(X >>s 31) -> (X >>u 31)<br>
+  if (isNullConstantOrNullSplatCons<wbr>tant(N0) &&<br>
+      (N1->getOpcode() == ISD::SRA || N1->getOpcode() == ISD::SRL)) {<br>
+    ConstantSDNode *ShiftAmt = isConstOrConstSplat(N1.getOper<wbr>and(1));<br>
+    if (ShiftAmt && ShiftAmt->getZExtValue() == VT.getScalarSizeInBits() - 1) {<br>
+      auto NewOpcode = N1->getOpcode() == ISD::SRA ? ISD::SRL :ISD::SRA;<br>
+      return DAG.getNode(NewOpcode, DL, VT, N1.getOperand(0), N1.getOperand(1));<br>
+    }<br>
+  }<br>
</blockquote>
<br></div></div>
You need to check whether the new node is legal.  It's possible to have a target where SRL is legal, but SRA isn't.<br>
<br>
Not sure what targets would actually trigger this issue off the top of my head, but they probably exist. SSE2 is missing an arithmetic shift right for <2 x i64>, but you can't trigger the issue there because it doesn't use ISD::SRL for vectors after legalization.<span class="HOEnZb"><font color="#888888"><br>
<br>
-Eli<br>
<br>
-- <br>
Employee of Qualcomm Innovation Center, Inc.<br>
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project<br>
<br>
</font></span></blockquote></div><br></div>