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/Analysis/CostModel.cpp | 6 +++++- llvm/lib/Analysis/TargetTransformInfo.cpp | 10 ++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'llvm/lib/Analysis') diff --git a/llvm/lib/Analysis/CostModel.cpp b/llvm/lib/Analysis/CostModel.cpp index 0383cbfbbe4..36a1db664e1 100644 --- a/llvm/lib/Analysis/CostModel.cpp +++ b/llvm/lib/Analysis/CostModel.cpp @@ -504,8 +504,12 @@ unsigned CostModelAnalysis::getInstructionCost(const Instruction *I) const { for (unsigned J = 0, JE = II->getNumArgOperands(); J != JE; ++J) Args.push_back(II->getArgOperand(J)); + FastMathFlags FMF; + if (auto *FPMO = dyn_cast(II)) + FMF = FPMO->getFastMathFlags(); + return TTI->getIntrinsicInstrCost(II->getIntrinsicID(), II->getType(), - Args); + Args, FMF); } return -1; default: diff --git a/llvm/lib/Analysis/TargetTransformInfo.cpp b/llvm/lib/Analysis/TargetTransformInfo.cpp index b64d4133420..48e441bac69 100644 --- a/llvm/lib/Analysis/TargetTransformInfo.cpp +++ b/llvm/lib/Analysis/TargetTransformInfo.cpp @@ -315,15 +315,17 @@ int TargetTransformInfo::getInterleavedMemoryOpCost( } int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy, - ArrayRef Tys) const { - int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Tys); + ArrayRef Tys, + FastMathFlags FMF) const { + int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Tys, FMF); assert(Cost >= 0 && "TTI should not produce negative costs!"); return Cost; } int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy, - ArrayRef Args) const { - int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Args); + ArrayRef Args, + FastMathFlags FMF) const { + int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Args, FMF); assert(Cost >= 0 && "TTI should not produce negative costs!"); return Cost; } -- cgit v1.2.3