From c70e33cd6e9422de4b5de9c992bed5d5e715e708 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Mon, 27 Mar 2006 06:58:47 +0000 Subject: [PATCH] Change isBuildVectorAllOnesInteger to isBuildVectorAllOnes. Also check for floating point cases. llvm-svn: 27165 --- llvm/include/llvm/CodeGen/SelectionDAGNodes.h | 4 +- .../lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 63 ++++++++++++------- 2 files changed, 41 insertions(+), 26 deletions(-) diff --git a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h index 4863940de272..ceb4ff752a6c 100644 --- a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h +++ b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h @@ -455,9 +455,9 @@ namespace ISD { /// Node predicates - /// 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 isBuildVectorAllOnesInteger(const SDNode *N); + bool isBuildVectorAllOnes(const SDNode *N); /// isBuildVectorAllZeros - Return true if the specified node is a /// BUILD_VECTOR where all of the elements are 0 or undef. diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index ecda64c220c4..9c8b13029f67 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -70,11 +70,10 @@ bool ConstantFPSDNode::isExactlyValue(double V) const { // 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 @@ bool ISD::isBuildVectorAllOnesInteger(const SDNode *N) { // Do not accept build_vectors that aren't all constants or which have non-~0 // elements. SDOperand NotZero = N->getOperand(i); - if (!isa(NotZero) || - !cast(NotZero)->isAllOnesValue()) + if (isa(NotZero)) { + if (!cast(NotZero)->isAllOnesValue()) + return false; + } else if (isa(NotZero)) { + if (!cast(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 @@ bool ISD::isBuildVectorAllOnesInteger(const SDNode *N) { /// 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(Elt)) { - if (!cast(Elt)->isNullValue()) - return false; - } else if (isa(Elt)) { - if (!cast(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(Zero)) { + if (!cast(Zero)->isNullValue()) + return false; + } else if (isa(Zero)) { + if (!cast(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)