1 #include <benchmark/benchmark.h>
4 #pragma clang diagnostic ignored "-Wreturn-type"
10 extern int ExternInt2
;
11 extern int ExternInt3
;
13 inline int Add42(int x
) { return x
+ 42; }
15 struct NotTriviallyCopyable
{
16 NotTriviallyCopyable();
17 explicit NotTriviallyCopyable(int x
) : value(x
) {}
18 NotTriviallyCopyable(NotTriviallyCopyable
const &);
27 // CHECK-LABEL: test_with_rvalue:
28 extern "C" void test_with_rvalue() {
29 benchmark::DoNotOptimize(Add42(0));
30 // CHECK: movl $42, %eax
34 // CHECK-LABEL: test_with_large_rvalue:
35 extern "C" void test_with_large_rvalue() {
36 benchmark::DoNotOptimize(Large
{ExternInt
, {ExternInt
, ExternInt
}});
37 // CHECK: ExternInt(%rip)
38 // CHECK: movl %eax, -{{[0-9]+}}(%[[REG:[a-z]+]]
39 // CHECK: movl %eax, -{{[0-9]+}}(%[[REG]])
40 // CHECK: movl %eax, -{{[0-9]+}}(%[[REG]])
44 // CHECK-LABEL: test_with_non_trivial_rvalue:
45 extern "C" void test_with_non_trivial_rvalue() {
46 benchmark::DoNotOptimize(NotTriviallyCopyable(ExternInt
));
47 // CHECK: mov{{l|q}} ExternInt(%rip)
51 // CHECK-LABEL: test_with_lvalue:
52 extern "C" void test_with_lvalue() {
54 benchmark::DoNotOptimize(x
);
55 // CHECK-GNU: movl $101, %eax
56 // CHECK-CLANG: movl $101, -{{[0-9]+}}(%[[REG:[a-z]+]])
60 // CHECK-LABEL: test_with_large_lvalue:
61 extern "C" void test_with_large_lvalue() {
62 Large L
{ExternInt
, {ExternInt
, ExternInt
}};
63 benchmark::DoNotOptimize(L
);
64 // CHECK: ExternInt(%rip)
65 // CHECK: movl %eax, -{{[0-9]+}}(%[[REG:[a-z]+]])
66 // CHECK: movl %eax, -{{[0-9]+}}(%[[REG]])
67 // CHECK: movl %eax, -{{[0-9]+}}(%[[REG]])
71 // CHECK-LABEL: test_with_non_trivial_lvalue:
72 extern "C" void test_with_non_trivial_lvalue() {
73 NotTriviallyCopyable
NTC(ExternInt
);
74 benchmark::DoNotOptimize(NTC
);
75 // CHECK: ExternInt(%rip)
76 // CHECK: movl %eax, -{{[0-9]+}}(%[[REG:[a-z]+]])
80 // CHECK-LABEL: test_with_const_lvalue:
81 extern "C" void test_with_const_lvalue() {
83 benchmark::DoNotOptimize(x
);
84 // CHECK: movl $123, %eax
88 // CHECK-LABEL: test_with_large_const_lvalue:
89 extern "C" void test_with_large_const_lvalue() {
90 const Large L
{ExternInt
, {ExternInt
, ExternInt
}};
91 benchmark::DoNotOptimize(L
);
92 // CHECK: ExternInt(%rip)
93 // CHECK: movl %eax, -{{[0-9]+}}(%[[REG:[a-z]+]])
94 // CHECK: movl %eax, -{{[0-9]+}}(%[[REG]])
95 // CHECK: movl %eax, -{{[0-9]+}}(%[[REG]])
99 // CHECK-LABEL: test_with_non_trivial_const_lvalue:
100 extern "C" void test_with_non_trivial_const_lvalue() {
101 const NotTriviallyCopyable
Obj(ExternInt
);
102 benchmark::DoNotOptimize(Obj
);
103 // CHECK: mov{{q|l}} ExternInt(%rip)
107 // CHECK-LABEL: test_div_by_two:
108 extern "C" int test_div_by_two(int input
) {
110 benchmark::DoNotOptimize(divisor
);
111 return input
/ divisor
;
112 // CHECK: movl $2, [[DEST:.*]]
113 // CHECK: idivl [[DEST]]
117 // CHECK-LABEL: test_inc_integer:
118 extern "C" int test_inc_integer() {
120 for (int i
= 0; i
< 5; ++i
) benchmark::DoNotOptimize(++x
);
121 // CHECK: movl $1, [[DEST:.*]]
122 // CHECK: {{(addl \$1,|incl)}} [[DEST]]
123 // CHECK: {{(addl \$1,|incl)}} [[DEST]]
124 // CHECK: {{(addl \$1,|incl)}} [[DEST]]
125 // CHECK: {{(addl \$1,|incl)}} [[DEST]]
126 // CHECK-CLANG: movl [[DEST]], %eax
131 // CHECK-LABEL: test_pointer_rvalue
132 extern "C" void test_pointer_rvalue() {
133 // CHECK: movl $42, [[DEST:.*]]
134 // CHECK: leaq [[DEST]], %rax
135 // CHECK-CLANG: movq %rax, -{{[0-9]+}}(%[[REG:[a-z]+]])
138 benchmark::DoNotOptimize(&x
);
141 // CHECK-LABEL: test_pointer_const_lvalue:
142 extern "C" void test_pointer_const_lvalue() {
143 // CHECK: movl $42, [[DEST:.*]]
144 // CHECK: leaq [[DEST]], %rax
145 // CHECK-CLANG: movq %rax, -{{[0-9]+}}(%[[REG:[a-z]+]])
149 benchmark::DoNotOptimize(xp
);
152 // CHECK-LABEL: test_pointer_lvalue:
153 extern "C" void test_pointer_lvalue() {
154 // CHECK: movl $42, [[DEST:.*]]
155 // CHECK: leaq [[DEST]], %rax
156 // CHECK-CLANG: movq %rax, -{{[0-9]+}}(%[[REG:[a-z+]+]])
160 benchmark::DoNotOptimize(xp
);