Skip to content

Commit f017073

Browse files
authored
[Clang][CodeGen] Promote in complex compound divassign (#131453)
When `-fcomplex-arithmetic=promoted` is set complex divassign `/=` should promote to a wider type the same way division (without assignment) does. Prior to this change, Smith's algorithm would be used for divassign. Fixes: #131129
1 parent 1bd6716 commit f017073

File tree

2 files changed

+221
-326
lines changed

2 files changed

+221
-326
lines changed

clang/lib/CodeGen/CGExprComplex.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -1214,21 +1214,24 @@ EmitCompoundAssignLValue(const CompoundAssignOperator *E,
12141214
OpInfo.FPFeatures = E->getFPFeaturesInEffect(CGF.getLangOpts());
12151215
CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, OpInfo.FPFeatures);
12161216

1217+
const bool IsComplexDivisor = E->getOpcode() == BO_DivAssign &&
1218+
E->getRHS()->getType()->isAnyComplexType();
1219+
12171220
// Load the RHS and LHS operands.
12181221
// __block variables need to have the rhs evaluated first, plus this should
12191222
// improve codegen a little.
12201223
QualType PromotionTypeCR;
1221-
PromotionTypeCR = getPromotionType(E->getStoredFPFeaturesOrDefault(),
1222-
E->getComputationResultType(),
1223-
/*IsComplexDivisor=*/false);
1224+
PromotionTypeCR =
1225+
getPromotionType(E->getStoredFPFeaturesOrDefault(),
1226+
E->getComputationResultType(), IsComplexDivisor);
12241227
if (PromotionTypeCR.isNull())
12251228
PromotionTypeCR = E->getComputationResultType();
12261229
OpInfo.Ty = PromotionTypeCR;
12271230
QualType ComplexElementTy =
12281231
OpInfo.Ty->castAs<ComplexType>()->getElementType();
12291232
QualType PromotionTypeRHS =
12301233
getPromotionType(E->getStoredFPFeaturesOrDefault(),
1231-
E->getRHS()->getType(), /*IsComplexDivisor=*/false);
1234+
E->getRHS()->getType(), IsComplexDivisor);
12321235

12331236
// The RHS should have been converted to the computation type.
12341237
if (E->getRHS()->getType()->isRealFloatingType()) {
@@ -1258,7 +1261,7 @@ EmitCompoundAssignLValue(const CompoundAssignOperator *E,
12581261
SourceLocation Loc = E->getExprLoc();
12591262
QualType PromotionTypeLHS =
12601263
getPromotionType(E->getStoredFPFeaturesOrDefault(),
1261-
E->getComputationLHSType(), /*IsComplexDivisor=*/false);
1264+
E->getComputationLHSType(), IsComplexDivisor);
12621265
if (LHSTy->isAnyComplexType()) {
12631266
ComplexPairTy LHSVal = EmitLoadOfLValue(LHS, Loc);
12641267
if (!PromotionTypeLHS.isNull())

0 commit comments

Comments
 (0)