1; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr8 < %s | FileCheck %s
2; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu -mcpu=pwr8 < %s | FileCheck %s
3
4; equivalent C code
5;   struct s64 {
6;   	int a:5;
7;   	int b:16;
8;   	long c:42;
9;   };
10;   void bitfieldinsert64(struct s *p, unsigned short v) {
11;   	p->b = v;
12;   }
13
14%struct.s64 = type { i64 }
15
16define void @bitfieldinsert64(%struct.s64* nocapture %p, i16 zeroext %v) {
17; CHECK-LABEL: @bitfieldinsert64
18; CHECK: ld [[REG1:[0-9]+]], 0(3)
19; CHECK-NEXT: rlwimi [[REG1]], 4, 5, 11, 26
20; CHECK-NEXT: std [[REG1]], 0(3)
21; CHECK-NEXT: blr
22entry:
23  %0 = getelementptr inbounds %struct.s64, %struct.s64* %p, i64 0, i32 0
24  %1 = zext i16 %v to i64
25  %bf.load = load i64, i64* %0, align 8
26  %bf.shl = shl nuw nsw i64 %1, 5
27  %bf.clear = and i64 %bf.load, -2097121
28  %bf.set = or i64 %bf.clear, %bf.shl
29  store i64 %bf.set, i64* %0, align 8
30  ret void
31}
32
33; bitfieldinsert32: Test for rlwimi
34; equivalent C code
35;   struct s32 {
36;   	int a:8;
37;   	int b:16;
38;   	int c:8;
39;   };
40;   void bitfieldinsert32(struct s32 *p, unsigned int v) {
41;   	p->b = v;
42;   }
43
44%struct.s32 = type { i32 }
45
46define void @bitfieldinsert32(%struct.s32* nocapture %p, i32 zeroext %v) {
47; CHECK-LABEL: @bitfieldinsert32
48; CHECK: lwz [[REG1:[0-9]+]], 0(3)
49; CHECK-NEXT: rlwimi [[REG1]], 4, 8, 8, 23
50; CHECK-NEXT: stw [[REG1]], 0(3)
51; CHECK-NEXT: blr
52entry:
53  %0 = getelementptr inbounds %struct.s32, %struct.s32* %p, i64 0, i32 0
54  %bf.load = load i32, i32* %0, align 4
55  %bf.value = shl i32 %v, 8
56  %bf.shl = and i32 %bf.value, 16776960
57  %bf.clear = and i32 %bf.load, -16776961
58  %bf.set = or i32 %bf.clear, %bf.shl
59  store i32 %bf.set, i32* %0, align 4
60  ret void
61}
62
63