|
| 1 | +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O1 -fclangir -emit-cir %s -o %t.cir |
| 2 | +// FileCheck --input-file=%t.cir %s |
| 3 | +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O1 -fclangir -fclangir-mem2reg -emit-cir %s -o %t.cir |
| 4 | +// FileCheck --input-file=%t.cir %s --check-prefix=MEM2REG |
| 5 | + |
| 6 | +int produce_int(); |
| 7 | +void blackbox(const int &); |
| 8 | +void blackbox(const volatile int &); |
| 9 | + |
| 10 | +int load_local_const_int() { |
| 11 | + const int x = produce_int(); |
| 12 | + int a = x; |
| 13 | + blackbox(x); |
| 14 | + int b = x; |
| 15 | + return a + b; |
| 16 | +} |
| 17 | + |
| 18 | +// CHECK-LABEL: @_Z20load_local_const_intv |
| 19 | +// CHECK: %[[#x_slot:]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["x", init, const] {alignment = 4 : i64} |
| 20 | +// CHECK-NEXT: %[[#a_slot:]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["a", init] {alignment = 4 : i64} |
| 21 | +// CHECK-NEXT: %[[#b_slot:]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["b", init] {alignment = 4 : i64} |
| 22 | +// CHECK-NEXT: %[[#init:]] = cir.call @_Z11produce_intv() : () -> !s32i |
| 23 | +// CHECK-NEXT: cir.store %[[#init]], %[[#x_slot]] : !s32i, !cir.ptr<!s32i> |
| 24 | +// CHECK-NEXT: cir.store %[[#init]], %[[#a_slot]] : !s32i, !cir.ptr<!s32i> |
| 25 | +// CHECK-NEXT: cir.call @_Z8blackboxRKi(%[[#x_slot]]) : (!cir.ptr<!s32i>) -> () |
| 26 | +// CHECK-NEXT: cir.store %[[#init]], %[[#b_slot]] : !s32i, !cir.ptr<!s32i> |
| 27 | +// CHECK: } |
| 28 | + |
| 29 | +// MEM2REG-LABEL: @_Z20load_local_const_intv |
| 30 | +// MEM2REG-NEXT: %[[#x_slot:]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["x", init, const] {alignment = 4 : i64} |
| 31 | +// MEM2REG-NEXT: %[[#init:]] = cir.call @_Z11produce_intv() : () -> !s32i |
| 32 | +// MEM2REG-NEXT: cir.store %[[#init]], %[[#x_slot]] : !s32i, !cir.ptr<!s32i> |
| 33 | +// MEM2REG-NEXT: cir.call @_Z8blackboxRKi(%[[#x_slot]]) : (!cir.ptr<!s32i>) -> () |
| 34 | +// MEM2REG-NEXT: %{{.+}} = cir.binop(add, %[[#init]], %[[#init]]) nsw : !s32i |
| 35 | +// MEM2REG: } |
| 36 | + |
| 37 | +int load_volatile_local_const_int() { |
| 38 | + const volatile int x = produce_int(); |
| 39 | + int a = x; |
| 40 | + blackbox(x); |
| 41 | + int b = x; |
| 42 | + return a + b; |
| 43 | +} |
| 44 | + |
| 45 | +// CHECKLABEL: @_Z29load_volatile_local_const_intv |
| 46 | +// CHECK: %[[#x_slot:]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["x", init, const] {alignment = 4 : i64} |
| 47 | +// CHECK-NEXT: %[[#a_slot:]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["a", init] {alignment = 4 : i64} |
| 48 | +// CHECK-NEXT: %[[#b_slot:]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["b", init] {alignment = 4 : i64} |
| 49 | +// CHECK-NEXT: %[[#init:]] = cir.call @_Z11produce_intv() : () -> !s32i |
| 50 | +// CHECK-NEXT: cir.store volatile %[[#init]], %[[#x_slot]] : !s32i, !cir.ptr<!s32i> |
| 51 | +// CHECK-NEXT: %[[#reload_1:]] = cir.load volatile %[[#x_slot]] : !cir.ptr<!s32i>, !s32i |
| 52 | +// CHECK-NEXT: cir.store %[[#reload_1]], %[[#a_slot]] : !s32i, !cir.ptr<!s32i> |
| 53 | +// CHECK-NEXT: cir.call @_Z8blackboxRVKi(%[[#x_slot]]) : (!cir.ptr<!s32i>) -> () |
| 54 | +// CHECK-NEXT: %[[#reload_2:]] = cir.load volatile %[[#x_slot]] : !cir.ptr<!s32i>, !s32i |
| 55 | +// CHECK-NEXT: cir.store %[[#reload_2]], %[[#b_slot]] : !s32i, !cir.ptr<!s32i> |
| 56 | +// CHECK: } |
| 57 | + |
| 58 | +// MEM2REG-LABEL: @_Z29load_volatile_local_const_intv |
| 59 | +// MEM2REG-NEXT: %[[#x_slot:]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["x", init, const] {alignment = 4 : i64} |
| 60 | +// MEM2REG-NEXT: %[[#init:]] = cir.call @_Z11produce_intv() : () -> !s32i |
| 61 | +// MEM2REG-NEXT: cir.store volatile %[[#init]], %[[#x_slot]] : !s32i, !cir.ptr<!s32i> |
| 62 | +// MEM2REG-NEXT: %{{.+}} = cir.load volatile %[[#x_slot]] : !cir.ptr<!s32i>, !s32i |
| 63 | +// MEM2REG-NEXT: cir.call @_Z8blackboxRVKi(%[[#x_slot]]) : (!cir.ptr<!s32i>) -> () |
| 64 | +// MEM2REG-NEXT: %{{.+}} = cir.load volatile %[[#x_slot]] : !cir.ptr<!s32i>, !s32i |
| 65 | +// MEM2REG: } |
0 commit comments