From c4e4c5b0761b4877e85cf456b5fa42afb7c982a3 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Fri, 11 May 2018 22:45:22 +0000 Subject: [PATCH] [DAG] clean up flag propagation for binops; NFCI llvm-svn: 332150 --- .../CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 56 ++++++++-------------- .../lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h | 2 +- 2 files changed, 22 insertions(+), 36 deletions(-) diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index c88a89c..ee17fb94 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -2739,46 +2739,32 @@ static bool isVectorReductionOp(const User *I) { return ReduxExtracted; } -void SelectionDAGBuilder::visitBinary(const User &I, unsigned OpCode) { - SDValue Op1 = getValue(I.getOperand(0)); - SDValue Op2 = getValue(I.getOperand(1)); - - bool nuw = false; - bool nsw = false; - bool exact = false; - bool vec_redux = false; - FastMathFlags FMF; - - if (const OverflowingBinaryOperator *OFBinOp = - dyn_cast(&I)) { - nuw = OFBinOp->hasNoUnsignedWrap(); - nsw = OFBinOp->hasNoSignedWrap(); +void SelectionDAGBuilder::visitBinary(const User &I, unsigned Opcode) { + SDNodeFlags Flags; + if (auto *OFBinOp = dyn_cast(&I)) { + Flags.setNoSignedWrap(OFBinOp->hasNoSignedWrap()); + Flags.setNoUnsignedWrap(OFBinOp->hasNoUnsignedWrap()); + } + if (auto *ExactOp = dyn_cast(&I)) { + Flags.setExact(ExactOp->isExact()); } - if (const PossiblyExactOperator *ExactOp = - dyn_cast(&I)) - exact = ExactOp->isExact(); - if (const FPMathOperator *FPOp = dyn_cast(&I)) - FMF = FPOp->getFastMathFlags(); - if (isVectorReductionOp(&I)) { - vec_redux = true; + Flags.setVectorReduction(true); DEBUG(dbgs() << "Detected a reduction operation:" << I << "\n"); } + if (auto *FPOp = dyn_cast(&I)) { + Flags.setAllowReciprocal(FPOp->hasAllowReciprocal()); + Flags.setAllowContract(FPOp->hasAllowContract()); + Flags.setNoInfs(FPOp->hasNoInfs()); + Flags.setNoNaNs(FPOp->hasNoNaNs()); + Flags.setNoSignedZeros(FPOp->hasNoSignedZeros()); + Flags.setApproximateFuncs(FPOp->hasApproxFunc()); + Flags.setAllowReassociation(FPOp->hasAllowReassoc()); + } - SDNodeFlags Flags; - Flags.setExact(exact); - Flags.setNoSignedWrap(nsw); - Flags.setNoUnsignedWrap(nuw); - Flags.setVectorReduction(vec_redux); - Flags.setAllowReciprocal(FMF.allowReciprocal()); - Flags.setAllowContract(FMF.allowContract()); - Flags.setNoInfs(FMF.noInfs()); - Flags.setNoNaNs(FMF.noNaNs()); - Flags.setNoSignedZeros(FMF.noSignedZeros()); - Flags.setApproximateFuncs(FMF.approxFunc()); - Flags.setAllowReassociation(FMF.allowReassoc()); - - SDValue BinNodeValue = DAG.getNode(OpCode, getCurSDLoc(), Op1.getValueType(), + SDValue Op1 = getValue(I.getOperand(0)); + SDValue Op2 = getValue(I.getOperand(1)); + SDValue BinNodeValue = DAG.getNode(Opcode, getCurSDLoc(), Op1.getValueType(), Op1, Op2, Flags); setValue(&I, BinNodeValue); } diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h index 780cd3e..bcea94e 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h @@ -847,7 +847,7 @@ private: void visitInvoke(const InvokeInst &I); void visitResume(const ResumeInst &I); - void visitBinary(const User &I, unsigned OpCode); + void visitBinary(const User &I, unsigned Opcode); void visitShift(const User &I, unsigned Opcode); void visitAdd(const User &I) { visitBinary(I, ISD::ADD); } void visitFAdd(const User &I) { visitBinary(I, ISD::FADD); } -- 2.7.4