summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6cae39f)
raw | patch | inline | side by side (parent: 6cae39f)
author | Sanjay Patel <spatel@rotateright.com> | |
Tue, 2 Sep 2014 20:03:00 +0000 (20:03 +0000) | ||
committer | Sanjay Patel <spatel@rotateright.com> | |
Tue, 2 Sep 2014 20:03:00 +0000 (20:03 +0000) |
"Setting" does not equal "copying". This bug has sat dormant for 2 reasons:
1. The unit test was not adequate.
2. Every current user of the "copyFastMathFlags" API is operating on a new instruction.
(ie, all existing fast-math flags are off). If you copy flags to an existing
instruction that has some flags on already, you will not necessarily turn them off
as expected.
I uncovered this bug while trying to implement a fix for PR20802.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216939 91177308-0d34-0410-b5e6-96231b3b80d8
1. The unit test was not adequate.
2. Every current user of the "copyFastMathFlags" API is operating on a new instruction.
(ie, all existing fast-math flags are off). If you copy flags to an existing
instruction that has some flags on already, you will not necessarily turn them off
as expected.
I uncovered this bug while trying to implement a fix for PR20802.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216939 91177308-0d34-0410-b5e6-96231b3b80d8
index 799f684349f125f261047253b3fafde89fb793e5..7ef245cbc46ea294aae4504c827652e4eba3fa31 100644 (file)
/// isExact - Determine whether the exact flag is set.
bool isExact() const;
- /// Convenience method to copy wrapping, exact, and fast-math flag values
+ /// Convenience method to copy supported wrapping, exact, and fast-math flags
/// from V to this instruction.
void copyFlags(const Value *V);
index 7665033ac125a2064ce637eba9507b6aad92614f..8dd2bbc1b140db782d09f945d8d8b97fa2c0fcb7 100644 (file)
/// this flag.
void setHasAllowReciprocal(bool B);
- /// Convenience function for setting all the fast-math flags on this
+ /// Convenience function for setting multiple fast-math flags on this
/// instruction, which must be an operator which supports these flags. See
/// LangRef.html for the meaning of these flags.
void setFastMathFlags(FastMathFlags FMF);
+ /// Convenience function for transferring all fast-math flag values to this
+ /// instruction, which must be an operator which supports these flags. See
+ /// LangRef.html for the meaning of these flags.
+ void copyFastMathFlags(FastMathFlags FMF);
+
/// Determine whether the unsafe-algebra flag is set.
bool hasUnsafeAlgebra() const;
index 762f4a75c315948e3897df7c7ed751012f6101a2..c25937c97ab0b6599c104abf48810a075ded0391 100644 (file)
(B * FastMathFlags::AllowReciprocal);
}
- /// Convenience function for setting all the fast-math flags
+ /// Convenience function for setting multiple fast-math flags.
+ /// FMF is a mask of the bits to set.
void setFastMathFlags(FastMathFlags FMF) {
SubclassOptionalData |= FMF.Flags;
}
+ /// Convenience function for copying all fast-math flags.
+ /// All values in FMF are transferred to this operator.
+ void copyFastMathFlags(FastMathFlags FMF) {
+ SubclassOptionalData = FMF.Flags;
+ }
+
public:
/// Test whether this operation is permitted to be
/// algebraically transformed, aka the 'A' fast-math property.
diff --git a/lib/IR/Instruction.cpp b/lib/IR/Instruction.cpp
index 86421c4ae9ffcfd6319efde23da9c04e58d4e216..50b1f04d41e1ebbd432e775144e5105bc4b2455e 100644 (file)
--- a/lib/IR/Instruction.cpp
+++ b/lib/IR/Instruction.cpp
cast<FPMathOperator>(this)->setFastMathFlags(FMF);
}
+void Instruction::copyFastMathFlags(FastMathFlags FMF) {
+ assert(isa<FPMathOperator>(this) && "copying fast-math flag on invalid op");
+ cast<FPMathOperator>(this)->copyFastMathFlags(FMF);
+}
+
/// Determine whether the unsafe-algebra flag is set.
bool Instruction::hasUnsafeAlgebra() const {
assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
/// Copy I's fast-math flags
void Instruction::copyFastMathFlags(const Instruction *I) {
- setFastMathFlags(I->getFastMathFlags());
+ copyFastMathFlags(I->getFastMathFlags());
}
index 16993f1bba545d074bce5bec4b9c24e32e975c9d..b113d51d4168fdee272c8a36411775417fdd8c14 100644 (file)
--- a/lib/IR/Instructions.cpp
+++ b/lib/IR/Instructions.cpp
// Copy the fast-math flags.
if (auto *FP = dyn_cast<FPMathOperator>(V))
- setFastMathFlags(FP->getFastMathFlags());
+ copyFastMathFlags(FP->getFastMathFlags());
}
//===----------------------------------------------------------------------===//
index 21085755fbadf9114bec9fd1ec4265e502baee15..df5c8406477983ffc58c60a4dc7990e5b5acabc4 100644 (file)
Builder.clearFastMathFlags();
+ // To test a copy, make sure that a '0' and a '1' change state.
F = Builder.CreateFDiv(F, F);
ASSERT_TRUE(isa<Instruction>(F));
FDiv = cast<Instruction>(F);
EXPECT_FALSE(FDiv->getFastMathFlags().any());
+ FDiv->setHasAllowReciprocal(true);
+ FAdd->setHasAllowReciprocal(false);
FDiv->copyFastMathFlags(FAdd);
EXPECT_TRUE(FDiv->hasNoNaNs());
+ EXPECT_FALSE(FDiv->hasAllowReciprocal());
}