diff options
author | Serge Pavlov <sepavloff@gmail.com> | 2023-01-13 22:32:10 +0700 |
---|---|---|
committer | Serge Pavlov <sepavloff@gmail.com> | 2023-01-24 16:40:11 +0700 |
commit | d595b59d5c9c8e56c3b3d142912ee16a02071690 (patch) | |
tree | 1e11b481fc8fcc7b8f9726ba8afe1bf861070a52 /clang/lib/CodeGen/CGExprComplex.cpp | |
parent | 2a16e1ff7d2735001dbe40e607823857f4bedd0e (diff) | |
download | llvm-d595b59d5c9c8e56c3b3d142912ee16a02071690.zip llvm-d595b59d5c9c8e56c3b3d142912ee16a02071690.tar.gz llvm-d595b59d5c9c8e56c3b3d142912ee16a02071690.tar.bz2 |
[FPEnv] Fix complex operations in strictfp mode
Operations on floating-point complex data had incorrect FP attributes
in strictfp mode, because IRBuilder object was not synchronized with AST
node attributes.
Differential Revision: https://reviews.llvm.org/D141765
Diffstat (limited to 'clang/lib/CodeGen/CGExprComplex.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGExprComplex.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGExprComplex.cpp b/clang/lib/CodeGen/CGExprComplex.cpp index e65e925..7a14a41 100644 --- a/clang/lib/CodeGen/CGExprComplex.cpp +++ b/clang/lib/CodeGen/CGExprComplex.cpp @@ -252,6 +252,7 @@ public: ComplexPairTy LHS; ComplexPairTy RHS; QualType Ty; // Computation Type. + FPOptions FPFeatures; }; BinOpInfo EmitBinOps(const BinaryOperator *E, @@ -643,6 +644,7 @@ ComplexPairTy ComplexExprEmitter::EmitBinAdd(const BinOpInfo &Op) { llvm::Value *ResR, *ResI; if (Op.LHS.first->getType()->isFloatingPointTy()) { + CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, Op.FPFeatures); ResR = Builder.CreateFAdd(Op.LHS.first, Op.RHS.first, "add.r"); if (Op.LHS.second && Op.RHS.second) ResI = Builder.CreateFAdd(Op.LHS.second, Op.RHS.second, "add.i"); @@ -661,6 +663,7 @@ ComplexPairTy ComplexExprEmitter::EmitBinAdd(const BinOpInfo &Op) { ComplexPairTy ComplexExprEmitter::EmitBinSub(const BinOpInfo &Op) { llvm::Value *ResR, *ResI; if (Op.LHS.first->getType()->isFloatingPointTy()) { + CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, Op.FPFeatures); ResR = Builder.CreateFSub(Op.LHS.first, Op.RHS.first, "sub.r"); if (Op.LHS.second && Op.RHS.second) ResI = Builder.CreateFSub(Op.LHS.second, Op.RHS.second, "sub.i"); @@ -753,6 +756,7 @@ ComplexPairTy ComplexExprEmitter::EmitBinMul(const BinOpInfo &Op) { // FIXME: C11 also provides for imaginary types which would allow folding // still more of this within the type system. + CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, Op.FPFeatures); if (Op.LHS.second && Op.RHS.second) { // If both operands are complex, emit the core math directly, and then // test for NaNs. If we find NaNs in the result, we delegate to a libcall @@ -854,6 +858,7 @@ ComplexPairTy ComplexExprEmitter::EmitBinDiv(const BinOpInfo &Op) { // // FIXME: We would be able to avoid the libcall in many places if we // supported imaginary types in addition to complex types. + CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, Op.FPFeatures); if (RHSi && !CGF.getLangOpts().FastMath) { BinOpInfo LibCallOp = Op; // If LHS was a real, supply a null imaginary part. @@ -1025,6 +1030,7 @@ ComplexExprEmitter::EmitBinOps(const BinaryOperator *E, Ops.Ty = PromotionType; else Ops.Ty = E->getType(); + Ops.FPFeatures = E->getFPFeaturesInEffect(CGF.getLangOpts()); return Ops; } @@ -1039,8 +1045,9 @@ EmitCompoundAssignLValue(const CompoundAssignOperator *E, if (const AtomicType *AT = LHSTy->getAs<AtomicType>()) LHSTy = AT->getValueType(); - CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E); BinOpInfo OpInfo; + OpInfo.FPFeatures = E->getFPFeaturesInEffect(CGF.getLangOpts()); + CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, OpInfo.FPFeatures); // Load the RHS and LHS operands. // __block variables need to have the rhs evaluated first, plus this should |