[SelectionDAG] add helper query for binops; NFC

We will also use this in a planned enhancement for vector insertelement.

llvm-svn: 340741
This commit is contained in:
Sanjay Patel 2018-08-27 14:20:15 +00:00
parent 5d06f17b8a
commit f645927875
2 changed files with 14 additions and 11 deletions

View File

@ -2444,6 +2444,18 @@ namespace ISD {
cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
}
/// Return true if the node is a math/logic binary operator. This corresponds
/// to the IR function of the same name.
inline bool isBinaryOp(const SDNode *N) {
auto Op = N->getOpcode();
return (Op == ISD::ADD || Op == ISD::SUB || Op == ISD::MUL ||
Op == ISD::AND || Op == ISD::OR || Op == ISD::XOR ||
Op == ISD::SHL || Op == ISD::SRL || Op == ISD::SRA ||
Op == ISD::SDIV || Op == ISD::UDIV || Op == ISD::SREM ||
Op == ISD::UREM || Op == ISD::FADD || Op == ISD::FSUB ||
Op == ISD::FMUL || Op == ISD::FDIV || Op == ISD::FREM);
}
/// Attempt to match a unary predicate against a scalar/splat constant or
/// every element of a constant BUILD_VECTOR.
bool matchUnaryPredicate(SDValue Op,

View File

@ -1874,17 +1874,7 @@ static ConstantSDNode *getAsNonOpaqueConstant(SDValue N) {
}
SDValue DAGCombiner::foldBinOpIntoSelect(SDNode *BO) {
auto BinOpcode = BO->getOpcode();
assert((BinOpcode == ISD::ADD || BinOpcode == ISD::SUB ||
BinOpcode == ISD::MUL || BinOpcode == ISD::SDIV ||
BinOpcode == ISD::UDIV || BinOpcode == ISD::SREM ||
BinOpcode == ISD::UREM || BinOpcode == ISD::AND ||
BinOpcode == ISD::OR || BinOpcode == ISD::XOR ||
BinOpcode == ISD::SHL || BinOpcode == ISD::SRL ||
BinOpcode == ISD::SRA || BinOpcode == ISD::FADD ||
BinOpcode == ISD::FSUB || BinOpcode == ISD::FMUL ||
BinOpcode == ISD::FDIV || BinOpcode == ISD::FREM) &&
"Unexpected binary operator");
assert(ISD::isBinaryOp(BO) && "Unexpected binary operator");
// Don't do this unless the old select is going away. We want to eliminate the
// binary operator, not replace a binop with a select.
@ -1914,6 +1904,7 @@ SDValue DAGCombiner::foldBinOpIntoSelect(SDNode *BO) {
// propagate non constant operands into select. I.e.:
// and (select Cond, 0, -1), X --> select Cond, 0, X
// or X, (select Cond, -1, 0) --> select Cond, -1, X
auto BinOpcode = BO->getOpcode();
bool CanFoldNonConst = (BinOpcode == ISD::AND || BinOpcode == ISD::OR) &&
(isNullConstantOrNullSplatConstant(CT) ||
isAllOnesConstantOrAllOnesSplatConstant(CT)) &&