From: Duncan Sands Date: Mon, 16 Apr 2012 19:39:33 +0000 (+0000) Subject: Remove support for the special 'fast' value for fpmath accuracy for the moment. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=2867c85a3754320f96e36afb63325bb76269caa4;p=oota-llvm.git Remove support for the special 'fast' value for fpmath accuracy for the moment. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154850 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/docs/LangRef.html b/docs/LangRef.html index 3a474a554d4..9989cc81971 100644 --- a/docs/LangRef.html +++ b/docs/LangRef.html @@ -3008,10 +3008,8 @@ call void @llvm.dbg.value(metadata !24, i64 0, metadata !25)

fpmath 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 "fast", 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:

+ more efficient but less accurate method of computing it. ULP is defined as + follows:

@@ -3024,13 +3022,11 @@ call void @llvm.dbg.value(metadata !24, i64 0, metadata !25)

The metadata node shall consist of a single positive floating point number - representing the maximum relative error, or the string "fast". - For example:

+ representing the maximum relative error, for example:

 !0 = metadata !{ float 2.5 } ; maximum acceptable inaccuracy is 2.5 ULPs
-!1 = metadata !{ !metadata !"fast" } ; potentially unbounded inaccuracy
 
diff --git a/include/llvm/Operator.h b/include/llvm/Operator.h index 6bd7e566075..1e86980cf30 100644 --- a/include/llvm/Operator.h +++ b/include/llvm/Operator.h @@ -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(); diff --git a/include/llvm/Support/MDBuilder.h b/include/llvm/Support/MDBuilder.h index f6d84526ab2..40f028a4327 100644 --- a/include/llvm/Support/MDBuilder.h +++ b/include/llvm/Support/MDBuilder.h @@ -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); diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index 185cd0557c1..6c5db328764 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -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(this)->getMetadata(LLVMContext::MD_fpmath); if (!MD) return 0.0; - Value *Op = MD->getOperand(0); - if (const ConstantFP *Accuracy = dyn_cast(Op)) - return Accuracy->getValueAPF().convertToFloat(); - // If it's not a floating point number then it must be 'fast'. - assert(isa(Op) && cast(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(this)->getMetadata(LLVMContext::MD_fpmath); - if (!MD) - return false; - Value *Op = MD->getOperand(0); - if (isa(Op)) - return false; - // If it's not a floating point number then it must be 'fast'. - assert(isa(Op) && cast(Op)->getString() == "fast" && - "Expected the 'fast' keyword!"); - return true; + ConstantFP *Accuracy = cast(MD->getOperand(0)); + return Accuracy->getValueAPF().convertToFloat(); } diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp index 2576766928c..47baef3e29d 100644 --- a/lib/VMCore/Verifier.cpp +++ b/lib/VMCore/Verifier.cpp @@ -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(Op0)) { - Assert1(S0->getString() == "fast", "wrong fpmath accuracy keyword!", &I); } else { Assert1(false, "invalid fpmath accuracy!", &I); } diff --git a/test/Verifier/fpmath.ll b/test/Verifier/fpmath.ll index a7d3ea8e898..b764a63f0a4 100644 --- a/test/Verifier/fpmath.ll +++ b/test/Verifier/fpmath.ll @@ -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" } diff --git a/unittests/Support/MDBuilderTest.cpp b/unittests/Support/MDBuilderTest.cpp index e8e0386dac6..d54c7e8e8d7 100644 --- a/unittests/Support/MDBuilderTest.cpp +++ b/unittests/Support/MDBuilderTest.cpp @@ -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(Op)); - EXPECT_EQ(cast(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(Op)); diff --git a/unittests/VMCore/InstructionsTest.cpp b/unittests/VMCore/InstructionsTest.cpp index 9c0cb4409f7..d002101cd3b 100644 --- a/unittests/VMCore/InstructionsTest.cpp +++ b/unittests/VMCore/InstructionsTest.cpp @@ -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(V1)); - EXPECT_TRUE(isa(VF)); FPMathOperator *O1 = cast(V1); - FPMathOperator *OF = cast(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; }