craig.topper created this revision. craig.topper added reviewers: cameron.mcinally, rjmccall, efriedma, rsmith.
We have an fneg instruction now and should use it instead of the fsub -0.0 idiom. Looks like we had no test that showed that we handled the negation cases here so I've added new tests. https://reviews.llvm.org/D72010 Files: clang/lib/CodeGen/CGExprScalar.cpp clang/test/CodeGen/fp-contract-pragma.cpp Index: clang/test/CodeGen/fp-contract-pragma.cpp =================================================================== --- clang/test/CodeGen/fp-contract-pragma.cpp +++ clang/test/CodeGen/fp-contract-pragma.cpp @@ -74,3 +74,18 @@ return (a = 2 * b) - c; } +float fp_contract_8(float a, float b, float c) { +// CHECK: _Z13fp_contract_8fff +// CHECK: fneg float %c +// CHECK: tail call float @llvm.fmuladd + #pragma STDC FP_CONTRACT ON + return a * b - c; +} + +float fp_contract_9(float a, float b, float c) { +// CHECK: _Z13fp_contract_9fff +// CHECK: fneg float %a +// CHECK: tail call float @llvm.fmuladd + #pragma STDC FP_CONTRACT ON + return c - a * b; +} Index: clang/lib/CodeGen/CGExprScalar.cpp =================================================================== --- clang/lib/CodeGen/CGExprScalar.cpp +++ clang/lib/CodeGen/CGExprScalar.cpp @@ -3345,17 +3345,10 @@ Value *MulOp0 = MulOp->getOperand(0); Value *MulOp1 = MulOp->getOperand(1); - if (negMul) { - MulOp0 = - Builder.CreateFSub( - llvm::ConstantFP::getZeroValueForNegation(MulOp0->getType()), MulOp0, - "neg"); - } else if (negAdd) { - Addend = - Builder.CreateFSub( - llvm::ConstantFP::getZeroValueForNegation(Addend->getType()), Addend, - "neg"); - } + if (negMul) + MulOp0 = Builder.CreateFNeg(MulOp0, "neg"); + if (negAdd) + Addend = Builder.CreateFNeg(Addend, "neg"); Value *FMulAdd = Builder.CreateCall( CGF.CGM.getIntrinsic(llvm::Intrinsic::fmuladd, Addend->getType()),
Index: clang/test/CodeGen/fp-contract-pragma.cpp =================================================================== --- clang/test/CodeGen/fp-contract-pragma.cpp +++ clang/test/CodeGen/fp-contract-pragma.cpp @@ -74,3 +74,18 @@ return (a = 2 * b) - c; } +float fp_contract_8(float a, float b, float c) { +// CHECK: _Z13fp_contract_8fff +// CHECK: fneg float %c +// CHECK: tail call float @llvm.fmuladd + #pragma STDC FP_CONTRACT ON + return a * b - c; +} + +float fp_contract_9(float a, float b, float c) { +// CHECK: _Z13fp_contract_9fff +// CHECK: fneg float %a +// CHECK: tail call float @llvm.fmuladd + #pragma STDC FP_CONTRACT ON + return c - a * b; +} Index: clang/lib/CodeGen/CGExprScalar.cpp =================================================================== --- clang/lib/CodeGen/CGExprScalar.cpp +++ clang/lib/CodeGen/CGExprScalar.cpp @@ -3345,17 +3345,10 @@ Value *MulOp0 = MulOp->getOperand(0); Value *MulOp1 = MulOp->getOperand(1); - if (negMul) { - MulOp0 = - Builder.CreateFSub( - llvm::ConstantFP::getZeroValueForNegation(MulOp0->getType()), MulOp0, - "neg"); - } else if (negAdd) { - Addend = - Builder.CreateFSub( - llvm::ConstantFP::getZeroValueForNegation(Addend->getType()), Addend, - "neg"); - } + if (negMul) + MulOp0 = Builder.CreateFNeg(MulOp0, "neg"); + if (negAdd) + Addend = Builder.CreateFNeg(Addend, "neg"); Value *FMulAdd = Builder.CreateCall( CGF.CGM.getIntrinsic(llvm::Intrinsic::fmuladd, Addend->getType()),
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits