Index: llvm/lib/Support/APFloat.cpp =================================================================== --- llvm/lib/Support/APFloat.cpp +++ llvm/lib/Support/APFloat.cpp @@ -986,9 +986,15 @@ integerPart *fullSignificand; lostFraction lost_fraction; bool ignored; + IEEEFloat extendedAddend(*semantics, 0); assert(semantics == rhs.semantics); + // Save the addend now, before we change our properties, as it may be equal to + // 'this' pointer. + if (addend) + extendedAddend = *addend; + precision = semantics->precision; // Allocate space for twice as many bits as the original significand, plus one @@ -1022,7 +1028,7 @@ // toward left by two bits, and adjust exponent accordingly. exponent += 2; - if (addend && addend->isNonZero()) { + if (extendedAddend.isNonZero()) { // The intermediate result of the multiplication has "2 * precision" // signicant bit; adjust the addend to be consistent with mul result. // @@ -1051,7 +1057,6 @@ significand.parts = fullSignificand; semantics = &extendedSemantics; - IEEEFloat extendedAddend(*addend); status = extendedAddend.convert(extendedSemantics, rmTowardZero, &ignored); assert(status == opOK); (void)status; Index: llvm/unittests/ADT/APFloatTest.cpp =================================================================== --- llvm/unittests/ADT/APFloatTest.cpp +++ llvm/unittests/ADT/APFloatTest.cpp @@ -530,6 +530,14 @@ EXPECT_FALSE(losesInfo); EXPECT_EQ(4.0f, M1.convertToFloat()); } + + // Test using only a single instance of APFloat. + { + APFloat F(1.5); + + F.fusedMultiplyAdd(F, F, APFloat::rmNearestTiesToEven); + EXPECT_EQ(3.75, F.convertToDouble()); + } } TEST(APFloatTest, MinNum) {