Add ISD::isBuildVectorAllZeros predicate
authorEvan Cheng <evan.cheng@apple.com>
Sun, 26 Mar 2006 09:50:58 +0000 (09:50 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Sun, 26 Mar 2006 09:50:58 +0000 (09:50 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27147 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/SelectionDAGNodes.h
lib/CodeGen/SelectionDAG/SelectionDAG.cpp

index df76524ca119a8a77ab90983c6501abb55ed0b5e..4863940de272112760df7cd7b81c90ae78007aa1 100644 (file)
@@ -458,7 +458,10 @@ namespace ISD {
   /// isBuildVectorAllOnesInteger - Return true if the specified node is a
   /// BUILD_VECTOR where all of the elements are ~0 or undef.
   bool isBuildVectorAllOnesInteger(const SDNode *N);
-  
+
+  /// isBuildVectorAllZeros - Return true if the specified node is a
+  /// BUILD_VECTOR where all of the elements are 0 or undef.
+  bool isBuildVectorAllZeros(const SDNode *N);
   
   //===--------------------------------------------------------------------===//
   /// ISD::CondCode enum - These are ordered carefully to make the bitfields
index 18e2ebcb45ee75cb43c145d70c792db7562aea1f..c0cd64670117b263e1a28e6ebbbd264dece1e95e 100644 (file)
@@ -101,6 +101,30 @@ bool ISD::isBuildVectorAllOnesInteger(const SDNode *N) {
 }
 
 
+/// isBuildVectorAllZeros - Return true if the specified node is a
+/// BUILD_VECTOR where all of the elements are 0 or undef.
+bool ISD::isBuildVectorAllZeros(const SDNode *N) {
+  if (N->getOpcode() != ISD::BUILD_VECTOR) return false;
+
+  bool AllUndef = true;
+  for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
+    SDOperand Elt = N->getOperand(i);
+    if (Elt.getOpcode() != ISD::UNDEF) {
+      AllUndef = false;
+      if (isa<ConstantSDNode>(Elt)) {
+        if (!cast<ConstantSDNode>(Elt)->isNullValue())
+          return false;
+      } else if (isa<ConstantFPSDNode>(Elt)) {
+        if (!cast<ConstantFPSDNode>(Elt)->isExactlyValue(0.0))
+          return false;
+      } else
+        return false;
+    }
+  }
+
+  return !AllUndef;
+}
+
 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
 /// when given the operation for (X op Y).
 ISD::CondCode ISD::getSetCCSwappedOperands(ISD::CondCode Operation) {