[PATCH] D15034: TargetLowering: Improve handling of (setcc ([sz]ext x) 0, cc) in SimplifySetCC

Tom Stellard via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 11 12:17:12 PST 2016


tstellarAMD updated this revision to Diff 44536.
tstellarAMD added a comment.

Handle more variants of [sz]ext + setcc


http://reviews.llvm.org/D15034

Files:
  lib/CodeGen/SelectionDAG/TargetLowering.cpp

Index: lib/CodeGen/SelectionDAG/TargetLowering.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -1376,6 +1376,38 @@
           SDValue C = DAG.getConstant(C1.trunc(MinBits), dl, MinVT);
           return DAG.getSetCC(dl, VT, Trunc, C, Cond);
         }
+
+        // If truncating the setcc operands is not desirable, we can still
+        // simplify the expression in some cases:
+        // setcc ([sz]ext (setcc x, y, cc)), 0, setne) -> setcc (x, y, cc)
+        // setcc ([sz]ext (setcc x, y, cc)), 0, seteq) -> setcc (x, y, inv(cc))
+        // setcc (zext (setcc x, y, cc)), 1, setne) -> setcc (x, y, inv(cc))
+        // setcc (zext (setcc x, y, cc)), 1, seteq) -> setcc (x, y, cc)
+        // setcc (sext (setcc x, y, cc)), -1, setne) -> setcc (x, y, inv(cc))
+        // setcc (sext (setcc x, y, cc)), -1, seteq) -> setcc (x, y, cc)
+        SDValue TopSetCC = N0->getOperand(0);
+        unsigned N0Opc = N0->getOpcode();
+        if (TopSetCC.getValueType() == MVT::i1 && VT == MVT::i1 &&
+            TopSetCC.getOpcode() == ISD::SETCC &&
+            ((N1C->isNullValue() && (N0Opc == ISD::ZERO_EXTEND ||
+                                    N0Opc == ISD::SIGN_EXTEND)) ||
+            (N1C->isOne() && N0Opc == ISD::ZERO_EXTEND) ||
+            (N1C->isAllOnesValue() && N0Opc == ISD::SIGN_EXTEND))) {
+
+          bool Inverse = (N1C->isNullValue() && Cond == ISD::SETEQ) ||
+                         (!N1C->isNullValue() && Cond == ISD::SETNE);
+
+          if (!Inverse)
+            return TopSetCC;
+
+          ISD::CondCode InvCond = ISD::getSetCCInverse(
+              cast<CondCodeSDNode>(TopSetCC.getOperand(2))->get(),
+              TopSetCC.getOperand(0).getValueType().isInteger());
+          return DAG.getSetCC(dl, VT, TopSetCC.getOperand(0),
+                                      TopSetCC.getOperand(1),
+                                      InvCond);
+
+        }
       }
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15034.44536.patch
Type: text/x-patch
Size: 2041 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160111/44fe8ad3/attachment.bin>


More information about the llvm-commits mailing list