From 0f26b0aeb4a91418d4c273bb25ab22f3b416a960 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Thu, 14 Apr 2016 07:13:24 +0000 Subject: [CodeGen] Teach LLVM how to lower @llvm.{min,max}num to {MIN,MAX}NAN The behavior of {MIN,MAX}NAN differs from that of {MIN,MAX}NUM when only one of the inputs is NaN: -NUM will return the non-NaN argument while -NAN would return NaN. It is desirable to lower to @llvm.{min,max}num to -NAN if they don't have a native instruction for -NUM. Notably, ARMv7 NEON's vmin has the -NAN semantics. N.B. Of course, it is only safe to do this if the intrinsic call is marked nnan. llvm-svn: 266279 --- llvm/lib/Transforms/Vectorize/BBVectorize.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'llvm/lib/Transforms/Vectorize/BBVectorize.cpp') diff --git a/llvm/lib/Transforms/Vectorize/BBVectorize.cpp b/llvm/lib/Transforms/Vectorize/BBVectorize.cpp index 5d3af4590d8..b43951d3f40 100644 --- a/llvm/lib/Transforms/Vectorize/BBVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/BBVectorize.cpp @@ -1117,16 +1117,25 @@ namespace { } if (IID && TTI) { + FastMathFlags FMFCI; + if (auto *FPMOCI = dyn_cast(CI)) + FMFCI = FPMOCI->getFastMathFlags(); + SmallVector Tys; for (unsigned i = 0, ie = CI->getNumArgOperands(); i != ie; ++i) Tys.push_back(CI->getArgOperand(i)->getType()); - unsigned ICost = TTI->getIntrinsicInstrCost(IID, IT1, Tys); + unsigned ICost = TTI->getIntrinsicInstrCost(IID, IT1, Tys, FMFCI); Tys.clear(); CallInst *CJ = cast(J); + + FastMathFlags FMFCJ; + if (auto *FPMOCJ = dyn_cast(CJ)) + FMFCJ = FPMOCJ->getFastMathFlags(); + for (unsigned i = 0, ie = CJ->getNumArgOperands(); i != ie; ++i) Tys.push_back(CJ->getArgOperand(i)->getType()); - unsigned JCost = TTI->getIntrinsicInstrCost(IID, JT1, Tys); + unsigned JCost = TTI->getIntrinsicInstrCost(IID, JT1, Tys, FMFCJ); Tys.clear(); assert(CI->getNumArgOperands() == CJ->getNumArgOperands() && @@ -1140,8 +1149,10 @@ namespace { CJ->getArgOperand(i)->getType())); } + FastMathFlags FMFV = FMFCI; + FMFV &= FMFCJ; Type *RetTy = getVecTypeForPair(IT1, JT1); - unsigned VCost = TTI->getIntrinsicInstrCost(IID, RetTy, Tys); + unsigned VCost = TTI->getIntrinsicInstrCost(IID, RetTy, Tys, FMFV); if (VCost > ICost + JCost) return false; -- cgit v1.2.3