blob: d7be2fd18c9c3818a43cd1b3a8bf5abf56ff9c03 [file] [log] [blame]
Ulrich Weigand49f487e2013-07-03 17:59:07 +00001; RUN: llc -O0 -disable-fp-elim -mtriple=powerpc-unknown-linux-gnu -mcpu=g5 < %s | FileCheck %s -check-prefix=PPC32
2; RUN: llc -O0 -mtriple=powerpc64-unknown-linux-gnu -mcpu=g5 < %s | FileCheck %s -check-prefix=PPC64
Chuang-Yu Cheng8676c3d2016-04-27 02:59:28 +00003; RUN: llc -O0 -mtriple=powerpc64le-unknown-linux-gnu -verify-machineinstrs < %s | FileCheck %s -check-prefix=PPC64-ELFv2
Roman Divackyc9e23d92012-09-12 14:47:47 +00004
5declare void @foo()
6
Rafael Espindolaa5c7cee2013-05-16 03:48:50 +00007define i32 @test_cr2() nounwind uwtable {
Roman Divackyc9e23d92012-09-12 14:47:47 +00008entry:
9 %ret = alloca i32, align 4
Ulrich Weigand6b577e22015-01-13 19:43:45 +000010 %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
Roman Divackyc9e23d92012-09-12 14:47:47 +000011 store i32 %0, i32* %ret, align 4
12 call void @foo()
David Blaikiea79ac142015-02-27 21:17:42 +000013 %1 = load i32, i32* %ret, align 4
Roman Divackyc9e23d92012-09-12 14:47:47 +000014 ret i32 %1
15}
16
Krzysztof Parzyszek020ec292016-09-06 12:30:00 +000017; PPC32-LABEL: test_cr2:
Bill Schmidtef3d1a22013-05-14 16:08:32 +000018; PPC32: stwu 1, -32(1)
Krzysztof Parzyszek020ec292016-09-06 12:30:00 +000019; PPC32: stw 31, 28(1)
Roman Divackyc9e23d92012-09-12 14:47:47 +000020; PPC32: mfcr 12
Bill Schmidtef3d1a22013-05-14 16:08:32 +000021; PPC32-NEXT: stw 12, 24(31)
22; PPC32: lwz 12, 24(31)
Ulrich Weigand49f487e2013-07-03 17:59:07 +000023; PPC32-NEXT: mtocrf 32, 12
Roman Divackyc9e23d92012-09-12 14:47:47 +000024
Rafael Espindolaa5c7cee2013-05-16 03:48:50 +000025; PPC64: .cfi_startproc
Roman Divackyc9e23d92012-09-12 14:47:47 +000026; PPC64: mfcr 12
Hal Finkel67369882013-04-15 02:07:05 +000027; PPC64: stw 12, 8(1)
28; PPC64: stdu 1, -[[AMT:[0-9]+]](1)
Rafael Espindolaa5c7cee2013-05-16 03:48:50 +000029; PPC64: .cfi_def_cfa_offset 128
30; PPC64: .cfi_offset lr, 16
31; PPC64: .cfi_offset cr2, 8
Hal Finkel67369882013-04-15 02:07:05 +000032; PPC64: addi 1, 1, [[AMT]]
Roman Divackyc9e23d92012-09-12 14:47:47 +000033; PPC64: lwz 12, 8(1)
Ulrich Weigand49f487e2013-07-03 17:59:07 +000034; PPC64: mtocrf 32, 12
Rafael Espindolaa5c7cee2013-05-16 03:48:50 +000035; PPC64: .cfi_endproc
Hal Finkeld85a04b2013-04-13 08:09:20 +000036
Roman Divackyc9e23d92012-09-12 14:47:47 +000037define i32 @test_cr234() nounwind {
38entry:
39 %ret = alloca i32, align 4
Ulrich Weigand6b577e22015-01-13 19:43:45 +000040 %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
Roman Divackyc9e23d92012-09-12 14:47:47 +000041 store i32 %0, i32* %ret, align 4
42 call void @foo()
David Blaikiea79ac142015-02-27 21:17:42 +000043 %1 = load i32, i32* %ret, align 4
Roman Divackyc9e23d92012-09-12 14:47:47 +000044 ret i32 %1
45}
46
Krzysztof Parzyszek020ec292016-09-06 12:30:00 +000047; PPC32-LABEL: test_cr234:
Bill Schmidtef3d1a22013-05-14 16:08:32 +000048; PPC32: stwu 1, -32(1)
Krzysztof Parzyszek020ec292016-09-06 12:30:00 +000049; PPC32: stw 31, 28(1)
Roman Divackyc9e23d92012-09-12 14:47:47 +000050; PPC32: mfcr 12
Bill Schmidtef3d1a22013-05-14 16:08:32 +000051; PPC32-NEXT: stw 12, 24(31)
52; PPC32: lwz 12, 24(31)
Ulrich Weigand49f487e2013-07-03 17:59:07 +000053; PPC32-NEXT: mtocrf 32, 12
54; PPC32-NEXT: mtocrf 16, 12
55; PPC32-NEXT: mtocrf 8, 12
Roman Divackyc9e23d92012-09-12 14:47:47 +000056
57; PPC64: mfcr 12
Hal Finkel67369882013-04-15 02:07:05 +000058; PPC64: stw 12, 8(1)
59; PPC64: stdu 1, -[[AMT:[0-9]+]](1)
60; PPC64: addi 1, 1, [[AMT]]
Roman Divackyc9e23d92012-09-12 14:47:47 +000061; PPC64: lwz 12, 8(1)
Ulrich Weigand49f487e2013-07-03 17:59:07 +000062; PPC64: mtocrf 32, 12
63; PPC64: mtocrf 16, 12
64; PPC64: mtocrf 8, 12
Hal Finkeld85a04b2013-04-13 08:09:20 +000065
Chuang-Yu Cheng6efde2f2016-04-12 03:04:44 +000066; Generate mfocrf in prologue when we need to save 1 nonvolatile CR field
67define void @cloberOneNvCrField() {
68entry:
69 tail call void asm sideeffect "# clobbers", "~{cr2}"()
70 ret void
71
72; PPC64-ELFv2-LABEL: @cloberOneNvCrField
73; PPC64-ELFv2: mfocrf [[REG1:[0-9]+]], 32
74}
75
76; Generate mfcr in prologue when we need to save all nonvolatile CR field
77define void @cloberAllNvCrField() {
78entry:
79 tail call void asm sideeffect "# clobbers", "~{cr2},~{cr3},~{cr4}"()
80 ret void
81
82; PPC64-ELFv2-LABEL: @cloberAllNvCrField
83; PPC64-ELFv2: mfcr [[REG1:[0-9]+]]
84}