| 1 |
// RUN: %clang_cc1 -triple aarch64_be-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir |
| 2 |
// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR |
| 3 |
// RUN: %clang_cc1 -triple aarch64_be-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll |
| 4 |
// RUN: FileCheck --input-file=%t-cir.ll %s --check-prefix=LLVM |
| 5 |
// RUN: %clang_cc1 -triple aarch64_be-unknown-linux-gnu -emit-llvm %s -o %t.ll |
| 6 |
// RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG |
| 7 |
|
| 8 |
typedef struct { |
| 9 |
int a : 4; |
| 10 |
int b : 11; |
| 11 |
int c : 17; |
| 12 |
} S; |
| 13 |
|
| 14 |
// CIR: !rec_S = !cir.record<struct "S" {!u32i}> |
| 15 |
// LLVM: %struct.S = type { i32 } |
| 16 |
// OGCG: %struct.S = type { i32 } |
| 17 |
void def() { |
| 18 |
S s; |
| 19 |
} |
| 20 |
int init(S* s) { |
| 21 |
return s->c; |
| 22 |
} |
| 23 |
|
| 24 |
//CIR: cir.func {{.*}} @init |
| 25 |
//CIR: [[TMP0:%.*]] = cir.alloca !cir.ptr<!rec_S>, !cir.ptr<!cir.ptr<!rec_S>>, ["s", init] {alignment = 8 : i64} |
| 26 |
//CIR: [[TMP1:%.*]] = cir.load align(8) [[TMP0]] : !cir.ptr<!cir.ptr<!rec_S>>, !cir.ptr<!rec_S> |
| 27 |
//CIR: [[TMP2:%.*]] = cir.get_member [[TMP1]][0] {name = "c"} : !cir.ptr<!rec_S> -> !cir.ptr<!u32i> |
| 28 |
//CIR: [[TMP3:%.*]] = cir.get_bitfield align(4) (#bfi_c, [[TMP2]] : !cir.ptr<!u32i>) -> !s32i |
| 29 |
|
| 30 |
//LLVM: define dso_local i32 @init(ptr %0){{.*}} { |
| 31 |
//LLVM: [[TMP0:%.*]] = alloca ptr, i64 1, align 8 |
| 32 |
//LLVM: [[TMP1:%.*]] = alloca i32, i64 1, align 4 |
| 33 |
//LLVM: [[TMP2:%.*]] = load ptr, ptr [[TMP0]], align 8 |
| 34 |
//LLVM: [[TMP3:%.*]] = getelementptr %struct.S, ptr [[TMP2]], i32 0, i32 0 |
| 35 |
//LLVM: [[TMP4:%.*]] = load i32, ptr [[TMP3]], align 4 |
| 36 |
//LLVM: [[TMP5:%.*]] = shl i32 [[TMP4]], 15 |
| 37 |
//LLVM: [[TMP6:%.*]] = ashr i32 [[TMP5]], 15 |
| 38 |
|
| 39 |
//OGCG: define dso_local i32 @init |
| 40 |
//OGCG: [[TMP0:%.*]] = alloca ptr, align 8 |
| 41 |
//OGCG: [[TMP1:%.*]] = load ptr, ptr [[TMP0]], align 8 |
| 42 |
//OGCG: [[TMP2:%.*]] = load i32, ptr [[TMP1]], align 4 |
| 43 |
//OGCG: [[TMP3:%.*]] = shl i32 [[TMP2]], 15 |
| 44 |
//OGCG: [[TMP4:%.*]] = ashr i32 [[TMP3]], 15 |
| 45 |
|
| 46 |
|
| 47 |
void load(S* s) { |
| 48 |
s->a = -4; |
| 49 |
s->b = 42; |
| 50 |
s->c = -12345; |
| 51 |
} |
| 52 |
|
| 53 |
// field 'a' |
| 54 |
// CIR: cir.func {{.*}} @load |
| 55 |
// CIR: %[[PTR0:.*]] = cir.alloca !cir.ptr<!rec_S>, !cir.ptr<!cir.ptr<!rec_S>>, ["s", init] |
| 56 |
// CIR: %[[CONST1:.*]] = cir.const #cir.int<-4> : !s32i |
| 57 |
// CIR: %[[VAL0:.*]] = cir.load align(8) %[[PTR0]] : !cir.ptr<!cir.ptr<!rec_S>>, !cir.ptr<!rec_S> |
| 58 |
// CIR: %[[GET0:.*]] = cir.get_member %[[VAL0]][0] {name = "a"} : !cir.ptr<!rec_S> -> !cir.ptr<!u32i> |
| 59 |
// CIR: %[[SET0:.*]] = cir.set_bitfield align(4) (#bfi_a, %[[GET0]] : !cir.ptr<!u32i>, %[[CONST1]] : !s32i) -> !s32i |
| 60 |
|
| 61 |
// LLVM: define dso_local void @load{{.*}}{{.*}} |
| 62 |
// LLVM: %[[PTR0:.*]] = load ptr |
| 63 |
// LLVM: %[[GET0:.*]] = getelementptr %struct.S, ptr %[[PTR0]], i32 0, i32 0 |
| 64 |
// LLVM: %[[VAL0:.*]] = load i32, ptr %[[GET0]], align 4 |
| 65 |
// LLVM: %[[AND0:.*]] = and i32 %[[VAL0]], 268435455 |
| 66 |
// LLVM: %[[OR0:.*]] = or i32 %[[AND0]], -1073741824 |
| 67 |
// LLVM: store i32 %[[OR0]], ptr %[[GET0]], align 4 |
| 68 |
|
| 69 |
// OGCG: define dso_local void @load |
| 70 |
// OGCG: %[[PTR0:.*]] = load ptr |
| 71 |
// OGCG: %[[VAL0:.*]] = load i32, ptr %[[PTR0]], align 4 |
| 72 |
// OGCG: %[[AND0:.*]] = and i32 %[[VAL0]], 268435455 |
| 73 |
// OGCG: %[[OR0:.*]] = or i32 %[[AND0]], -1073741824 |
| 74 |
// OGCG: store i32 %[[OR0]], ptr %[[PTR0]], align 4 |
| 75 |
|
| 76 |
// field 'b' |
| 77 |
// CIR: %[[CONST2:.*]] = cir.const #cir.int<42> : !s32i |
| 78 |
// CIR: %[[VAL1:.*]] = cir.load align(8) %[[PTR0]] : !cir.ptr<!cir.ptr<!rec_S>>, !cir.ptr<!rec_S> |
| 79 |
// CIR: %[[GET1:.*]] = cir.get_member %[[VAL1]][0] {name = "b"} : !cir.ptr<!rec_S> -> !cir.ptr<!u32i> |
| 80 |
// CIR: %[[SET1:.*]] = cir.set_bitfield align(4) (#bfi_b, %[[GET1]] : !cir.ptr<!u32i>, %[[CONST2]] : !s32i) -> !s32i |
| 81 |
|
| 82 |
// LLVM: %[[PTR1:.*]] = load ptr |
| 83 |
// LLVM: %[[GET1:.*]] = getelementptr %struct.S, ptr %[[PTR1]], i32 0, i32 0 |
| 84 |
// LLVM: %[[VAL1:.*]] = load i32, ptr %[[GET1]], align 4 |
| 85 |
// LLVM: %[[AND1:.*]] = and i32 %[[VAL1]], -268304385 |
| 86 |
// LLVM: %[[OR1:.*]] = or i32 %[[AND1]], 5505024 |
| 87 |
// LLVM: store i32 %[[OR1]], ptr %[[GET1]], align 4 |
| 88 |
|
| 89 |
// OGCG: %[[PTR1:.*]] = load ptr |
| 90 |
// OGCG: %[[VAL1:.*]] = load i32, ptr %[[PTR1]], align 4 |
| 91 |
// OGCG: %[[AND1:.*]] = and i32 %[[VAL1]], -268304385 |
| 92 |
// OGCG: %[[OR1:.*]] = or i32 %[[AND1]], 5505024 |
| 93 |
// OGCG: store i32 %[[OR1]], ptr %[[PTR1]], align 4 |
| 94 |
|
| 95 |
// field 'c' |
| 96 |
// CIR: %[[CONST3:.*]] = cir.const #cir.int<-12345> : !s32i |
| 97 |
// CIR: %[[VAL2:.*]] = cir.load align(8) %[[PTR0]] : !cir.ptr<!cir.ptr<!rec_S>>, !cir.ptr<!rec_S> |
| 98 |
// CIR: %[[GET2:.*]] = cir.get_member %[[VAL2]][0] {name = "c"} : !cir.ptr<!rec_S> -> !cir.ptr<!u32i> |
| 99 |
// CIR: %[[SET2:.*]] = cir.set_bitfield align(4) (#bfi_c, %[[GET2]] : !cir.ptr<!u32i>, %[[CONST3]] : !s32i) -> !s32i |
| 100 |
|
| 101 |
// LLVM: %[[PTR2:.*]] = load ptr |
| 102 |
// LLVM: %[[GET2:.*]] = getelementptr %struct.S, ptr %[[PTR2]], i32 0, i32 0 |
| 103 |
// LLVM: %[[VAL2:.*]] = load i32, ptr %[[GET2]], align 4 |
| 104 |
// LLVM: %[[AND2:.*]] = and i32 %[[VAL2]], -131072 |
| 105 |
// LLVM: %[[OR2:.*]] = or i32 %[[AND2]], 118727 |
| 106 |
// LLVM: store i32 %[[OR2]], ptr %[[GET2]], align 4 |
| 107 |
|
| 108 |
// OGCG: %[[PTR2:.*]] = load ptr |
| 109 |
// OGCG: %[[VAL2:.*]] = load i32, ptr %[[PTR2]], align 4 |
| 110 |
// OGCG: %[[AND2:.*]] = and i32 %[[VAL2]], -131072 |
| 111 |
// OGCG: %[[OR2:.*]] = or i32 %[[AND2]], 118727 |
| 112 |
// OGCG: store i32 %[[OR2]], ptr %[[PTR2]], align 4 |