[llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Evan Cheng evan.cheng at apple.com
Sun Mar 26 22:59:00 PST 2006



Changes in directory llvm/lib/CodeGen/SelectionDAG:

SelectionDAG.cpp updated: 1.285 -> 1.286
---
Log message:

Change isBuildVectorAllOnesInteger to isBuildVectorAllOnes. Also check for
floating point cases.


---
Diffs of the changes:  (+39 -24)

 SelectionDAG.cpp |   63 ++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 39 insertions(+), 24 deletions(-)


Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.285 llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.286
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.285	Mon Mar 27 00:45:25 2006
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp	Mon Mar 27 00:58:47 2006
@@ -70,11 +70,10 @@
 //                              ISD Namespace
 //===----------------------------------------------------------------------===//
 
-/// isBuildVectorAllOnesInteger - Return true if the specified node is a
+/// isBuildVectorAllOnes - Return true if the specified node is a
 /// BUILD_VECTOR where all of the elements are ~0 or undef.
-bool ISD::isBuildVectorAllOnesInteger(const SDNode *N) {
-  if (N->getOpcode() != ISD::BUILD_VECTOR ||
-      !MVT::isInteger(N->getOperand(0).getValueType())) return false;
+bool ISD::isBuildVectorAllOnes(const SDNode *N) {
+  if (N->getOpcode() != ISD::BUILD_VECTOR) return false;
   
   unsigned i = 0, e = N->getNumOperands();
   
@@ -88,8 +87,13 @@
   // Do not accept build_vectors that aren't all constants or which have non-~0
   // elements.
   SDOperand NotZero = N->getOperand(i);
-  if (!isa<ConstantSDNode>(NotZero) ||
-      !cast<ConstantSDNode>(NotZero)->isAllOnesValue())
+  if (isa<ConstantSDNode>(NotZero)) {
+    if (!cast<ConstantSDNode>(NotZero)->isAllOnesValue())
+      return false;
+  } else if (isa<ConstantFPSDNode>(NotZero)) {
+    if (!cast<ConstantFPSDNode>(NotZero)->isExactlyValue(-1))
+      return false;
+  } else
     return false;
   
   // Okay, we have at least one ~0 value, check to see if the rest match or are
@@ -106,24 +110,35 @@
 /// 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;
+  
+  unsigned i = 0, e = N->getNumOperands();
+  
+  // Skip over all of the undef values.
+  while (i != e && N->getOperand(i).getOpcode() == ISD::UNDEF)
+    ++i;
+  
+  // Do not accept an all-undef vector.
+  if (i == e) return false;
+  
+  // Do not accept build_vectors that aren't all constants or which have non-~0
+  // elements.
+  SDOperand Zero = N->getOperand(i);
+  if (isa<ConstantSDNode>(Zero)) {
+    if (!cast<ConstantSDNode>(Zero)->isNullValue())
+      return false;
+  } else if (isa<ConstantFPSDNode>(Zero)) {
+    if (!cast<ConstantFPSDNode>(Zero)->isExactlyValue(0.0))
+      return false;
+  } else
+    return false;
+  
+  // Okay, we have at least one ~0 value, check to see if the rest match or are
+  // undefs.
+  for (++i; i != e; ++i)
+    if (N->getOperand(i) != Zero &&
+        N->getOperand(i).getOpcode() != ISD::UNDEF)
+      return false;
+  return true;
 }
 
 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)






More information about the llvm-commits mailing list