Skip to content

Commit 2bdd0be

Browse files
authored
[CIR] Fix emitCompoundAssignLValue with promotion rhs type (#1774)
Fix emitCompoundAssignLValue with promotion RHS type Ref: llvm/llvm-project#150759 (comment)
1 parent 7493e0f commit 2bdd0be

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -696,9 +696,7 @@ LValue ComplexExprEmitter::emitCompoundAssignLValue(
696696
}
697697
} else {
698698
if (!PromotionTypeRHS.isNull()) {
699-
OpInfo.RHS = createComplexFromReal(
700-
CGF.getBuilder(), CGF.getLoc(E->getExprLoc()),
701-
CGF.emitPromotedComplexExpr(E->getRHS(), PromotionTypeRHS));
699+
OpInfo.RHS = CGF.emitPromotedComplexExpr(E->getRHS(), PromotionTypeRHS);
702700
} else {
703701
assert(CGF.getContext().hasSameUnqualifiedType(OpInfo.Ty,
704702
E->getRHS()->getType()));

clang/test/CIR/CodeGen/complex-arithmetic.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,67 @@ void add_assign() {
581581

582582
// CHECK: }
583583

584+
585+
void add_assign_float16() {
586+
_Float16 _Complex a;
587+
_Float16 _Complex b;
588+
a += b;
589+
}
590+
591+
// CLANG: @add_assign_float16
592+
// CPPLANG: @_Z18add_assign_float16v
593+
594+
// CIRGRN: %{{.*}} = cir.binop(add, %{{.*}}, %{{.*}}) : !cir.complex<!cir.f16>
595+
596+
// CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!cir.f16>, !cir.ptr<!cir.complex<!cir.f16>>, ["a"]
597+
// CIR: %[[B_ADDR:.*]] = cir.alloca !cir.complex<!cir.f16>, !cir.ptr<!cir.complex<!cir.f16>>, ["b"]
598+
// CIR: %[[TMP_B:.*]] = cir.load{{.*}} %[[B_ADDR]] : !cir.ptr<!cir.complex<!cir.f16>>, !cir.complex<!cir.f16>
599+
// CIR: %[[B_REAL:.*]] = cir.complex.real %[[TMP_B]] : !cir.complex<!cir.f16> -> !cir.f16
600+
// CIR: %[[B_IMAG:.*]] = cir.complex.imag %[[TMP_B]] : !cir.complex<!cir.f16> -> !cir.f16
601+
// CIR: %[[B_REAL_F32:.*]] = cir.cast(floating, %[[B_REAL]] : !cir.f16), !cir.float
602+
// CIR: %[[B_IMAG_F32:.*]] = cir.cast(floating, %[[B_IMAG]] : !cir.f16), !cir.float
603+
// CIR: %[[B_F32_COMPLEX:.*]] = cir.complex.create %[[B_REAL_F32]], %[[B_IMAG_F32]] : !cir.float -> !cir.complex<!cir.float>
604+
// CIR: %[[TMP_A:.*]] = cir.load{{.*}} %[[A_ADDR]] : !cir.ptr<!cir.complex<!cir.f16>>, !cir.complex<!cir.f16>
605+
// CIR: %[[A_REAL:.*]] = cir.complex.real %[[TMP_A]] : !cir.complex<!cir.f16> -> !cir.f16
606+
// CIR: %[[A_IMAG:.*]] = cir.complex.imag %[[TMP_A]] : !cir.complex<!cir.f16> -> !cir.f16
607+
// CIR: %[[A_REAL_F32:.*]] = cir.cast(floating, %[[A_REAL]] : !cir.f16), !cir.float
608+
// CIR: %[[A_IMAG_F32:.*]] = cir.cast(floating, %[[A_IMAG]] : !cir.f16), !cir.float
609+
// CIR: %[[A_F32_COMPLEX:.*]] = cir.complex.create %[[A_REAL_F32]], %[[A_IMAG_F32]] : !cir.float -> !cir.complex<!cir.float>
610+
// CIR: %[[A_F32_REAL:.*]] = cir.complex.real %[[A_F32_COMPLEX]] : !cir.complex<!cir.float> -> !cir.float
611+
// CIR: %[[A_F32_IMAG:.*]] = cir.complex.imag %[[A_F32_COMPLEX]] : !cir.complex<!cir.float> -> !cir.float
612+
// CIR: %[[B_F32_REAL:.*]] = cir.complex.real %[[B_F32_COMPLEX]] : !cir.complex<!cir.float> -> !cir.float
613+
// CIR: %[[B_F32_IMAG:.*]] = cir.complex.imag %[[B_F32_COMPLEX]] : !cir.complex<!cir.float> -> !cir.float
614+
// CIR: %[[ADD_REAL:.*]] = cir.binop(add, %[[A_F32_REAL]], %[[B_F32_REAL]]) : !cir.float
615+
// CIR: %[[ADD_IMAG:.*]] = cir.binop(add, %[[A_F32_IMAG]], %[[B_F32_IMAG]]) : !cir.float
616+
// CIR: %[[RESULT:.*]] = cir.complex.create %[[ADD_REAL]], %[[ADD_IMAG]] : !cir.float -> !cir.complex<!cir.float>
617+
618+
// LLVM: %[[A_ADDR:.*]] = alloca { half, half }, i64 1, align 2
619+
// LLVM: %[[B_ADDR:.*]] = alloca { half, half }, i64 1, align 2
620+
// LLVM: %[[TMP_B:.*]] = load { half, half }, ptr %[[B_ADDR]], align 2
621+
// LLVM: %[[B_REAL:.*]] = extractvalue { half, half } %[[TMP_B]], 0
622+
// LLVM: %[[B_IMAG:.*]] = extractvalue { half, half } %[[TMP_B]], 1
623+
// LLVM: %[[B_REAL_F32:.*]] = fpext half %[[B_REAL]] to float
624+
// LLVM: %[[B_IMAG_F32:.*]] = fpext half %[[B_IMAG]] to float
625+
// LLVM: %[[TMP_B_COMPLEX_F32:.*]] = insertvalue { float, float } {{.*}}, float %[[B_REAL_F32]], 0
626+
// LLVM: %[[B_COMPLEX_F32:.*]] = insertvalue { float, float } %[[TMP_B_COMPLEX_F32]], float %[[B_IMAG_F32]], 1
627+
// LLVM: %[[TMP_A:.*]] = load { half, half }, ptr %[[A_ADDR]], align 2
628+
// LLVM: %[[A_REAL:.*]] = extractvalue { half, half } %[[TMP_A]], 0
629+
// LLVM: %[[A_IMAG:.*]] = extractvalue { half, half } %[[TMP_A]], 1
630+
// LLVM: %[[A_REAL_F32:.*]] = fpext half %[[A_REAL]] to float
631+
// LLVM: %[[A_IMAG_F32:.*]] = fpext half %[[A_IMAG]] to float
632+
// LLVM: %[[TMP_A_COMPLEX_F32:.*]] = insertvalue { float, float } {{.*}}, float %[[A_REAL_F32]], 0
633+
// LLVM: %[[A_COMPLEX_F32:.*]] = insertvalue { float, float } %[[TMP_A_COMPLEX_F32]], float %[[A_IMAG_F32]], 1
634+
// LLVM: %[[A_F32_REAL:.*]] = extractvalue { float, float } %[[A_COMPLEX_F32]], 0
635+
// LLVM: %[[A_F32_IMAG:.*]] = extractvalue { float, float } %[[A_COMPLEX_F32]], 1
636+
// LLVM: %[[B_F32_REAL:.*]] = extractvalue { float, float } %[[B_COMPLEX_F32]], 0
637+
// LLVM: %[[B_F32_IMAG:.*]] = extractvalue { float, float } %[[B_COMPLEX_F32]], 1
638+
// LLVM: %[[ADD_REAL:.*]] = fadd float %[[A_F32_REAL]], %[[B_F32_REAL]]
639+
// LLVM: %[[ADD_IMAG:.*]] = fadd float %[[A_F32_IMAG]], %[[B_F32_IMAG]]
640+
// LLVM: %[[TMP_RESULT:.*]] = insertvalue { float, float } {{.*}}, float %[[ADD_REAL]], 0
641+
// LLVM: %[[RESULT:.*]] = insertvalue { float, float } %[[TMP_RESULT]], float %[[ADD_IMAG]], 1
642+
643+
// CHECK: }
644+
584645
void sub_assign() {
585646
cd1 -= cd2;
586647
ci1 -= ci2;

0 commit comments

Comments
 (0)