clobber_memory_assembly_test.cc 1.3 KB

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