Skip to content

Commit cb837e5

Browse files
Add requested test and update description
1 parent b960b63 commit cb837e5

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1682,7 +1682,7 @@ def SetBitfieldOp : CIR_Op<"set_bitfield"> {
16821682
A bitfield info attribute must be provided to describe the location of
16831683
the bitfield within the memory referenced by the $addr argument.
16841684
The $src argument is inserted at the appropriate place in the memory and
1685-
the value that was stored. Returns a value being stored.
1685+
the value that was stored. Returns the value being stored.
16861686

16871687
A unit attribute `volatile` can be used to indicate a volatile store of the
16881688
bitfield.

clang/test/CIR/CodeGen/bitfields.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,45 @@ void store_field() {
8383
// OGCG: [[TMP2:%.*]] = and i64 [[TMP1]], -16
8484
// OGCG: [[TMP3:%.*]] = or i64 [[TMP2]], 3
8585
// OGCG: store i64 [[TMP3]], ptr [[TMP0]], align 4
86+
87+
void store_bitfield_to_bitfield(S* s) {
88+
s->a = s->b = 3;
89+
}
90+
91+
// CIR: cir.func dso_local @_Z26store_bitfield_to_bitfieldP1S
92+
// CIR: [[TMP0:%.*]] = cir.alloca !cir.ptr<!rec_S>, !cir.ptr<!cir.ptr<!rec_S>>, ["s", init] {alignment = 8 : i64}
93+
// CIR: [[TMP1:%.*]] = cir.const #cir.int<3> : !s32i
94+
// CIR: [[TMP2:%.*]] = cir.load align(8) [[TMP0]] : !cir.ptr<!cir.ptr<!rec_S>>, !cir.ptr<!rec_S>
95+
// CIR: [[TMP3:%.*]] = cir.get_member [[TMP2]][0] {name = "b"} : !cir.ptr<!rec_S> -> !cir.ptr<!u64i>
96+
// CIR: [[TMP4:%.*]] = cir.set_bitfield(#bfi_b, [[TMP3]] : !cir.ptr<!u64i>, [[TMP1]] : !s32i) -> !s32i
97+
// CIR: [[TMP5:%.*]] = cir.load align(8) [[TMP0]] : !cir.ptr<!cir.ptr<!rec_S>>, !cir.ptr<!rec_S>
98+
// CIR: [[TMP6:%.*]] = cir.get_member [[TMP5]][0] {name = "a"} : !cir.ptr<!rec_S> -> !cir.ptr<!u64i>
99+
// CIR: [[TMP7:%.*]] = cir.set_bitfield(#bfi_a, [[TMP6]] : !cir.ptr<!u64i>, [[TMP4]] : !s32i) -> !s32i
100+
101+
// LLVM: define dso_local void @_Z26store_bitfield_to_bitfieldP1S
102+
// LLVM: [[TMP0:%.*]] = alloca ptr, i64 1, align 8
103+
// LLVM: [[TMP1:%.*]] = load ptr, ptr [[TMP0]], align 8
104+
// LLVM: [[TMP2:%.*]] = getelementptr %struct.S, ptr [[TMP1]], i32 0, i32 0
105+
// LLVM: [[TMP3:%.*]] = load i64, ptr [[TMP2]], align 8
106+
// LLVM: [[TMP4:%.*]] = and i64 [[TMP3]], -2147483633
107+
// LLVM: [[TMP5:%.*]] = or i64 [[TMP4]], 48
108+
// LLVM: store i64 [[TMP5]], ptr [[TMP2]], align 8
109+
// LLVM: [[TMP6:%.*]] = load ptr, ptr [[TMP0]], align 8
110+
// LLVM: [[TMP7:%.*]] = getelementptr %struct.S, ptr [[TMP6]], i32 0, i32 0
111+
// LLVM: [[TMP8:%.*]] = load i64, ptr [[TMP7]], align 8
112+
// LLVM: [[TMP9:%.*]] = and i64 [[TMP8]], -16
113+
// LLVM: [[TMP10:%.*]] = or i64 [[TMP9]], 3
114+
// LLVM: store i64 [[TMP10]], ptr [[TMP7]], align 8
115+
116+
// OGCG: define dso_local void @_Z26store_bitfield_to_bitfieldP1S
117+
// OGCG: [[TMP0:%.*]] = alloca ptr, align 8
118+
// OGCG: [[TMP1:%.*]] = load ptr, ptr [[TMP0]], align 8
119+
// OGCG: [[TMP2:%.*]] = load i64, ptr [[TMP1]], align 4
120+
// OGCG: [[TMP3:%.*]] = and i64 [[TMP2]], -2147483633
121+
// OGCG: [[TMP4:%.*]] = or i64 [[TMP3]], 48
122+
// OGCG: store i64 [[TMP4]], ptr [[TMP1]], align 4
123+
// OGCG: [[TMP5:%.*]] = load ptr, ptr [[TMP0]], align 8
124+
// OGCG: [[TMP6:%.*]] = load i64, ptr [[TMP5]], align 4
125+
// OGCG: [[TMP7:%.*]] = and i64 [[TMP6]], -16
126+
// OGCG: [[TMP8:%.*]] = or i64 [[TMP7]], 3
127+
// OGCG: store i64 [[TMP8]], ptr [[TMP5]], align 4

0 commit comments

Comments
 (0)