1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

Remove support for the special 'fast' value for fpmath accuracy for the moment.

llvm-svn: 154850
This commit is contained in:
Duncan Sands 2012-04-16 19:39:33 +00:00
parent 971d090cbb
commit 518668bd76
8 changed files with 10 additions and 83 deletions

View File

@ -3008,10 +3008,8 @@ call void @llvm.dbg.value(metadata !24, i64 0, metadata !25)
<p><tt>fpmath</tt> metadata may be attached to any instruction of floating point
type. It can be used to express the maximum acceptable error in the result of
that instruction, in ULPs, thus potentially allowing the compiler to use a
more efficient but less accurate method of computing it. The number of ULPs
may also be the string <tt>"fast"</tt>, which tells the compiler that speed
matters more than accuracy, so any fairly accurate method of computation is
fine as long as it is quick. ULP is defined as follows:</p>
more efficient but less accurate method of computing it. ULP is defined as
follows:</p>
<blockquote>
@ -3024,13 +3022,11 @@ call void @llvm.dbg.value(metadata !24, i64 0, metadata !25)
</blockquote>
<p>The metadata node shall consist of a single positive floating point number
representing the maximum relative error, or the string <tt>"fast"</tt>.
For example:</p>
representing the maximum relative error, for example:</p>
<div class="doc_code">
<pre>
!0 = metadata !{ float 2.5 } ; maximum acceptable inaccuracy is 2.5 ULPs
!1 = metadata !{ !metadata !"fast" } ; potentially unbounded inaccuracy
</pre>
</div>

View File

@ -174,13 +174,9 @@ public:
/// \brief Get the maximum error permitted by this operation in ULPs. An
/// accuracy of 0.0 means that the operation should be performed with the
/// default precision. A huge value is returned if the accuracy is 'fast'.
/// default precision.
float getFPAccuracy() const;
/// \brief Return true if the accuracy is 'fast'. This indicates that speed
/// is more important than accuracy.
bool isFastFPAccuracy() const;
static inline bool classof(const FPMathOperator *) { return true; }
static inline bool classof(const Instruction *I) {
return I->getType()->isFPOrFPVectorTy();

View File

@ -26,9 +26,6 @@ namespace llvm {
class MDBuilder {
LLVMContext &Context;
MDString *getFastString() {
return createString("fast");
}
public:
MDBuilder(LLVMContext &context) : Context(context) {}
@ -41,19 +38,12 @@ namespace llvm {
// FPMath metadata.
//===------------------------------------------------------------------===//
/// \brief Return metadata with appropriate settings for 'fast math'.
MDNode *createFastFPMath() {
return MDNode::get(Context, getFastString());
}
/// \brief Return metadata with the given settings. Special values for the
/// Accuracy parameter are 0.0, which means the default (maximal precision)
/// setting; and negative values which all mean 'fast'.
/// \brief Return metadata with the given settings. The special value 0.0
/// for the Accuracy parameter indicates the default (maximal precision)
/// setting.
MDNode *createFPMath(float Accuracy) {
if (Accuracy == 0.0)
return 0;
if (Accuracy < 0.0)
return MDNode::get(Context, getFastString());
assert(Accuracy > 0.0 && "Invalid fpmath accuracy!");
Value *Op = ConstantFP::get(Type::getFloatTy(Context), Accuracy);
return MDNode::get(Context, Op);

View File

@ -2008,35 +2008,14 @@ bool BinaryOperator::isExact() const {
/// getFPAccuracy - Get the maximum error permitted by this operation in ULPs.
/// An accuracy of 0.0 means that the operation should be performed with the
/// default precision. A huge value is returned if the accuracy is 'fast'.
/// default precision.
float FPMathOperator::getFPAccuracy() const {
const MDNode *MD =
cast<Instruction>(this)->getMetadata(LLVMContext::MD_fpmath);
if (!MD)
return 0.0;
Value *Op = MD->getOperand(0);
if (const ConstantFP *Accuracy = dyn_cast<ConstantFP>(Op))
return Accuracy->getValueAPF().convertToFloat();
// If it's not a floating point number then it must be 'fast'.
assert(isa<MDString>(Op) && cast<MDString>(Op)->getString() == "fast" &&
"Expected the 'fast' keyword!");
return HUGE_VALF;
}
/// isFastFPAccuracy - Return true if the accuracy is 'fast'. This says that
/// speed is more important than accuracy.
bool FPMathOperator::isFastFPAccuracy() const {
const MDNode *MD =
cast<Instruction>(this)->getMetadata(LLVMContext::MD_fpmath);
if (!MD)
return false;
Value *Op = MD->getOperand(0);
if (isa<ConstantFP>(Op))
return false;
// If it's not a floating point number then it must be 'fast'.
assert(isa<MDString>(Op) && cast<MDString>(Op)->getString() == "fast" &&
"Expected the 'fast' keyword!");
return true;
ConstantFP *Accuracy = cast<ConstantFP>(MD->getOperand(0));
return Accuracy->getValueAPF().convertToFloat();
}

View File

@ -1662,8 +1662,6 @@ void Verifier::visitInstruction(Instruction &I) {
APFloat Accuracy = CFP0->getValueAPF();
Assert1(Accuracy.isNormal() && !Accuracy.isNegative(),
"fpmath accuracy not a positive number!", &I);
} else if (MDString *S0 = dyn_cast_or_null<MDString>(Op0)) {
Assert1(S0->getString() == "fast", "wrong fpmath accuracy keyword!", &I);
} else {
Assert1(false, "invalid fpmath accuracy!", &I);
}

View File

@ -22,16 +22,6 @@ define void @fpmath1(i32 %i, float %f, <2 x float> %g) {
ret void
}
define void @fpmath2(float %f, <2 x float> %g) {
%w = fadd float %f, %f, !fpmath !7
; Above line is correct.
%w2 = fadd <2 x float> %g, %g, !fpmath !7
; Above line is correct.
%x = fadd float %f, %f, !fpmath !8
; CHECK: wrong fpmath accuracy keyword!
ret void
}
!0 = metadata !{ float 1.0 }
!1 = metadata !{ }
!2 = metadata !{ float 1.0, float 1.0 }
@ -39,5 +29,3 @@ define void @fpmath2(float %f, <2 x float> %g) {
!4 = metadata !{ float -1.0 }
!5 = metadata !{ float 0.0 }
!6 = metadata !{ float 0x7FFFFFFF00000000 }
!7 = metadata !{ metadata !"fast" }
!8 = metadata !{ metadata !"slow" }

View File

@ -27,24 +27,12 @@ TEST_F(MDBuilderTest, createString) {
EXPECT_EQ(Str0->getString(), StringRef(""));
EXPECT_EQ(Str1->getString(), StringRef("string"));
}
TEST_F(MDBuilderTest, createFastFPMath) {
MDBuilder MDHelper(Context);
MDNode *MD = MDHelper.createFastFPMath();
EXPECT_NE(MD, (MDNode *)0);
EXPECT_EQ(MD->getNumOperands(), 1U);
Value *Op = MD->getOperand(0);
EXPECT_TRUE(isa<MDString>(Op));
EXPECT_EQ(cast<MDString>(Op)->getString(), "fast");
}
TEST_F(MDBuilderTest, createFPMath) {
MDBuilder MDHelper(Context);
MDNode *MD0 = MDHelper.createFPMath(0.0);
MDNode *MD1 = MDHelper.createFPMath(1.0);
MDNode *MDF = MDHelper.createFPMath(-1.0);
MDNode *MDF2 = MDHelper.createFastFPMath();
EXPECT_EQ(MD0, (MDNode *)0);
EXPECT_NE(MD1, (MDNode *)0);
EXPECT_EQ(MDF, MDF2);
EXPECT_EQ(MD1->getNumOperands(), 1U);
Value *Op = MD1->getOperand(0);
EXPECT_TRUE(isa<ConstantFP>(Op));

View File

@ -235,19 +235,11 @@ TEST(InstructionsTest, FPMathOperator) {
MDBuilder MDHelper(Context);
Instruction *I = Builder.CreatePHI(Builder.getDoubleTy(), 0);
MDNode *MD1 = MDHelper.createFPMath(1.0);
MDNode *MDF = MDHelper.createFastFPMath();
Value *V1 = Builder.CreateFAdd(I, I, "", MD1);
Value *VF = Builder.CreateFAdd(I, I, "", MDF);
EXPECT_TRUE(isa<FPMathOperator>(V1));
EXPECT_TRUE(isa<FPMathOperator>(VF));
FPMathOperator *O1 = cast<FPMathOperator>(V1);
FPMathOperator *OF = cast<FPMathOperator>(VF);
EXPECT_FALSE(O1->isFastFPAccuracy());
EXPECT_TRUE(OF->isFastFPAccuracy());
EXPECT_EQ(O1->getFPAccuracy(), 1.0);
EXPECT_GT(OF->getFPAccuracy(), 999.0);
delete V1;
delete VF;
delete I;
}