xref: /aosp_15_r20/external/llvm/test/CodeGen/PowerPC/crsave.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc -O0 -disable-fp-elim -mtriple=powerpc-unknown-linux-gnu -mcpu=g5 < %s | FileCheck %s -check-prefix=PPC32
2*9880d681SAndroid Build Coastguard Worker; RUN: llc -O0 -mtriple=powerpc64-unknown-linux-gnu -mcpu=g5 < %s | FileCheck %s -check-prefix=PPC64
3*9880d681SAndroid Build Coastguard Worker; RUN: llc -O0 -mtriple=powerpc64le-unknown-linux-gnu -verify-machineinstrs < %s | FileCheck %s -check-prefix=PPC64-ELFv2
4*9880d681SAndroid Build Coastguard Worker
5*9880d681SAndroid Build Coastguard Workerdeclare void @foo()
6*9880d681SAndroid Build Coastguard Worker
7*9880d681SAndroid Build Coastguard Workerdefine i32 @test_cr2() nounwind uwtable {
8*9880d681SAndroid Build Coastguard Workerentry:
9*9880d681SAndroid Build Coastguard Worker  %ret = alloca i32, align 4
10*9880d681SAndroid Build Coastguard Worker  %0 = call i32 asm sideeffect "\0A\09mtcr $4\0A\09cmpw 2,$2,$1\0A\09mfcr $0", "=r,r,r,r,r,~{cr2}"(i32 1, i32 2, i32 3, i32 0) nounwind
11*9880d681SAndroid Build Coastguard Worker  store i32 %0, i32* %ret, align 4
12*9880d681SAndroid Build Coastguard Worker  call void @foo()
13*9880d681SAndroid Build Coastguard Worker  %1 = load i32, i32* %ret, align 4
14*9880d681SAndroid Build Coastguard Worker  ret i32 %1
15*9880d681SAndroid Build Coastguard Worker}
16*9880d681SAndroid Build Coastguard Worker
17*9880d681SAndroid Build Coastguard Worker; PPC32: stw 31, -4(1)
18*9880d681SAndroid Build Coastguard Worker; PPC32: stwu 1, -32(1)
19*9880d681SAndroid Build Coastguard Worker; PPC32: mfcr 12
20*9880d681SAndroid Build Coastguard Worker; PPC32-NEXT: stw 12, 24(31)
21*9880d681SAndroid Build Coastguard Worker; PPC32: lwz 12, 24(31)
22*9880d681SAndroid Build Coastguard Worker; PPC32-NEXT: mtocrf 32, 12
23*9880d681SAndroid Build Coastguard Worker
24*9880d681SAndroid Build Coastguard Worker; PPC64: .cfi_startproc
25*9880d681SAndroid Build Coastguard Worker; PPC64: mfcr 12
26*9880d681SAndroid Build Coastguard Worker; PPC64: stw 12, 8(1)
27*9880d681SAndroid Build Coastguard Worker; PPC64: stdu 1, -[[AMT:[0-9]+]](1)
28*9880d681SAndroid Build Coastguard Worker; PPC64: .cfi_def_cfa_offset 128
29*9880d681SAndroid Build Coastguard Worker; PPC64: .cfi_offset lr, 16
30*9880d681SAndroid Build Coastguard Worker; PPC64: .cfi_offset cr2, 8
31*9880d681SAndroid Build Coastguard Worker; PPC64: addi 1, 1, [[AMT]]
32*9880d681SAndroid Build Coastguard Worker; PPC64: lwz 12, 8(1)
33*9880d681SAndroid Build Coastguard Worker; PPC64: mtocrf 32, 12
34*9880d681SAndroid Build Coastguard Worker; PPC64: .cfi_endproc
35*9880d681SAndroid Build Coastguard Worker
36*9880d681SAndroid Build Coastguard Workerdefine i32 @test_cr234() nounwind {
37*9880d681SAndroid Build Coastguard Workerentry:
38*9880d681SAndroid Build Coastguard Worker  %ret = alloca i32, align 4
39*9880d681SAndroid Build Coastguard Worker  %0 = call i32 asm sideeffect "\0A\09mtcr $4\0A\09cmpw 2,$2,$1\0A\09cmpw 3,$2,$2\0A\09cmpw 4,$2,$3\0A\09mfcr $0", "=r,r,r,r,r,~{cr2},~{cr3},~{cr4}"(i32 1, i32 2, i32 3, i32 0) nounwind
40*9880d681SAndroid Build Coastguard Worker  store i32 %0, i32* %ret, align 4
41*9880d681SAndroid Build Coastguard Worker  call void @foo()
42*9880d681SAndroid Build Coastguard Worker  %1 = load i32, i32* %ret, align 4
43*9880d681SAndroid Build Coastguard Worker  ret i32 %1
44*9880d681SAndroid Build Coastguard Worker}
45*9880d681SAndroid Build Coastguard Worker
46*9880d681SAndroid Build Coastguard Worker; PPC32: stw 31, -4(1)
47*9880d681SAndroid Build Coastguard Worker; PPC32: stwu 1, -32(1)
48*9880d681SAndroid Build Coastguard Worker; PPC32: mfcr 12
49*9880d681SAndroid Build Coastguard Worker; PPC32-NEXT: stw 12, 24(31)
50*9880d681SAndroid Build Coastguard Worker; PPC32: lwz 12, 24(31)
51*9880d681SAndroid Build Coastguard Worker; PPC32-NEXT: mtocrf 32, 12
52*9880d681SAndroid Build Coastguard Worker; PPC32-NEXT: mtocrf 16, 12
53*9880d681SAndroid Build Coastguard Worker; PPC32-NEXT: mtocrf 8, 12
54*9880d681SAndroid Build Coastguard Worker
55*9880d681SAndroid Build Coastguard Worker; PPC64: mfcr 12
56*9880d681SAndroid Build Coastguard Worker; PPC64: stw 12, 8(1)
57*9880d681SAndroid Build Coastguard Worker; PPC64: stdu 1, -[[AMT:[0-9]+]](1)
58*9880d681SAndroid Build Coastguard Worker; PPC64: addi 1, 1, [[AMT]]
59*9880d681SAndroid Build Coastguard Worker; PPC64: lwz 12, 8(1)
60*9880d681SAndroid Build Coastguard Worker; PPC64: mtocrf 32, 12
61*9880d681SAndroid Build Coastguard Worker; PPC64: mtocrf 16, 12
62*9880d681SAndroid Build Coastguard Worker; PPC64: mtocrf 8, 12
63*9880d681SAndroid Build Coastguard Worker
64*9880d681SAndroid Build Coastguard Worker; Generate mfocrf in prologue when we need to save 1 nonvolatile CR field
65*9880d681SAndroid Build Coastguard Workerdefine void @cloberOneNvCrField() {
66*9880d681SAndroid Build Coastguard Workerentry:
67*9880d681SAndroid Build Coastguard Worker  tail call void asm sideeffect "# clobbers", "~{cr2}"()
68*9880d681SAndroid Build Coastguard Worker  ret void
69*9880d681SAndroid Build Coastguard Worker
70*9880d681SAndroid Build Coastguard Worker; PPC64-ELFv2-LABEL: @cloberOneNvCrField
71*9880d681SAndroid Build Coastguard Worker; PPC64-ELFv2: mfocrf [[REG1:[0-9]+]], 32
72*9880d681SAndroid Build Coastguard Worker}
73*9880d681SAndroid Build Coastguard Worker
74*9880d681SAndroid Build Coastguard Worker; Generate mfcr in prologue when we need to save all nonvolatile CR field
75*9880d681SAndroid Build Coastguard Workerdefine void @cloberAllNvCrField() {
76*9880d681SAndroid Build Coastguard Workerentry:
77*9880d681SAndroid Build Coastguard Worker  tail call void asm sideeffect "# clobbers", "~{cr2},~{cr3},~{cr4}"()
78*9880d681SAndroid Build Coastguard Worker  ret void
79*9880d681SAndroid Build Coastguard Worker
80*9880d681SAndroid Build Coastguard Worker; PPC64-ELFv2-LABEL: @cloberAllNvCrField
81*9880d681SAndroid Build Coastguard Worker; PPC64-ELFv2: mfcr [[REG1:[0-9]+]]
82*9880d681SAndroid Build Coastguard Worker}
83