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