1; RUN: llc -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr8 < %s | FileCheck %s -check-prefix=PPC64-P8
2; RUN: llc -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr7 < %s | FileCheck %s -check-prefix=PPC64
3; RUN: llc -mtriple=powerpc64-unknown-linux-gnu -mcpu=pwr8 < %s | FileCheck %s -check-prefix=PPC64-P8
4; RUN: llc -mtriple=powerpc64-unknown-linux-gnu -mcpu=pwr7 < %s | FileCheck %s -check-prefix=PPC64
5; RUN: llc -mtriple=powerpc-unknown-linux-gnu < %s | FileCheck %s -check-prefix=PPC32
6
7define i128 @test_abs(ppc_fp128 %x) nounwind  {
8entry:
9; PPC64-LABEL: test_abs:
10; PPC64-DAG: stxsdx 2, 0, [[ADDR_HI:[0-9]+]]
11; PPC64-DAG: stxsdx 1, 0, [[ADDR_LO:[0-9]+]]
12; PPC64-DAG: addi [[ADDR_HI]], [[SP:[0-9]+]], [[OFFSET_HI:-?[0-9]+]]
13; PPC64-DAG: addi [[ADDR_LO]], [[SP]], [[OFFSET_LO:-?[0-9]+]]
14; PPC64-DAG: li [[MASK_REG:[0-9]+]], 1
15; PPC64: sldi [[MASK_REG]], [[MASK_REG]], 63
16; PPC64-DAG: ld [[HI:[0-9]+]], [[OFFSET_LO]]([[SP]])
17; PPC64-DAG: ld [[LO:[0-9]+]], [[OFFSET_HI]]([[SP]])
18; PPC64: and [[FLIP_BIT:[0-9]+]], [[HI]], [[MASK_REG]]
19; PPC64-DAG: xor 3, [[HI]], [[FLIP_BIT]]
20; PPC64-DAG: xor 4, [[LO]], [[FLIP_BIT]]
21; PPC64: blr
22
23; PPC64-P8-LABEL: test_abs:
24; PPC64-P8-DAG: mfvsrd [[LO:[0-9]+]], 2
25; PPC64-P8-DAG: mfvsrd [[HI:[0-9]+]], 1
26; PPC64-P8-DAG: li [[MASK_REG:[0-9]+]], 1
27; PPC64-P8-DAG: sldi [[SHIFT_REG:[0-9]+]], [[MASK_REG]], 63
28; PPC64-P8: and [[FLIP_BIT:[0-9]+]], [[HI]], [[SHIFT_REG]]
29; PPC64-P8-DAG: xor 3, [[HI]], [[FLIP_BIT]]
30; PPC64-P8-DAG: xor 4, [[LO]], [[FLIP_BIT]]
31; PPC64-P8: blr
32
33; PPC32-DAG: stfd 1, 24(1)
34; PPC32-DAG: stfd 2, 16(1)
35; PPC32: nop
36; PPC32-DAG: lwz [[HI0:[0-9]+]], 24(1)
37; PPC32-DAG: lwz [[LO0:[0-9]+]], 16(1)
38; PPC32-DAG: lwz [[HI1:[0-9]+]], 28(1)
39; PPC32-DAG: lwz [[LO1:[0-9]+]], 20(1)
40; PPC32: rlwinm [[FLIP_BIT:[0-9]+]], [[HI0]], 0, 0, 0
41; PPC32-DAG: xor [[HI0]], [[HI0]], [[FLIP_BIT]]
42; PPC32-DAG: xor [[LO0]], [[LO0]], [[FLIP_BIT]]
43; PPC32: blr
44	%0 = tail call ppc_fp128 @llvm.fabs.ppcf128(ppc_fp128 %x)
45	%1 = bitcast ppc_fp128 %0 to i128
46	ret i128 %1
47}
48
49define i128 @test_neg(ppc_fp128 %x) nounwind  {
50entry:
51; PPC64-LABEL: test_neg:
52; PPC64-DAG: stxsdx 2, 0, [[ADDR_HI:[0-9]+]]
53; PPC64-DAG: stxsdx 1, 0, [[ADDR_LO:[0-9]+]]
54; PPC64-DAG: addi [[ADDR_HI]], [[SP:[0-9]+]], [[OFFSET_HI:-?[0-9]+]]
55; PPC64-DAG: addi [[ADDR_LO]], [[SP]], [[OFFSET_LO:-?[0-9]+]]
56; PPC64-DAG: li [[FLIP_BIT:[0-9]+]], 1
57; PPC64-DAG: sldi [[FLIP_BIT]], [[FLIP_BIT]], 63
58; PPC64-DAG: ld [[HI:[0-9]+]], [[OFFSET_LO]]([[SP]])
59; PPC64-DAG: ld [[LO:[0-9]+]], [[OFFSET_HI]]([[SP]])
60; PPC64-NOT: BARRIER
61; PPC64-DAG: xor 3, [[HI]], [[FLIP_BIT]]
62; PPC64-DAG: xor 4, [[LO]], [[FLIP_BIT]]
63; PPC64: blr
64
65; PPC64-P8-LABEL: test_neg:
66; PPC64-P8-DAG: mfvsrd [[LO:[0-9]+]], 2
67; PPC64-P8-DAG: mfvsrd [[HI:[0-9]+]], 1
68; PPC64-P8-DAG: li [[IMM1:[0-9]+]], 1
69; PPC64-P8-DAG: sldi [[FLIP_BIT]], [[IMM1]], 63
70; PPC64-P8-NOT: BARRIER
71; PPC64-P8-DAG: xor 3, [[HI]], [[FLIP_BIT]]
72; PPC64-P8-DAG: xor 4, [[LO]], [[FLIP_BIT]]
73; PPC64-P8: blr
74
75; PPC32-DAG: stfd 1, 24(1)
76; PPC32-DAG: stfd 2, 16(1)
77; PPC32: nop
78; PPC32-DAG: lwz [[HI0:[0-9]+]], 24(1)
79; PPC32-DAG: lwz [[LO0:[0-9]+]], 16(1)
80; PPC32-DAG: lwz [[HI1:[0-9]+]], 28(1)
81; PPC32-DAG: lwz [[LO1:[0-9]+]], 20(1)
82; PPC32-NOT: BARRIER
83; PPC32-DAG: xoris [[HI0]], [[HI0]], 32768
84; PPC32-DAG: xoris [[LO0]], [[LO0]], 32768
85; PPC32: blr
86	%0 = fsub ppc_fp128 0xM80000000000000000000000000000000, %x
87	%1 = bitcast ppc_fp128 %0 to i128
88	ret i128 %1
89}
90
91define i128 @test_copysign(ppc_fp128 %x) nounwind  {
92entry:
93; PPC64-LABEL: test_copysign:
94; PPC64-DAG: stxsdx 1, 0, [[ADDR_REG:[0-9]+]]
95; PPC64-DAG: addi [[ADDR_REG]], 1, [[OFFSET:-?[0-9]+]]
96; PPC64-DAG: li [[SIGN:[0-9]+]], 1
97; PPC64-DAG: sldi [[SIGN]], [[SIGN]], 63
98; PPC64-DAG: li [[HI_TMP:[0-9]+]], 16399
99; PPC64-DAG: sldi [[CST_HI:[0-9]+]], [[HI_TMP]], 48
100; PPC64-DAG: li [[LO_TMP:[0-9]+]], 3019
101; PPC64-DAG: sldi [[CST_LO:[0-9]+]], [[LO_TMP]], 52
102; PPC64-NOT: BARRIER
103; PPC64-DAG: ld [[X_HI:[0-9]+]], [[OFFSET]](1)
104; PPC64-DAG: and [[NEW_HI_TMP:[0-9]+]], [[X_HI]], [[SIGN]]
105; PPC64-DAG: or 3, [[NEW_HI_TMP]], [[CST_HI]]
106; PPC64-DAG: xor 4, [[SIGN]], [[CST_LO]]
107; PPC64: blr
108
109; PPC64-P8-LABEL: test_copysign:
110; PPC64-P8-DAG: mfvsrd [[X_HI:[0-9]+]], 1
111; PPC64-P8-DAG: li [[SIGN:[0-9]+]], 1
112; PPC64-P8-DAG: sldi [[SIGN]], [[SIGN]], 63
113; PPC64-P8-DAG: li [[HI_TMP:[0-9]+]], 16399
114; PPC64-P8-DAG: sldi [[CST_HI:[0-9]+]], [[HI_TMP]], 48
115; PPC64-P8-DAG: li [[LO_TMP:[0-9]+]], 3019
116; PPC64-P8-DAG: sldi [[CST_LO:[0-9]+]], [[LO_TMP]], 52
117; PPC64-P8-NOT: BARRIER
118; PPC64-P8-DAG: and [[NEW_HI_TMP:[0-9]+]], [[X_HI]], [[SIGN]]
119; PPC64-P8-DAG: or 3, [[NEW_HI_TMP]], [[CST_HI]]
120; PPC64-P8-DAG: xor 4, [[NEW_HI_TMP]], [[CST_LO]]
121; PPC64-P8: blr
122
123; PPC32: stfd 1, [[STACK:[0-9]+]](1)
124; PPC32: nop
125; PPC32: lwz [[HI:[0-9]+]], [[STACK]](1)
126; PPC32: rlwinm [[FLIP_BIT:[0-9]+]], [[HI]], 0, 0, 0
127; PPC32-NOT: BARRIER
128; PPC32-DAG: oris {{[0-9]+}}, [[FLIP_BIT]], 16399
129; PPC32-DAG: xoris {{[0-9]+}}, [[FLIP_BIT]], 48304
130; PPC32: blr
131	%0 = tail call ppc_fp128 @llvm.copysign.ppcf128(ppc_fp128 0xMBCB0000000000000400F000000000000, ppc_fp128 %x)
132	%1 = bitcast ppc_fp128 %0 to i128
133	ret i128 %1
134}
135
136declare ppc_fp128 @llvm.fabs.ppcf128(ppc_fp128)
137declare ppc_fp128 @llvm.copysign.ppcf128(ppc_fp128, ppc_fp128)
138