Express the number of ULPs in fpaccuracy metadata as a real rather than a

rational number, eg as 2.5 rather than 5, 2.  OK'd by Peter Collingbourne.

llvm-svn: 154388
This commit is contained in:
Duncan Sands 2012-04-10 08:23:07 +00:00
parent af06b26c8e
commit e81111ca71
4 changed files with 7 additions and 11 deletions

View File

@ -3001,16 +3001,13 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E, llvm::Value *Dest) {
return ConvertTempToRValue(*this, E->getType(), OrigDest);
}
void CodeGenFunction::SetFPAccuracy(llvm::Value *Val, unsigned AccuracyN,
unsigned AccuracyD) {
void CodeGenFunction::SetFPAccuracy(llvm::Value *Val, float Accuracy) {
assert(Val->getType()->isFPOrFPVectorTy());
if (!AccuracyN || !isa<llvm::Instruction>(Val))
if (Accuracy == 0.0 || !isa<llvm::Instruction>(Val))
return;
llvm::Value *Vals[2];
Vals[0] = llvm::ConstantInt::get(Int32Ty, AccuracyN);
Vals[1] = llvm::ConstantInt::get(Int32Ty, AccuracyD);
llvm::MDNode *Node = llvm::MDNode::get(getLLVMContext(), Vals);
llvm::Value *ULPs = llvm::ConstantFP::get(Builder.getFloatTy(), Accuracy);
llvm::MDNode *Node = llvm::MDNode::get(getLLVMContext(), ULPs);
cast<llvm::Instruction>(Val)->setMetadata(llvm::LLVMContext::MD_fpaccuracy,
Node);

View File

@ -1807,7 +1807,7 @@ Value *ScalarExprEmitter::EmitDiv(const BinOpInfo &Ops) {
if (ValTy->isFloatTy() ||
(isa<llvm::VectorType>(ValTy) &&
cast<llvm::VectorType>(ValTy)->getElementType()->isFloatTy()))
CGF.SetFPAccuracy(Val, 5, 2);
CGF.SetFPAccuracy(Val, 2.5);
}
return Val;
}

View File

@ -2518,8 +2518,7 @@ public:
/// SetFPAccuracy - Set the minimum required accuracy of the given floating
/// point operation, expressed as the maximum relative error in ulp.
void SetFPAccuracy(llvm::Value *Val, unsigned AccuracyN,
unsigned AccuracyD = 1);
void SetFPAccuracy(llvm::Value *Val, float Accuracy);
private:
llvm::MDNode *getRangeForLoadFromType(QualType Ty);

View File

@ -22,4 +22,4 @@ double dpscalardiv(double a, double b) {
return a / b;
}
// CHECK: ![[MD]] = metadata !{i{{[0-9]+}} 5, i{{[0-9]+}} 2}
// CHECK: ![[MD]] = metadata !{float 2.500000e+00}