From 075b04a55f74daf3a75944fe91dc210974a6f703 Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Wed, 11 Jul 2018 09:56:41 +0000 Subject: [PATCH] [SelectionDAG] Add constant buildvector support to isKnownNeverZero This allows us to use SelectionDAG::isKnownNeverZero in DAGCombiner::visitREM (visitSDIVLike/visitUDIVLike handle the checking for constants). llvm-svn: 336779 --- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 5 +---- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 10 ++++++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index b2525b7..5375e91 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -3297,10 +3297,7 @@ SDValue DAGCombiner::visitREM(SDNode *N) { // by skipping the simplification if isIntDivCheap(). When div is not cheap, // combine will not return a DIVREM. Regardless, checking cheapness here // makes sense since the simplification results in fatter code. - // TODO: replace matchUnaryPredicate with SelectionDAG::isKnownNeverZero(N1). - if (ISD::matchUnaryPredicate( - N1, [](ConstantSDNode *C) { return !C->isNullValue(); }) && - !TLI.isIntDivCheap(VT, Attr)) { + if (DAG.isKnownNeverZero(N1) && !TLI.isIntDivCheap(VT, Attr)) { SDValue OptimizedDiv = isSigned ? visitSDIVLike(N0, N1, N) : visitUDIVLike(N0, N1, N); if (OptimizedDiv.getNode() && OptimizedDiv.getOpcode() != ISD::UDIVREM && diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 4b02b0c..9870f21 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -3626,12 +3626,18 @@ bool SelectionDAG::isKnownNeverZero(SDValue Op) const { assert(!Op.getValueType().isFloatingPoint() && "Floating point types unsupported - use isKnownNeverZeroFloat"); + // If the value is a constant, we can obviously see if it is a zero or not. + if (ISD::matchUnaryPredicate( + Op, [](ConstantSDNode *C) { return !C->isNullValue(); })) + return true; + // TODO: Recognize more cases here. switch (Op.getOpcode()) { default: break; case ISD::OR: - if (const ConstantSDNode *C = dyn_cast(Op.getOperand(1))) - return !C->isNullValue(); + if (isKnownNeverZero(Op.getOperand(1)) || + isKnownNeverZero(Op.getOperand(0))) + return true; break; } -- 2.7.4