1a8c51b3fSopenharmony_ci#include <benchmark/benchmark.h>
2a8c51b3fSopenharmony_ci
3a8c51b3fSopenharmony_ci#ifdef __clang__
4a8c51b3fSopenharmony_ci#pragma clang diagnostic ignored "-Wreturn-type"
5a8c51b3fSopenharmony_ci#endif
6a8c51b3fSopenharmony_ciBENCHMARK_DISABLE_DEPRECATED_WARNING
7a8c51b3fSopenharmony_ci
8a8c51b3fSopenharmony_ciextern "C" {
9a8c51b3fSopenharmony_ci
10a8c51b3fSopenharmony_ciextern int ExternInt;
11a8c51b3fSopenharmony_ciextern int ExternInt2;
12a8c51b3fSopenharmony_ciextern int ExternInt3;
13a8c51b3fSopenharmony_ci}
14a8c51b3fSopenharmony_ci
15a8c51b3fSopenharmony_ci// CHECK-LABEL: test_basic:
16a8c51b3fSopenharmony_ciextern "C" void test_basic() {
17a8c51b3fSopenharmony_ci  int x;
18a8c51b3fSopenharmony_ci  benchmark::DoNotOptimize(&x);
19a8c51b3fSopenharmony_ci  x = 101;
20a8c51b3fSopenharmony_ci  benchmark::ClobberMemory();
21a8c51b3fSopenharmony_ci  // CHECK: leaq [[DEST:[^,]+]], %rax
22a8c51b3fSopenharmony_ci  // CHECK: movl $101, [[DEST]]
23a8c51b3fSopenharmony_ci  // CHECK: ret
24a8c51b3fSopenharmony_ci}
25a8c51b3fSopenharmony_ci
26a8c51b3fSopenharmony_ci// CHECK-LABEL: test_redundant_store:
27a8c51b3fSopenharmony_ciextern "C" void test_redundant_store() {
28a8c51b3fSopenharmony_ci  ExternInt = 3;
29a8c51b3fSopenharmony_ci  benchmark::ClobberMemory();
30a8c51b3fSopenharmony_ci  ExternInt = 51;
31a8c51b3fSopenharmony_ci  // CHECK-DAG: ExternInt
32a8c51b3fSopenharmony_ci  // CHECK-DAG: movl $3
33a8c51b3fSopenharmony_ci  // CHECK: movl $51
34a8c51b3fSopenharmony_ci}
35a8c51b3fSopenharmony_ci
36a8c51b3fSopenharmony_ci// CHECK-LABEL: test_redundant_read:
37a8c51b3fSopenharmony_ciextern "C" void test_redundant_read() {
38a8c51b3fSopenharmony_ci  int x;
39a8c51b3fSopenharmony_ci  benchmark::DoNotOptimize(&x);
40a8c51b3fSopenharmony_ci  x = ExternInt;
41a8c51b3fSopenharmony_ci  benchmark::ClobberMemory();
42a8c51b3fSopenharmony_ci  x = ExternInt2;
43a8c51b3fSopenharmony_ci  // CHECK: leaq [[DEST:[^,]+]], %rax
44a8c51b3fSopenharmony_ci  // CHECK: ExternInt(%rip)
45a8c51b3fSopenharmony_ci  // CHECK: movl %eax, [[DEST]]
46a8c51b3fSopenharmony_ci  // CHECK-NOT: ExternInt2
47a8c51b3fSopenharmony_ci  // CHECK: ret
48a8c51b3fSopenharmony_ci}
49a8c51b3fSopenharmony_ci
50a8c51b3fSopenharmony_ci// CHECK-LABEL: test_redundant_read2:
51a8c51b3fSopenharmony_ciextern "C" void test_redundant_read2() {
52a8c51b3fSopenharmony_ci  int x;
53a8c51b3fSopenharmony_ci  benchmark::DoNotOptimize(&x);
54a8c51b3fSopenharmony_ci  x = ExternInt;
55a8c51b3fSopenharmony_ci  benchmark::ClobberMemory();
56a8c51b3fSopenharmony_ci  x = ExternInt2;
57a8c51b3fSopenharmony_ci  benchmark::ClobberMemory();
58a8c51b3fSopenharmony_ci  // CHECK: leaq [[DEST:[^,]+]], %rax
59a8c51b3fSopenharmony_ci  // CHECK: ExternInt(%rip)
60a8c51b3fSopenharmony_ci  // CHECK: movl %eax, [[DEST]]
61a8c51b3fSopenharmony_ci  // CHECK: ExternInt2(%rip)
62a8c51b3fSopenharmony_ci  // CHECK: movl %eax, [[DEST]]
63a8c51b3fSopenharmony_ci  // CHECK: ret
64a8c51b3fSopenharmony_ci}
65