@@ -25,21 +25,81 @@ void foo() {
2525
2626void foo2 () {
2727 float _Complex a;
28- float b = 1 .0f ?: __real__ a;
28+ float _Complex b;
29+ float _Complex c = a ?: b;
2930}
3031
3132// CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["a"]
32- // CIR: %[[B_ADDR:.*]] = cir.alloca !cir.float, !cir.ptr<!cir.float>, ["b", init]
33- // CIR: %[[CONST_1:.*]] = cir.const #cir.fp<1.000000e+00> : !cir.float
34- // CIR: cir.store{{.*}} %[[CONST_1]], %[[B_ADDR]] : !cir.float, !cir.ptr<!cir.float>
33+ // CIR: %[[B_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["b"]
34+ // CIR: %[[C_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["c", init]
35+ // CIR: %[[TMP_A:.*]] = cir.load{{.*}} %[[A_ADDR]] : !cir.ptr<!cir.complex<!cir.float>>, !cir.complex<!cir.float>
36+ // CIR: %[[A_REAL:.*]] = cir.complex.real %[[TMP_A]] : !cir.complex<!cir.float> -> !cir.float
37+ // CIR: %[[A_IMAG:.*]] = cir.complex.imag %[[TMP_A]] : !cir.complex<!cir.float> -> !cir.float
38+ // CIR: %[[A_REAL_BOOL:.*]] = cir.cast(float_to_bool, %[[A_REAL]] : !cir.float), !cir.bool
39+ // CIR: %[[A_IMAG_BOOL:.*]] = cir.cast(float_to_bool, %[[A_IMAG]] : !cir.float), !cir.bool
40+ // CIR: %[[CONST_TRUE:.*]] = cir.const #true
41+ // CIR: %[[COND:.*]] = cir.select if %[[A_REAL_BOOL]] then %[[CONST_TRUE]] else %[[A_IMAG_BOOL]] : (!cir.bool, !cir.bool, !cir.bool) -> !cir.bool
42+ // CIR: %[[RESULT:.*]] = cir.ternary(%[[COND]], true {
43+ // CIR: %[[TMP_A:.*]] = cir.load{{.*}} %[[A_ADDR]] : !cir.ptr<!cir.complex<!cir.float>>, !cir.complex<!cir.float>
44+ // CIR: cir.yield %[[TMP_A]] : !cir.complex<!cir.float>
45+ // CIR: }, false {
46+ // CIR: %[[TMP_B:.*]] = cir.load{{.*}} %[[B_ADDR]] : !cir.ptr<!cir.complex<!cir.float>>, !cir.complex<!cir.float>
47+ // CIR: cir.yield %[[TMP_B]] : !cir.complex<!cir.float>
48+ // CIR: }) : (!cir.bool) -> !cir.complex<!cir.float>
49+ // CIR: cir.store{{.*}} %[[RESULT]], %[[C_ADDR]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
3550
3651// LLVM: %[[A_ADDR:.*]] = alloca { float, float }, i64 1, align 4
37- // LLVM: %[[B_ADDR:.*]] = alloca float, i64 1, align 4
38- // LLVM: store float 1.000000e+00, ptr %[[B_ADDR]], align 4
52+ // LLVM: %[[B_ADDR:.*]] = alloca { float, float }, i64 1, align 4
53+ // LLVM: %[[C_ADDR:.*]] = alloca { float, float }, i64 1, align 4
54+ // LLVM: %[[TMP_A:.*]] = load { float, float }, ptr %[[A_ADDR]], align 4
55+ // LLVM: %[[A_REAL:.*]] = extractvalue { float, float } %[[TMP_A]], 0
56+ // LLVM: %[[A_IMAG:.*]] = extractvalue { float, float } %[[TMP_A]], 1
57+ // LLVM: %[[A_REAL_BOOL:.*]] = fcmp une float %[[A_REAL]], 0.000000e+00
58+ // LLVM: %[[A_IMAG_BOOL:.*]] = fcmp une float %[[A_IMAG]], 0.000000e+00
59+ // LLVM: %[[COND:.*]] = or i1 %[[A_REAL_BOOL]], %[[A_IMAG_BOOL]]
60+ // LLVM: br i1 %[[COND]], label %[[COND_TRUE:.*]], label %[[COND_FALSE:.*]]
61+ // LLVM: [[COND_TRUE]]:
62+ // LLVM: %[[TMP_A:.*]] = load { float, float }, ptr %[[A_ADDR]], align 4
63+ // LLVM: br label %[[COND_RESULT:.*]]
64+ // LLVM: [[COND_FALSE]]:
65+ // LLVM: %[[TMP_B:.*]] = load { float, float }, ptr %[[B_ADDR]], align 4
66+ // LLVM: br label %[[COND_RESULT]]
67+ // LLVM: [[COND_RESULT]]:
68+ // LLVM: %[[RESULT:.*]] = phi { float, float } [ %[[TMP_B]], %[[COND_FALSE]] ], [ %[[TMP_A]], %[[COND_TRUE]] ]
69+ // LLVM: br label %[[COND_END:.*]]
70+ // LLVM: [[COND_END]]:
71+ // LLVM: store { float, float } %[[RESULT]], ptr %[[C_ADDR]], align 4
3972
4073// OGCG: %[[A_ADDR:.*]] = alloca { float, float }, align 4
41- // OGCG: %[[B_ADDR:.*]] = alloca float, align 4
42- // OGCG: store float 1.000000e+00, ptr %[[B_ADDR]], align 4
74+ // OGCG: %[[B_ADDR:.*]] = alloca { float, float }, align 4
75+ // OGCG: %[[C_ADDR:.*]] = alloca { float, float }, align 4
76+ // OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 0
77+ // OGCG: %[[A_REAL:.*]] = load float, ptr %[[A_REAL_PTR]], align 4
78+ // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 1
79+ // OGCG: %[[A_IMAG:.*]] = load float, ptr %[[A_IMAG_PTR]], align 4
80+ // OGCG: %[[A_REAL_BOOL:.*]] = fcmp une float %[[A_REAL]], 0.000000e+00
81+ // OGCG: %[[A_IMAG_BOOL:.*]] = fcmp une float %[[A_IMAG]], 0.000000e+00
82+ // OGCG: %[[COND:.*]] = or i1 %[[A_REAL_BOOL]], %[[A_IMAG_BOOL]]
83+ // OGCG: br i1 %tobool2, label %[[COND_TRUE:.*]], label %[[COND_FALSE:.*]]
84+ // OGCG: [[COND_TRUE]]:
85+ // OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 0
86+ // OGCG: %[[A_REAL:.*]] = load float, ptr %[[A_REAL_PTR]], align 4
87+ // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 1
88+ // OGCG: %[[A_IMAG:.*]] = load float, ptr %[[A_IMAG_PTR]], align 4
89+ // OGCG: br label %[[COND_END:.*]]
90+ // OGCG: [[COND_FALSE]]:
91+ // OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[B_ADDR]], i32 0, i32 0
92+ // OGCG: %[[B_REAL:.*]] = load float, ptr %[[B_REAL_PTR]], align 4
93+ // OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[B_ADDR]], i32 0, i32 1
94+ // OGCG: %[[B_IMAG:.*]] = load float, ptr %[[B_IMAG_PTR]], align 4
95+ // OGCG: br label %[[COND_END]]
96+ // OGCG: [[COND_END]]:
97+ // OGCG: %[[RESULT_REAL:.*]] = phi float [ %[[A_REAL]], %[[COND_TRUE]] ], [ %[[B_REAL]], %[[COND_FALSE]] ]
98+ // OGCG: %[[RESULT_IMAG:.*]] = phi float [ %[[A_IMAG]], %[[COND_TRUE]] ], [ %[[B_IMAG]], %[[COND_FALSE]] ]
99+ // OGCG: %[[C_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[C_ADDR]], i32 0, i32 0
100+ // OGCG: %[[C_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[C_ADDR]], i32 0, i32 1
101+ // OGCG: store float %[[RESULT_REAL]], ptr %[[C_REAL_PTR]], align 4
102+ // OGCG: store float %[[RESULT_IMAG]], ptr %[[C_IMAG_PTR]], align 4
43103
44104void foo3 () {
45105 int a;
0 commit comments