1; RUN: llc -mtriple powerpc64-ibm-aix-xcoff -stop-after=machine-cp -mcpu=pwr4 \
2; RUN: -mattr=-altivec -verify-machineinstrs < %s | \
3; RUN: FileCheck %s
4
5; RUN: llc -verify-machineinstrs -mcpu=pwr4 -mattr=-altivec \
6; RUN:  -mtriple powerpc64-ibm-aix-xcoff < %s | \
7; RUN: FileCheck --check-prefix=ASM %s
8
9%struct.S5 = type { [5 x i8] }
10
11define zeroext i8 @test_byval_5Byte(%struct.S5* byval(%struct.S5) align 1 %s) {
12entry:
13  %arrayidx = getelementptr inbounds %struct.S5, %struct.S5* %s, i32 0, i32 0, i32 4
14  %0 = load i8, i8* %arrayidx, align 1
15  ret i8 %0
16}
17
18; CHECK-LABEL: name:            test_byval_5Byte
19
20; CHECK:      fixedStack:
21; CHECK-NEXT:   - { id: 0, type: default, offset: 48, size: 8, alignment: 16,
22; CHECK:        bb.0.entry:
23; CHECK-NEXT:     liveins: $x3
24; CHECK:          STD killed renamable $x3, 0, %fixed-stack.0 :: (store 8 into %fixed-stack.0, align 16)
25; CHECK-NEXT:     renamable $x3 = LBZ8 4, %fixed-stack.0 :: (dereferenceable load 1
26
27; CHECKASM-LABEL: .test_byval_5Byte:
28
29; ASM:       std 3, 48(1)
30; ASM-NEXT:  lbz 3, 52(1)
31; ASM-NEXT:  blr
32
33
34%struct.S6 = type { [6 x i8] }
35
36define zeroext i8 @test_byval_6Byte(%struct.S6* byval(%struct.S6) align 1 %s) {
37entry:
38  %arrayidx = getelementptr inbounds %struct.S6, %struct.S6* %s, i32 0, i32 0, i32 5
39  %0 = load i8, i8* %arrayidx, align 1
40  ret i8 %0
41}
42
43; CHECK-LABEL: name:            test_byval_6Byte
44
45; CHECK:      fixedStack:
46; CHECK-NEXT:   - { id: 0, type: default, offset: 48, size: 8, alignment: 16,
47; CHECK:        bb.0.entry:
48; CHECK-NEXT:     liveins: $x3
49; CHECK:          STD killed renamable $x3, 0, %fixed-stack.0 :: (store 8 into %fixed-stack.0, align 16)
50; CHECK-NEXT:     renamable $x3 = LBZ8 5, %fixed-stack.0 :: (dereferenceable load 1
51
52; CHECKASM-LABEL: .test_byval_6Byte:
53
54; ASM:       std 3, 48(1)
55; ASM-NEXT:  lbz 3, 53(1)
56; ASM-NEXT:  blr
57
58
59%struct.S7 = type { [7 x i8] }
60
61define zeroext i8 @test_byval_7Byte(%struct.S7* byval(%struct.S7) align 1 %s) {
62entry:
63  %arrayidx = getelementptr inbounds %struct.S7, %struct.S7* %s, i32 0, i32 0, i32 6
64  %0 = load i8, i8* %arrayidx, align 1
65  ret i8 %0
66}
67
68; CHECK-LABEL: name:            test_byval_7Byte
69
70; CHECK:      fixedStack:
71; CHECK-NEXT:   - { id: 0, type: default, offset: 48, size: 8, alignment: 16,
72; CHECK:        bb.0.entry:
73; CHECK-NEXT:     liveins: $x3
74; CHECK:          STD killed renamable $x3, 0, %fixed-stack.0 :: (store 8 into %fixed-stack.0, align 16)
75; CHECK-NEXT:     renamable $x3 = LBZ8 6, %fixed-stack.0 :: (dereferenceable load 1
76
77; CHECKASM-LABEL: .test_byval_7Byte:
78
79; ASM:       std 3, 48(1)
80; ASM-NEXT:  lbz 3, 54(1)
81; ASM-NEXT:  blr
82
83
84%struct.S8 = type { [8 x i8] }
85
86define zeroext i8 @test_byval_8Byte(%struct.S8* byval(%struct.S8) align 1 %s) {
87entry:
88  %arrayidx = getelementptr inbounds %struct.S8, %struct.S8* %s, i32 0, i32 0, i32 7
89  %0 = load i8, i8* %arrayidx, align 1
90  ret i8 %0
91}
92
93; CHECK-LABEL: name:            test_byval_8Byte
94
95; CHECK:      fixedStack:
96; CHECK-NEXT:   - { id: 0, type: default, offset: 48, size: 8, alignment: 16,
97; CHECK:        bb.0.entry:
98; CHECK-NEXT:     liveins: $x3
99; CHECK:          renamable $x[[SCRATCH:[0-9]+]] = COPY $x3
100; CHECK-DAG:      renamable $x3 = RLDICL $x3, 0, 56
101; CHECK-DAG:      STD killed renamable $x[[SCRATCH]], 0, %fixed-stack.0 :: (store 8 into %fixed-stack.0, align 16)
102
103
104; CHECKASM-LABEL: .test_byval_8Byte:
105
106; ASM:       mr [[SCRATCH:[0-9]+]], 3
107; ASM-DAG:   clrldi  3, 3, 56
108; ASM-DAG:   std [[SCRATCH]], 48(1)
109; ASM-NEXT:  blr
110
111
112%struct.S64 = type { [64 x i8] }
113
114@gS64 = external global %struct.S64, align 1
115
116define void @call_test_byval_64Byte() {
117entry:
118  call void @test_byval_64Byte(%struct.S64* byval(%struct.S64) align 1 @gS64)
119  ret void
120}
121
122declare void @test_byval_64Byte(%struct.S64* byval(%struct.S64) align 1)
123
124; CHECK-LABEL: name: call_test_byval_64Byte{{.*}}
125
126; The DAG block permits some invalid inputs for the benefit of allowing more valid orderings.
127; CHECK:       ADJCALLSTACKDOWN 112, 0, implicit-def dead $r1, implicit $r1
128; CHECK-NEXT:  renamable $x[[REGADDR:[0-9]+]] = LDtoc @gS64, $x2 :: (load 8 from got)
129; CHECK-DAG:   renamable $x3 = LD 0, killed renamable $x[[REGADDR]] :: (load 8)
130; CHECK-DAG:   renamable $x4 = LD 8, renamable $x[[REGADDR]] :: (load 8)
131; CHECK-DAG:   renamable $x5 = LD 16, renamable $x[[REGADDR]] :: (load 8)
132; CHECK-DAG:   renamable $x6 = LD 24, renamable $x[[REGADDR]] :: (load 8)
133; CHECK-DAG:   renamable $x7 = LD 32, renamable $x[[REGADDR]] :: (load 8)
134; CHECK-DAG:   renamable $x8 = LD 40, renamable $x[[REGADDR]] :: (load 8)
135; CHECK-DAG:   renamable $x9 = LD 48, renamable $x[[REGADDR]] :: (load 8)
136; CHECK-DAG:   renamable $x10 = LD 56, renamable $x[[REGADDR]] :: (load 8)
137; CHECK-NEXT:  BL8_NOP <mcsymbol .test_byval_64Byte[PR]>, csr_ppc64, implicit-def dead $lr8, implicit $rm, implicit $x3, implicit $x4, implicit $x5, implicit $x6, implicit $x7, implicit $x8, implicit $x9, implicit $x10, implicit $x2, implicit-def $r1
138; CHECK-NEXT:  ADJCALLSTACKUP 112, 0, implicit-def dead $r1, implicit $r1
139
140; CHECKASM-LABEL: .test_byval_64Byte:
141
142; ASM:         stdu 1, -112(1)
143; ASM-NEXT:    ld [[REG:[0-9]+]], L..C{{[0-9]+}}(2)
144; ASM-DAG:     ld 3, 0([[REG]])
145; ASM-DAG:     ld 4, 8([[REG]])
146; ASM-DAG:     ld 5, 16([[REG]])
147; ASM-DAG:     ld 6, 24([[REG]])
148; ASM-DAG:     ld 7, 32([[REG]])
149; ASM-DAG:     ld 8, 40([[REG]])
150; ASM-DAG:     ld 9, 48([[REG]])
151; ASM-DAG:     ld 10, 56([[REG]])
152; ASM-NEXT:    bl .test_byval_64Byte
153; ASM-NEXT:    nop
154