From 8a8d703be0986dd6785cba0b610c9c4708b83e89 Mon Sep 17 00:00:00 2001 From: John McCall Date: Mon, 1 Jun 2020 21:02:02 -0400 Subject: Fix how cc1 command line options are mapped into FP options. Canonicalize on storing FP options in LangOptions instead of redundantly in CodeGenOptions. Incorporate -ffast-math directly into the values of those LangOptions rather than considering it separately when building FPOptions. Build IR attributes from those options rather than a mix of sources. We should really simplify the driver/cc1 interaction here and have the driver pass down options that cc1 directly honors. That can happen in a follow-up, though. Patch by Michele Scandale! https://reviews.llvm.org/D80315 --- clang/lib/CodeGen/CodeGenFunction.cpp | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp') diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index a348103..d6622a4 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -71,26 +71,7 @@ CodeGenFunction::CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext) if (!suppressNewContext) CGM.getCXXABI().getMangleContext().startNewFunction(); - llvm::FastMathFlags FMF; - if (CGM.getLangOpts().FastMath) - FMF.setFast(); - if (CGM.getLangOpts().FiniteMathOnly) { - FMF.setNoNaNs(); - FMF.setNoInfs(); - } - if (CGM.getCodeGenOpts().NoNaNsFPMath) { - FMF.setNoNaNs(); - } - if (CGM.getCodeGenOpts().NoSignedZeros) { - FMF.setNoSignedZeros(); - } - if (CGM.getCodeGenOpts().ReciprocalMath) { - FMF.setAllowReciprocal(); - } - if (CGM.getCodeGenOpts().Reassociate) { - FMF.setAllowReassoc(); - } - Builder.setFastMathFlags(FMF); + SetFastMathFlags(FPOptions(CGM.getLangOpts())); SetFPModel(); } @@ -139,6 +120,18 @@ void CodeGenFunction::SetFPModel() { RM != llvm::RoundingMode::NearestTiesToEven); } +void CodeGenFunction::SetFastMathFlags(FPOptions FPFeatures) { + llvm::FastMathFlags FMF; + FMF.setAllowReassoc(FPFeatures.allowAssociativeMath()); + FMF.setNoNaNs(FPFeatures.noHonorNaNs()); + FMF.setNoInfs(FPFeatures.noHonorInfs()); + FMF.setNoSignedZeros(FPFeatures.noSignedZeros()); + FMF.setAllowReciprocal(FPFeatures.allowReciprocalMath()); + FMF.setApproxFunc(FPFeatures.allowApproximateFunctions()); + FMF.setAllowContract(FPFeatures.allowFPContractAcrossStatement()); + Builder.setFastMathFlags(FMF); +} + LValue CodeGenFunction::MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T) { LValueBaseInfo BaseInfo; TBAAAccessInfo TBAAInfo; -- cgit v1.1