@@ -125,3 +125,73 @@ func.func @test2() -> !quake.veq<2> {
125125// GLOBAL-DAG: cc.global constant private @__nvqpp__mlirgen__function_test_complex_constant_array._Z27test_complex_constant_arrayv.rodata_{{[0-9]+}} (dense<[(0.707106769,0.000000e+00), (0.707106769,0.000000e+00), (0.000000e+00,0.000000e+00), (0.000000e+00,0.000000e+00)]> : tensor<4xcomplex<f32>>) : !cc.array<complex<f32> x 4>
126126// GLOBAL-DAG: cc.global constant private @__nvqpp__mlirgen__function_custom_h_generator_1._Z20custom_h_generator_1v.rodata_{{[0-9]+}} (dense<[(0.70710678118654757,0.000000e+00), (0.70710678118654757,0.000000e+00), (0.70710678118654757,0.000000e+00), (-0.70710678118654757,0.000000e+00)]> : tensor<4xcomplex<f64>>) : !cc.array<complex<f64> x 4>
127127// GLOBAL-DAG: cc.global constant private @test2.rodata_{{[0-9]+}} (dense<[1.000000e+00, 2.000000e+00, 6.000000e+00, 9.000000e+00]>" : tensor<4xf64>) : !cc.array<f64 x 4>
128+
129+ func.func @test_two_stores() {
130+ %c0_i64 = arith.constant 0 : i64
131+ %c1_i64 = arith.constant 1 : i64
132+
133+ // qubits = cudaq.qvector(2)
134+ %0 = quake.alloca !quake.veq<2>
135+
136+ // arr1 = [1]
137+ %1 = cc.alloca !cc.array<i64 x 1>
138+ %2 = cc.cast %1 : (!cc.ptr<!cc.array<i64 x 1>>) -> !cc.ptr<i64>
139+ cc.store %c1_i64, %2 : !cc.ptr<i64>
140+
141+ // t = arr1[0]
142+ %3 = cc.load %2 : !cc.ptr<i64>
143+
144+ // arr2 = [0]
145+ %4 = cc.alloca !cc.array<i64 x 1>
146+ %5 = cc.cast %4 : (!cc.ptr<!cc.array<i64 x 1>>) -> !cc.ptr<i64>
147+ cc.store %c0_i64, %5 : !cc.ptr<i64> // Dominates the next store, don't lift
148+
149+ // arr2[0] = t
150+ cc.store %3, %5 : !cc.ptr<i64>
151+
152+ // b = arr2[0]
153+ %6 = cc.load %5 : !cc.ptr<i64>
154+
155+ // x(qubits[b])
156+ %7 = quake.extract_ref %0[%6] : (!quake.veq<2>, i64) -> !quake.ref
157+ quake.x %7 : (!quake.ref) -> ()
158+ return
159+ }
160+
161+ // CHECK-LABEL: func.func @test_two_stores() {
162+ // CHECK: %[[VAL_0:.*]] = arith.constant 0 : i64
163+ // CHECK: %[[VAL_1:.*]] = quake.alloca !quake.veq<2>
164+ // CHECK: %[[VAL_2:.*]] = cc.const_array [1] : !cc.array<i64 x 1>
165+ // CHECK: %[[VAL_3:.*]] = cc.extract_value %[[VAL_2]][0] : (!cc.array<i64 x 1>) -> i64
166+ // CHECK: %[[VAL_4:.*]] = cc.alloca !cc.array<i64 x 1>
167+ // CHECK: %[[VAL_5:.*]] = cc.cast %[[VAL_4]] : (!cc.ptr<!cc.array<i64 x 1>>) -> !cc.ptr<i64>
168+ // CHECK: cc.store %[[VAL_0]], %[[VAL_5]] : !cc.ptr<i64>
169+ // CHECK: cc.store %[[VAL_3]], %[[VAL_5]] : !cc.ptr<i64>
170+ // CHECK: %[[VAL_6:.*]] = cc.load %[[VAL_5]] : !cc.ptr<i64>
171+ // CHECK: %[[VAL_7:.*]] = quake.extract_ref %[[VAL_1]][%[[VAL_6]]] : (!quake.veq<2>, i64) -> !quake.ref
172+ // CHECK: quake.x %[[VAL_7]] : (!quake.ref) -> ()
173+ // CHECK: return
174+ // CHECK: }
175+
176+ func.func @test_complex_array() {
177+ %cst = complex.constant [0.000000e+00 : f32, 1.000000e+00 : f32] : complex<f32>
178+ %cst_0 = complex.constant [1.000000e+00 : f32, 0.000000e+00 : f32] : complex<f32>
179+ %0 = cc.alloca !cc.array<complex<f32> x 2>
180+ %1 = cc.cast %0 : (!cc.ptr<!cc.array<complex<f32> x 2>>) -> !cc.ptr<complex<f32>>
181+ cc.store %cst_0, %1 : !cc.ptr<complex<f32>>
182+ %2 = cc.compute_ptr %0[1] : (!cc.ptr<!cc.array<complex<f32> x 2>>) -> !cc.ptr<complex<f32>>
183+ cc.store %cst, %2 : !cc.ptr<complex<f32>>
184+ %3 = quake.alloca !quake.veq<1>
185+ %4 = quake.init_state %3, %1 : (!quake.veq<1>, !cc.ptr<complex<f32>>) -> !quake.veq<1>
186+ return
187+ }
188+
189+ // CHECK-LABEL: func.func @test_complex_array() {
190+ // CHECK: %[[VAL_0:.*]] = cc.const_array {{\[}}[1.000000e+00 : f32, 0.000000e+00 : f32], [0.000000e+00 : f32, 1.000000e+00 : f32]{{\]}} : !cc.array<complex<f32> x 2>
191+ // CHECK: %[[VAL_1:.*]] = cc.alloca !cc.array<complex<f32> x 2>
192+ // CHECK: cc.store %[[VAL_0]], %[[VAL_1]] : !cc.ptr<!cc.array<complex<f32> x 2>>
193+ // CHECK: %[[VAL_2:.*]] = cc.cast %[[VAL_1]] : (!cc.ptr<!cc.array<complex<f32> x 2>>) -> !cc.ptr<complex<f32>>
194+ // CHECK: %[[VAL_3:.*]] = quake.alloca !quake.veq<1>
195+ // CHECK: %[[VAL_4:.*]] = quake.init_state %[[VAL_3]], %[[VAL_2]] : (!quake.veq<1>, !cc.ptr<complex<f32>>) -> !quake.veq<1>
196+ // CHECK: return
197+ // CHECK: }
0 commit comments