From 0f9db96fbc48a4d69c21e3dd87ed86416f2549a2 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Wed, 3 Sep 2014 01:06:50 +0000 Subject: [PATCH] Change name of copyFlags() to copyIRFlags(). Add convenience method for logical 'and' of all flags. NFC. Adding 'IR' to the names in an attempt to be less ambiguous about the flags we're dealing with here. The 'and' method is needed by the SLPVectorizer (PR20802) and possibly other passes. llvm-svn: 217004 --- include/llvm/IR/InstrTypes.h | 6 +++++- lib/IR/Instructions.cpp | 19 ++++++++++++++++++- lib/Transforms/Vectorize/LoopVectorize.cpp | 2 +- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/llvm/IR/InstrTypes.h b/include/llvm/IR/InstrTypes.h index 7ef245cbc46..83c5e5cc13f 100644 --- a/include/llvm/IR/InstrTypes.h +++ b/include/llvm/IR/InstrTypes.h @@ -360,7 +360,11 @@ public: /// Convenience method to copy supported wrapping, exact, and fast-math flags /// from V to this instruction. - void copyFlags(const Value *V); + void copyIRFlags(const Value *V); + + /// Logical 'and' of any supported wrapping, exact, and fast-math flags of + /// V and this instruction. + void andIRFlags(const Value *V); // Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const Instruction *I) { diff --git a/lib/IR/Instructions.cpp b/lib/IR/Instructions.cpp index b113d51d416..be32dee0638 100644 --- a/lib/IR/Instructions.cpp +++ b/lib/IR/Instructions.cpp @@ -2030,7 +2030,7 @@ bool BinaryOperator::isExact() const { return cast(this)->isExact(); } -void BinaryOperator::copyFlags(const Value *V) { +void BinaryOperator::copyIRFlags(const Value *V) { // Copy the wrapping flags. if (auto *OB = dyn_cast(V)) { setHasNoSignedWrap(OB->hasNoSignedWrap()); @@ -2046,6 +2046,23 @@ void BinaryOperator::copyFlags(const Value *V) { copyFastMathFlags(FP->getFastMathFlags()); } +void BinaryOperator::andIRFlags(const Value *V) { + if (auto *OB = dyn_cast(V)) { + setHasNoSignedWrap(hasNoSignedWrap() & OB->hasNoSignedWrap()); + setHasNoUnsignedWrap(hasNoUnsignedWrap() & OB->hasNoUnsignedWrap()); + } + + if (auto *PE = dyn_cast(V)) + setIsExact(isExact() & PE->isExact()); + + if (auto *FP = dyn_cast(V)) { + FastMathFlags FM = getFastMathFlags(); + FM &= FP->getFastMathFlags(); + copyFastMathFlags(FM); + } +} + + //===----------------------------------------------------------------------===// // FPMathOperator Class //===----------------------------------------------------------------------===// diff --git a/lib/Transforms/Vectorize/LoopVectorize.cpp b/lib/Transforms/Vectorize/LoopVectorize.cpp index ba330128788..f2d928ca0bb 100644 --- a/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -3249,7 +3249,7 @@ void InnerLoopVectorizer::vectorizeBlockInLoop(BasicBlock *BB, PhiVector *PV) { Value *V = Builder.CreateBinOp(BinOp->getOpcode(), A[Part], B[Part]); if (BinaryOperator *VecOp = dyn_cast(V)) - VecOp->copyFlags(BinOp); + VecOp->copyIRFlags(BinOp); Entry[Part] = V; }