From a67899195f74afe6b2350328cb73a6772bf40b48 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Sun, 26 Mar 2006 09:50:58 +0000 Subject: [PATCH] Add ISD::isBuildVectorAllZeros predicate llvm-svn: 27147 --- llvm/include/llvm/CodeGen/SelectionDAGNodes.h | 5 +++- .../lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h index df76524ca119..4863940de272 100644 --- a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h +++ b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h @@ -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 diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 18e2ebcb45ee..c0cd64670117 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -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(Elt)) { + if (!cast(Elt)->isNullValue()) + return false; + } else if (isa(Elt)) { + if (!cast(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) {