Skip to content

Commit 1ea6ce8

Browse files
authored
[CIR] Fix lowering Complex to Complex cast (#1750)
Fix lowering Complex to Complex cast, backported from llvm/llvm-project#149717
1 parent 6f28fff commit 1ea6ce8

File tree

1 file changed

+45
-8
lines changed

1 file changed

+45
-8
lines changed

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

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,21 @@ void scalar_to_complex() {
5151
// CIR-AFTER-NEXT: %{{.+}} = cir.complex.create %[[#REAL]], %[[#IMAG]] : !s32i -> !cir.complex<!s32i>
5252

5353
// LLVM: %[[#REAL:]] = load volatile double, ptr @sd, align 8
54-
// LLVM-NEXT: %[[#A:]] = insertvalue { double, double } undef, double %[[#REAL]], 0
54+
// LLVM-NEXT: %[[#A:]] = insertvalue { double, double } {{.*}}, double %[[#REAL]], 0
5555
// LLVM-NEXT: %{{.+}} = insertvalue { double, double } %[[#A]], double 0.000000e+00, 1
5656

5757
// LLVM: %[[#REAL:]] = load volatile i32, ptr @si, align 4
58-
// LLVM-NEXT: %[[#A:]] = insertvalue { i32, i32 } undef, i32 %[[#REAL]], 0
58+
// LLVM-NEXT: %[[#A:]] = insertvalue { i32, i32 } {{.*}}, i32 %[[#REAL]], 0
5959
// LLVM-NEXT: %{{.+}} = insertvalue { i32, i32 } %[[#A]], i32 0, 1
6060

6161
// LLVM: %[[#A:]] = load volatile i32, ptr @si, align 4
6262
// LLVM-NEXT: %[[#REAL:]] = sitofp i32 %[[#A]] to double
63-
// LLVM-NEXT: %[[#B:]] = insertvalue { double, double } undef, double %[[#REAL]], 0
63+
// LLVM-NEXT: %[[#B:]] = insertvalue { double, double } {{.*}}, double %[[#REAL]], 0
6464
// LLVM-NEXT: %{{.+}} = insertvalue { double, double } %[[#B]], double 0.000000e+00, 1
6565

6666
// LLVM: %[[#A:]] = load volatile double, ptr @sd, align 8
6767
// LLVM-NEXT: %[[#REAL:]] = fptosi double %[[#A]] to i32
68-
// LLVM-NEXT: %[[#B:]] = insertvalue { i32, i32 } undef, i32 %[[#REAL]], 0
68+
// LLVM-NEXT: %[[#B:]] = insertvalue { i32, i32 } {{.*}}, i32 %[[#REAL]], 0
6969
// LLVM-NEXT: %{{.+}} = insertvalue { i32, i32 } %[[#B]], i32 0, 1
7070

7171
// CHECK: }
@@ -84,15 +84,15 @@ void scalar_to_complex_explicit() {
8484
// CIR-AFTER: %[[#IMAG:]] = cir.const #cir.fp<0.000000e+00> : !cir.double
8585
// CIR-AFTER-NEXT: %{{.+}} = cir.complex.create %{{.+}}, %[[#IMAG]] : !cir.double -> !cir.complex<!cir.double>
8686

87-
// LLVM: %[[#A:]] = insertvalue { double, double } undef, double %{{.+}}, 0
87+
// LLVM: %[[#A:]] = insertvalue { double, double } {{.*}}, double %{{.+}}, 0
8888
// LLVM-NEXT: %{{.+}} = insertvalue { double, double } %[[#A]], double 0.000000e+00, 1
8989

9090
// CIR-BEFORE: %{{.+}} = cir.cast(int_to_complex, %{{.+}} : !s32i), !cir.complex<!s32i>
9191

9292
// CIR-AFTER: %[[#IMAG:]] = cir.const #cir.int<0> : !s32i
9393
// CIR-AFTER-NEXT: %{{.+}} = cir.complex.create %{{.+}}, %[[#IMAG]] : !s32i -> !cir.complex<!s32i>
9494

95-
// LLVM: %[[#A:]] = insertvalue { i32, i32 } undef, i32 %{{.+}}, 0
95+
// LLVM: %[[#A:]] = insertvalue { i32, i32 } {{.*}}, i32 %{{.+}}, 0
9696
// LLVM-NEXT: %{{.+}} = insertvalue { i32, i32 } %[[#A]], i32 0, 1
9797

9898
// CIR-BEFORE: %[[#A:]] = cir.cast(int_to_float, %{{.+}} : !s32i), !cir.double
@@ -103,7 +103,7 @@ void scalar_to_complex_explicit() {
103103
// CIR-AFTER-NEXT: %{{.+}} = cir.complex.create %[[#REAL]], %[[#IMAG]] : !cir.double -> !cir.complex<!cir.double>
104104

105105
// LLVM: %[[#REAL:]] = sitofp i32 %{{.+}} to double
106-
// LLVM-NEXT: %[[#A:]] = insertvalue { double, double } undef, double %[[#REAL]], 0
106+
// LLVM-NEXT: %[[#A:]] = insertvalue { double, double } {{.*}}, double %[[#REAL]], 0
107107
// LLVM-NEXT: %{{.+}} = insertvalue { double, double } %[[#A]], double 0.000000e+00, 1
108108

109109
// CIR-BEFORE: %[[#A:]] = cir.cast(float_to_int, %{{.+}} : !cir.double), !s32i
@@ -114,7 +114,7 @@ void scalar_to_complex_explicit() {
114114
// CIR-AFTER-NEXT: %{{.+}} = cir.complex.create %[[#REAL]], %[[#IMAG]] : !s32i -> !cir.complex<!s32i>
115115

116116
// LLVM: %[[#REAL:]] = fptosi double %{{.+}} to i32
117-
// LLVM-NEXT: %[[#A:]] = insertvalue { i32, i32 } undef, i32 %[[#REAL]], 0
117+
// LLVM-NEXT: %[[#A:]] = insertvalue { i32, i32 } {{.*}}, i32 %[[#REAL]], 0
118118
// LLVM-NEXT: %{{.+}} = insertvalue { i32, i32 } %[[#A]], i32 0, 1
119119

120120
// CHECK: }
@@ -199,6 +199,43 @@ void complex_to_bool() {
199199

200200
// CHECK: }
201201

202+
void complex_to_complex_cast() {
203+
cd = cf;
204+
ci = cs;
205+
}
206+
207+
// CIR-BEFORE: %[[TMP:.*]] = cir.load{{.*}} %{{.*}} : !cir.ptr<!cir.complex<!cir.float>>, !cir.complex<!cir.float>
208+
// CIR-BEFORE: %[[FP_COMPLEX:.*]] = cir.cast(float_complex, %[[TMP]] : !cir.complex<!cir.float>), !cir.complex<!cir.double>
209+
210+
// CIR-AFTER: %[[#REAL:]] = cir.complex.real %{{.*}} : !cir.complex<!cir.float> -> !cir.float
211+
// CIR-AFTER: %[[#IMAG:]] = cir.complex.imag %{{.*}} : !cir.complex<!cir.float> -> !cir.float
212+
// CIR-AFTER: %[[#REAL_FP_CAST:]] = cir.cast(floating, %[[#REAL]] : !cir.float), !cir.double
213+
// CIR-AFTER: %[[#IMAG_FP_CAST:]] = cir.cast(floating, %[[#IMAG]] : !cir.float), !cir.double
214+
// CIR-AFTER: %{{.*}} = cir.complex.create %[[#REAL_FP_CAST]], %[[#IMAG_FP_CAST]] : !cir.double -> !cir.complex<!cir.double>
215+
216+
// LLVM: %[[#REAL:]] = extractvalue { float, float } %{{.*}}, 0
217+
// LLVM: %[[#IMAG:]] = extractvalue { float, float } %{{.*}}, 1
218+
// LLVM: %[[#REAL_FP_CAST:]] = fpext float %[[#REAL]] to double
219+
// LLVM: %[[#IMAG_FP_CAST:]] = fpext float %[[#IMAG]] to double
220+
// LLVM: %[[TMP:.*]] = insertvalue { double, double } {{.*}}, double %[[#REAL_FP_CAST]], 0
221+
// LLVM: %{{.*}} = insertvalue { double, double } %[[TMP]], double %[[#IMAG_FP_CAST]], 1
222+
223+
// CIR-BEFORE: %[[TMP:.*]] = cir.load{{.*}} %{{.*}} : !cir.ptr<!cir.complex<!s16i>>, !cir.complex<!s16i>
224+
// CIR-BEFORE: %[[INT_COMPLEX:.*]] = cir.cast(int_complex, %[[TMP]] : !cir.complex<!s16i>), !cir.complex<!s32i>
225+
226+
// CIR-AFTER: %[[#REAL:]] = cir.complex.real %{{.*}} : !cir.complex<!s16i> -> !s16i
227+
// CIR-AFTER: %[[#IMAG:]] = cir.complex.imag %{{.*}} : !cir.complex<!s16i> -> !s16i
228+
// CIR-AFTER: %[[#REAL_INT_CAST:]] = cir.cast(integral, %[[#REAL]] : !s16i), !s32i
229+
// CIR-AFTER: %[[#IMAG_INT_CAST:]] = cir.cast(integral, %[[#IMAG]] : !s16i), !s32i
230+
// CIR-AFTER: %{{.*}} = cir.complex.create %[[#REAL_INT_CAST]], %[[#IMAG_INT_CAST]] : !s32i -> !cir.complex<!s32i>
231+
232+
// LLVM: %[[#REAL:]] = extractvalue { i16, i16 } %{{.*}}, 0
233+
// LLVM: %[[#IMAG:]] = extractvalue { i16, i16 } %{{.*}}, 1
234+
// LLVM: %[[#REAL_INT_CAST:]] = sext i16 %[[#REAL]] to i32
235+
// LLVM: %[[#IMAG_INT_CAST:]] = sext i16 %[[#IMAG]] to i32
236+
// LLVM: %[[TMP:.*]] = insertvalue { i32, i32 } {{.*}}, i32 %[[#REAL_INT_CAST]], 0
237+
// LLVM: %{{.*}} = insertvalue { i32, i32 } %[[TMP]], i32 %[[#IMAG_INT_CAST]], 1
238+
202239
void promotion() {
203240
cd = cf + cf;
204241
}

0 commit comments

Comments
 (0)