forked from NVIDIA/cuda-quantum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrite_after_write_elimination.qke
More file actions
89 lines (81 loc) · 4.08 KB
/
write_after_write_elimination.qke
File metadata and controls
89 lines (81 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// ========================================================================== //
// Copyright (c) 2022 - 2025 NVIDIA Corporation & Affiliates. //
// All rights reserved. //
// //
// This source code and the accompanying materials are made available under //
// the terms of the Apache License 2.0 which accompanies this distribution. //
// ========================================================================== //
// RUN: cudaq-opt -write-after-write-elimination %s | FileCheck %s
func.func @test_two_stores_same_pointer() {
%c0_i64 = arith.constant 0 : i64
%0 = quake.alloca !quake.veq<2>
%1 = cc.const_array [1] : !cc.array<i64 x 1>
%2 = cc.extract_value %1[0] : (!cc.array<i64 x 1>) -> i64
%3 = cc.alloca !cc.array<i64 x 1>
%4 = cc.cast %3 : (!cc.ptr<!cc.array<i64 x 1>>) -> !cc.ptr<i64>
cc.store %c0_i64, %4 : !cc.ptr<i64>
cc.store %2, %4 : !cc.ptr<i64>
%5 = cc.load %4 : !cc.ptr<i64>
%6 = quake.extract_ref %0[%5] : (!quake.veq<2>, i64) -> !quake.ref
quake.x %6 : (!quake.ref) -> ()
return
}
// CHECK-LABEL: func.func @test_two_stores_same_pointer() {
// CHECK: %[[VAL_1:.*]] = quake.alloca !quake.veq<2>
// CHECK: %[[VAL_2:.*]] = cc.const_array [1] : !cc.array<i64 x 1>
// CHECK: %[[VAL_3:.*]] = cc.extract_value %[[VAL_2]][0] : (!cc.array<i64 x 1>) -> i64
// CHECK: %[[VAL_4:.*]] = cc.alloca !cc.array<i64 x 1>
// CHECK: %[[VAL_5:.*]] = cc.cast %[[VAL_4]] : (!cc.ptr<!cc.array<i64 x 1>>) -> !cc.ptr<i64>
// CHECK: cc.store %[[VAL_3]], %[[VAL_5]] : !cc.ptr<i64>
// CHECK: %[[VAL_6:.*]] = cc.load %[[VAL_5]] : !cc.ptr<i64>
// CHECK: %[[VAL_7:.*]] = quake.extract_ref %[[VAL_1]][%[[VAL_6]]] : (!quake.veq<2>, i64) -> !quake.ref
// CHECK: quake.x %[[VAL_7]] : (!quake.ref) -> ()
// CHECK: return
// CHECK: }
func.func @test_two_stores_different_pointers() {
%c0_i64 = arith.constant 0 : i64
%c1_i64 = arith.constant 1 : i64
%0 = quake.alloca !quake.veq<2>
%1 = cc.alloca !cc.array<i64 x 1>
%2 = cc.alloca i64
cc.store %c0_i64, %2 : !cc.ptr<i64>
%3 = cc.alloca i64
cc.store %c1_i64, %3 : !cc.ptr<i64>
return
}
// CHECK-LABEL: func.func @test_two_stores_different_pointers() {
// CHECK: %[[VAL_0:.*]] = arith.constant 0 : i64
// CHECK: %[[VAL_1:.*]] = arith.constant 1 : i64
// CHECK: %[[VAL_2:.*]] = quake.alloca !quake.veq<2>
// CHECK: %[[VAL_3:.*]] = cc.alloca !cc.array<i64 x 1>
// CHECK: %[[VAL_4:.*]] = cc.alloca i64
// CHECK: cc.store %[[VAL_0]], %[[VAL_4]] : !cc.ptr<i64>
// CHECK: %[[VAL_5:.*]] = cc.alloca i64
// CHECK: cc.store %[[VAL_1]], %[[VAL_5]] : !cc.ptr<i64>
// CHECK: return
// CHECK: }
func.func @test_two_stores_same_pointer_interleaving() {
%c0_i64 = arith.constant 0 : i64
%c1_i64 = arith.constant 1 : i64
%c2_i64 = arith.constant 2 : i64
%0 = cc.alloca !cc.array<i64 x 2>
%1 = cc.cast %0 : (!cc.ptr<!cc.array<i64 x 2>>) -> !cc.ptr<i64>
cc.store %c0_i64, %1 : !cc.ptr<i64>
%2 = cc.compute_ptr %0[1] : (!cc.ptr<!cc.array<i64 x 2>>) -> !cc.ptr<i64>
cc.store %c2_i64, %1 : !cc.ptr<i64>
cc.store %c0_i64, %2 : !cc.ptr<i64>
cc.store %c1_i64, %1 : !cc.ptr<i64>
cc.store %c1_i64, %2 : !cc.ptr<i64>
return
}
// CHECK-LABEL: func.func @test_two_stores_same_pointer_interleaving() {
// CHECK: %[[VAL_c0:.*]] = arith.constant 0 : i64
// CHECK: %[[VAL_c1:.*]] = arith.constant 1 : i64
// CHECK: %[[VAL_c2:.*]] = arith.constant 2 : i64
// CHECK: %[[VAL_1:.*]] = cc.alloca !cc.array<i64 x 2>
// CHECK: %[[VAL_2:.*]] = cc.cast %[[VAL_1]] : (!cc.ptr<!cc.array<i64 x 2>>) -> !cc.ptr<i64>
// CHECK: %[[VAL_3:.*]] = cc.compute_ptr %[[VAL_1]][1] : (!cc.ptr<!cc.array<i64 x 2>>) -> !cc.ptr<i64>
// CHECK: cc.store %[[VAL_c1]], %[[VAL_2]] : !cc.ptr<i64>
// CHECK: cc.store %[[VAL_c1]], %[[VAL_3]] : !cc.ptr<i64>
// CHECK: return
// CHECK: }