xref: /freebsd/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCInstrVSX.td (revision 1323ec571215a77ddd21294f0871979d5ad6b992)
1//===- PPCInstrVSX.td - The PowerPC VSX Extension --*- tablegen -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file describes the VSX extension to the PowerPC instruction set.
10//
11//===----------------------------------------------------------------------===//
12
13// *********************************** NOTE ***********************************
14// ** For POWER8 Little Endian, the VSX swap optimization relies on knowing  **
15// ** which VMX and VSX instructions are lane-sensitive and which are not.   **
16// ** A lane-sensitive instruction relies, implicitly or explicitly, on      **
17// ** whether lanes are numbered from left to right.  An instruction like    **
18// ** VADDFP is not lane-sensitive, because each lane of the result vector   **
19// ** relies only on the corresponding lane of the source vectors.  However, **
20// ** an instruction like VMULESB is lane-sensitive, because "even" and      **
21// ** "odd" lanes are different for big-endian and little-endian numbering.  **
22// **                                                                        **
23// ** When adding new VMX and VSX instructions, please consider whether they **
24// ** are lane-sensitive.  If so, they must be added to a switch statement   **
25// ** in PPCVSXSwapRemoval::gatherVectorInstructions().                      **
26// ****************************************************************************
27
28// *********************************** NOTE ***********************************
29// ** When adding new anonymous patterns to this file, please add them to    **
30// ** the section titled Anonymous Patterns. Chances are that the existing   **
31// ** predicate blocks already contain a combination of features that you    **
32// ** are after. There is a list of blocks at the top of the section. If     **
33// ** you definitely need a new combination of predicates, please add that   **
34// ** combination to the list.                                               **
35// ** File Structure:                                                        **
36// ** - Custom PPCISD node definitions                                       **
37// ** - Predicate definitions: predicates to specify the subtargets for      **
38// **   which an instruction or pattern can be emitted.                      **
39// ** - Instruction formats: classes instantiated by the instructions.       **
40// **   These generally correspond to instruction formats in section 1.6 of  **
41// **   the ISA document.                                                    **
42// ** - Instruction definitions: the actual definitions of the instructions  **
43// **   often including input patterns that they match.                      **
44// ** - Helper DAG definitions: We define a number of dag objects to use as  **
45// **   input or output patterns for consciseness of the code.               **
46// ** - Anonymous patterns: input patterns that an instruction matches can   **
47// **   often not be specified as part of the instruction definition, so an  **
48// **   anonymous pattern must be specified mapping an input pattern to an   **
49// **   output pattern. These are generally guarded by subtarget predicates. **
50// ** - Instruction aliases: used to define extended mnemonics for assembly  **
51// **   printing (for example: xxswapd for xxpermdi with 0x2 as the imm).    **
52// ****************************************************************************
53
54def PPCRegVSRCAsmOperand : AsmOperandClass {
55  let Name = "RegVSRC"; let PredicateMethod = "isVSRegNumber";
56}
57def vsrc : RegisterOperand<VSRC> {
58  let ParserMatchClass = PPCRegVSRCAsmOperand;
59}
60
61def PPCRegVSFRCAsmOperand : AsmOperandClass {
62  let Name = "RegVSFRC"; let PredicateMethod = "isVSRegNumber";
63}
64def vsfrc : RegisterOperand<VSFRC> {
65  let ParserMatchClass = PPCRegVSFRCAsmOperand;
66}
67
68def PPCRegVSSRCAsmOperand : AsmOperandClass {
69  let Name = "RegVSSRC"; let PredicateMethod = "isVSRegNumber";
70}
71def vssrc : RegisterOperand<VSSRC> {
72  let ParserMatchClass = PPCRegVSSRCAsmOperand;
73}
74
75def PPCRegSPILLTOVSRRCAsmOperand : AsmOperandClass {
76  let Name = "RegSPILLTOVSRRC"; let PredicateMethod = "isVSRegNumber";
77}
78
79def spilltovsrrc : RegisterOperand<SPILLTOVSRRC> {
80  let ParserMatchClass = PPCRegSPILLTOVSRRCAsmOperand;
81}
82
83def SDT_PPCldvsxlh : SDTypeProfile<1, 1, [
84  SDTCisVT<0, v4f32>, SDTCisPtrTy<1>
85]>;
86
87def SDT_PPCfpexth : SDTypeProfile<1, 2, [
88  SDTCisVT<0, v2f64>, SDTCisVT<1, v4f32>, SDTCisPtrTy<2>
89]>;
90
91def SDT_PPCldsplat : SDTypeProfile<1, 1, [
92  SDTCisVec<0>, SDTCisPtrTy<1>
93]>;
94
95// Little-endian-specific nodes.
96def SDT_PPClxvd2x : SDTypeProfile<1, 1, [
97  SDTCisVT<0, v2f64>, SDTCisPtrTy<1>
98]>;
99def SDT_PPCstxvd2x : SDTypeProfile<0, 2, [
100  SDTCisVT<0, v2f64>, SDTCisPtrTy<1>
101]>;
102def SDT_PPCxxswapd : SDTypeProfile<1, 1, [
103  SDTCisSameAs<0, 1>
104]>;
105def SDTVecConv : SDTypeProfile<1, 2, [
106  SDTCisVec<0>, SDTCisVec<1>, SDTCisPtrTy<2>
107]>;
108def SDTVabsd : SDTypeProfile<1, 3, [
109  SDTCisVec<0>, SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisVT<3, i32>
110]>;
111def SDT_PPCld_vec_be : SDTypeProfile<1, 1, [
112  SDTCisVec<0>, SDTCisPtrTy<1>
113]>;
114def SDT_PPCst_vec_be : SDTypeProfile<0, 2, [
115  SDTCisVec<0>, SDTCisPtrTy<1>
116]>;
117
118//--------------------------- Custom PPC nodes -------------------------------//
119def PPClxvd2x  : SDNode<"PPCISD::LXVD2X", SDT_PPClxvd2x,
120                        [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
121def PPCstxvd2x : SDNode<"PPCISD::STXVD2X", SDT_PPCstxvd2x,
122                        [SDNPHasChain, SDNPMayStore]>;
123def PPCld_vec_be  : SDNode<"PPCISD::LOAD_VEC_BE", SDT_PPCld_vec_be,
124                        [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
125def PPCst_vec_be : SDNode<"PPCISD::STORE_VEC_BE", SDT_PPCst_vec_be,
126                        [SDNPHasChain, SDNPMayStore]>;
127def PPCxxswapd : SDNode<"PPCISD::XXSWAPD", SDT_PPCxxswapd, [SDNPHasChain]>;
128def PPCmfvsr : SDNode<"PPCISD::MFVSR", SDTUnaryOp, []>;
129def PPCmtvsra : SDNode<"PPCISD::MTVSRA", SDTUnaryOp, []>;
130def PPCmtvsrz : SDNode<"PPCISD::MTVSRZ", SDTUnaryOp, []>;
131def PPCsvec2fp : SDNode<"PPCISD::SINT_VEC_TO_FP", SDTVecConv, []>;
132def PPCuvec2fp: SDNode<"PPCISD::UINT_VEC_TO_FP", SDTVecConv, []>;
133def PPCswapNoChain : SDNode<"PPCISD::SWAP_NO_CHAIN", SDT_PPCxxswapd>;
134def PPCvabsd : SDNode<"PPCISD::VABSD", SDTVabsd, []>;
135
136def PPCfpexth : SDNode<"PPCISD::FP_EXTEND_HALF", SDT_PPCfpexth, []>;
137def PPCldvsxlh : SDNode<"PPCISD::LD_VSX_LH", SDT_PPCldvsxlh,
138                        [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
139def PPCldsplat : SDNode<"PPCISD::LD_SPLAT", SDT_PPCldsplat,
140                        [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
141def PPCSToV : SDNode<"PPCISD::SCALAR_TO_VECTOR_PERMUTED",
142                     SDTypeProfile<1, 1, []>, []>;
143
144//-------------------------- Predicate definitions ---------------------------//
145def HasVSX : Predicate<"Subtarget->hasVSX()">;
146def IsLittleEndian : Predicate<"Subtarget->isLittleEndian()">;
147def IsBigEndian : Predicate<"!Subtarget->isLittleEndian()">;
148def IsPPC64 : Predicate<"Subtarget->isPPC64()">;
149def HasOnlySwappingMemOps : Predicate<"!Subtarget->hasP9Vector()">;
150def HasP8Vector : Predicate<"Subtarget->hasP8Vector()">;
151def HasDirectMove : Predicate<"Subtarget->hasDirectMove()">;
152def NoP9Vector : Predicate<"!Subtarget->hasP9Vector()">;
153def HasP9Vector : Predicate<"Subtarget->hasP9Vector()">;
154def NoP9Altivec : Predicate<"!Subtarget->hasP9Altivec()">;
155def NoP10Vector: Predicate<"!Subtarget->hasP10Vector()">;
156
157//--------------------- VSX-specific instruction formats ---------------------//
158// By default, all VSX instructions are to be selected over their Altivec
159// counter parts and they do not have unmodeled sideeffects.
160let AddedComplexity = 400, hasSideEffects = 0 in {
161multiclass XX3Form_Rcr<bits<6> opcode, bits<7> xo, string asmbase,
162                    string asmstr, InstrItinClass itin, Intrinsic Int,
163                    ValueType OutTy, ValueType InTy> {
164  let BaseName = asmbase in {
165    def NAME : XX3Form_Rc<opcode, xo, (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB),
166                       !strconcat(asmbase, !strconcat(" ", asmstr)), itin,
167                       [(set OutTy:$XT, (Int InTy:$XA, InTy:$XB))]>;
168    let Defs = [CR6] in
169    def _rec    : XX3Form_Rc<opcode, xo, (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB),
170                       !strconcat(asmbase, !strconcat(". ", asmstr)), itin,
171                       [(set InTy:$XT,
172                                (InTy (PPCvcmp_rec InTy:$XA, InTy:$XB, xo)))]>,
173                       isRecordForm;
174  }
175}
176
177// Instruction form with a single input register for instructions such as
178// XXPERMDI. The reason for defining this is that specifying multiple chained
179// operands (such as loads) to an instruction will perform both chained
180// operations rather than coalescing them into a single register - even though
181// the source memory location is the same. This simply forces the instruction
182// to use the same register for both inputs.
183// For example, an output DAG such as this:
184//   (XXPERMDI (LXSIBZX xoaddr:$src), (LXSIBZX xoaddr:$src ), 0))
185// would result in two load instructions emitted and used as separate inputs
186// to the XXPERMDI instruction.
187class XX3Form_2s<bits<6> opcode, bits<5> xo, dag OOL, dag IOL, string asmstr,
188                 InstrItinClass itin, list<dag> pattern>
189  : XX3Form_2<opcode, xo, OOL, IOL, asmstr, itin, pattern> {
190    let XB = XA;
191}
192
193let Predicates = [HasVSX, HasP9Vector] in {
194class X_VT5_XO5_VB5<bits<6> opcode, bits<5> xo2, bits<10> xo, string opc,
195                    list<dag> pattern>
196  : X_RD5_XO5_RS5<opcode, xo2, xo, (outs vrrc:$vT), (ins vrrc:$vB),
197                  !strconcat(opc, " $vT, $vB"), IIC_VecFP, pattern>;
198
199// [PO VRT XO VRB XO RO], Round to Odd version of [PO VRT XO VRB XO /]
200class X_VT5_XO5_VB5_Ro<bits<6> opcode, bits<5> xo2, bits<10> xo, string opc,
201                       list<dag> pattern>
202  : X_VT5_XO5_VB5<opcode, xo2, xo, opc, pattern>, isRecordForm;
203
204// [PO VRT XO VRB XO /], but the VRB is only used the left 64 bits (or less),
205// So we use different operand class for VRB
206class X_VT5_XO5_VB5_TyVB<bits<6> opcode, bits<5> xo2, bits<10> xo, string opc,
207                         RegisterOperand vbtype, list<dag> pattern>
208  : X_RD5_XO5_RS5<opcode, xo2, xo, (outs vrrc:$vT), (ins vbtype:$vB),
209                  !strconcat(opc, " $vT, $vB"), IIC_VecFP, pattern>;
210
211// [PO VRT XO VRB XO /]
212class X_VT5_XO5_VB5_VSFR<bits<6> opcode, bits<5> xo2, bits<10> xo, string opc,
213                    list<dag> pattern>
214  : X_RD5_XO5_RS5<opcode, xo2, xo, (outs vfrc:$vT), (ins vrrc:$vB),
215                  !strconcat(opc, " $vT, $vB"), IIC_VecFP, pattern>;
216
217// [PO VRT XO VRB XO RO], Round to Odd version of [PO VRT XO VRB XO /]
218class X_VT5_XO5_VB5_VSFR_Ro<bits<6> opcode, bits<5> xo2, bits<10> xo, string opc,
219                       list<dag> pattern>
220  : X_VT5_XO5_VB5_VSFR<opcode, xo2, xo, opc, pattern>, isRecordForm;
221
222// [PO T XO B XO BX /]
223class XX2_RT5_XO5_XB6<bits<6> opcode, bits<5> xo2, bits<9> xo, string opc,
224                      list<dag> pattern>
225  : XX2_RD5_XO5_RS6<opcode, xo2, xo, (outs g8rc:$rT), (ins vsfrc:$XB),
226                    !strconcat(opc, " $rT, $XB"), IIC_VecFP, pattern>;
227
228// [PO T XO B XO BX TX]
229class XX2_XT6_XO5_XB6<bits<6> opcode, bits<5> xo2, bits<9> xo, string opc,
230                      RegisterOperand vtype, list<dag> pattern>
231  : XX2_RD6_XO5_RS6<opcode, xo2, xo, (outs vtype:$XT), (ins vtype:$XB),
232                    !strconcat(opc, " $XT, $XB"), IIC_VecFP, pattern>;
233
234// [PO T A B XO AX BX TX], src and dest register use different operand class
235class XX3_XT5_XA5_XB5<bits<6> opcode, bits<8> xo, string opc,
236                RegisterOperand xty, RegisterOperand aty, RegisterOperand bty,
237                InstrItinClass itin, list<dag> pattern>
238  : XX3Form<opcode, xo, (outs xty:$XT), (ins aty:$XA, bty:$XB),
239            !strconcat(opc, " $XT, $XA, $XB"), itin, pattern>;
240
241// [PO VRT VRA VRB XO /]
242class X_VT5_VA5_VB5<bits<6> opcode, bits<10> xo, string opc,
243                    list<dag> pattern>
244  : XForm_1<opcode, xo, (outs vrrc:$vT), (ins vrrc:$vA, vrrc:$vB),
245            !strconcat(opc, " $vT, $vA, $vB"), IIC_VecFP, pattern>;
246
247// [PO VRT VRA VRB XO RO], Round to Odd version of [PO VRT VRA VRB XO /]
248class X_VT5_VA5_VB5_Ro<bits<6> opcode, bits<10> xo, string opc,
249                       list<dag> pattern>
250  : X_VT5_VA5_VB5<opcode, xo, opc, pattern>, isRecordForm;
251
252// [PO VRT VRA VRB XO /]
253class X_VT5_VA5_VB5_FMA<bits<6> opcode, bits<10> xo, string opc,
254                        list<dag> pattern>
255  : XForm_1<opcode, xo, (outs vrrc:$vT), (ins vrrc:$vTi, vrrc:$vA, vrrc:$vB),
256            !strconcat(opc, " $vT, $vA, $vB"), IIC_VecFP, pattern>,
257            RegConstraint<"$vTi = $vT">, NoEncode<"$vTi">;
258
259// [PO VRT VRA VRB XO RO], Round to Odd version of [PO VRT VRA VRB XO /]
260class X_VT5_VA5_VB5_FMA_Ro<bits<6> opcode, bits<10> xo, string opc,
261                        list<dag> pattern>
262  : X_VT5_VA5_VB5_FMA<opcode, xo, opc, pattern>, isRecordForm;
263
264class Z23_VT5_R1_VB5_RMC2_EX1<bits<6> opcode, bits<8> xo, bit ex, string opc,
265                              list<dag> pattern>
266  : Z23Form_8<opcode, xo,
267              (outs vrrc:$vT), (ins u1imm:$r, vrrc:$vB, u2imm:$rmc),
268              !strconcat(opc, " $r, $vT, $vB, $rmc"), IIC_VecFP, pattern> {
269  let RC = ex;
270}
271
272// [PO BF // VRA VRB XO /]
273class X_BF3_VA5_VB5<bits<6> opcode, bits<10> xo, string opc,
274                    list<dag> pattern>
275  : XForm_17<opcode, xo, (outs crrc:$crD), (ins vrrc:$VA, vrrc:$VB),
276             !strconcat(opc, " $crD, $VA, $VB"), IIC_FPCompare> {
277  let Pattern = pattern;
278}
279
280// [PO T RA RB XO TX] almost equal to [PO S RA RB XO SX], but has different
281// "out" and "in" dag
282class X_XT6_RA5_RB5<bits<6> opcode, bits<10> xo, string opc,
283                    RegisterOperand vtype, list<dag> pattern>
284  : XX1Form_memOp<opcode, xo, (outs vtype:$XT), (ins memrr:$src),
285            !strconcat(opc, " $XT, $src"), IIC_LdStLFD, pattern>;
286
287// [PO S RA RB XO SX]
288class X_XS6_RA5_RB5<bits<6> opcode, bits<10> xo, string opc,
289                    RegisterOperand vtype, list<dag> pattern>
290  : XX1Form_memOp<opcode, xo, (outs), (ins vtype:$XT, memrr:$dst),
291            !strconcat(opc, " $XT, $dst"), IIC_LdStSTFD, pattern>;
292} // Predicates = HasP9Vector
293} // AddedComplexity = 400, hasSideEffects = 0
294
295multiclass ScalToVecWPermute<ValueType Ty, dag In, dag NonPermOut, dag PermOut> {
296  def : Pat<(Ty (scalar_to_vector In)), (Ty NonPermOut)>;
297  def : Pat<(Ty (PPCSToV In)), (Ty PermOut)>;
298}
299
300//-------------------------- Instruction definitions -------------------------//
301// VSX instructions require the VSX feature, they are to be selected over
302// equivalent Altivec patterns (as they address a larger register set) and
303// they do not have unmodeled side effects.
304let Predicates = [HasVSX], AddedComplexity = 400 in {
305let hasSideEffects = 0 in {
306
307  // Load indexed instructions
308  let mayLoad = 1, mayStore = 0 in {
309    let CodeSize = 3 in
310    def LXSDX : XX1Form_memOp<31, 588,
311                        (outs vsfrc:$XT), (ins memrr:$src),
312                        "lxsdx $XT, $src", IIC_LdStLFD,
313                        []>;
314
315    // Pseudo instruction XFLOADf64 will be expanded to LXSDX or LFDX later
316    let CodeSize = 3 in
317      def XFLOADf64  : PseudoXFormMemOp<(outs vsfrc:$XT), (ins memrr:$src),
318                              "#XFLOADf64",
319                              [(set f64:$XT, (load XForm:$src))]>;
320
321    let Predicates = [HasVSX, HasOnlySwappingMemOps] in
322    def LXVD2X : XX1Form_memOp<31, 844,
323                         (outs vsrc:$XT), (ins memrr:$src),
324                         "lxvd2x $XT, $src", IIC_LdStLFD,
325                         []>;
326
327    def LXVDSX : XX1Form_memOp<31, 332,
328                         (outs vsrc:$XT), (ins memrr:$src),
329                         "lxvdsx $XT, $src", IIC_LdStLFD, []>;
330
331    let Predicates = [HasVSX, HasOnlySwappingMemOps] in
332    def LXVW4X : XX1Form_memOp<31, 780,
333                         (outs vsrc:$XT), (ins memrr:$src),
334                         "lxvw4x $XT, $src", IIC_LdStLFD,
335                         []>;
336  } // mayLoad
337
338  // Store indexed instructions
339  let mayStore = 1, mayLoad = 0 in {
340    let CodeSize = 3 in
341    def STXSDX : XX1Form_memOp<31, 716,
342                        (outs), (ins vsfrc:$XT, memrr:$dst),
343                        "stxsdx $XT, $dst", IIC_LdStSTFD,
344                        []>;
345
346    // Pseudo instruction XFSTOREf64  will be expanded to STXSDX or STFDX later
347    let CodeSize = 3 in
348      def XFSTOREf64 : PseudoXFormMemOp<(outs), (ins vsfrc:$XT, memrr:$dst),
349                              "#XFSTOREf64",
350                              [(store f64:$XT, XForm:$dst)]>;
351
352    let Predicates = [HasVSX, HasOnlySwappingMemOps] in {
353    // The behaviour of this instruction is endianness-specific so we provide no
354    // pattern to match it without considering endianness.
355    def STXVD2X : XX1Form_memOp<31, 972,
356                         (outs), (ins vsrc:$XT, memrr:$dst),
357                         "stxvd2x $XT, $dst", IIC_LdStSTFD,
358                         []>;
359
360    def STXVW4X : XX1Form_memOp<31, 908,
361                         (outs), (ins vsrc:$XT, memrr:$dst),
362                         "stxvw4x $XT, $dst", IIC_LdStSTFD,
363                         []>;
364    }
365  } // mayStore
366
367  let mayRaiseFPException = 1 in {
368  let Uses = [RM] in {
369  // Add/Mul Instructions
370  let isCommutable = 1 in {
371    def XSADDDP : XX3Form<60, 32,
372                          (outs vsfrc:$XT), (ins vsfrc:$XA, vsfrc:$XB),
373                          "xsadddp $XT, $XA, $XB", IIC_VecFP,
374                          [(set f64:$XT, (any_fadd f64:$XA, f64:$XB))]>;
375    def XSMULDP : XX3Form<60, 48,
376                          (outs vsfrc:$XT), (ins vsfrc:$XA, vsfrc:$XB),
377                          "xsmuldp $XT, $XA, $XB", IIC_VecFP,
378                          [(set f64:$XT, (any_fmul f64:$XA, f64:$XB))]>;
379
380    def XVADDDP : XX3Form<60, 96,
381                          (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB),
382                          "xvadddp $XT, $XA, $XB", IIC_VecFP,
383                          [(set v2f64:$XT, (any_fadd v2f64:$XA, v2f64:$XB))]>;
384
385    def XVADDSP : XX3Form<60, 64,
386                          (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB),
387                          "xvaddsp $XT, $XA, $XB", IIC_VecFP,
388                          [(set v4f32:$XT, (any_fadd v4f32:$XA, v4f32:$XB))]>;
389
390    def XVMULDP : XX3Form<60, 112,
391                          (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB),
392                          "xvmuldp $XT, $XA, $XB", IIC_VecFP,
393                          [(set v2f64:$XT, (any_fmul v2f64:$XA, v2f64:$XB))]>;
394
395    def XVMULSP : XX3Form<60, 80,
396                          (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB),
397                          "xvmulsp $XT, $XA, $XB", IIC_VecFP,
398                          [(set v4f32:$XT, (any_fmul v4f32:$XA, v4f32:$XB))]>;
399  }
400
401  // Subtract Instructions
402  def XSSUBDP : XX3Form<60, 40,
403                        (outs vsfrc:$XT), (ins vsfrc:$XA, vsfrc:$XB),
404                        "xssubdp $XT, $XA, $XB", IIC_VecFP,
405                        [(set f64:$XT, (any_fsub f64:$XA, f64:$XB))]>;
406
407  def XVSUBDP : XX3Form<60, 104,
408                        (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB),
409                        "xvsubdp $XT, $XA, $XB", IIC_VecFP,
410                        [(set v2f64:$XT, (any_fsub v2f64:$XA, v2f64:$XB))]>;
411  def XVSUBSP : XX3Form<60, 72,
412                        (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB),
413                        "xvsubsp $XT, $XA, $XB", IIC_VecFP,
414                        [(set v4f32:$XT, (any_fsub v4f32:$XA, v4f32:$XB))]>;
415
416  // FMA Instructions
417  let BaseName = "XSMADDADP" in {
418  let isCommutable = 1 in
419  def XSMADDADP : XX3Form<60, 33,
420                          (outs vsfrc:$XT), (ins vsfrc:$XTi, vsfrc:$XA, vsfrc:$XB),
421                          "xsmaddadp $XT, $XA, $XB", IIC_VecFP,
422                          [(set f64:$XT, (any_fma f64:$XA, f64:$XB, f64:$XTi))]>,
423                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
424                          AltVSXFMARel;
425  let IsVSXFMAAlt = 1 in
426  def XSMADDMDP : XX3Form<60, 41,
427                          (outs vsfrc:$XT), (ins vsfrc:$XTi, vsfrc:$XA, vsfrc:$XB),
428                          "xsmaddmdp $XT, $XA, $XB", IIC_VecFP, []>,
429                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
430                          AltVSXFMARel;
431  }
432
433  let BaseName = "XSMSUBADP" in {
434  let isCommutable = 1 in
435  def XSMSUBADP : XX3Form<60, 49,
436                          (outs vsfrc:$XT), (ins vsfrc:$XTi, vsfrc:$XA, vsfrc:$XB),
437                          "xsmsubadp $XT, $XA, $XB", IIC_VecFP,
438                          [(set f64:$XT, (any_fma f64:$XA, f64:$XB, (fneg f64:$XTi)))]>,
439                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
440                          AltVSXFMARel;
441  let IsVSXFMAAlt = 1 in
442  def XSMSUBMDP : XX3Form<60, 57,
443                          (outs vsfrc:$XT), (ins vsfrc:$XTi, vsfrc:$XA, vsfrc:$XB),
444                          "xsmsubmdp $XT, $XA, $XB", IIC_VecFP, []>,
445                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
446                          AltVSXFMARel;
447  }
448
449  let BaseName = "XSNMADDADP" in {
450  let isCommutable = 1 in
451  def XSNMADDADP : XX3Form<60, 161,
452                          (outs vsfrc:$XT), (ins vsfrc:$XTi, vsfrc:$XA, vsfrc:$XB),
453                          "xsnmaddadp $XT, $XA, $XB", IIC_VecFP,
454                          [(set f64:$XT, (fneg (any_fma f64:$XA, f64:$XB, f64:$XTi)))]>,
455                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
456                          AltVSXFMARel;
457  let IsVSXFMAAlt = 1 in
458  def XSNMADDMDP : XX3Form<60, 169,
459                          (outs vsfrc:$XT), (ins vsfrc:$XTi, vsfrc:$XA, vsfrc:$XB),
460                          "xsnmaddmdp $XT, $XA, $XB", IIC_VecFP, []>,
461                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
462                          AltVSXFMARel;
463  }
464
465  let BaseName = "XSNMSUBADP" in {
466  let isCommutable = 1 in
467  def XSNMSUBADP : XX3Form<60, 177,
468                          (outs vsfrc:$XT), (ins vsfrc:$XTi, vsfrc:$XA, vsfrc:$XB),
469                          "xsnmsubadp $XT, $XA, $XB", IIC_VecFP,
470                          [(set f64:$XT, (fneg (any_fma f64:$XA, f64:$XB, (fneg f64:$XTi))))]>,
471                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
472                          AltVSXFMARel;
473  let IsVSXFMAAlt = 1 in
474  def XSNMSUBMDP : XX3Form<60, 185,
475                          (outs vsfrc:$XT), (ins vsfrc:$XTi, vsfrc:$XA, vsfrc:$XB),
476                          "xsnmsubmdp $XT, $XA, $XB", IIC_VecFP, []>,
477                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
478                          AltVSXFMARel;
479  }
480
481  let BaseName = "XVMADDADP" in {
482  let isCommutable = 1 in
483  def XVMADDADP : XX3Form<60, 97,
484                          (outs vsrc:$XT), (ins vsrc:$XTi, vsrc:$XA, vsrc:$XB),
485                          "xvmaddadp $XT, $XA, $XB", IIC_VecFP,
486                          [(set v2f64:$XT, (any_fma v2f64:$XA, v2f64:$XB, v2f64:$XTi))]>,
487                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
488                          AltVSXFMARel;
489  let IsVSXFMAAlt = 1 in
490  def XVMADDMDP : XX3Form<60, 105,
491                          (outs vsrc:$XT), (ins vsrc:$XTi, vsrc:$XA, vsrc:$XB),
492                          "xvmaddmdp $XT, $XA, $XB", IIC_VecFP, []>,
493                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
494                          AltVSXFMARel;
495  }
496
497  let BaseName = "XVMADDASP" in {
498  let isCommutable = 1 in
499  def XVMADDASP : XX3Form<60, 65,
500                          (outs vsrc:$XT), (ins vsrc:$XTi, vsrc:$XA, vsrc:$XB),
501                          "xvmaddasp $XT, $XA, $XB", IIC_VecFP,
502                          [(set v4f32:$XT, (any_fma v4f32:$XA, v4f32:$XB, v4f32:$XTi))]>,
503                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
504                          AltVSXFMARel;
505  let IsVSXFMAAlt = 1 in
506  def XVMADDMSP : XX3Form<60, 73,
507                          (outs vsrc:$XT), (ins vsrc:$XTi, vsrc:$XA, vsrc:$XB),
508                          "xvmaddmsp $XT, $XA, $XB", IIC_VecFP, []>,
509                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
510                          AltVSXFMARel;
511  }
512
513  let BaseName = "XVMSUBADP" in {
514  let isCommutable = 1 in
515  def XVMSUBADP : XX3Form<60, 113,
516                          (outs vsrc:$XT), (ins vsrc:$XTi, vsrc:$XA, vsrc:$XB),
517                          "xvmsubadp $XT, $XA, $XB", IIC_VecFP,
518                          [(set v2f64:$XT, (any_fma v2f64:$XA, v2f64:$XB, (fneg v2f64:$XTi)))]>,
519                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
520                          AltVSXFMARel;
521  let IsVSXFMAAlt = 1 in
522  def XVMSUBMDP : XX3Form<60, 121,
523                          (outs vsrc:$XT), (ins vsrc:$XTi, vsrc:$XA, vsrc:$XB),
524                          "xvmsubmdp $XT, $XA, $XB", IIC_VecFP, []>,
525                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
526                          AltVSXFMARel;
527  }
528
529  let BaseName = "XVMSUBASP" in {
530  let isCommutable = 1 in
531  def XVMSUBASP : XX3Form<60, 81,
532                          (outs vsrc:$XT), (ins vsrc:$XTi, vsrc:$XA, vsrc:$XB),
533                          "xvmsubasp $XT, $XA, $XB", IIC_VecFP,
534                          [(set v4f32:$XT, (any_fma v4f32:$XA, v4f32:$XB, (fneg v4f32:$XTi)))]>,
535                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
536                          AltVSXFMARel;
537  let IsVSXFMAAlt = 1 in
538  def XVMSUBMSP : XX3Form<60, 89,
539                          (outs vsrc:$XT), (ins vsrc:$XTi, vsrc:$XA, vsrc:$XB),
540                          "xvmsubmsp $XT, $XA, $XB", IIC_VecFP, []>,
541                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
542                          AltVSXFMARel;
543  }
544
545  let BaseName = "XVNMADDADP" in {
546  let isCommutable = 1 in
547  def XVNMADDADP : XX3Form<60, 225,
548                          (outs vsrc:$XT), (ins vsrc:$XTi, vsrc:$XA, vsrc:$XB),
549                          "xvnmaddadp $XT, $XA, $XB", IIC_VecFP,
550                          [(set v2f64:$XT, (fneg (any_fma v2f64:$XA, v2f64:$XB, v2f64:$XTi)))]>,
551                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
552                          AltVSXFMARel;
553  let IsVSXFMAAlt = 1 in
554  def XVNMADDMDP : XX3Form<60, 233,
555                          (outs vsrc:$XT), (ins vsrc:$XTi, vsrc:$XA, vsrc:$XB),
556                          "xvnmaddmdp $XT, $XA, $XB", IIC_VecFP, []>,
557                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
558                          AltVSXFMARel;
559  }
560
561  let BaseName = "XVNMADDASP" in {
562  let isCommutable = 1 in
563  def XVNMADDASP : XX3Form<60, 193,
564                          (outs vsrc:$XT), (ins vsrc:$XTi, vsrc:$XA, vsrc:$XB),
565                          "xvnmaddasp $XT, $XA, $XB", IIC_VecFP,
566                          [(set v4f32:$XT, (fneg (fma v4f32:$XA, v4f32:$XB, v4f32:$XTi)))]>,
567                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
568                          AltVSXFMARel;
569  let IsVSXFMAAlt = 1 in
570  def XVNMADDMSP : XX3Form<60, 201,
571                          (outs vsrc:$XT), (ins vsrc:$XTi, vsrc:$XA, vsrc:$XB),
572                          "xvnmaddmsp $XT, $XA, $XB", IIC_VecFP, []>,
573                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
574                          AltVSXFMARel;
575  }
576
577  let BaseName = "XVNMSUBADP" in {
578  let isCommutable = 1 in
579  def XVNMSUBADP : XX3Form<60, 241,
580                          (outs vsrc:$XT), (ins vsrc:$XTi, vsrc:$XA, vsrc:$XB),
581                          "xvnmsubadp $XT, $XA, $XB", IIC_VecFP,
582                          [(set v2f64:$XT, (fneg (any_fma v2f64:$XA, v2f64:$XB, (fneg v2f64:$XTi))))]>,
583                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
584                          AltVSXFMARel;
585  let IsVSXFMAAlt = 1 in
586  def XVNMSUBMDP : XX3Form<60, 249,
587                          (outs vsrc:$XT), (ins vsrc:$XTi, vsrc:$XA, vsrc:$XB),
588                          "xvnmsubmdp $XT, $XA, $XB", IIC_VecFP, []>,
589                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
590                          AltVSXFMARel;
591  }
592
593  let BaseName = "XVNMSUBASP" in {
594  let isCommutable = 1 in
595  def XVNMSUBASP : XX3Form<60, 209,
596                          (outs vsrc:$XT), (ins vsrc:$XTi, vsrc:$XA, vsrc:$XB),
597                          "xvnmsubasp $XT, $XA, $XB", IIC_VecFP,
598                          [(set v4f32:$XT, (fneg (any_fma v4f32:$XA, v4f32:$XB, (fneg v4f32:$XTi))))]>,
599                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
600                          AltVSXFMARel;
601  let IsVSXFMAAlt = 1 in
602  def XVNMSUBMSP : XX3Form<60, 217,
603                          (outs vsrc:$XT), (ins vsrc:$XTi, vsrc:$XA, vsrc:$XB),
604                          "xvnmsubmsp $XT, $XA, $XB", IIC_VecFP, []>,
605                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
606                          AltVSXFMARel;
607  }
608
609  // Division Instructions
610  def XSDIVDP : XX3Form<60, 56,
611                        (outs vsfrc:$XT), (ins vsfrc:$XA, vsfrc:$XB),
612                        "xsdivdp $XT, $XA, $XB", IIC_FPDivD,
613                        [(set f64:$XT, (any_fdiv f64:$XA, f64:$XB))]>;
614  def XSSQRTDP : XX2Form<60, 75,
615                        (outs vsfrc:$XT), (ins vsfrc:$XB),
616                        "xssqrtdp $XT, $XB", IIC_FPSqrtD,
617                        [(set f64:$XT, (any_fsqrt f64:$XB))]>;
618
619  def XSREDP : XX2Form<60, 90,
620                        (outs vsfrc:$XT), (ins vsfrc:$XB),
621                        "xsredp $XT, $XB", IIC_VecFP,
622                        [(set f64:$XT, (PPCfre f64:$XB))]>;
623  def XSRSQRTEDP : XX2Form<60, 74,
624                           (outs vsfrc:$XT), (ins vsfrc:$XB),
625                           "xsrsqrtedp $XT, $XB", IIC_VecFP,
626                           [(set f64:$XT, (PPCfrsqrte f64:$XB))]>;
627
628  let mayRaiseFPException = 0 in {
629  def XSTDIVDP : XX3Form_1<60, 61,
630                         (outs crrc:$crD), (ins vsfrc:$XA, vsfrc:$XB),
631                         "xstdivdp $crD, $XA, $XB", IIC_FPCompare, []>;
632  def XSTSQRTDP : XX2Form_1<60, 106,
633                          (outs crrc:$crD), (ins vsfrc:$XB),
634                          "xstsqrtdp $crD, $XB", IIC_FPCompare,
635                          [(set i32:$crD, (PPCftsqrt f64:$XB))]>;
636  def XVTDIVDP : XX3Form_1<60, 125,
637                         (outs crrc:$crD), (ins vsrc:$XA, vsrc:$XB),
638                         "xvtdivdp $crD, $XA, $XB", IIC_FPCompare, []>;
639  def XVTDIVSP : XX3Form_1<60, 93,
640                         (outs crrc:$crD), (ins vsrc:$XA, vsrc:$XB),
641                         "xvtdivsp $crD, $XA, $XB", IIC_FPCompare, []>;
642
643  def XVTSQRTDP : XX2Form_1<60, 234,
644                          (outs crrc:$crD), (ins vsrc:$XB),
645                          "xvtsqrtdp $crD, $XB", IIC_FPCompare,
646                          [(set i32:$crD, (PPCftsqrt v2f64:$XB))]>;
647  def XVTSQRTSP : XX2Form_1<60, 170,
648                          (outs crrc:$crD), (ins vsrc:$XB),
649                          "xvtsqrtsp $crD, $XB", IIC_FPCompare,
650                          [(set i32:$crD, (PPCftsqrt v4f32:$XB))]>;
651  }
652
653  def XVDIVDP : XX3Form<60, 120,
654                        (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB),
655                        "xvdivdp $XT, $XA, $XB", IIC_FPDivD,
656                        [(set v2f64:$XT, (any_fdiv v2f64:$XA, v2f64:$XB))]>;
657  def XVDIVSP : XX3Form<60, 88,
658                        (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB),
659                        "xvdivsp $XT, $XA, $XB", IIC_FPDivS,
660                        [(set v4f32:$XT, (any_fdiv v4f32:$XA, v4f32:$XB))]>;
661
662  def XVSQRTDP : XX2Form<60, 203,
663                        (outs vsrc:$XT), (ins vsrc:$XB),
664                        "xvsqrtdp $XT, $XB", IIC_FPSqrtD,
665                        [(set v2f64:$XT, (any_fsqrt v2f64:$XB))]>;
666  def XVSQRTSP : XX2Form<60, 139,
667                        (outs vsrc:$XT), (ins vsrc:$XB),
668                        "xvsqrtsp $XT, $XB", IIC_FPSqrtS,
669                        [(set v4f32:$XT, (any_fsqrt v4f32:$XB))]>;
670
671  def XVREDP : XX2Form<60, 218,
672                        (outs vsrc:$XT), (ins vsrc:$XB),
673                        "xvredp $XT, $XB", IIC_VecFP,
674                        [(set v2f64:$XT, (PPCfre v2f64:$XB))]>;
675  def XVRESP : XX2Form<60, 154,
676                        (outs vsrc:$XT), (ins vsrc:$XB),
677                        "xvresp $XT, $XB", IIC_VecFP,
678                        [(set v4f32:$XT, (PPCfre v4f32:$XB))]>;
679
680  def XVRSQRTEDP : XX2Form<60, 202,
681                           (outs vsrc:$XT), (ins vsrc:$XB),
682                           "xvrsqrtedp $XT, $XB", IIC_VecFP,
683                           [(set v2f64:$XT, (PPCfrsqrte v2f64:$XB))]>;
684  def XVRSQRTESP : XX2Form<60, 138,
685                           (outs vsrc:$XT), (ins vsrc:$XB),
686                           "xvrsqrtesp $XT, $XB", IIC_VecFP,
687                           [(set v4f32:$XT, (PPCfrsqrte v4f32:$XB))]>;
688
689  // Compare Instructions
690  def XSCMPODP : XX3Form_1<60, 43,
691                           (outs crrc:$crD), (ins vsfrc:$XA, vsfrc:$XB),
692                           "xscmpodp $crD, $XA, $XB", IIC_FPCompare, []>;
693  def XSCMPUDP : XX3Form_1<60, 35,
694                           (outs crrc:$crD), (ins vsfrc:$XA, vsfrc:$XB),
695                           "xscmpudp $crD, $XA, $XB", IIC_FPCompare, []>;
696
697  defm XVCMPEQDP : XX3Form_Rcr<60, 99,
698                             "xvcmpeqdp", "$XT, $XA, $XB", IIC_VecFPCompare,
699                             int_ppc_vsx_xvcmpeqdp, v2i64, v2f64>;
700  defm XVCMPEQSP : XX3Form_Rcr<60, 67,
701                             "xvcmpeqsp", "$XT, $XA, $XB", IIC_VecFPCompare,
702                             int_ppc_vsx_xvcmpeqsp, v4i32, v4f32>;
703  defm XVCMPGEDP : XX3Form_Rcr<60, 115,
704                             "xvcmpgedp", "$XT, $XA, $XB", IIC_VecFPCompare,
705                             int_ppc_vsx_xvcmpgedp, v2i64, v2f64>;
706  defm XVCMPGESP : XX3Form_Rcr<60, 83,
707                             "xvcmpgesp", "$XT, $XA, $XB", IIC_VecFPCompare,
708                             int_ppc_vsx_xvcmpgesp, v4i32, v4f32>;
709  defm XVCMPGTDP : XX3Form_Rcr<60, 107,
710                             "xvcmpgtdp", "$XT, $XA, $XB", IIC_VecFPCompare,
711                             int_ppc_vsx_xvcmpgtdp, v2i64, v2f64>;
712  defm XVCMPGTSP : XX3Form_Rcr<60, 75,
713                             "xvcmpgtsp", "$XT, $XA, $XB", IIC_VecFPCompare,
714                             int_ppc_vsx_xvcmpgtsp, v4i32, v4f32>;
715
716  // Move Instructions
717  let mayRaiseFPException = 0 in {
718  def XSABSDP : XX2Form<60, 345,
719                      (outs vsfrc:$XT), (ins vsfrc:$XB),
720                      "xsabsdp $XT, $XB", IIC_VecFP,
721                      [(set f64:$XT, (fabs f64:$XB))]>;
722  def XSNABSDP : XX2Form<60, 361,
723                      (outs vsfrc:$XT), (ins vsfrc:$XB),
724                      "xsnabsdp $XT, $XB", IIC_VecFP,
725                      [(set f64:$XT, (fneg (fabs f64:$XB)))]>;
726  def XSNEGDP : XX2Form<60, 377,
727                      (outs vsfrc:$XT), (ins vsfrc:$XB),
728                      "xsnegdp $XT, $XB", IIC_VecFP,
729                      [(set f64:$XT, (fneg f64:$XB))]>;
730  def XSCPSGNDP : XX3Form<60, 176,
731                      (outs vsfrc:$XT), (ins vsfrc:$XA, vsfrc:$XB),
732                      "xscpsgndp $XT, $XA, $XB", IIC_VecFP,
733                      [(set f64:$XT, (fcopysign f64:$XB, f64:$XA))]>;
734
735  def XVABSDP : XX2Form<60, 473,
736                      (outs vsrc:$XT), (ins vsrc:$XB),
737                      "xvabsdp $XT, $XB", IIC_VecFP,
738                      [(set v2f64:$XT, (fabs v2f64:$XB))]>;
739
740  def XVABSSP : XX2Form<60, 409,
741                      (outs vsrc:$XT), (ins vsrc:$XB),
742                      "xvabssp $XT, $XB", IIC_VecFP,
743                      [(set v4f32:$XT, (fabs v4f32:$XB))]>;
744
745  def XVCPSGNDP : XX3Form<60, 240,
746                      (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB),
747                      "xvcpsgndp $XT, $XA, $XB", IIC_VecFP,
748                      [(set v2f64:$XT, (fcopysign v2f64:$XB, v2f64:$XA))]>;
749  def XVCPSGNSP : XX3Form<60, 208,
750                      (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB),
751                      "xvcpsgnsp $XT, $XA, $XB", IIC_VecFP,
752                      [(set v4f32:$XT, (fcopysign v4f32:$XB, v4f32:$XA))]>;
753
754  def XVNABSDP : XX2Form<60, 489,
755                      (outs vsrc:$XT), (ins vsrc:$XB),
756                      "xvnabsdp $XT, $XB", IIC_VecFP,
757                      [(set v2f64:$XT, (fneg (fabs v2f64:$XB)))]>;
758  def XVNABSSP : XX2Form<60, 425,
759                      (outs vsrc:$XT), (ins vsrc:$XB),
760                      "xvnabssp $XT, $XB", IIC_VecFP,
761                      [(set v4f32:$XT, (fneg (fabs v4f32:$XB)))]>;
762
763  def XVNEGDP : XX2Form<60, 505,
764                      (outs vsrc:$XT), (ins vsrc:$XB),
765                      "xvnegdp $XT, $XB", IIC_VecFP,
766                      [(set v2f64:$XT, (fneg v2f64:$XB))]>;
767  def XVNEGSP : XX2Form<60, 441,
768                      (outs vsrc:$XT), (ins vsrc:$XB),
769                      "xvnegsp $XT, $XB", IIC_VecFP,
770                      [(set v4f32:$XT, (fneg v4f32:$XB))]>;
771  }
772
773  // Conversion Instructions
774  def XSCVDPSP : XX2Form<60, 265,
775                      (outs vsfrc:$XT), (ins vsfrc:$XB),
776                      "xscvdpsp $XT, $XB", IIC_VecFP, []>;
777  def XSCVDPSXDS : XX2Form<60, 344,
778                      (outs vsfrc:$XT), (ins vsfrc:$XB),
779                      "xscvdpsxds $XT, $XB", IIC_VecFP,
780                      [(set f64:$XT, (PPCany_fctidz f64:$XB))]>;
781  let isCodeGenOnly = 1 in
782  def XSCVDPSXDSs : XX2Form<60, 344,
783                      (outs vssrc:$XT), (ins vssrc:$XB),
784                      "xscvdpsxds $XT, $XB", IIC_VecFP,
785                      [(set f32:$XT, (PPCany_fctidz f32:$XB))]>;
786  def XSCVDPSXWS : XX2Form<60, 88,
787                      (outs vsfrc:$XT), (ins vsfrc:$XB),
788                      "xscvdpsxws $XT, $XB", IIC_VecFP,
789                      [(set f64:$XT, (PPCany_fctiwz f64:$XB))]>;
790  let isCodeGenOnly = 1 in
791  def XSCVDPSXWSs : XX2Form<60, 88,
792                      (outs vssrc:$XT), (ins vssrc:$XB),
793                      "xscvdpsxws $XT, $XB", IIC_VecFP,
794                      [(set f32:$XT, (PPCany_fctiwz f32:$XB))]>;
795  def XSCVDPUXDS : XX2Form<60, 328,
796                      (outs vsfrc:$XT), (ins vsfrc:$XB),
797                      "xscvdpuxds $XT, $XB", IIC_VecFP,
798                      [(set f64:$XT, (PPCany_fctiduz f64:$XB))]>;
799  let isCodeGenOnly = 1 in
800  def XSCVDPUXDSs : XX2Form<60, 328,
801                      (outs vssrc:$XT), (ins vssrc:$XB),
802                      "xscvdpuxds $XT, $XB", IIC_VecFP,
803                      [(set f32:$XT, (PPCany_fctiduz f32:$XB))]>;
804  def XSCVDPUXWS : XX2Form<60, 72,
805                      (outs vsfrc:$XT), (ins vsfrc:$XB),
806                      "xscvdpuxws $XT, $XB", IIC_VecFP,
807                      [(set f64:$XT, (PPCany_fctiwuz f64:$XB))]>;
808  let isCodeGenOnly = 1 in
809  def XSCVDPUXWSs : XX2Form<60, 72,
810                      (outs vssrc:$XT), (ins vssrc:$XB),
811                      "xscvdpuxws $XT, $XB", IIC_VecFP,
812                      [(set f32:$XT, (PPCany_fctiwuz f32:$XB))]>;
813  def XSCVSPDP : XX2Form<60, 329,
814                      (outs vsfrc:$XT), (ins vsfrc:$XB),
815                      "xscvspdp $XT, $XB", IIC_VecFP, []>;
816  def XSCVSXDDP : XX2Form<60, 376,
817                      (outs vsfrc:$XT), (ins vsfrc:$XB),
818                      "xscvsxddp $XT, $XB", IIC_VecFP,
819                      [(set f64:$XT, (PPCany_fcfid f64:$XB))]>;
820  def XSCVUXDDP : XX2Form<60, 360,
821                      (outs vsfrc:$XT), (ins vsfrc:$XB),
822                      "xscvuxddp $XT, $XB", IIC_VecFP,
823                      [(set f64:$XT, (PPCany_fcfidu f64:$XB))]>;
824
825  def XVCVDPSP : XX2Form<60, 393,
826                      (outs vsrc:$XT), (ins vsrc:$XB),
827                      "xvcvdpsp $XT, $XB", IIC_VecFP,
828                      [(set v4f32:$XT, (int_ppc_vsx_xvcvdpsp v2f64:$XB))]>;
829  def XVCVDPSXDS : XX2Form<60, 472,
830                      (outs vsrc:$XT), (ins vsrc:$XB),
831                      "xvcvdpsxds $XT, $XB", IIC_VecFP,
832                      [(set v2i64:$XT, (any_fp_to_sint v2f64:$XB))]>;
833  def XVCVDPSXWS : XX2Form<60, 216,
834                      (outs vsrc:$XT), (ins vsrc:$XB),
835                      "xvcvdpsxws $XT, $XB", IIC_VecFP,
836                      [(set v4i32:$XT, (int_ppc_vsx_xvcvdpsxws v2f64:$XB))]>;
837  def XVCVDPUXDS : XX2Form<60, 456,
838                      (outs vsrc:$XT), (ins vsrc:$XB),
839                      "xvcvdpuxds $XT, $XB", IIC_VecFP,
840                      [(set v2i64:$XT, (any_fp_to_uint v2f64:$XB))]>;
841  def XVCVDPUXWS : XX2Form<60, 200,
842                      (outs vsrc:$XT), (ins vsrc:$XB),
843                      "xvcvdpuxws $XT, $XB", IIC_VecFP,
844                      [(set v4i32:$XT, (int_ppc_vsx_xvcvdpuxws v2f64:$XB))]>;
845
846  def XVCVSPDP : XX2Form<60, 457,
847                      (outs vsrc:$XT), (ins vsrc:$XB),
848                      "xvcvspdp $XT, $XB", IIC_VecFP,
849                      [(set v2f64:$XT, (int_ppc_vsx_xvcvspdp v4f32:$XB))]>;
850  def XVCVSPSXDS : XX2Form<60, 408,
851                      (outs vsrc:$XT), (ins vsrc:$XB),
852                      "xvcvspsxds $XT, $XB", IIC_VecFP,
853                      [(set v2i64:$XT, (int_ppc_vsx_xvcvspsxds v4f32:$XB))]>;
854  def XVCVSPSXWS : XX2Form<60, 152,
855                      (outs vsrc:$XT), (ins vsrc:$XB),
856                      "xvcvspsxws $XT, $XB", IIC_VecFP,
857                      [(set v4i32:$XT, (any_fp_to_sint v4f32:$XB))]>;
858  def XVCVSPUXDS : XX2Form<60, 392,
859                      (outs vsrc:$XT), (ins vsrc:$XB),
860                      "xvcvspuxds $XT, $XB", IIC_VecFP,
861                      [(set v2i64:$XT, (int_ppc_vsx_xvcvspuxds v4f32:$XB))]>;
862  def XVCVSPUXWS : XX2Form<60, 136,
863                      (outs vsrc:$XT), (ins vsrc:$XB),
864                      "xvcvspuxws $XT, $XB", IIC_VecFP,
865                      [(set v4i32:$XT, (any_fp_to_uint v4f32:$XB))]>;
866  def XVCVSXDDP : XX2Form<60, 504,
867                      (outs vsrc:$XT), (ins vsrc:$XB),
868                      "xvcvsxddp $XT, $XB", IIC_VecFP,
869                      [(set v2f64:$XT, (any_sint_to_fp v2i64:$XB))]>;
870  def XVCVSXDSP : XX2Form<60, 440,
871                      (outs vsrc:$XT), (ins vsrc:$XB),
872                      "xvcvsxdsp $XT, $XB", IIC_VecFP,
873                      [(set v4f32:$XT, (int_ppc_vsx_xvcvsxdsp v2i64:$XB))]>;
874  def XVCVSXWSP : XX2Form<60, 184,
875                      (outs vsrc:$XT), (ins vsrc:$XB),
876                      "xvcvsxwsp $XT, $XB", IIC_VecFP,
877                      [(set v4f32:$XT, (any_sint_to_fp v4i32:$XB))]>;
878  def XVCVUXDDP : XX2Form<60, 488,
879                      (outs vsrc:$XT), (ins vsrc:$XB),
880                      "xvcvuxddp $XT, $XB", IIC_VecFP,
881                      [(set v2f64:$XT, (any_uint_to_fp v2i64:$XB))]>;
882  def XVCVUXDSP : XX2Form<60, 424,
883                      (outs vsrc:$XT), (ins vsrc:$XB),
884                      "xvcvuxdsp $XT, $XB", IIC_VecFP,
885                      [(set v4f32:$XT, (int_ppc_vsx_xvcvuxdsp v2i64:$XB))]>;
886  def XVCVUXWSP : XX2Form<60, 168,
887                      (outs vsrc:$XT), (ins vsrc:$XB),
888                      "xvcvuxwsp $XT, $XB", IIC_VecFP,
889                      [(set v4f32:$XT, (any_uint_to_fp v4i32:$XB))]>;
890
891  let mayRaiseFPException = 0 in {
892  def XVCVSXWDP : XX2Form<60, 248,
893                    (outs vsrc:$XT), (ins vsrc:$XB),
894                    "xvcvsxwdp $XT, $XB", IIC_VecFP,
895                    [(set v2f64:$XT, (int_ppc_vsx_xvcvsxwdp v4i32:$XB))]>;
896  def XVCVUXWDP : XX2Form<60, 232,
897                      (outs vsrc:$XT), (ins vsrc:$XB),
898                      "xvcvuxwdp $XT, $XB", IIC_VecFP,
899                      [(set v2f64:$XT, (int_ppc_vsx_xvcvuxwdp v4i32:$XB))]>;
900  }
901
902  // Rounding Instructions respecting current rounding mode
903  def XSRDPIC : XX2Form<60, 107,
904                      (outs vsfrc:$XT), (ins vsfrc:$XB),
905                      "xsrdpic $XT, $XB", IIC_VecFP,
906                      [(set f64:$XT, (fnearbyint f64:$XB))]>;
907  def XVRDPIC : XX2Form<60, 235,
908                      (outs vsrc:$XT), (ins vsrc:$XB),
909                      "xvrdpic $XT, $XB", IIC_VecFP,
910                      [(set v2f64:$XT, (fnearbyint v2f64:$XB))]>;
911  def XVRSPIC : XX2Form<60, 171,
912                      (outs vsrc:$XT), (ins vsrc:$XB),
913                      "xvrspic $XT, $XB", IIC_VecFP,
914                      [(set v4f32:$XT, (fnearbyint v4f32:$XB))]>;
915  // Max/Min Instructions
916  let isCommutable = 1 in {
917  def XSMAXDP : XX3Form<60, 160,
918                        (outs vsfrc:$XT), (ins vsfrc:$XA, vsfrc:$XB),
919                        "xsmaxdp $XT, $XA, $XB", IIC_VecFP,
920                        [(set vsfrc:$XT,
921                              (int_ppc_vsx_xsmaxdp vsfrc:$XA, vsfrc:$XB))]>;
922  def XSMINDP : XX3Form<60, 168,
923                        (outs vsfrc:$XT), (ins vsfrc:$XA, vsfrc:$XB),
924                        "xsmindp $XT, $XA, $XB", IIC_VecFP,
925                        [(set vsfrc:$XT,
926                              (int_ppc_vsx_xsmindp vsfrc:$XA, vsfrc:$XB))]>;
927
928  def XVMAXDP : XX3Form<60, 224,
929                        (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB),
930                        "xvmaxdp $XT, $XA, $XB", IIC_VecFP,
931                        [(set vsrc:$XT,
932                              (int_ppc_vsx_xvmaxdp vsrc:$XA, vsrc:$XB))]>;
933  def XVMINDP : XX3Form<60, 232,
934                        (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB),
935                        "xvmindp $XT, $XA, $XB", IIC_VecFP,
936                        [(set vsrc:$XT,
937                              (int_ppc_vsx_xvmindp vsrc:$XA, vsrc:$XB))]>;
938
939  def XVMAXSP : XX3Form<60, 192,
940                        (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB),
941                        "xvmaxsp $XT, $XA, $XB", IIC_VecFP,
942                        [(set vsrc:$XT,
943                              (int_ppc_vsx_xvmaxsp vsrc:$XA, vsrc:$XB))]>;
944  def XVMINSP : XX3Form<60, 200,
945                        (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB),
946                        "xvminsp $XT, $XA, $XB", IIC_VecFP,
947                        [(set vsrc:$XT,
948                              (int_ppc_vsx_xvminsp vsrc:$XA, vsrc:$XB))]>;
949  } // isCommutable
950  } // Uses = [RM]
951
952  // Rounding Instructions with static direction.
953  def XSRDPI : XX2Form<60, 73,
954                      (outs vsfrc:$XT), (ins vsfrc:$XB),
955                      "xsrdpi $XT, $XB", IIC_VecFP,
956                      [(set f64:$XT, (any_fround f64:$XB))]>;
957  def XSRDPIM : XX2Form<60, 121,
958                      (outs vsfrc:$XT), (ins vsfrc:$XB),
959                      "xsrdpim $XT, $XB", IIC_VecFP,
960                      [(set f64:$XT, (any_ffloor f64:$XB))]>;
961  def XSRDPIP : XX2Form<60, 105,
962                      (outs vsfrc:$XT), (ins vsfrc:$XB),
963                      "xsrdpip $XT, $XB", IIC_VecFP,
964                      [(set f64:$XT, (any_fceil f64:$XB))]>;
965  def XSRDPIZ : XX2Form<60, 89,
966                      (outs vsfrc:$XT), (ins vsfrc:$XB),
967                      "xsrdpiz $XT, $XB", IIC_VecFP,
968                      [(set f64:$XT, (any_ftrunc f64:$XB))]>;
969
970  def XVRDPI : XX2Form<60, 201,
971                      (outs vsrc:$XT), (ins vsrc:$XB),
972                      "xvrdpi $XT, $XB", IIC_VecFP,
973                      [(set v2f64:$XT, (any_fround v2f64:$XB))]>;
974  def XVRDPIM : XX2Form<60, 249,
975                      (outs vsrc:$XT), (ins vsrc:$XB),
976                      "xvrdpim $XT, $XB", IIC_VecFP,
977                      [(set v2f64:$XT, (any_ffloor v2f64:$XB))]>;
978  def XVRDPIP : XX2Form<60, 233,
979                      (outs vsrc:$XT), (ins vsrc:$XB),
980                      "xvrdpip $XT, $XB", IIC_VecFP,
981                      [(set v2f64:$XT, (any_fceil v2f64:$XB))]>;
982  def XVRDPIZ : XX2Form<60, 217,
983                      (outs vsrc:$XT), (ins vsrc:$XB),
984                      "xvrdpiz $XT, $XB", IIC_VecFP,
985                      [(set v2f64:$XT, (any_ftrunc v2f64:$XB))]>;
986
987  def XVRSPI : XX2Form<60, 137,
988                      (outs vsrc:$XT), (ins vsrc:$XB),
989                      "xvrspi $XT, $XB", IIC_VecFP,
990                      [(set v4f32:$XT, (any_fround v4f32:$XB))]>;
991  def XVRSPIM : XX2Form<60, 185,
992                      (outs vsrc:$XT), (ins vsrc:$XB),
993                      "xvrspim $XT, $XB", IIC_VecFP,
994                      [(set v4f32:$XT, (any_ffloor v4f32:$XB))]>;
995  def XVRSPIP : XX2Form<60, 169,
996                      (outs vsrc:$XT), (ins vsrc:$XB),
997                      "xvrspip $XT, $XB", IIC_VecFP,
998                      [(set v4f32:$XT, (any_fceil v4f32:$XB))]>;
999  def XVRSPIZ : XX2Form<60, 153,
1000                      (outs vsrc:$XT), (ins vsrc:$XB),
1001                      "xvrspiz $XT, $XB", IIC_VecFP,
1002                      [(set v4f32:$XT, (any_ftrunc v4f32:$XB))]>;
1003  } // mayRaiseFPException
1004
1005  // Logical Instructions
1006  let isCommutable = 1 in
1007  def XXLAND : XX3Form<60, 130,
1008                       (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB),
1009                       "xxland $XT, $XA, $XB", IIC_VecGeneral,
1010                       [(set v4i32:$XT, (and v4i32:$XA, v4i32:$XB))]>;
1011  def XXLANDC : XX3Form<60, 138,
1012                        (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB),
1013                        "xxlandc $XT, $XA, $XB", IIC_VecGeneral,
1014                        [(set v4i32:$XT, (and v4i32:$XA,
1015                                              (vnot v4i32:$XB)))]>;
1016  let isCommutable = 1 in {
1017  def XXLNOR : XX3Form<60, 162,
1018                       (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB),
1019                       "xxlnor $XT, $XA, $XB", IIC_VecGeneral,
1020                       [(set v4i32:$XT, (vnot (or v4i32:$XA,
1021                                               v4i32:$XB)))]>;
1022  def XXLOR : XX3Form<60, 146,
1023                      (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB),
1024                      "xxlor $XT, $XA, $XB", IIC_VecGeneral,
1025                      [(set v4i32:$XT, (or v4i32:$XA, v4i32:$XB))]>;
1026  let isCodeGenOnly = 1 in
1027  def XXLORf: XX3Form<60, 146,
1028                      (outs vsfrc:$XT), (ins vsfrc:$XA, vsfrc:$XB),
1029                      "xxlor $XT, $XA, $XB", IIC_VecGeneral, []>;
1030  def XXLXOR : XX3Form<60, 154,
1031                       (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB),
1032                       "xxlxor $XT, $XA, $XB", IIC_VecGeneral,
1033                       [(set v4i32:$XT, (xor v4i32:$XA, v4i32:$XB))]>;
1034  } // isCommutable
1035
1036  let isCodeGenOnly = 1, isMoveImm = 1, isAsCheapAsAMove = 1,
1037      isReMaterializable = 1 in {
1038    def XXLXORz : XX3Form_SameOp<60, 154, (outs vsrc:$XT), (ins),
1039                       "xxlxor $XT, $XT, $XT", IIC_VecGeneral,
1040                       [(set v4i32:$XT, (v4i32 immAllZerosV))]>;
1041    def XXLXORdpz : XX3Form_SameOp<60, 154,
1042                         (outs vsfrc:$XT), (ins),
1043                         "xxlxor $XT, $XT, $XT", IIC_VecGeneral,
1044                         [(set f64:$XT, (fpimm0))]>;
1045    def XXLXORspz : XX3Form_SameOp<60, 154,
1046                         (outs vssrc:$XT), (ins),
1047                         "xxlxor $XT, $XT, $XT", IIC_VecGeneral,
1048                         [(set f32:$XT, (fpimm0))]>;
1049  }
1050
1051  // Permutation Instructions
1052  def XXMRGHW : XX3Form<60, 18,
1053                       (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB),
1054                       "xxmrghw $XT, $XA, $XB", IIC_VecPerm, []>;
1055  def XXMRGLW : XX3Form<60, 50,
1056                       (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB),
1057                       "xxmrglw $XT, $XA, $XB", IIC_VecPerm, []>;
1058
1059  def XXPERMDI : XX3Form_2<60, 10,
1060                       (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB, u2imm:$DM),
1061                       "xxpermdi $XT, $XA, $XB, $DM", IIC_VecPerm,
1062                       [(set v2i64:$XT, (PPCxxpermdi v2i64:$XA, v2i64:$XB,
1063                         imm32SExt16:$DM))]>;
1064  let isCodeGenOnly = 1 in
1065  def XXPERMDIs : XX3Form_2s<60, 10, (outs vsrc:$XT), (ins vsfrc:$XA, u2imm:$DM),
1066                             "xxpermdi $XT, $XA, $XA, $DM", IIC_VecPerm, []>;
1067  def XXSEL : XX4Form<60, 3,
1068                      (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB, vsrc:$XC),
1069                      "xxsel $XT, $XA, $XB, $XC", IIC_VecPerm, []>;
1070
1071  def XXSLDWI : XX3Form_2<60, 2,
1072                       (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB, u2imm:$SHW),
1073                       "xxsldwi $XT, $XA, $XB, $SHW", IIC_VecPerm,
1074                       [(set v4i32:$XT, (PPCvecshl v4i32:$XA, v4i32:$XB,
1075                                                  imm32SExt16:$SHW))]>;
1076
1077  let isCodeGenOnly = 1 in
1078  def XXSLDWIs : XX3Form_2s<60, 2,
1079                       (outs vsrc:$XT), (ins vsfrc:$XA, u2imm:$SHW),
1080                       "xxsldwi $XT, $XA, $XA, $SHW", IIC_VecPerm, []>;
1081
1082  def XXSPLTW : XX2Form_2<60, 164,
1083                       (outs vsrc:$XT), (ins vsrc:$XB, u2imm:$UIM),
1084                       "xxspltw $XT, $XB, $UIM", IIC_VecPerm,
1085                       [(set v4i32:$XT,
1086                             (PPCxxsplt v4i32:$XB, imm32SExt16:$UIM))]>;
1087  let isCodeGenOnly = 1 in
1088  def XXSPLTWs : XX2Form_2<60, 164,
1089                       (outs vsrc:$XT), (ins vsfrc:$XB, u2imm:$UIM),
1090                       "xxspltw $XT, $XB, $UIM", IIC_VecPerm, []>;
1091
1092// The following VSX instructions were introduced in Power ISA 2.07
1093let Predicates = [HasVSX, HasP8Vector] in {
1094  let isCommutable = 1 in {
1095    def XXLEQV : XX3Form<60, 186,
1096                         (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB),
1097                         "xxleqv $XT, $XA, $XB", IIC_VecGeneral,
1098                         [(set v4i32:$XT, (vnot (xor v4i32:$XA, v4i32:$XB)))]>;
1099    def XXLNAND : XX3Form<60, 178,
1100                          (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB),
1101                          "xxlnand $XT, $XA, $XB", IIC_VecGeneral,
1102                          [(set v4i32:$XT, (vnot (and v4i32:$XA, v4i32:$XB)))]>;
1103  } // isCommutable
1104
1105  let isCodeGenOnly = 1, isMoveImm = 1, isAsCheapAsAMove = 1,
1106      isReMaterializable = 1 in {
1107    def XXLEQVOnes : XX3Form_SameOp<60, 186, (outs vsrc:$XT), (ins),
1108                         "xxleqv $XT, $XT, $XT", IIC_VecGeneral,
1109                         [(set v4i32:$XT, (bitconvert (v16i8 immAllOnesV)))]>;
1110  }
1111
1112  def XXLORC : XX3Form<60, 170,
1113                       (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB),
1114                       "xxlorc $XT, $XA, $XB", IIC_VecGeneral,
1115                       [(set v4i32:$XT, (or v4i32:$XA, (vnot v4i32:$XB)))]>;
1116
1117  // VSX scalar loads introduced in ISA 2.07
1118  let mayLoad = 1, mayStore = 0 in {
1119    let CodeSize = 3 in
1120    def LXSSPX : XX1Form_memOp<31, 524, (outs vssrc:$XT), (ins memrr:$src),
1121                         "lxsspx $XT, $src", IIC_LdStLFD, []>;
1122    def LXSIWAX : XX1Form_memOp<31, 76, (outs vsfrc:$XT), (ins memrr:$src),
1123                          "lxsiwax $XT, $src", IIC_LdStLFD, []>;
1124    def LXSIWZX : XX1Form_memOp<31, 12, (outs vsfrc:$XT), (ins memrr:$src),
1125                          "lxsiwzx $XT, $src", IIC_LdStLFD, []>;
1126
1127    // Pseudo instruction XFLOADf32 will be expanded to LXSSPX or LFSX later
1128    let CodeSize = 3 in
1129    def XFLOADf32  : PseudoXFormMemOp<(outs vssrc:$XT), (ins memrr:$src),
1130                            "#XFLOADf32",
1131                            [(set f32:$XT, (load XForm:$src))]>;
1132    // Pseudo instruction LIWAX will be expanded to LXSIWAX or LFIWAX later
1133    def LIWAX : PseudoXFormMemOp<(outs vsfrc:$XT), (ins memrr:$src),
1134                       "#LIWAX",
1135                       [(set f64:$XT, (PPClfiwax ForceXForm:$src))]>;
1136    // Pseudo instruction LIWZX will be expanded to LXSIWZX or LFIWZX later
1137    def LIWZX : PseudoXFormMemOp<(outs vsfrc:$XT), (ins memrr:$src),
1138                       "#LIWZX",
1139                       [(set f64:$XT, (PPClfiwzx ForceXForm:$src))]>;
1140  } // mayLoad
1141
1142  // VSX scalar stores introduced in ISA 2.07
1143  let mayStore = 1, mayLoad = 0 in {
1144    let CodeSize = 3 in
1145    def STXSSPX : XX1Form_memOp<31, 652, (outs), (ins vssrc:$XT, memrr:$dst),
1146                          "stxsspx $XT, $dst", IIC_LdStSTFD, []>;
1147    def STXSIWX : XX1Form_memOp<31, 140, (outs), (ins vsfrc:$XT, memrr:$dst),
1148                          "stxsiwx $XT, $dst", IIC_LdStSTFD, []>;
1149
1150    // Pseudo instruction XFSTOREf32 will be expanded to STXSSPX or STFSX later
1151    let CodeSize = 3 in
1152    def XFSTOREf32 : PseudoXFormMemOp<(outs), (ins vssrc:$XT, memrr:$dst),
1153                            "#XFSTOREf32",
1154                            [(store f32:$XT, XForm:$dst)]>;
1155    // Pseudo instruction STIWX will be expanded to STXSIWX or STFIWX later
1156    def STIWX : PseudoXFormMemOp<(outs), (ins vsfrc:$XT, memrr:$dst),
1157                       "#STIWX",
1158                      [(PPCstfiwx f64:$XT, ForceXForm:$dst)]>;
1159  } // mayStore
1160
1161  // VSX Elementary Scalar FP arithmetic (SP)
1162  let mayRaiseFPException = 1 in {
1163  let isCommutable = 1 in {
1164    def XSADDSP : XX3Form<60, 0,
1165                          (outs vssrc:$XT), (ins vssrc:$XA, vssrc:$XB),
1166                          "xsaddsp $XT, $XA, $XB", IIC_VecFP,
1167                          [(set f32:$XT, (any_fadd f32:$XA, f32:$XB))]>;
1168    def XSMULSP : XX3Form<60, 16,
1169                          (outs vssrc:$XT), (ins vssrc:$XA, vssrc:$XB),
1170                          "xsmulsp $XT, $XA, $XB", IIC_VecFP,
1171                          [(set f32:$XT, (any_fmul f32:$XA, f32:$XB))]>;
1172  } // isCommutable
1173
1174  def XSSUBSP : XX3Form<60, 8,
1175                        (outs vssrc:$XT), (ins vssrc:$XA, vssrc:$XB),
1176                        "xssubsp $XT, $XA, $XB", IIC_VecFP,
1177                        [(set f32:$XT, (any_fsub f32:$XA, f32:$XB))]>;
1178  def XSDIVSP : XX3Form<60, 24,
1179                        (outs vssrc:$XT), (ins vssrc:$XA, vssrc:$XB),
1180                        "xsdivsp $XT, $XA, $XB", IIC_FPDivS,
1181                        [(set f32:$XT, (any_fdiv f32:$XA, f32:$XB))]>;
1182
1183  def XSRESP : XX2Form<60, 26,
1184                        (outs vssrc:$XT), (ins vssrc:$XB),
1185                        "xsresp $XT, $XB", IIC_VecFP,
1186                        [(set f32:$XT, (PPCfre f32:$XB))]>;
1187  // FIXME: Setting the hasSideEffects flag here to match current behaviour.
1188  let hasSideEffects = 1 in
1189  def XSRSP : XX2Form<60, 281,
1190                        (outs vssrc:$XT), (ins vsfrc:$XB),
1191                        "xsrsp $XT, $XB", IIC_VecFP,
1192                        [(set f32:$XT, (any_fpround f64:$XB))]>;
1193  def XSSQRTSP : XX2Form<60, 11,
1194                        (outs vssrc:$XT), (ins vssrc:$XB),
1195                        "xssqrtsp $XT, $XB", IIC_FPSqrtS,
1196                        [(set f32:$XT, (any_fsqrt f32:$XB))]>;
1197  def XSRSQRTESP : XX2Form<60, 10,
1198                           (outs vssrc:$XT), (ins vssrc:$XB),
1199                           "xsrsqrtesp $XT, $XB", IIC_VecFP,
1200                           [(set f32:$XT, (PPCfrsqrte f32:$XB))]>;
1201
1202  // FMA Instructions
1203  let BaseName = "XSMADDASP" in {
1204  let isCommutable = 1 in
1205  def XSMADDASP : XX3Form<60, 1,
1206                          (outs vssrc:$XT),
1207                          (ins vssrc:$XTi, vssrc:$XA, vssrc:$XB),
1208                          "xsmaddasp $XT, $XA, $XB", IIC_VecFP,
1209                          [(set f32:$XT, (any_fma f32:$XA, f32:$XB, f32:$XTi))]>,
1210                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
1211                          AltVSXFMARel;
1212  // FIXME: Setting the hasSideEffects flag here to match current behaviour.
1213  let IsVSXFMAAlt = 1, hasSideEffects = 1 in
1214  def XSMADDMSP : XX3Form<60, 9,
1215                          (outs vssrc:$XT),
1216                          (ins vssrc:$XTi, vssrc:$XA, vssrc:$XB),
1217                          "xsmaddmsp $XT, $XA, $XB", IIC_VecFP, []>,
1218                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
1219                          AltVSXFMARel;
1220  }
1221
1222  let BaseName = "XSMSUBASP" in {
1223  let isCommutable = 1 in
1224  def XSMSUBASP : XX3Form<60, 17,
1225                          (outs vssrc:$XT),
1226                          (ins vssrc:$XTi, vssrc:$XA, vssrc:$XB),
1227                          "xsmsubasp $XT, $XA, $XB", IIC_VecFP,
1228                          [(set f32:$XT, (any_fma f32:$XA, f32:$XB,
1229                                              (fneg f32:$XTi)))]>,
1230                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
1231                          AltVSXFMARel;
1232  // FIXME: Setting the hasSideEffects flag here to match current behaviour.
1233  let IsVSXFMAAlt = 1, hasSideEffects = 1 in
1234  def XSMSUBMSP : XX3Form<60, 25,
1235                          (outs vssrc:$XT),
1236                          (ins vssrc:$XTi, vssrc:$XA, vssrc:$XB),
1237                          "xsmsubmsp $XT, $XA, $XB", IIC_VecFP, []>,
1238                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
1239                          AltVSXFMARel;
1240  }
1241
1242  let BaseName = "XSNMADDASP" in {
1243  let isCommutable = 1 in
1244  def XSNMADDASP : XX3Form<60, 129,
1245                          (outs vssrc:$XT),
1246                          (ins vssrc:$XTi, vssrc:$XA, vssrc:$XB),
1247                          "xsnmaddasp $XT, $XA, $XB", IIC_VecFP,
1248                          [(set f32:$XT, (fneg (any_fma f32:$XA, f32:$XB,
1249                                                    f32:$XTi)))]>,
1250                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
1251                          AltVSXFMARel;
1252  // FIXME: Setting the hasSideEffects flag here to match current behaviour.
1253  let IsVSXFMAAlt = 1, hasSideEffects = 1 in
1254  def XSNMADDMSP : XX3Form<60, 137,
1255                          (outs vssrc:$XT),
1256                          (ins vssrc:$XTi, vssrc:$XA, vssrc:$XB),
1257                          "xsnmaddmsp $XT, $XA, $XB", IIC_VecFP, []>,
1258                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
1259                          AltVSXFMARel;
1260  }
1261
1262  let BaseName = "XSNMSUBASP" in {
1263  let isCommutable = 1 in
1264  def XSNMSUBASP : XX3Form<60, 145,
1265                          (outs vssrc:$XT),
1266                          (ins vssrc:$XTi, vssrc:$XA, vssrc:$XB),
1267                          "xsnmsubasp $XT, $XA, $XB", IIC_VecFP,
1268                          [(set f32:$XT, (fneg (any_fma f32:$XA, f32:$XB,
1269                                                    (fneg f32:$XTi))))]>,
1270                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
1271                          AltVSXFMARel;
1272  // FIXME: Setting the hasSideEffects flag here to match current behaviour.
1273  let IsVSXFMAAlt = 1, hasSideEffects = 1 in
1274  def XSNMSUBMSP : XX3Form<60, 153,
1275                          (outs vssrc:$XT),
1276                          (ins vssrc:$XTi, vssrc:$XA, vssrc:$XB),
1277                          "xsnmsubmsp $XT, $XA, $XB", IIC_VecFP, []>,
1278                          RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">,
1279                          AltVSXFMARel;
1280  }
1281
1282  // Single Precision Conversions (FP <-> INT)
1283  def XSCVSXDSP : XX2Form<60, 312,
1284                      (outs vssrc:$XT), (ins vsfrc:$XB),
1285                      "xscvsxdsp $XT, $XB", IIC_VecFP,
1286                      [(set f32:$XT, (PPCany_fcfids f64:$XB))]>;
1287  def XSCVUXDSP : XX2Form<60, 296,
1288                      (outs vssrc:$XT), (ins vsfrc:$XB),
1289                      "xscvuxdsp $XT, $XB", IIC_VecFP,
1290                      [(set f32:$XT, (PPCany_fcfidus f64:$XB))]>;
1291  } // mayRaiseFPException
1292
1293  // Conversions between vector and scalar single precision
1294  def XSCVDPSPN : XX2Form<60, 267, (outs vsrc:$XT), (ins vssrc:$XB),
1295                          "xscvdpspn $XT, $XB", IIC_VecFP, []>;
1296  def XSCVSPDPN : XX2Form<60, 331, (outs vssrc:$XT), (ins vsrc:$XB),
1297                          "xscvspdpn $XT, $XB", IIC_VecFP, []>;
1298
1299  let Predicates = [HasVSX, HasDirectMove] in {
1300  // VSX direct move instructions
1301  def MFVSRD : XX1_RS6_RD5_XO<31, 51, (outs g8rc:$rA), (ins vsfrc:$XT),
1302                              "mfvsrd $rA, $XT", IIC_VecGeneral,
1303                              [(set i64:$rA, (PPCmfvsr f64:$XT))]>,
1304      Requires<[In64BitMode]>;
1305  // FIXME: Setting the hasSideEffects flag here to match current behaviour.
1306  let isCodeGenOnly = 1, hasSideEffects = 1 in
1307  def MFVRD : XX1_RS6_RD5_XO<31, 51, (outs g8rc:$rA), (ins vsrc:$XT),
1308                             "mfvsrd $rA, $XT", IIC_VecGeneral,
1309                             []>,
1310      Requires<[In64BitMode]>;
1311  def MFVSRWZ : XX1_RS6_RD5_XO<31, 115, (outs gprc:$rA), (ins vsfrc:$XT),
1312                               "mfvsrwz $rA, $XT", IIC_VecGeneral,
1313                               [(set i32:$rA, (PPCmfvsr f64:$XT))]>;
1314  // FIXME: Setting the hasSideEffects flag here to match current behaviour.
1315  let isCodeGenOnly = 1, hasSideEffects = 1 in
1316  def MFVRWZ : XX1_RS6_RD5_XO<31, 115, (outs gprc:$rA), (ins vsrc:$XT),
1317                               "mfvsrwz $rA, $XT", IIC_VecGeneral,
1318                               []>;
1319  def MTVSRD : XX1_RS6_RD5_XO<31, 179, (outs vsfrc:$XT), (ins g8rc:$rA),
1320                              "mtvsrd $XT, $rA", IIC_VecGeneral,
1321                              [(set f64:$XT, (PPCmtvsra i64:$rA))]>,
1322      Requires<[In64BitMode]>;
1323  // FIXME: Setting the hasSideEffects flag here to match current behaviour.
1324  let isCodeGenOnly = 1, hasSideEffects = 1 in
1325  def MTVRD : XX1_RS6_RD5_XO<31, 179, (outs vsrc:$XT), (ins g8rc:$rA),
1326                              "mtvsrd $XT, $rA", IIC_VecGeneral,
1327                              []>,
1328      Requires<[In64BitMode]>;
1329  def MTVSRWA : XX1_RS6_RD5_XO<31, 211, (outs vsfrc:$XT), (ins gprc:$rA),
1330                               "mtvsrwa $XT, $rA", IIC_VecGeneral,
1331                               [(set f64:$XT, (PPCmtvsra i32:$rA))]>;
1332  // FIXME: Setting the hasSideEffects flag here to match current behaviour.
1333  let isCodeGenOnly = 1, hasSideEffects = 1 in
1334  def MTVRWA : XX1_RS6_RD5_XO<31, 211, (outs vsrc:$XT), (ins gprc:$rA),
1335                               "mtvsrwa $XT, $rA", IIC_VecGeneral,
1336                               []>;
1337  def MTVSRWZ : XX1_RS6_RD5_XO<31, 243, (outs vsfrc:$XT), (ins gprc:$rA),
1338                               "mtvsrwz $XT, $rA", IIC_VecGeneral,
1339                               [(set f64:$XT, (PPCmtvsrz i32:$rA))]>;
1340  // FIXME: Setting the hasSideEffects flag here to match current behaviour.
1341  let isCodeGenOnly = 1, hasSideEffects = 1 in
1342  def MTVRWZ : XX1_RS6_RD5_XO<31, 243, (outs vsrc:$XT), (ins gprc:$rA),
1343                               "mtvsrwz $XT, $rA", IIC_VecGeneral,
1344                               []>;
1345  } // HasDirectMove
1346
1347} // HasVSX, HasP8Vector
1348
1349let Predicates = [HasVSX, IsISA3_0, HasDirectMove] in {
1350def MTVSRWS: XX1_RS6_RD5_XO<31, 403, (outs vsrc:$XT), (ins gprc:$rA),
1351                            "mtvsrws $XT, $rA", IIC_VecGeneral, []>;
1352
1353def MTVSRDD: XX1Form<31, 435, (outs vsrc:$XT), (ins g8rc_nox0:$rA, g8rc:$rB),
1354                     "mtvsrdd $XT, $rA, $rB", IIC_VecGeneral,
1355                     []>, Requires<[In64BitMode]>;
1356
1357def MFVSRLD: XX1_RS6_RD5_XO<31, 307, (outs g8rc:$rA), (ins vsrc:$XT),
1358                            "mfvsrld $rA, $XT", IIC_VecGeneral,
1359                            []>, Requires<[In64BitMode]>;
1360
1361} // HasVSX, IsISA3_0, HasDirectMove
1362
1363let Predicates = [HasVSX, HasP9Vector] in {
1364  // Quad-Precision Scalar Move Instructions:
1365  // Copy Sign
1366  def XSCPSGNQP : X_VT5_VA5_VB5<63, 100, "xscpsgnqp",
1367                                [(set f128:$vT,
1368                                      (fcopysign f128:$vB, f128:$vA))]>;
1369
1370  // Absolute/Negative-Absolute/Negate
1371  def XSABSQP   : X_VT5_XO5_VB5<63,  0, 804, "xsabsqp",
1372                                [(set f128:$vT, (fabs f128:$vB))]>;
1373  def XSNABSQP  : X_VT5_XO5_VB5<63,  8, 804, "xsnabsqp",
1374                                [(set f128:$vT, (fneg (fabs f128:$vB)))]>;
1375  def XSNEGQP   : X_VT5_XO5_VB5<63, 16, 804, "xsnegqp",
1376                                [(set f128:$vT, (fneg f128:$vB))]>;
1377
1378  //===--------------------------------------------------------------------===//
1379  // Quad-Precision Scalar Floating-Point Arithmetic Instructions:
1380
1381  // Add/Divide/Multiply/Subtract
1382  let mayRaiseFPException = 1 in {
1383  let isCommutable = 1 in {
1384  def XSADDQP   : X_VT5_VA5_VB5   <63,   4, "xsaddqp",
1385                                   [(set f128:$vT, (any_fadd f128:$vA, f128:$vB))]>;
1386  def XSMULQP   : X_VT5_VA5_VB5   <63,  36, "xsmulqp",
1387                                   [(set f128:$vT, (any_fmul f128:$vA, f128:$vB))]>;
1388  }
1389  def XSSUBQP   : X_VT5_VA5_VB5   <63, 516, "xssubqp" ,
1390                                   [(set f128:$vT, (any_fsub f128:$vA, f128:$vB))]>;
1391  def XSDIVQP   : X_VT5_VA5_VB5   <63, 548, "xsdivqp",
1392                                   [(set f128:$vT, (any_fdiv f128:$vA, f128:$vB))]>;
1393  // Square-Root
1394  def XSSQRTQP  : X_VT5_XO5_VB5   <63, 27, 804, "xssqrtqp",
1395                                   [(set f128:$vT, (any_fsqrt f128:$vB))]>;
1396  // (Negative) Multiply-{Add/Subtract}
1397  def XSMADDQP : X_VT5_VA5_VB5_FMA <63, 388, "xsmaddqp",
1398                                    [(set f128:$vT,
1399                                          (any_fma f128:$vA, f128:$vB, f128:$vTi))]>;
1400  def XSMSUBQP  : X_VT5_VA5_VB5_FMA   <63, 420, "xsmsubqp"  ,
1401                                       [(set f128:$vT,
1402                                             (any_fma f128:$vA, f128:$vB,
1403                                                      (fneg f128:$vTi)))]>;
1404  def XSNMADDQP : X_VT5_VA5_VB5_FMA <63, 452, "xsnmaddqp",
1405                                     [(set f128:$vT,
1406                                           (fneg (any_fma f128:$vA, f128:$vB,
1407                                                          f128:$vTi)))]>;
1408  def XSNMSUBQP : X_VT5_VA5_VB5_FMA <63, 484, "xsnmsubqp",
1409                                     [(set f128:$vT,
1410                                           (fneg (any_fma f128:$vA, f128:$vB,
1411                                                          (fneg f128:$vTi))))]>;
1412
1413  let isCommutable = 1 in {
1414  def XSADDQPO : X_VT5_VA5_VB5_Ro<63, 4, "xsaddqpo",
1415                                  [(set f128:$vT,
1416                                  (int_ppc_addf128_round_to_odd
1417                                  f128:$vA, f128:$vB))]>;
1418  def XSMULQPO : X_VT5_VA5_VB5_Ro<63, 36, "xsmulqpo",
1419                                  [(set f128:$vT,
1420                                  (int_ppc_mulf128_round_to_odd
1421                                  f128:$vA, f128:$vB))]>;
1422  }
1423  def XSSUBQPO : X_VT5_VA5_VB5_Ro<63, 516, "xssubqpo",
1424                                  [(set f128:$vT,
1425                                  (int_ppc_subf128_round_to_odd
1426                                  f128:$vA, f128:$vB))]>;
1427  def XSDIVQPO : X_VT5_VA5_VB5_Ro<63, 548, "xsdivqpo",
1428                                  [(set f128:$vT,
1429                                  (int_ppc_divf128_round_to_odd
1430                                  f128:$vA, f128:$vB))]>;
1431  def XSSQRTQPO : X_VT5_XO5_VB5_Ro<63, 27, 804, "xssqrtqpo",
1432                                  [(set f128:$vT,
1433                                  (int_ppc_sqrtf128_round_to_odd f128:$vB))]>;
1434
1435
1436  def XSMADDQPO : X_VT5_VA5_VB5_FMA_Ro<63, 388, "xsmaddqpo",
1437                                      [(set f128:$vT,
1438                                      (int_ppc_fmaf128_round_to_odd
1439                                      f128:$vA,f128:$vB,f128:$vTi))]>;
1440
1441  def XSMSUBQPO : X_VT5_VA5_VB5_FMA_Ro<63, 420, "xsmsubqpo" ,
1442                                      [(set f128:$vT,
1443                                      (int_ppc_fmaf128_round_to_odd
1444                                      f128:$vA, f128:$vB, (fneg f128:$vTi)))]>;
1445  def XSNMADDQPO: X_VT5_VA5_VB5_FMA_Ro<63, 452, "xsnmaddqpo",
1446                                      [(set f128:$vT,
1447                                      (fneg (int_ppc_fmaf128_round_to_odd
1448                                      f128:$vA, f128:$vB, f128:$vTi)))]>;
1449  def XSNMSUBQPO: X_VT5_VA5_VB5_FMA_Ro<63, 484, "xsnmsubqpo",
1450                                      [(set f128:$vT,
1451                                      (fneg (int_ppc_fmaf128_round_to_odd
1452                                      f128:$vA, f128:$vB, (fneg f128:$vTi))))]>;
1453  } // mayRaiseFPException
1454
1455  // FIXME: Setting the hasSideEffects flag here to match current behaviour.
1456  // QP Compare Ordered/Unordered
1457  let hasSideEffects = 1 in {
1458    // DP/QP Compare Exponents
1459    def XSCMPEXPDP : XX3Form_1<60, 59,
1460                               (outs crrc:$crD), (ins vsfrc:$XA, vsfrc:$XB),
1461                               "xscmpexpdp $crD, $XA, $XB", IIC_FPCompare, []>;
1462    def XSCMPEXPQP : X_BF3_VA5_VB5<63, 164, "xscmpexpqp", []>;
1463
1464    let mayRaiseFPException = 1 in {
1465    def XSCMPOQP : X_BF3_VA5_VB5<63, 132, "xscmpoqp", []>;
1466    def XSCMPUQP : X_BF3_VA5_VB5<63, 644, "xscmpuqp", []>;
1467
1468    // DP Compare ==, >=, >, !=
1469    // Use vsrc for XT, because the entire register of XT is set.
1470    // XT.dword[1] = 0x0000_0000_0000_0000
1471    def XSCMPEQDP : XX3_XT5_XA5_XB5<60,  3, "xscmpeqdp", vsrc, vsfrc, vsfrc,
1472                                    IIC_FPCompare, []>;
1473    def XSCMPGEDP : XX3_XT5_XA5_XB5<60, 19, "xscmpgedp", vsrc, vsfrc, vsfrc,
1474                                    IIC_FPCompare, []>;
1475    def XSCMPGTDP : XX3_XT5_XA5_XB5<60, 11, "xscmpgtdp", vsrc, vsfrc, vsfrc,
1476                                    IIC_FPCompare, []>;
1477    }
1478  }
1479
1480  //===--------------------------------------------------------------------===//
1481  // Quad-Precision Floating-Point Conversion Instructions:
1482
1483  let mayRaiseFPException = 1 in {
1484    // Convert DP -> QP
1485    def XSCVDPQP  : X_VT5_XO5_VB5_TyVB<63, 22, 836, "xscvdpqp", vfrc,
1486                                       [(set f128:$vT, (any_fpextend f64:$vB))]>;
1487
1488    // Round & Convert QP -> DP (dword[1] is set to zero)
1489    def XSCVQPDP  : X_VT5_XO5_VB5_VSFR<63, 20, 836, "xscvqpdp" , []>;
1490    def XSCVQPDPO : X_VT5_XO5_VB5_VSFR_Ro<63, 20, 836, "xscvqpdpo",
1491                                          [(set f64:$vT,
1492                                          (int_ppc_truncf128_round_to_odd
1493                                          f128:$vB))]>;
1494  }
1495
1496  // Truncate & Convert QP -> (Un)Signed (D)Word (dword[1] is set to zero)
1497  let mayRaiseFPException = 1 in {
1498    def XSCVQPSDZ : X_VT5_XO5_VB5<63, 25, 836, "xscvqpsdz", []>;
1499    def XSCVQPSWZ : X_VT5_XO5_VB5<63,  9, 836, "xscvqpswz", []>;
1500    def XSCVQPUDZ : X_VT5_XO5_VB5<63, 17, 836, "xscvqpudz", []>;
1501    def XSCVQPUWZ : X_VT5_XO5_VB5<63,  1, 836, "xscvqpuwz", []>;
1502  }
1503
1504  // Convert (Un)Signed DWord -> QP.
1505  def XSCVSDQP  : X_VT5_XO5_VB5_TyVB<63, 10, 836, "xscvsdqp", vfrc, []>;
1506  def XSCVUDQP  : X_VT5_XO5_VB5_TyVB<63,  2, 836, "xscvudqp", vfrc, []>;
1507
1508  // (Round &) Convert DP <-> HP
1509  // Note! xscvdphp's src and dest register both use the left 64 bits, so we use
1510  // vsfrc for src and dest register. xscvhpdp's src only use the left 16 bits,
1511  // but we still use vsfrc for it.
1512  // FIXME: Setting the hasSideEffects flag here to match current behaviour.
1513  let hasSideEffects = 1, mayRaiseFPException = 1 in {
1514    def XSCVDPHP : XX2_XT6_XO5_XB6<60, 17, 347, "xscvdphp", vsfrc, []>;
1515    def XSCVHPDP : XX2_XT6_XO5_XB6<60, 16, 347, "xscvhpdp", vsfrc, []>;
1516  }
1517
1518  let mayRaiseFPException = 1 in {
1519  // Vector HP -> SP
1520  // FIXME: Setting the hasSideEffects flag here to match current behaviour.
1521  let hasSideEffects = 1 in
1522  def XVCVHPSP : XX2_XT6_XO5_XB6<60, 24, 475, "xvcvhpsp", vsrc, []>;
1523  def XVCVSPHP : XX2_XT6_XO5_XB6<60, 25, 475, "xvcvsphp", vsrc,
1524                                 [(set v4f32:$XT,
1525                                     (int_ppc_vsx_xvcvsphp v4f32:$XB))]>;
1526
1527  // Round to Quad-Precision Integer [with Inexact]
1528  def XSRQPI   : Z23_VT5_R1_VB5_RMC2_EX1<63,  5, 0, "xsrqpi" , []>;
1529  def XSRQPIX  : Z23_VT5_R1_VB5_RMC2_EX1<63,  5, 1, "xsrqpix", []>;
1530
1531  // Round Quad-Precision to Double-Extended Precision (fp80)
1532  // FIXME: Setting the hasSideEffects flag here to match current behaviour.
1533  let hasSideEffects = 1 in
1534  def XSRQPXP  : Z23_VT5_R1_VB5_RMC2_EX1<63, 37, 0, "xsrqpxp", []>;
1535  }
1536
1537  //===--------------------------------------------------------------------===//
1538  // Insert/Extract Instructions
1539
1540  // Insert Exponent DP/QP
1541  // XT NOTE: XT.dword[1] = 0xUUUU_UUUU_UUUU_UUUU
1542  def XSIEXPDP : XX1Form <60, 918, (outs vsrc:$XT), (ins g8rc:$rA, g8rc:$rB),
1543                          "xsiexpdp $XT, $rA, $rB", IIC_VecFP, []>;
1544  // FIXME: Setting the hasSideEffects flag here to match current behaviour.
1545  let hasSideEffects = 1 in {
1546    // vB NOTE: only vB.dword[0] is used, that's why we don't use
1547    //          X_VT5_VA5_VB5 form
1548    def XSIEXPQP : XForm_18<63, 868, (outs vrrc:$vT), (ins vrrc:$vA, vsfrc:$vB),
1549                            "xsiexpqp $vT, $vA, $vB", IIC_VecFP, []>;
1550  }
1551
1552  // Extract Exponent/Significand DP/QP
1553  def XSXEXPDP : XX2_RT5_XO5_XB6<60,  0, 347, "xsxexpdp", []>;
1554  def XSXSIGDP : XX2_RT5_XO5_XB6<60,  1, 347, "xsxsigdp", []>;
1555
1556  // FIXME: Setting the hasSideEffects flag here to match current behaviour.
1557  let hasSideEffects = 1 in {
1558    def XSXEXPQP : X_VT5_XO5_VB5  <63,  2, 804, "xsxexpqp", []>;
1559    def XSXSIGQP : X_VT5_XO5_VB5  <63, 18, 804, "xsxsigqp", []>;
1560  }
1561
1562  // Vector Insert Word
1563  // XB NOTE: Only XB.dword[1] is used, but we use vsrc on XB.
1564  def XXINSERTW   :
1565    XX2_RD6_UIM5_RS6<60, 181, (outs vsrc:$XT),
1566                     (ins vsrc:$XTi, vsrc:$XB, u4imm:$UIM),
1567                     "xxinsertw $XT, $XB, $UIM", IIC_VecFP,
1568                     [(set v4i32:$XT, (PPCvecinsert v4i32:$XTi, v4i32:$XB,
1569                                                   imm32SExt16:$UIM))]>,
1570                     RegConstraint<"$XTi = $XT">, NoEncode<"$XTi">;
1571
1572  // Vector Extract Unsigned Word
1573  // FIXME: Setting the hasSideEffects flag here to match current behaviour.
1574  let hasSideEffects = 1 in
1575  def XXEXTRACTUW : XX2_RD6_UIM5_RS6<60, 165,
1576                                  (outs vsfrc:$XT), (ins vsrc:$XB, u4imm:$UIMM),
1577                                  "xxextractuw $XT, $XB, $UIMM", IIC_VecFP, []>;
1578
1579  // Vector Insert Exponent DP/SP
1580  def XVIEXPDP : XX3_XT5_XA5_XB5<60, 248, "xviexpdp", vsrc, vsrc, vsrc,
1581    IIC_VecFP, [(set v2f64: $XT,(int_ppc_vsx_xviexpdp v2i64:$XA, v2i64:$XB))]>;
1582  def XVIEXPSP : XX3_XT5_XA5_XB5<60, 216, "xviexpsp", vsrc, vsrc, vsrc,
1583    IIC_VecFP, [(set v4f32: $XT,(int_ppc_vsx_xviexpsp v4i32:$XA, v4i32:$XB))]>;
1584
1585  // Vector Extract Exponent/Significand DP/SP
1586  def XVXEXPDP : XX2_XT6_XO5_XB6<60,  0, 475, "xvxexpdp", vsrc,
1587                                 [(set v2i64: $XT,
1588                                  (int_ppc_vsx_xvxexpdp v2f64:$XB))]>;
1589  def XVXEXPSP : XX2_XT6_XO5_XB6<60,  8, 475, "xvxexpsp", vsrc,
1590                                 [(set v4i32: $XT,
1591                                  (int_ppc_vsx_xvxexpsp v4f32:$XB))]>;
1592  def XVXSIGDP : XX2_XT6_XO5_XB6<60,  1, 475, "xvxsigdp", vsrc,
1593                                 [(set v2i64: $XT,
1594                                  (int_ppc_vsx_xvxsigdp v2f64:$XB))]>;
1595  def XVXSIGSP : XX2_XT6_XO5_XB6<60,  9, 475, "xvxsigsp", vsrc,
1596                                 [(set v4i32: $XT,
1597                                  (int_ppc_vsx_xvxsigsp v4f32:$XB))]>;
1598
1599  // Test Data Class SP/DP/QP
1600  // FIXME: Setting the hasSideEffects flag here to match current behaviour.
1601  let hasSideEffects = 1 in {
1602    def XSTSTDCSP : XX2_BF3_DCMX7_RS6<60, 298,
1603                                (outs crrc:$BF), (ins u7imm:$DCMX, vsfrc:$XB),
1604                                "xststdcsp $BF, $XB, $DCMX", IIC_VecFP, []>;
1605    def XSTSTDCDP : XX2_BF3_DCMX7_RS6<60, 362,
1606                                (outs crrc:$BF), (ins u7imm:$DCMX, vsfrc:$XB),
1607                                "xststdcdp $BF, $XB, $DCMX", IIC_VecFP, []>;
1608    def XSTSTDCQP : X_BF3_DCMX7_RS5  <63, 708,
1609                                (outs crrc:$BF), (ins u7imm:$DCMX, vrrc:$vB),
1610                                "xststdcqp $BF, $vB, $DCMX", IIC_VecFP, []>;
1611  }
1612
1613  // Vector Test Data Class SP/DP
1614  def XVTSTDCSP : XX2_RD6_DCMX7_RS6<60, 13, 5,
1615                              (outs vsrc:$XT), (ins u7imm:$DCMX, vsrc:$XB),
1616                              "xvtstdcsp $XT, $XB, $DCMX", IIC_VecFP,
1617                              [(set v4i32: $XT,
1618                               (int_ppc_vsx_xvtstdcsp v4f32:$XB, timm:$DCMX))]>;
1619  def XVTSTDCDP : XX2_RD6_DCMX7_RS6<60, 15, 5,
1620                              (outs vsrc:$XT), (ins u7imm:$DCMX, vsrc:$XB),
1621                              "xvtstdcdp $XT, $XB, $DCMX", IIC_VecFP,
1622                              [(set v2i64: $XT,
1623                               (int_ppc_vsx_xvtstdcdp v2f64:$XB, timm:$DCMX))]>;
1624
1625  // Maximum/Minimum Type-C/Type-J DP
1626  let mayRaiseFPException = 1 in {
1627  def XSMAXCDP : XX3_XT5_XA5_XB5<60, 128, "xsmaxcdp", vsfrc, vsfrc, vsfrc,
1628                                 IIC_VecFP,
1629                                 [(set f64:$XT, (PPCxsmaxc f64:$XA, f64:$XB))]>;
1630  def XSMINCDP : XX3_XT5_XA5_XB5<60, 136, "xsmincdp", vsfrc, vsfrc, vsfrc,
1631                                 IIC_VecFP,
1632                                 [(set f64:$XT, (PPCxsminc f64:$XA, f64:$XB))]>;
1633
1634  // FIXME: Setting the hasSideEffects flag here to match current behaviour.
1635  let hasSideEffects = 1 in {
1636    def XSMAXJDP : XX3_XT5_XA5_XB5<60, 144, "xsmaxjdp", vsrc, vsfrc, vsfrc,
1637                                   IIC_VecFP, []>;
1638    def XSMINJDP : XX3_XT5_XA5_XB5<60, 152, "xsminjdp", vsrc, vsfrc, vsfrc,
1639                                   IIC_VecFP, []>;
1640  }
1641  }
1642
1643  // Vector Byte-Reverse H/W/D/Q Word
1644  // FIXME: Setting the hasSideEffects flag here to match current behaviour.
1645  let hasSideEffects = 1 in
1646  def XXBRH : XX2_XT6_XO5_XB6<60,  7, 475, "xxbrh", vsrc, []>;
1647  def XXBRW : XX2_XT6_XO5_XB6<60, 15, 475, "xxbrw", vsrc,
1648    [(set v4i32:$XT, (bswap v4i32:$XB))]>;
1649  def XXBRD : XX2_XT6_XO5_XB6<60, 23, 475, "xxbrd", vsrc,
1650    [(set v2i64:$XT, (bswap v2i64:$XB))]>;
1651  // FIXME: Setting the hasSideEffects flag here to match current behaviour.
1652  let hasSideEffects = 1 in
1653  def XXBRQ : XX2_XT6_XO5_XB6<60, 31, 475, "xxbrq", vsrc, []>;
1654
1655  // Vector Permute
1656  // FIXME: Setting the hasSideEffects flag here to match current behaviour.
1657  let hasSideEffects = 1 in {
1658    def XXPERM  : XX3_XT5_XA5_XB5<60, 26, "xxperm" , vsrc, vsrc, vsrc,
1659                                  IIC_VecPerm, []>;
1660    def XXPERMR : XX3_XT5_XA5_XB5<60, 58, "xxpermr", vsrc, vsrc, vsrc,
1661                                  IIC_VecPerm, []>;
1662  }
1663
1664  // Vector Splat Immediate Byte
1665  // FIXME: Setting the hasSideEffects flag here to match current behaviour.
1666  let hasSideEffects = 1 in
1667  def XXSPLTIB : X_RD6_IMM8<60, 360, (outs vsrc:$XT), (ins u8imm:$IMM8),
1668                            "xxspltib $XT, $IMM8", IIC_VecPerm, []>;
1669
1670  // When adding new D-Form loads/stores, be sure to update the ImmToIdxMap in
1671  // PPCRegisterInfo::PPCRegisterInfo and maybe save yourself some debugging.
1672  let mayLoad = 1, mayStore = 0 in {
1673  // Load Vector
1674  def LXV : DQ_RD6_RS5_DQ12<61, 1, (outs vsrc:$XT), (ins memrix16:$src),
1675                            "lxv $XT, $src", IIC_LdStLFD, []>;
1676  // Load DWord
1677  def LXSD  : DSForm_1<57, 2, (outs vfrc:$vD), (ins memrix:$src),
1678                       "lxsd $vD, $src", IIC_LdStLFD, []>;
1679  // Load SP from src, convert it to DP, and place in dword[0]
1680  def LXSSP : DSForm_1<57, 3, (outs vfrc:$vD), (ins memrix:$src),
1681                       "lxssp $vD, $src", IIC_LdStLFD, []>;
1682
1683  // Load as Integer Byte/Halfword & Zero Indexed
1684  def LXSIBZX : X_XT6_RA5_RB5<31, 781, "lxsibzx", vsfrc,
1685                              [(set f64:$XT, (PPClxsizx ForceXForm:$src, 1))]>;
1686  def LXSIHZX : X_XT6_RA5_RB5<31, 813, "lxsihzx", vsfrc,
1687                              [(set f64:$XT, (PPClxsizx ForceXForm:$src, 2))]>;
1688
1689  // Load Vector Halfword*8/Byte*16 Indexed
1690  def LXVH8X  : X_XT6_RA5_RB5<31, 812, "lxvh8x" , vsrc, []>;
1691  def LXVB16X : X_XT6_RA5_RB5<31, 876, "lxvb16x", vsrc, []>;
1692
1693  // Load Vector Indexed
1694  def LXVX    : X_XT6_RA5_RB5<31, 268, "lxvx"   , vsrc,
1695                [(set v2f64:$XT, (load XForm:$src))]>;
1696  // Load Vector (Left-justified) with Length
1697  def LXVL : XX1Form_memOp<31, 269, (outs vsrc:$XT), (ins memr:$src, g8rc:$rB),
1698                   "lxvl $XT, $src, $rB", IIC_LdStLoad,
1699                   [(set v4i32:$XT, (int_ppc_vsx_lxvl addr:$src, i64:$rB))]>;
1700  def LXVLL : XX1Form_memOp<31,301, (outs vsrc:$XT), (ins memr:$src, g8rc:$rB),
1701                   "lxvll $XT, $src, $rB", IIC_LdStLoad,
1702                   [(set v4i32:$XT, (int_ppc_vsx_lxvll addr:$src, i64:$rB))]>;
1703
1704  // Load Vector Word & Splat Indexed
1705  def LXVWSX  : X_XT6_RA5_RB5<31, 364, "lxvwsx" , vsrc, []>;
1706  } // mayLoad
1707
1708  // When adding new D-Form loads/stores, be sure to update the ImmToIdxMap in
1709  // PPCRegisterInfo::PPCRegisterInfo and maybe save yourself some debugging.
1710  let mayStore = 1, mayLoad = 0 in {
1711  // Store Vector
1712  def STXV : DQ_RD6_RS5_DQ12<61, 5, (outs), (ins vsrc:$XT, memrix16:$dst),
1713                             "stxv $XT, $dst", IIC_LdStSTFD, []>;
1714  // Store DWord
1715  def STXSD  : DSForm_1<61, 2, (outs), (ins vfrc:$vS, memrix:$dst),
1716                        "stxsd $vS, $dst", IIC_LdStSTFD, []>;
1717  // Convert DP of dword[0] to SP, and Store to dst
1718  def STXSSP : DSForm_1<61, 3, (outs), (ins vfrc:$vS, memrix:$dst),
1719                        "stxssp $vS, $dst", IIC_LdStSTFD, []>;
1720
1721  // Store as Integer Byte/Halfword Indexed
1722  def STXSIBX  : X_XS6_RA5_RB5<31,  909, "stxsibx" , vsfrc,
1723                               [(PPCstxsix f64:$XT, ForceXForm:$dst, 1)]>;
1724  def STXSIHX  : X_XS6_RA5_RB5<31,  941, "stxsihx" , vsfrc,
1725                               [(PPCstxsix f64:$XT, ForceXForm:$dst, 2)]>;
1726  let isCodeGenOnly = 1 in {
1727    def STXSIBXv  : X_XS6_RA5_RB5<31,  909, "stxsibx" , vsrc, []>;
1728    def STXSIHXv  : X_XS6_RA5_RB5<31,  941, "stxsihx" , vsrc, []>;
1729  }
1730
1731  // Store Vector Halfword*8/Byte*16 Indexed
1732  def STXVH8X  : X_XS6_RA5_RB5<31,  940, "stxvh8x" , vsrc, []>;
1733  def STXVB16X : X_XS6_RA5_RB5<31, 1004, "stxvb16x", vsrc, []>;
1734
1735  // Store Vector Indexed
1736  def STXVX    : X_XS6_RA5_RB5<31,  396, "stxvx"   , vsrc,
1737                 [(store v2f64:$XT, XForm:$dst)]>;
1738
1739  // Store Vector (Left-justified) with Length
1740  def STXVL : XX1Form_memOp<31, 397, (outs),
1741                            (ins vsrc:$XT, memr:$dst, g8rc:$rB),
1742                            "stxvl $XT, $dst, $rB", IIC_LdStLoad,
1743                            [(int_ppc_vsx_stxvl v4i32:$XT, addr:$dst,
1744                              i64:$rB)]>;
1745  def STXVLL : XX1Form_memOp<31, 429, (outs),
1746                            (ins vsrc:$XT, memr:$dst, g8rc:$rB),
1747                            "stxvll $XT, $dst, $rB", IIC_LdStLoad,
1748                            [(int_ppc_vsx_stxvll v4i32:$XT, addr:$dst,
1749                              i64:$rB)]>;
1750  } // mayStore
1751
1752  def DFLOADf32  : PPCPostRAExpPseudo<(outs vssrc:$XT), (ins memrix:$src),
1753                          "#DFLOADf32",
1754                          [(set f32:$XT, (load DSForm:$src))]>;
1755  def DFLOADf64  : PPCPostRAExpPseudo<(outs vsfrc:$XT), (ins memrix:$src),
1756                          "#DFLOADf64",
1757                          [(set f64:$XT, (load DSForm:$src))]>;
1758  def DFSTOREf32 : PPCPostRAExpPseudo<(outs), (ins vssrc:$XT, memrix:$dst),
1759                          "#DFSTOREf32",
1760                          [(store f32:$XT, DSForm:$dst)]>;
1761  def DFSTOREf64 : PPCPostRAExpPseudo<(outs), (ins vsfrc:$XT, memrix:$dst),
1762                          "#DFSTOREf64",
1763                          [(store f64:$XT, DSForm:$dst)]>;
1764
1765  let mayStore = 1 in {
1766    def SPILLTOVSR_STX : PseudoXFormMemOp<(outs),
1767                                          (ins spilltovsrrc:$XT, memrr:$dst),
1768                                          "#SPILLTOVSR_STX", []>;
1769    def SPILLTOVSR_ST : PPCPostRAExpPseudo<(outs), (ins spilltovsrrc:$XT, memrix:$dst),
1770                              "#SPILLTOVSR_ST", []>;
1771  }
1772  let mayLoad = 1 in {
1773    def SPILLTOVSR_LDX : PseudoXFormMemOp<(outs spilltovsrrc:$XT),
1774                                          (ins memrr:$src),
1775                                          "#SPILLTOVSR_LDX", []>;
1776    def SPILLTOVSR_LD : PPCPostRAExpPseudo<(outs spilltovsrrc:$XT), (ins memrix:$src),
1777                              "#SPILLTOVSR_LD", []>;
1778
1779  }
1780  } // HasP9Vector
1781} // hasSideEffects = 0
1782
1783let PPC970_Single = 1, AddedComplexity = 400 in {
1784
1785  def SELECT_CC_VSRC: PPCCustomInserterPseudo<(outs vsrc:$dst),
1786                             (ins crrc:$cond, vsrc:$T, vsrc:$F, i32imm:$BROPC),
1787                             "#SELECT_CC_VSRC",
1788                             []>;
1789  def SELECT_VSRC: PPCCustomInserterPseudo<(outs vsrc:$dst),
1790                          (ins crbitrc:$cond, vsrc:$T, vsrc:$F),
1791                          "#SELECT_VSRC",
1792                          [(set v2f64:$dst,
1793                                (select i1:$cond, v2f64:$T, v2f64:$F))]>;
1794  def SELECT_CC_VSFRC: PPCCustomInserterPseudo<(outs f8rc:$dst),
1795                              (ins crrc:$cond, f8rc:$T, f8rc:$F,
1796                               i32imm:$BROPC), "#SELECT_CC_VSFRC",
1797                              []>;
1798  def SELECT_VSFRC: PPCCustomInserterPseudo<(outs f8rc:$dst),
1799                           (ins crbitrc:$cond, f8rc:$T, f8rc:$F),
1800                           "#SELECT_VSFRC",
1801                           [(set f64:$dst,
1802                                 (select i1:$cond, f64:$T, f64:$F))]>;
1803  def SELECT_CC_VSSRC: PPCCustomInserterPseudo<(outs f4rc:$dst),
1804                              (ins crrc:$cond, f4rc:$T, f4rc:$F,
1805                               i32imm:$BROPC), "#SELECT_CC_VSSRC",
1806                              []>;
1807  def SELECT_VSSRC: PPCCustomInserterPseudo<(outs f4rc:$dst),
1808                           (ins crbitrc:$cond, f4rc:$T, f4rc:$F),
1809                           "#SELECT_VSSRC",
1810                           [(set f32:$dst,
1811                                 (select i1:$cond, f32:$T, f32:$F))]>;
1812}
1813}
1814
1815//----------------------------- DAG Definitions ------------------------------//
1816
1817// Output dag used to bitcast f32 to i32 and f64 to i64
1818def Bitcast {
1819  dag FltToInt = (i32 (MFVSRWZ (EXTRACT_SUBREG (XSCVDPSPN $A), sub_64)));
1820  dag DblToLong = (i64 (MFVSRD $A));
1821}
1822
1823def FpMinMax {
1824  dag F32Min = (COPY_TO_REGCLASS (XSMINDP (COPY_TO_REGCLASS $A, VSFRC),
1825                                          (COPY_TO_REGCLASS $B, VSFRC)),
1826                                 VSSRC);
1827  dag F32Max = (COPY_TO_REGCLASS (XSMAXDP (COPY_TO_REGCLASS $A, VSFRC),
1828                                          (COPY_TO_REGCLASS $B, VSFRC)),
1829                                 VSSRC);
1830}
1831
1832def ScalarLoads {
1833  dag Li8 =       (i32 (extloadi8 ForceXForm:$src));
1834  dag ZELi8 =     (i32 (zextloadi8 ForceXForm:$src));
1835  dag ZELi8i64 =  (i64 (zextloadi8 ForceXForm:$src));
1836  dag SELi8 =     (i32 (sext_inreg (extloadi8 ForceXForm:$src), i8));
1837  dag SELi8i64 =  (i64 (sext_inreg (extloadi8 ForceXForm:$src), i8));
1838
1839  dag Li16 =      (i32 (extloadi16 ForceXForm:$src));
1840  dag ZELi16 =    (i32 (zextloadi16 ForceXForm:$src));
1841  dag ZELi16i64 = (i64 (zextloadi16 ForceXForm:$src));
1842  dag SELi16 =    (i32 (sextloadi16 ForceXForm:$src));
1843  dag SELi16i64 = (i64 (sextloadi16 ForceXForm:$src));
1844
1845  dag Li32 = (i32 (load ForceXForm:$src));
1846}
1847
1848def DWToSPExtractConv {
1849  dag El0US1 = (f32 (PPCfcfidus
1850                    (f64 (PPCmtvsra (i64 (vector_extract v2i64:$S1, 0))))));
1851  dag El1US1 = (f32 (PPCfcfidus
1852                    (f64 (PPCmtvsra (i64 (vector_extract v2i64:$S1, 1))))));
1853  dag El0US2 = (f32 (PPCfcfidus
1854                    (f64 (PPCmtvsra (i64 (vector_extract v2i64:$S2, 0))))));
1855  dag El1US2 = (f32 (PPCfcfidus
1856                    (f64 (PPCmtvsra (i64 (vector_extract v2i64:$S2, 1))))));
1857  dag El0SS1 = (f32 (PPCfcfids
1858                    (f64 (PPCmtvsra (i64 (vector_extract v2i64:$S1, 0))))));
1859  dag El1SS1 = (f32 (PPCfcfids
1860                    (f64 (PPCmtvsra (i64 (vector_extract v2i64:$S1, 1))))));
1861  dag El0SS2 = (f32 (PPCfcfids
1862                    (f64 (PPCmtvsra (i64 (vector_extract v2i64:$S2, 0))))));
1863  dag El1SS2 = (f32 (PPCfcfids
1864                    (f64 (PPCmtvsra (i64 (vector_extract v2i64:$S2, 1))))));
1865  dag BVU = (v4f32 (build_vector El0US1, El1US1, El0US2, El1US2));
1866  dag BVS = (v4f32 (build_vector El0SS1, El1SS1, El0SS2, El1SS2));
1867}
1868
1869def WToDPExtractConv {
1870  dag El0S = (f64 (PPCfcfid (PPCmtvsra (extractelt v4i32:$A, 0))));
1871  dag El1S = (f64 (PPCfcfid (PPCmtvsra (extractelt v4i32:$A, 1))));
1872  dag El2S = (f64 (PPCfcfid (PPCmtvsra (extractelt v4i32:$A, 2))));
1873  dag El3S = (f64 (PPCfcfid (PPCmtvsra (extractelt v4i32:$A, 3))));
1874  dag El0U = (f64 (PPCfcfidu (PPCmtvsrz (extractelt v4i32:$A, 0))));
1875  dag El1U = (f64 (PPCfcfidu (PPCmtvsrz (extractelt v4i32:$A, 1))));
1876  dag El2U = (f64 (PPCfcfidu (PPCmtvsrz (extractelt v4i32:$A, 2))));
1877  dag El3U = (f64 (PPCfcfidu (PPCmtvsrz (extractelt v4i32:$A, 3))));
1878  dag BV02S = (v2f64 (build_vector El0S, El2S));
1879  dag BV13S = (v2f64 (build_vector El1S, El3S));
1880  dag BV02U = (v2f64 (build_vector El0U, El2U));
1881  dag BV13U = (v2f64 (build_vector El1U, El3U));
1882}
1883
1884/*  Direct moves of various widths from GPR's into VSR's. Each move lines
1885    the value up into element 0 (both BE and LE). Namely, entities smaller than
1886    a doubleword are shifted left and moved for BE. For LE, they're moved, then
1887    swapped to go into the least significant element of the VSR.
1888*/
1889def MovesToVSR {
1890  dag BE_BYTE_0 =
1891    (MTVSRD
1892      (RLDICR
1893        (INSERT_SUBREG (i64 (IMPLICIT_DEF)), $A, sub_32), 56, 7));
1894  dag BE_HALF_0 =
1895    (MTVSRD
1896      (RLDICR
1897        (INSERT_SUBREG (i64 (IMPLICIT_DEF)), $A, sub_32), 48, 15));
1898  dag BE_WORD_0 =
1899    (MTVSRD
1900      (RLDICR
1901        (INSERT_SUBREG (i64 (IMPLICIT_DEF)), $A, sub_32), 32, 31));
1902  dag BE_DWORD_0 = (MTVSRD $A);
1903
1904  dag LE_MTVSRW = (MTVSRD (INSERT_SUBREG (i64 (IMPLICIT_DEF)), $A, sub_32));
1905  dag LE_WORD_1 = (v2i64 (INSERT_SUBREG (v2i64 (IMPLICIT_DEF)),
1906                                        LE_MTVSRW, sub_64));
1907  dag LE_WORD_0 = (XXPERMDI LE_WORD_1, LE_WORD_1, 2);
1908  dag LE_DWORD_1 = (v2i64 (INSERT_SUBREG (v2i64 (IMPLICIT_DEF)),
1909                                         BE_DWORD_0, sub_64));
1910  dag LE_DWORD_0 = (XXPERMDI LE_DWORD_1, LE_DWORD_1, 2);
1911}
1912
1913/*  Patterns for extracting elements out of vectors. Integer elements are
1914    extracted using direct move operations. Patterns for extracting elements
1915    whose indices are not available at compile time are also provided with
1916    various _VARIABLE_ patterns.
1917    The numbering for the DAG's is for LE, but when used on BE, the correct
1918    LE element can just be used (i.e. LE_BYTE_2 == BE_BYTE_13).
1919*/
1920def VectorExtractions {
1921  // Doubleword extraction
1922  dag LE_DWORD_0 =
1923    (MFVSRD
1924      (EXTRACT_SUBREG
1925        (XXPERMDI (COPY_TO_REGCLASS $S, VSRC),
1926                  (COPY_TO_REGCLASS $S, VSRC), 2), sub_64));
1927  dag LE_DWORD_1 = (MFVSRD
1928                     (EXTRACT_SUBREG
1929                       (v2i64 (COPY_TO_REGCLASS $S, VSRC)), sub_64));
1930
1931  // Word extraction
1932  dag LE_WORD_0 = (MFVSRWZ (EXTRACT_SUBREG (XXPERMDI $S, $S, 2), sub_64));
1933  dag LE_WORD_1 = (MFVSRWZ (EXTRACT_SUBREG (XXSLDWI $S, $S, 1), sub_64));
1934  dag LE_WORD_2 = (MFVSRWZ (EXTRACT_SUBREG
1935                             (v2i64 (COPY_TO_REGCLASS $S, VSRC)), sub_64));
1936  dag LE_WORD_3 = (MFVSRWZ (EXTRACT_SUBREG (XXSLDWI $S, $S, 3), sub_64));
1937
1938  // Halfword extraction
1939  dag LE_HALF_0 = (i32 (EXTRACT_SUBREG (RLDICL LE_DWORD_0, 0, 48), sub_32));
1940  dag LE_HALF_1 = (i32 (EXTRACT_SUBREG (RLDICL LE_DWORD_0, 48, 48), sub_32));
1941  dag LE_HALF_2 = (i32 (EXTRACT_SUBREG (RLDICL LE_DWORD_0, 32, 48), sub_32));
1942  dag LE_HALF_3 = (i32 (EXTRACT_SUBREG (RLDICL LE_DWORD_0, 16, 48), sub_32));
1943  dag LE_HALF_4 = (i32 (EXTRACT_SUBREG (RLDICL LE_DWORD_1, 0, 48), sub_32));
1944  dag LE_HALF_5 = (i32 (EXTRACT_SUBREG (RLDICL LE_DWORD_1, 48, 48), sub_32));
1945  dag LE_HALF_6 = (i32 (EXTRACT_SUBREG (RLDICL LE_DWORD_1, 32, 48), sub_32));
1946  dag LE_HALF_7 = (i32 (EXTRACT_SUBREG (RLDICL LE_DWORD_1, 16, 48), sub_32));
1947
1948  // Byte extraction
1949  dag LE_BYTE_0 = (i32 (EXTRACT_SUBREG (RLDICL LE_DWORD_0, 0, 56), sub_32));
1950  dag LE_BYTE_1 = (i32 (EXTRACT_SUBREG (RLDICL LE_DWORD_0, 56, 56), sub_32));
1951  dag LE_BYTE_2 = (i32 (EXTRACT_SUBREG (RLDICL LE_DWORD_0, 48, 56), sub_32));
1952  dag LE_BYTE_3 = (i32 (EXTRACT_SUBREG (RLDICL LE_DWORD_0, 40, 56), sub_32));
1953  dag LE_BYTE_4 = (i32 (EXTRACT_SUBREG (RLDICL LE_DWORD_0, 32, 56), sub_32));
1954  dag LE_BYTE_5 = (i32 (EXTRACT_SUBREG (RLDICL LE_DWORD_0, 24, 56), sub_32));
1955  dag LE_BYTE_6 = (i32 (EXTRACT_SUBREG (RLDICL LE_DWORD_0, 16, 56), sub_32));
1956  dag LE_BYTE_7 = (i32 (EXTRACT_SUBREG (RLDICL LE_DWORD_0, 8, 56), sub_32));
1957  dag LE_BYTE_8 = (i32 (EXTRACT_SUBREG (RLDICL LE_DWORD_1, 0, 56), sub_32));
1958  dag LE_BYTE_9 = (i32 (EXTRACT_SUBREG (RLDICL LE_DWORD_1, 56, 56), sub_32));
1959  dag LE_BYTE_10 = (i32 (EXTRACT_SUBREG (RLDICL LE_DWORD_1, 48, 56), sub_32));
1960  dag LE_BYTE_11 = (i32 (EXTRACT_SUBREG (RLDICL LE_DWORD_1, 40, 56), sub_32));
1961  dag LE_BYTE_12 = (i32 (EXTRACT_SUBREG (RLDICL LE_DWORD_1, 32, 56), sub_32));
1962  dag LE_BYTE_13 = (i32 (EXTRACT_SUBREG (RLDICL LE_DWORD_1, 24, 56), sub_32));
1963  dag LE_BYTE_14 = (i32 (EXTRACT_SUBREG (RLDICL LE_DWORD_1, 16, 56), sub_32));
1964  dag LE_BYTE_15 = (i32 (EXTRACT_SUBREG (RLDICL LE_DWORD_1, 8, 56), sub_32));
1965
1966  /* Variable element number (BE and LE patterns must be specified separately)
1967     This is a rather involved process.
1968
1969     Conceptually, this is how the move is accomplished:
1970     1. Identify which doubleword contains the element
1971     2. Shift in the VMX register so that the correct doubleword is correctly
1972        lined up for the MFVSRD
1973     3. Perform the move so that the element (along with some extra stuff)
1974        is in the GPR
1975     4. Right shift within the GPR so that the element is right-justified
1976
1977     Of course, the index is an element number which has a different meaning
1978     on LE/BE so the patterns have to be specified separately.
1979
1980     Note: The final result will be the element right-justified with high
1981           order bits being arbitrarily defined (namely, whatever was in the
1982           vector register to the left of the value originally).
1983  */
1984
1985  /*  LE variable byte
1986      Number 1. above:
1987      - For elements 0-7, we shift left by 8 bytes since they're on the right
1988      - For elements 8-15, we need not shift (shift left by zero bytes)
1989      This is accomplished by inverting the bits of the index and AND-ing
1990      with 0x8 (i.e. clearing all bits of the index and inverting bit 60).
1991  */
1992  dag LE_VBYTE_PERM_VEC = (v16i8 (LVSL ZERO8, (ANDC8 (LI8 8), $Idx)));
1993
1994  //  Number 2. above:
1995  //  - Now that we set up the shift amount, we shift in the VMX register
1996  dag LE_VBYTE_PERMUTE = (v16i8 (VPERM $S, $S, LE_VBYTE_PERM_VEC));
1997
1998  //  Number 3. above:
1999  //  - The doubleword containing our element is moved to a GPR
2000  dag LE_MV_VBYTE = (MFVSRD
2001                      (EXTRACT_SUBREG
2002                        (v2i64 (COPY_TO_REGCLASS LE_VBYTE_PERMUTE, VSRC)),
2003                        sub_64));
2004
2005  /*  Number 4. above:
2006      - Truncate the element number to the range 0-7 (8-15 are symmetrical
2007        and out of range values are truncated accordingly)
2008      - Multiply by 8 as we need to shift right by the number of bits, not bytes
2009      - Shift right in the GPR by the calculated value
2010  */
2011  dag LE_VBYTE_SHIFT = (EXTRACT_SUBREG (RLDICR (AND8 (LI8 7), $Idx), 3, 60),
2012                                       sub_32);
2013  dag LE_VARIABLE_BYTE = (EXTRACT_SUBREG (SRD LE_MV_VBYTE, LE_VBYTE_SHIFT),
2014                                         sub_32);
2015
2016  /*  LE variable halfword
2017      Number 1. above:
2018      - For elements 0-3, we shift left by 8 since they're on the right
2019      - For elements 4-7, we need not shift (shift left by zero bytes)
2020      Similarly to the byte pattern, we invert the bits of the index, but we
2021      AND with 0x4 (i.e. clear all bits of the index and invert bit 61).
2022      Of course, the shift is still by 8 bytes, so we must multiply by 2.
2023  */
2024  dag LE_VHALF_PERM_VEC =
2025    (v16i8 (LVSL ZERO8, (RLDICR (ANDC8 (LI8 4), $Idx), 1, 62)));
2026
2027  //  Number 2. above:
2028  //  - Now that we set up the shift amount, we shift in the VMX register
2029  dag LE_VHALF_PERMUTE = (v16i8 (VPERM $S, $S, LE_VHALF_PERM_VEC));
2030
2031  //  Number 3. above:
2032  //  - The doubleword containing our element is moved to a GPR
2033  dag LE_MV_VHALF = (MFVSRD
2034                      (EXTRACT_SUBREG
2035                        (v2i64 (COPY_TO_REGCLASS LE_VHALF_PERMUTE, VSRC)),
2036                        sub_64));
2037
2038  /*  Number 4. above:
2039      - Truncate the element number to the range 0-3 (4-7 are symmetrical
2040        and out of range values are truncated accordingly)
2041      - Multiply by 16 as we need to shift right by the number of bits
2042      - Shift right in the GPR by the calculated value
2043  */
2044  dag LE_VHALF_SHIFT = (EXTRACT_SUBREG (RLDICR (AND8 (LI8 3), $Idx), 4, 59),
2045                                       sub_32);
2046  dag LE_VARIABLE_HALF = (EXTRACT_SUBREG (SRD LE_MV_VHALF, LE_VHALF_SHIFT),
2047                                         sub_32);
2048
2049  /*  LE variable word
2050      Number 1. above:
2051      - For elements 0-1, we shift left by 8 since they're on the right
2052      - For elements 2-3, we need not shift
2053  */
2054  dag LE_VWORD_PERM_VEC = (v16i8 (LVSL ZERO8,
2055                                       (RLDICR (ANDC8 (LI8 2), $Idx), 2, 61)));
2056
2057  //  Number 2. above:
2058  //  - Now that we set up the shift amount, we shift in the VMX register
2059  dag LE_VWORD_PERMUTE = (v16i8 (VPERM $S, $S, LE_VWORD_PERM_VEC));
2060
2061  //  Number 3. above:
2062  //  - The doubleword containing our element is moved to a GPR
2063  dag LE_MV_VWORD = (MFVSRD
2064                      (EXTRACT_SUBREG
2065                        (v2i64 (COPY_TO_REGCLASS LE_VWORD_PERMUTE, VSRC)),
2066                        sub_64));
2067
2068  /*  Number 4. above:
2069      - Truncate the element number to the range 0-1 (2-3 are symmetrical
2070        and out of range values are truncated accordingly)
2071      - Multiply by 32 as we need to shift right by the number of bits
2072      - Shift right in the GPR by the calculated value
2073  */
2074  dag LE_VWORD_SHIFT = (EXTRACT_SUBREG (RLDICR (AND8 (LI8 1), $Idx), 5, 58),
2075                                       sub_32);
2076  dag LE_VARIABLE_WORD = (EXTRACT_SUBREG (SRD LE_MV_VWORD, LE_VWORD_SHIFT),
2077                                         sub_32);
2078
2079  /*  LE variable doubleword
2080      Number 1. above:
2081      - For element 0, we shift left by 8 since it's on the right
2082      - For element 1, we need not shift
2083  */
2084  dag LE_VDWORD_PERM_VEC = (v16i8 (LVSL ZERO8,
2085                                        (RLDICR (ANDC8 (LI8 1), $Idx), 3, 60)));
2086
2087  //  Number 2. above:
2088  //  - Now that we set up the shift amount, we shift in the VMX register
2089  dag LE_VDWORD_PERMUTE = (v16i8 (VPERM $S, $S, LE_VDWORD_PERM_VEC));
2090
2091  // Number 3. above:
2092  //  - The doubleword containing our element is moved to a GPR
2093  //  - Number 4. is not needed for the doubleword as the value is 64-bits
2094  dag LE_VARIABLE_DWORD =
2095        (MFVSRD (EXTRACT_SUBREG
2096                  (v2i64 (COPY_TO_REGCLASS LE_VDWORD_PERMUTE, VSRC)),
2097                  sub_64));
2098
2099  /*  LE variable float
2100      - Shift the vector to line up the desired element to BE Word 0
2101      - Convert 32-bit float to a 64-bit single precision float
2102  */
2103  dag LE_VFLOAT_PERM_VEC = (v16i8 (LVSL ZERO8,
2104                                  (RLDICR (XOR8 (LI8 3), $Idx), 2, 61)));
2105  dag LE_VFLOAT_PERMUTE = (VPERM $S, $S, LE_VFLOAT_PERM_VEC);
2106  dag LE_VARIABLE_FLOAT = (XSCVSPDPN LE_VFLOAT_PERMUTE);
2107
2108  /*  LE variable double
2109      Same as the LE doubleword except there is no move.
2110  */
2111  dag LE_VDOUBLE_PERMUTE = (v16i8 (VPERM (v16i8 (COPY_TO_REGCLASS $S, VRRC)),
2112                                         (v16i8 (COPY_TO_REGCLASS $S, VRRC)),
2113                                         LE_VDWORD_PERM_VEC));
2114  dag LE_VARIABLE_DOUBLE = (COPY_TO_REGCLASS LE_VDOUBLE_PERMUTE, VSRC);
2115
2116  /*  BE variable byte
2117      The algorithm here is the same as the LE variable byte except:
2118      - The shift in the VMX register is by 0/8 for opposite element numbers so
2119        we simply AND the element number with 0x8
2120      - The order of elements after the move to GPR is reversed, so we invert
2121        the bits of the index prior to truncating to the range 0-7
2122  */
2123  dag BE_VBYTE_PERM_VEC = (v16i8 (LVSL ZERO8, (ANDI8_rec $Idx, 8)));
2124  dag BE_VBYTE_PERMUTE = (v16i8 (VPERM $S, $S, BE_VBYTE_PERM_VEC));
2125  dag BE_MV_VBYTE = (MFVSRD
2126                      (EXTRACT_SUBREG
2127                        (v2i64 (COPY_TO_REGCLASS BE_VBYTE_PERMUTE, VSRC)),
2128                        sub_64));
2129  dag BE_VBYTE_SHIFT = (EXTRACT_SUBREG (RLDICR (ANDC8 (LI8 7), $Idx), 3, 60),
2130                                       sub_32);
2131  dag BE_VARIABLE_BYTE = (EXTRACT_SUBREG (SRD BE_MV_VBYTE, BE_VBYTE_SHIFT),
2132                                         sub_32);
2133
2134  /*  BE variable halfword
2135      The algorithm here is the same as the LE variable halfword except:
2136      - The shift in the VMX register is by 0/8 for opposite element numbers so
2137        we simply AND the element number with 0x4 and multiply by 2
2138      - The order of elements after the move to GPR is reversed, so we invert
2139        the bits of the index prior to truncating to the range 0-3
2140  */
2141  dag BE_VHALF_PERM_VEC = (v16i8 (LVSL ZERO8,
2142                                       (RLDICR (ANDI8_rec $Idx, 4), 1, 62)));
2143  dag BE_VHALF_PERMUTE = (v16i8 (VPERM $S, $S, BE_VHALF_PERM_VEC));
2144  dag BE_MV_VHALF = (MFVSRD
2145                      (EXTRACT_SUBREG
2146                        (v2i64 (COPY_TO_REGCLASS BE_VHALF_PERMUTE, VSRC)),
2147                        sub_64));
2148  dag BE_VHALF_SHIFT = (EXTRACT_SUBREG (RLDICR (ANDC8 (LI8 3), $Idx), 4, 59),
2149                                       sub_32);
2150  dag BE_VARIABLE_HALF = (EXTRACT_SUBREG (SRD BE_MV_VHALF, BE_VHALF_SHIFT),
2151                                         sub_32);
2152
2153  /*  BE variable word
2154      The algorithm is the same as the LE variable word except:
2155      - The shift in the VMX register happens for opposite element numbers
2156      - The order of elements after the move to GPR is reversed, so we invert
2157        the bits of the index prior to truncating to the range 0-1
2158  */
2159  dag BE_VWORD_PERM_VEC = (v16i8 (LVSL ZERO8,
2160                                       (RLDICR (ANDI8_rec $Idx, 2), 2, 61)));
2161  dag BE_VWORD_PERMUTE = (v16i8 (VPERM $S, $S, BE_VWORD_PERM_VEC));
2162  dag BE_MV_VWORD = (MFVSRD
2163                      (EXTRACT_SUBREG
2164                        (v2i64 (COPY_TO_REGCLASS BE_VWORD_PERMUTE, VSRC)),
2165                        sub_64));
2166  dag BE_VWORD_SHIFT = (EXTRACT_SUBREG (RLDICR (ANDC8 (LI8 1), $Idx), 5, 58),
2167                                       sub_32);
2168  dag BE_VARIABLE_WORD = (EXTRACT_SUBREG (SRD BE_MV_VWORD, BE_VWORD_SHIFT),
2169                                         sub_32);
2170
2171  /*  BE variable doubleword
2172      Same as the LE doubleword except we shift in the VMX register for opposite
2173      element indices.
2174  */
2175  dag BE_VDWORD_PERM_VEC = (v16i8 (LVSL ZERO8,
2176                                        (RLDICR (ANDI8_rec $Idx, 1), 3, 60)));
2177  dag BE_VDWORD_PERMUTE = (v16i8 (VPERM $S, $S, BE_VDWORD_PERM_VEC));
2178  dag BE_VARIABLE_DWORD =
2179        (MFVSRD (EXTRACT_SUBREG
2180                  (v2i64 (COPY_TO_REGCLASS BE_VDWORD_PERMUTE, VSRC)),
2181                  sub_64));
2182
2183  /*  BE variable float
2184      - Shift the vector to line up the desired element to BE Word 0
2185      - Convert 32-bit float to a 64-bit single precision float
2186  */
2187  dag BE_VFLOAT_PERM_VEC = (v16i8 (LVSL ZERO8, (RLDICR $Idx, 2, 61)));
2188  dag BE_VFLOAT_PERMUTE = (VPERM $S, $S, BE_VFLOAT_PERM_VEC);
2189  dag BE_VARIABLE_FLOAT = (XSCVSPDPN BE_VFLOAT_PERMUTE);
2190
2191  //  BE variable float 32-bit version
2192  dag BE_32B_VFLOAT_PERM_VEC = (v16i8 (LVSL (i32 ZERO), (RLWINM $Idx, 2, 0, 29)));
2193  dag BE_32B_VFLOAT_PERMUTE = (VPERM $S, $S, BE_32B_VFLOAT_PERM_VEC);
2194  dag BE_32B_VARIABLE_FLOAT = (XSCVSPDPN BE_32B_VFLOAT_PERMUTE);
2195
2196  /* BE variable double
2197      Same as the BE doubleword except there is no move.
2198  */
2199  dag BE_VDOUBLE_PERMUTE = (v16i8 (VPERM (v16i8 (COPY_TO_REGCLASS $S, VRRC)),
2200                                         (v16i8 (COPY_TO_REGCLASS $S, VRRC)),
2201                                         BE_VDWORD_PERM_VEC));
2202  dag BE_VARIABLE_DOUBLE = (COPY_TO_REGCLASS BE_VDOUBLE_PERMUTE, VSRC);
2203
2204  //  BE variable double 32-bit version
2205  dag BE_32B_VDWORD_PERM_VEC = (v16i8 (LVSL (i32 ZERO),
2206                                        (RLWINM (ANDI_rec $Idx, 1), 3, 0, 28)));
2207  dag BE_32B_VDOUBLE_PERMUTE = (v16i8 (VPERM (v16i8 (COPY_TO_REGCLASS $S, VRRC)),
2208                                      (v16i8 (COPY_TO_REGCLASS $S, VRRC)),
2209                                      BE_32B_VDWORD_PERM_VEC));
2210  dag BE_32B_VARIABLE_DOUBLE = (COPY_TO_REGCLASS BE_32B_VDOUBLE_PERMUTE, VSRC);
2211}
2212
2213def AlignValues {
2214  dag F32_TO_BE_WORD1 = (v4f32 (XSCVDPSPN $B));
2215  dag I32_TO_BE_WORD1 = (SUBREG_TO_REG (i64 1), (MTVSRWZ $B), sub_64);
2216}
2217
2218// Integer extend helper dags 32 -> 64
2219def AnyExts {
2220  dag A = (INSERT_SUBREG (i64 (IMPLICIT_DEF)), $A, sub_32);
2221  dag B = (INSERT_SUBREG (i64 (IMPLICIT_DEF)), $B, sub_32);
2222  dag C = (INSERT_SUBREG (i64 (IMPLICIT_DEF)), $C, sub_32);
2223  dag D = (INSERT_SUBREG (i64 (IMPLICIT_DEF)), $D, sub_32);
2224}
2225
2226def DblToFlt {
2227  dag A0 = (f32 (any_fpround (f64 (extractelt v2f64:$A, 0))));
2228  dag A1 = (f32 (any_fpround (f64 (extractelt v2f64:$A, 1))));
2229  dag B0 = (f32 (any_fpround (f64 (extractelt v2f64:$B, 0))));
2230  dag B1 = (f32 (any_fpround (f64 (extractelt v2f64:$B, 1))));
2231}
2232
2233def ExtDbl {
2234  dag A0S = (i32 (PPCmfvsr (f64 (PPCfctiwz (f64 (extractelt v2f64:$A, 0))))));
2235  dag A1S = (i32 (PPCmfvsr (f64 (PPCfctiwz (f64 (extractelt v2f64:$A, 1))))));
2236  dag B0S = (i32 (PPCmfvsr (f64 (PPCfctiwz (f64 (extractelt v2f64:$B, 0))))));
2237  dag B1S = (i32 (PPCmfvsr (f64 (PPCfctiwz (f64 (extractelt v2f64:$B, 1))))));
2238  dag A0U = (i32 (PPCmfvsr (f64 (PPCfctiwuz (f64 (extractelt v2f64:$A, 0))))));
2239  dag A1U = (i32 (PPCmfvsr (f64 (PPCfctiwuz (f64 (extractelt v2f64:$A, 1))))));
2240  dag B0U = (i32 (PPCmfvsr (f64 (PPCfctiwuz (f64 (extractelt v2f64:$B, 0))))));
2241  dag B1U = (i32 (PPCmfvsr (f64 (PPCfctiwuz (f64 (extractelt v2f64:$B, 1))))));
2242}
2243
2244def ByteToWord {
2245  dag LE_A0 = (i32 (sext_inreg (i32 (vector_extract v16i8:$A, 0)), i8));
2246  dag LE_A1 = (i32 (sext_inreg (i32 (vector_extract v16i8:$A, 4)), i8));
2247  dag LE_A2 = (i32 (sext_inreg (i32 (vector_extract v16i8:$A, 8)), i8));
2248  dag LE_A3 = (i32 (sext_inreg (i32 (vector_extract v16i8:$A, 12)), i8));
2249  dag BE_A0 = (i32 (sext_inreg (i32 (vector_extract v16i8:$A, 3)), i8));
2250  dag BE_A1 = (i32 (sext_inreg (i32 (vector_extract v16i8:$A, 7)), i8));
2251  dag BE_A2 = (i32 (sext_inreg (i32 (vector_extract v16i8:$A, 11)), i8));
2252  dag BE_A3 = (i32 (sext_inreg (i32 (vector_extract v16i8:$A, 15)), i8));
2253}
2254
2255def ByteToDWord {
2256  dag LE_A0 = (i64 (sext_inreg
2257              (i64 (anyext (i32 (vector_extract v16i8:$A, 0)))), i8));
2258  dag LE_A1 = (i64 (sext_inreg
2259              (i64 (anyext (i32 (vector_extract v16i8:$A, 8)))), i8));
2260  dag BE_A0 = (i64 (sext_inreg
2261              (i64 (anyext (i32 (vector_extract v16i8:$A, 7)))), i8));
2262  dag BE_A1 = (i64 (sext_inreg
2263              (i64 (anyext (i32 (vector_extract v16i8:$A, 15)))), i8));
2264}
2265
2266def HWordToWord {
2267  dag LE_A0 = (i32 (sext_inreg (i32 (vector_extract v8i16:$A, 0)), i16));
2268  dag LE_A1 = (i32 (sext_inreg (i32 (vector_extract v8i16:$A, 2)), i16));
2269  dag LE_A2 = (i32 (sext_inreg (i32 (vector_extract v8i16:$A, 4)), i16));
2270  dag LE_A3 = (i32 (sext_inreg (i32 (vector_extract v8i16:$A, 6)), i16));
2271  dag BE_A0 = (i32 (sext_inreg (i32 (vector_extract v8i16:$A, 1)), i16));
2272  dag BE_A1 = (i32 (sext_inreg (i32 (vector_extract v8i16:$A, 3)), i16));
2273  dag BE_A2 = (i32 (sext_inreg (i32 (vector_extract v8i16:$A, 5)), i16));
2274  dag BE_A3 = (i32 (sext_inreg (i32 (vector_extract v8i16:$A, 7)), i16));
2275}
2276
2277def HWordToDWord {
2278  dag LE_A0 = (i64 (sext_inreg
2279              (i64 (anyext (i32 (vector_extract v8i16:$A, 0)))), i16));
2280  dag LE_A1 = (i64 (sext_inreg
2281              (i64 (anyext (i32 (vector_extract v8i16:$A, 4)))), i16));
2282  dag BE_A0 = (i64 (sext_inreg
2283              (i64 (anyext (i32 (vector_extract v8i16:$A, 3)))), i16));
2284  dag BE_A1 = (i64 (sext_inreg
2285              (i64 (anyext (i32 (vector_extract v8i16:$A, 7)))), i16));
2286}
2287
2288def WordToDWord {
2289  dag LE_A0 = (i64 (sext (i32 (vector_extract v4i32:$A, 0))));
2290  dag LE_A1 = (i64 (sext (i32 (vector_extract v4i32:$A, 2))));
2291  dag BE_A0 = (i64 (sext (i32 (vector_extract v4i32:$A, 1))));
2292  dag BE_A1 = (i64 (sext (i32 (vector_extract v4i32:$A, 3))));
2293}
2294
2295def FltToIntLoad {
2296  dag A = (i32 (PPCmfvsr (PPCfctiwz (f64 (extloadf32 ForceXForm:$A)))));
2297}
2298def FltToUIntLoad {
2299  dag A = (i32 (PPCmfvsr (PPCfctiwuz (f64 (extloadf32 ForceXForm:$A)))));
2300}
2301def FltToLongLoad {
2302  dag A = (i64 (PPCmfvsr (PPCfctidz (f64 (extloadf32 ForceXForm:$A)))));
2303}
2304def FltToLongLoadP9 {
2305  dag A = (i64 (PPCmfvsr (PPCfctidz (f64 (extloadf32 DSForm:$A)))));
2306}
2307def FltToULongLoad {
2308  dag A = (i64 (PPCmfvsr (PPCfctiduz (f64 (extloadf32 ForceXForm:$A)))));
2309}
2310def FltToULongLoadP9 {
2311  dag A = (i64 (PPCmfvsr (PPCfctiduz (f64 (extloadf32 DSForm:$A)))));
2312}
2313def FltToLong {
2314  dag A = (i64 (PPCmfvsr (f64 (PPCfctidz (fpextend f32:$A)))));
2315}
2316def FltToULong {
2317  dag A = (i64 (PPCmfvsr (f64 (PPCfctiduz (fpextend f32:$A)))));
2318}
2319def DblToInt {
2320  dag A = (i32 (PPCmfvsr (f64 (PPCfctiwz f64:$A))));
2321  dag B = (i32 (PPCmfvsr (f64 (PPCfctiwz f64:$B))));
2322  dag C = (i32 (PPCmfvsr (f64 (PPCfctiwz f64:$C))));
2323  dag D = (i32 (PPCmfvsr (f64 (PPCfctiwz f64:$D))));
2324}
2325def DblToUInt {
2326  dag A = (i32 (PPCmfvsr (f64 (PPCfctiwuz f64:$A))));
2327  dag B = (i32 (PPCmfvsr (f64 (PPCfctiwuz f64:$B))));
2328  dag C = (i32 (PPCmfvsr (f64 (PPCfctiwuz f64:$C))));
2329  dag D = (i32 (PPCmfvsr (f64 (PPCfctiwuz f64:$D))));
2330}
2331def DblToLong {
2332  dag A = (i64 (PPCmfvsr (f64 (PPCfctidz f64:$A))));
2333}
2334def DblToULong {
2335  dag A = (i64 (PPCmfvsr (f64 (PPCfctiduz f64:$A))));
2336}
2337def DblToIntLoad {
2338  dag A = (i32 (PPCmfvsr (PPCfctiwz (f64 (load ForceXForm:$A)))));
2339}
2340def DblToIntLoadP9 {
2341  dag A = (i32 (PPCmfvsr (PPCfctiwz (f64 (load DSForm:$A)))));
2342}
2343def DblToUIntLoad {
2344  dag A = (i32 (PPCmfvsr (PPCfctiwuz (f64 (load ForceXForm:$A)))));
2345}
2346def DblToUIntLoadP9 {
2347  dag A = (i32 (PPCmfvsr (PPCfctiwuz (f64 (load DSForm:$A)))));
2348}
2349def DblToLongLoad {
2350  dag A = (i64 (PPCmfvsr (PPCfctidz (f64 (load ForceXForm:$A)))));
2351}
2352def DblToULongLoad {
2353  dag A = (i64 (PPCmfvsr (PPCfctiduz (f64 (load ForceXForm:$A)))));
2354}
2355
2356// FP load dags (for f32 -> v4f32)
2357def LoadFP {
2358  dag A = (f32 (load ForceXForm:$A));
2359  dag B = (f32 (load ForceXForm:$B));
2360  dag C = (f32 (load ForceXForm:$C));
2361  dag D = (f32 (load ForceXForm:$D));
2362}
2363
2364// FP merge dags (for f32 -> v4f32)
2365def MrgFP {
2366  dag LD32A = (SUBREG_TO_REG (i64 1), (LIWZX ForceXForm:$A), sub_64);
2367  dag LD32B = (SUBREG_TO_REG (i64 1), (LIWZX ForceXForm:$B), sub_64);
2368  dag LD32C = (SUBREG_TO_REG (i64 1), (LIWZX ForceXForm:$C), sub_64);
2369  dag LD32D = (SUBREG_TO_REG (i64 1), (LIWZX ForceXForm:$D), sub_64);
2370  dag AC = (XVCVDPSP (XXPERMDI (SUBREG_TO_REG (i64 1), $A, sub_64),
2371                               (SUBREG_TO_REG (i64 1), $C, sub_64), 0));
2372  dag BD = (XVCVDPSP (XXPERMDI (SUBREG_TO_REG (i64 1), $B, sub_64),
2373                               (SUBREG_TO_REG (i64 1), $D, sub_64), 0));
2374  dag ABhToFlt = (XVCVDPSP (XXPERMDI $A, $B, 0));
2375  dag ABlToFlt = (XVCVDPSP (XXPERMDI $A, $B, 3));
2376  dag BAhToFlt = (XVCVDPSP (XXPERMDI $B, $A, 0));
2377  dag BAlToFlt = (XVCVDPSP (XXPERMDI $B, $A, 3));
2378}
2379
2380// Word-element merge dags - conversions from f64 to i32 merged into vectors.
2381def MrgWords {
2382  // For big endian, we merge low and hi doublewords (A, B).
2383  dag A0B0 = (v2f64 (XXPERMDI v2f64:$A, v2f64:$B, 0));
2384  dag A1B1 = (v2f64 (XXPERMDI v2f64:$A, v2f64:$B, 3));
2385  dag CVA1B1S = (v4i32 (XVCVDPSXWS A1B1));
2386  dag CVA0B0S = (v4i32 (XVCVDPSXWS A0B0));
2387  dag CVA1B1U = (v4i32 (XVCVDPUXWS A1B1));
2388  dag CVA0B0U = (v4i32 (XVCVDPUXWS A0B0));
2389
2390  // For little endian, we merge low and hi doublewords (B, A).
2391  dag B1A1 = (v2f64 (XXPERMDI v2f64:$B, v2f64:$A, 0));
2392  dag B0A0 = (v2f64 (XXPERMDI v2f64:$B, v2f64:$A, 3));
2393  dag CVB1A1S = (v4i32 (XVCVDPSXWS B1A1));
2394  dag CVB0A0S = (v4i32 (XVCVDPSXWS B0A0));
2395  dag CVB1A1U = (v4i32 (XVCVDPUXWS B1A1));
2396  dag CVB0A0U = (v4i32 (XVCVDPUXWS B0A0));
2397
2398  // For big endian, we merge hi doublewords of (A, C) and (B, D), convert
2399  // then merge.
2400  dag AC = (v2f64 (XXPERMDI (SUBREG_TO_REG (i64 1), f64:$A, sub_64),
2401                            (SUBREG_TO_REG (i64 1), f64:$C, sub_64), 0));
2402  dag BD = (v2f64 (XXPERMDI (SUBREG_TO_REG (i64 1), f64:$B, sub_64),
2403                            (SUBREG_TO_REG (i64 1), f64:$D, sub_64), 0));
2404  dag CVACS = (v4i32 (XVCVDPSXWS AC));
2405  dag CVBDS = (v4i32 (XVCVDPSXWS BD));
2406  dag CVACU = (v4i32 (XVCVDPUXWS AC));
2407  dag CVBDU = (v4i32 (XVCVDPUXWS BD));
2408
2409  // For little endian, we merge hi doublewords of (D, B) and (C, A), convert
2410  // then merge.
2411  dag DB = (v2f64 (XXPERMDI (SUBREG_TO_REG (i64 1), f64:$D, sub_64),
2412                            (SUBREG_TO_REG (i64 1), f64:$B, sub_64), 0));
2413  dag CA = (v2f64 (XXPERMDI (SUBREG_TO_REG (i64 1), f64:$C, sub_64),
2414                            (SUBREG_TO_REG (i64 1), f64:$A, sub_64), 0));
2415  dag CVDBS = (v4i32 (XVCVDPSXWS DB));
2416  dag CVCAS = (v4i32 (XVCVDPSXWS CA));
2417  dag CVDBU = (v4i32 (XVCVDPUXWS DB));
2418  dag CVCAU = (v4i32 (XVCVDPUXWS CA));
2419}
2420
2421def DblwdCmp {
2422  dag SGTW = (v2i64 (v2i64 (VCMPGTSW v2i64:$vA, v2i64:$vB)));
2423  dag UGTW = (v2i64 (v2i64 (VCMPGTUW v2i64:$vA, v2i64:$vB)));
2424  dag EQW = (v2i64 (v2i64 (VCMPEQUW v2i64:$vA, v2i64:$vB)));
2425  dag UGTWSHAND = (v2i64 (XXLAND (v2i64 (XXSLDWI UGTW, UGTW, 1)), EQW));
2426  dag EQWSHAND = (v2i64 (XXLAND (v2i64 (XXSLDWI EQW, EQW, 1)), EQW));
2427  dag SGTWOR = (v2i64 (XXLOR SGTW, UGTWSHAND));
2428  dag UGTWOR = (v2i64 (XXLOR UGTW, UGTWSHAND));
2429  dag MRGSGT = (v2i64 (XXPERMDI (v2i64 (XXSPLTW SGTWOR, 0)),
2430                                (v2i64 (XXSPLTW SGTWOR, 2)), 0));
2431  dag MRGUGT = (v2i64 (XXPERMDI (v2i64 (XXSPLTW UGTWOR, 0)),
2432                                (v2i64 (XXSPLTW UGTWOR, 2)), 0));
2433  dag MRGEQ = (v2i64 (XXPERMDI (v2i64 (XXSPLTW EQWSHAND, 0)),
2434                               (v2i64 (XXSPLTW EQWSHAND, 2)), 0));
2435}
2436
2437//---------------------------- Anonymous Patterns ----------------------------//
2438// Predicate combinations are kept in roughly chronological order in terms of
2439// instruction availability in the architecture. For example, VSX came in with
2440// ISA 2.06 (Power7). There have since been additions in ISA 2.07 (Power8) and
2441// ISA 3.0 (Power9). However, the granularity of features on later subtargets
2442// is finer for various reasons. For example, we have Power8Vector,
2443// Power8Altivec, DirectMove that all came in with ISA 2.07. The situation is
2444// similar with ISA 3.0 with Power9Vector, Power9Altivec, IsISA3_0. Then there
2445// are orthogonal predicates such as endianness for which the order was
2446// arbitrarily chosen to be Big, Little.
2447//
2448// Predicate combinations available:
2449// [HasVSX, IsLittleEndian, HasP8Altivec] Altivec patterns using VSX instr.
2450// [HasVSX, IsBigEndian, HasP8Altivec] Altivec patterns using VSX instr.
2451// [HasVSX]
2452// [HasVSX, IsBigEndian]
2453// [HasVSX, IsLittleEndian]
2454// [HasVSX, NoP9Vector]
2455// [HasVSX, NoP9Vector, IsLittleEndian]
2456// [HasVSX, NoP9Vector, IsBigEndian]
2457// [HasVSX, HasOnlySwappingMemOps]
2458// [HasVSX, HasOnlySwappingMemOps, IsBigEndian]
2459// [HasVSX, HasP8Vector]
2460// [HasVSX, HasP8Vector, IsBigEndian]
2461// [HasVSX, HasP8Vector, IsBigEndian, IsPPC64]
2462// [HasVSX, HasP8Vector, IsLittleEndian]
2463// [HasVSX, HasP8Vector, NoP9Vector, IsBigEndian, IsPPC64]
2464// [HasVSX, HasP8Vector, NoP9Vector, IsLittleEndian]
2465// [HasVSX, HasDirectMove]
2466// [HasVSX, HasDirectMove, IsBigEndian]
2467// [HasVSX, HasDirectMove, IsLittleEndian]
2468// [HasVSX, HasDirectMove, NoP9Altivec, IsBigEndian, IsPPC64]
2469// [HasVSX, HasDirectMove, NoP9Vector, IsBigEndian, IsPPC64]
2470// [HasVSX, HasDirectMove, NoP9Altivec, IsLittleEndian]
2471// [HasVSX, HasDirectMove, NoP9Vector, IsLittleEndian]
2472// [HasVSX, HasP9Vector]
2473// [HasVSX, HasP9Vector, NoP10Vector]
2474// [HasVSX, HasP9Vector, IsBigEndian]
2475// [HasVSX, HasP9Vector, IsBigEndian, IsPPC64]
2476// [HasVSX, HasP9Vector, IsLittleEndian]
2477// [HasVSX, HasP9Altivec]
2478// [HasVSX, HasP9Altivec, IsBigEndian, IsPPC64]
2479// [HasVSX, HasP9Altivec, IsLittleEndian]
2480// [HasVSX, IsISA3_0, HasDirectMove, IsBigEndian, IsPPC64]
2481// [HasVSX, IsISA3_0, HasDirectMove, IsLittleEndian]
2482
2483// These Altivec patterns are here because we need a VSX instruction to match
2484// the intrinsic (but only for little endian system).
2485let Predicates = [HasVSX, IsLittleEndian, HasP8Altivec] in
2486  def : Pat<(v16i8 (int_ppc_altivec_crypto_vpermxor v16i8:$a,
2487                                                    v16i8:$b, v16i8:$c)),
2488            (v16i8 (VPERMXOR $a, $b, (XXLNOR (COPY_TO_REGCLASS $c, VSRC),
2489                                             (COPY_TO_REGCLASS $c, VSRC))))>;
2490let Predicates = [HasVSX, IsBigEndian, HasP8Altivec] in
2491  def : Pat<(v16i8 (int_ppc_altivec_crypto_vpermxor v16i8:$a,
2492                                                    v16i8:$b, v16i8:$c)),
2493            (v16i8 (VPERMXOR $a, $b, $c))>;
2494
2495let AddedComplexity = 400 in {
2496// Valid for any VSX subtarget, regardless of endianness.
2497let Predicates = [HasVSX] in {
2498def : Pat<(v4i32 (vnot v4i32:$A)),
2499          (v4i32 (XXLNOR $A, $A))>;
2500def : Pat<(v4i32 (or (and (vnot v4i32:$C), v4i32:$A),
2501                     (and v4i32:$B, v4i32:$C))),
2502          (v4i32 (XXSEL $A, $B, $C))>;
2503
2504// Additional fnmsub pattern for PPC specific ISD opcode
2505def : Pat<(PPCfnmsub f64:$A, f64:$B, f64:$C),
2506          (XSNMSUBADP $C, $A, $B)>;
2507def : Pat<(fneg (PPCfnmsub f64:$A, f64:$B, f64:$C)),
2508          (XSMSUBADP $C, $A, $B)>;
2509def : Pat<(PPCfnmsub f64:$A, f64:$B, (fneg f64:$C)),
2510          (XSNMADDADP $C, $A, $B)>;
2511
2512def : Pat<(PPCfnmsub v2f64:$A, v2f64:$B, v2f64:$C),
2513          (XVNMSUBADP $C, $A, $B)>;
2514def : Pat<(fneg (PPCfnmsub v2f64:$A, v2f64:$B, v2f64:$C)),
2515          (XVMSUBADP $C, $A, $B)>;
2516def : Pat<(PPCfnmsub v2f64:$A, v2f64:$B, (fneg v2f64:$C)),
2517          (XVNMADDADP $C, $A, $B)>;
2518
2519def : Pat<(PPCfnmsub v4f32:$A, v4f32:$B, v4f32:$C),
2520          (XVNMSUBASP $C, $A, $B)>;
2521def : Pat<(fneg (PPCfnmsub v4f32:$A, v4f32:$B, v4f32:$C)),
2522          (XVMSUBASP $C, $A, $B)>;
2523def : Pat<(PPCfnmsub v4f32:$A, v4f32:$B, (fneg v4f32:$C)),
2524          (XVNMADDASP $C, $A, $B)>;
2525
2526def : Pat<(PPCfsqrt f64:$frA), (XSSQRTDP $frA)>;
2527def : Pat<(PPCfsqrt v2f64:$frA), (XVSQRTDP $frA)>;
2528def : Pat<(PPCfsqrt v4f32:$frA), (XVSQRTSP $frA)>;
2529
2530def : Pat<(v2f64 (bitconvert v4f32:$A)),
2531          (COPY_TO_REGCLASS $A, VSRC)>;
2532def : Pat<(v2f64 (bitconvert v4i32:$A)),
2533          (COPY_TO_REGCLASS $A, VSRC)>;
2534def : Pat<(v2f64 (bitconvert v8i16:$A)),
2535          (COPY_TO_REGCLASS $A, VSRC)>;
2536def : Pat<(v2f64 (bitconvert v16i8:$A)),
2537          (COPY_TO_REGCLASS $A, VSRC)>;
2538
2539def : Pat<(v4f32 (bitconvert v2f64:$A)),
2540          (COPY_TO_REGCLASS $A, VRRC)>;
2541def : Pat<(v4i32 (bitconvert v2f64:$A)),
2542          (COPY_TO_REGCLASS $A, VRRC)>;
2543def : Pat<(v8i16 (bitconvert v2f64:$A)),
2544          (COPY_TO_REGCLASS $A, VRRC)>;
2545def : Pat<(v16i8 (bitconvert v2f64:$A)),
2546          (COPY_TO_REGCLASS $A, VRRC)>;
2547
2548def : Pat<(v2i64 (bitconvert v4f32:$A)),
2549          (COPY_TO_REGCLASS $A, VSRC)>;
2550def : Pat<(v2i64 (bitconvert v4i32:$A)),
2551          (COPY_TO_REGCLASS $A, VSRC)>;
2552def : Pat<(v2i64 (bitconvert v8i16:$A)),
2553          (COPY_TO_REGCLASS $A, VSRC)>;
2554def : Pat<(v2i64 (bitconvert v16i8:$A)),
2555          (COPY_TO_REGCLASS $A, VSRC)>;
2556
2557def : Pat<(v4f32 (bitconvert v2i64:$A)),
2558          (COPY_TO_REGCLASS $A, VRRC)>;
2559def : Pat<(v4i32 (bitconvert v2i64:$A)),
2560          (COPY_TO_REGCLASS $A, VRRC)>;
2561def : Pat<(v8i16 (bitconvert v2i64:$A)),
2562          (COPY_TO_REGCLASS $A, VRRC)>;
2563def : Pat<(v16i8 (bitconvert v2i64:$A)),
2564          (COPY_TO_REGCLASS $A, VRRC)>;
2565
2566def : Pat<(v2f64 (bitconvert v2i64:$A)),
2567          (COPY_TO_REGCLASS $A, VRRC)>;
2568def : Pat<(v2i64 (bitconvert v2f64:$A)),
2569          (COPY_TO_REGCLASS $A, VRRC)>;
2570
2571def : Pat<(v2f64 (bitconvert v1i128:$A)),
2572          (COPY_TO_REGCLASS $A, VRRC)>;
2573def : Pat<(v1i128 (bitconvert v2f64:$A)),
2574          (COPY_TO_REGCLASS $A, VRRC)>;
2575
2576def : Pat<(v2i64 (bitconvert f128:$A)),
2577          (COPY_TO_REGCLASS $A, VRRC)>;
2578def : Pat<(v4i32 (bitconvert f128:$A)),
2579          (COPY_TO_REGCLASS $A, VRRC)>;
2580def : Pat<(v8i16 (bitconvert f128:$A)),
2581          (COPY_TO_REGCLASS $A, VRRC)>;
2582def : Pat<(v16i8 (bitconvert f128:$A)),
2583          (COPY_TO_REGCLASS $A, VRRC)>;
2584
2585def : Pat<(v2f64 (PPCsvec2fp v4i32:$C, 0)),
2586          (v2f64 (XVCVSXWDP (v2i64 (XXMRGHW $C, $C))))>;
2587def : Pat<(v2f64 (PPCsvec2fp v4i32:$C, 1)),
2588          (v2f64 (XVCVSXWDP (v2i64 (XXMRGLW $C, $C))))>;
2589
2590def : Pat<(v2f64 (PPCuvec2fp v4i32:$C, 0)),
2591          (v2f64 (XVCVUXWDP (v2i64 (XXMRGHW $C, $C))))>;
2592def : Pat<(v2f64 (PPCuvec2fp v4i32:$C, 1)),
2593          (v2f64 (XVCVUXWDP (v2i64 (XXMRGLW $C, $C))))>;
2594
2595def : Pat<(v2f64 (PPCfpexth v4f32:$C, 0)), (XVCVSPDP (XXMRGHW $C, $C))>;
2596def : Pat<(v2f64 (PPCfpexth v4f32:$C, 1)), (XVCVSPDP (XXMRGLW $C, $C))>;
2597
2598// Permutes.
2599def : Pat<(v2f64 (PPCxxswapd v2f64:$src)), (XXPERMDI $src, $src, 2)>;
2600def : Pat<(v2i64 (PPCxxswapd v2i64:$src)), (XXPERMDI $src, $src, 2)>;
2601def : Pat<(v4f32 (PPCxxswapd v4f32:$src)), (XXPERMDI $src, $src, 2)>;
2602def : Pat<(v4i32 (PPCxxswapd v4i32:$src)), (XXPERMDI $src, $src, 2)>;
2603def : Pat<(v2f64 (PPCswapNoChain v2f64:$src)), (XXPERMDI $src, $src, 2)>;
2604
2605// PPCvecshl XT, XA, XA, 2 can be selected to both XXSLDWI XT,XA,XA,2 and
2606// XXSWAPD XT,XA (i.e. XXPERMDI XT,XA,XA,2), the later one is more profitable.
2607def : Pat<(v4i32 (PPCvecshl v4i32:$src, v4i32:$src, 2)),
2608          (XXPERMDI $src, $src, 2)>;
2609
2610// Selects.
2611def : Pat<(v2f64 (selectcc i1:$lhs, i1:$rhs, v2f64:$tval, v2f64:$fval, SETLT)),
2612          (SELECT_VSRC (CRANDC $lhs, $rhs), $tval, $fval)>;
2613def : Pat<(v2f64 (selectcc i1:$lhs, i1:$rhs, v2f64:$tval, v2f64:$fval, SETULT)),
2614          (SELECT_VSRC (CRANDC $rhs, $lhs), $tval, $fval)>;
2615def : Pat<(v2f64 (selectcc i1:$lhs, i1:$rhs, v2f64:$tval, v2f64:$fval, SETLE)),
2616          (SELECT_VSRC (CRORC  $lhs, $rhs), $tval, $fval)>;
2617def : Pat<(v2f64 (selectcc i1:$lhs, i1:$rhs, v2f64:$tval, v2f64:$fval, SETULE)),
2618          (SELECT_VSRC (CRORC  $rhs, $lhs), $tval, $fval)>;
2619def : Pat<(v2f64 (selectcc i1:$lhs, i1:$rhs, v2f64:$tval, v2f64:$fval, SETEQ)),
2620          (SELECT_VSRC (CREQV $lhs, $rhs), $tval, $fval)>;
2621def : Pat<(v2f64 (selectcc i1:$lhs, i1:$rhs, v2f64:$tval, v2f64:$fval, SETGE)),
2622          (SELECT_VSRC (CRORC  $rhs, $lhs), $tval, $fval)>;
2623def : Pat<(v2f64 (selectcc i1:$lhs, i1:$rhs, v2f64:$tval, v2f64:$fval, SETUGE)),
2624          (SELECT_VSRC (CRORC  $lhs, $rhs), $tval, $fval)>;
2625def : Pat<(v2f64 (selectcc i1:$lhs, i1:$rhs, v2f64:$tval, v2f64:$fval, SETGT)),
2626          (SELECT_VSRC (CRANDC $rhs, $lhs), $tval, $fval)>;
2627def : Pat<(v2f64 (selectcc i1:$lhs, i1:$rhs, v2f64:$tval, v2f64:$fval, SETUGT)),
2628          (SELECT_VSRC (CRANDC $lhs, $rhs), $tval, $fval)>;
2629def : Pat<(v2f64 (selectcc i1:$lhs, i1:$rhs, v2f64:$tval, v2f64:$fval, SETNE)),
2630          (SELECT_VSRC (CRXOR $lhs, $rhs), $tval, $fval)>;
2631
2632def : Pat<(f64 (selectcc i1:$lhs, i1:$rhs, f64:$tval, f64:$fval, SETLT)),
2633          (SELECT_VSFRC (CRANDC $lhs, $rhs), $tval, $fval)>;
2634def : Pat<(f64 (selectcc i1:$lhs, i1:$rhs, f64:$tval, f64:$fval, SETULT)),
2635          (SELECT_VSFRC (CRANDC $rhs, $lhs), $tval, $fval)>;
2636def : Pat<(f64 (selectcc i1:$lhs, i1:$rhs, f64:$tval, f64:$fval, SETLE)),
2637          (SELECT_VSFRC (CRORC  $lhs, $rhs), $tval, $fval)>;
2638def : Pat<(f64 (selectcc i1:$lhs, i1:$rhs, f64:$tval, f64:$fval, SETULE)),
2639          (SELECT_VSFRC (CRORC  $rhs, $lhs), $tval, $fval)>;
2640def : Pat<(f64 (selectcc i1:$lhs, i1:$rhs, f64:$tval, f64:$fval, SETEQ)),
2641          (SELECT_VSFRC (CREQV $lhs, $rhs), $tval, $fval)>;
2642def : Pat<(f64 (selectcc i1:$lhs, i1:$rhs, f64:$tval, f64:$fval, SETGE)),
2643          (SELECT_VSFRC (CRORC  $rhs, $lhs), $tval, $fval)>;
2644def : Pat<(f64 (selectcc i1:$lhs, i1:$rhs, f64:$tval, f64:$fval, SETUGE)),
2645          (SELECT_VSFRC (CRORC  $lhs, $rhs), $tval, $fval)>;
2646def : Pat<(f64 (selectcc i1:$lhs, i1:$rhs, f64:$tval, f64:$fval, SETGT)),
2647          (SELECT_VSFRC (CRANDC $rhs, $lhs), $tval, $fval)>;
2648def : Pat<(f64 (selectcc i1:$lhs, i1:$rhs, f64:$tval, f64:$fval, SETUGT)),
2649          (SELECT_VSFRC (CRANDC $lhs, $rhs), $tval, $fval)>;
2650def : Pat<(f64 (selectcc i1:$lhs, i1:$rhs, f64:$tval, f64:$fval, SETNE)),
2651          (SELECT_VSFRC (CRXOR $lhs, $rhs), $tval, $fval)>;
2652
2653// Divides.
2654def : Pat<(int_ppc_vsx_xvdivsp v4f32:$A, v4f32:$B),
2655          (XVDIVSP $A, $B)>;
2656def : Pat<(int_ppc_vsx_xvdivdp v2f64:$A, v2f64:$B),
2657          (XVDIVDP $A, $B)>;
2658
2659// Vector test for software divide and sqrt.
2660def : Pat<(i32 (int_ppc_vsx_xvtdivdp v2f64:$A, v2f64:$B)),
2661          (COPY_TO_REGCLASS (XVTDIVDP $A, $B), GPRC)>;
2662def : Pat<(i32 (int_ppc_vsx_xvtdivsp v4f32:$A, v4f32:$B)),
2663          (COPY_TO_REGCLASS (XVTDIVSP $A, $B), GPRC)>;
2664def : Pat<(i32 (int_ppc_vsx_xvtsqrtdp v2f64:$A)),
2665          (COPY_TO_REGCLASS (XVTSQRTDP $A), GPRC)>;
2666def : Pat<(i32 (int_ppc_vsx_xvtsqrtsp v4f32:$A)),
2667          (COPY_TO_REGCLASS (XVTSQRTSP $A), GPRC)>;
2668
2669// Reciprocal estimate
2670def : Pat<(int_ppc_vsx_xvresp v4f32:$A),
2671          (XVRESP $A)>;
2672def : Pat<(int_ppc_vsx_xvredp v2f64:$A),
2673          (XVREDP $A)>;
2674
2675// Recip. square root estimate
2676def : Pat<(int_ppc_vsx_xvrsqrtesp v4f32:$A),
2677          (XVRSQRTESP $A)>;
2678def : Pat<(int_ppc_vsx_xvrsqrtedp v2f64:$A),
2679          (XVRSQRTEDP $A)>;
2680
2681// Vector selection
2682def : Pat<(v16i8 (vselect v16i8:$vA, v16i8:$vB, v16i8:$vC)),
2683          (COPY_TO_REGCLASS
2684                 (XXSEL (COPY_TO_REGCLASS $vC, VSRC),
2685                        (COPY_TO_REGCLASS $vB, VSRC),
2686                        (COPY_TO_REGCLASS $vA, VSRC)), VRRC)>;
2687def : Pat<(v8i16 (vselect v8i16:$vA, v8i16:$vB, v8i16:$vC)),
2688          (COPY_TO_REGCLASS
2689                 (XXSEL (COPY_TO_REGCLASS $vC, VSRC),
2690                        (COPY_TO_REGCLASS $vB, VSRC),
2691                        (COPY_TO_REGCLASS $vA, VSRC)), VRRC)>;
2692def : Pat<(vselect v4i32:$vA, v4i32:$vB, v4i32:$vC),
2693          (XXSEL $vC, $vB, $vA)>;
2694def : Pat<(vselect v2i64:$vA, v2i64:$vB, v2i64:$vC),
2695          (XXSEL $vC, $vB, $vA)>;
2696def : Pat<(vselect v4i32:$vA, v4f32:$vB, v4f32:$vC),
2697          (XXSEL $vC, $vB, $vA)>;
2698def : Pat<(vselect v2i64:$vA, v2f64:$vB, v2f64:$vC),
2699          (XXSEL $vC, $vB, $vA)>;
2700def : Pat<(v1i128 (vselect v1i128:$vA, v1i128:$vB, v1i128:$vC)),
2701          (COPY_TO_REGCLASS
2702                 (XXSEL (COPY_TO_REGCLASS $vC, VSRC),
2703                        (COPY_TO_REGCLASS $vB, VSRC),
2704                        (COPY_TO_REGCLASS $vA, VSRC)), VRRC)>;
2705
2706def : Pat<(v4f32 (any_fmaxnum v4f32:$src1, v4f32:$src2)),
2707          (v4f32 (XVMAXSP $src1, $src2))>;
2708def : Pat<(v4f32 (any_fminnum v4f32:$src1, v4f32:$src2)),
2709          (v4f32 (XVMINSP $src1, $src2))>;
2710def : Pat<(v2f64 (any_fmaxnum v2f64:$src1, v2f64:$src2)),
2711          (v2f64 (XVMAXDP $src1, $src2))>;
2712def : Pat<(v2f64 (any_fminnum v2f64:$src1, v2f64:$src2)),
2713          (v2f64 (XVMINDP $src1, $src2))>;
2714
2715// f32 abs
2716def : Pat<(f32 (fabs f32:$S)),
2717          (f32 (COPY_TO_REGCLASS (XSABSDP
2718               (COPY_TO_REGCLASS $S, VSFRC)), VSSRC))>;
2719
2720// f32 nabs
2721def : Pat<(f32 (fneg (fabs f32:$S))),
2722          (f32 (COPY_TO_REGCLASS (XSNABSDP
2723               (COPY_TO_REGCLASS $S, VSFRC)), VSSRC))>;
2724
2725// f32 Min.
2726def : Pat<(f32 (fminnum_ieee f32:$A, f32:$B)),
2727          (f32 FpMinMax.F32Min)>;
2728def : Pat<(f32 (fminnum_ieee (fcanonicalize f32:$A), f32:$B)),
2729          (f32 FpMinMax.F32Min)>;
2730def : Pat<(f32 (fminnum_ieee f32:$A, (fcanonicalize f32:$B))),
2731          (f32 FpMinMax.F32Min)>;
2732def : Pat<(f32 (fminnum_ieee (fcanonicalize f32:$A), (fcanonicalize f32:$B))),
2733          (f32 FpMinMax.F32Min)>;
2734// F32 Max.
2735def : Pat<(f32 (fmaxnum_ieee f32:$A, f32:$B)),
2736          (f32 FpMinMax.F32Max)>;
2737def : Pat<(f32 (fmaxnum_ieee (fcanonicalize f32:$A), f32:$B)),
2738          (f32 FpMinMax.F32Max)>;
2739def : Pat<(f32 (fmaxnum_ieee f32:$A, (fcanonicalize f32:$B))),
2740          (f32 FpMinMax.F32Max)>;
2741def : Pat<(f32 (fmaxnum_ieee (fcanonicalize f32:$A), (fcanonicalize f32:$B))),
2742          (f32 FpMinMax.F32Max)>;
2743
2744// f64 Min.
2745def : Pat<(f64 (fminnum_ieee f64:$A, f64:$B)),
2746          (f64 (XSMINDP $A, $B))>;
2747def : Pat<(f64 (fminnum_ieee (fcanonicalize f64:$A), f64:$B)),
2748          (f64 (XSMINDP $A, $B))>;
2749def : Pat<(f64 (fminnum_ieee f64:$A, (fcanonicalize f64:$B))),
2750          (f64 (XSMINDP $A, $B))>;
2751def : Pat<(f64 (fminnum_ieee (fcanonicalize f64:$A), (fcanonicalize f64:$B))),
2752          (f64 (XSMINDP $A, $B))>;
2753// f64 Max.
2754def : Pat<(f64 (fmaxnum_ieee f64:$A, f64:$B)),
2755          (f64 (XSMAXDP $A, $B))>;
2756def : Pat<(f64 (fmaxnum_ieee (fcanonicalize f64:$A), f64:$B)),
2757          (f64 (XSMAXDP $A, $B))>;
2758def : Pat<(f64 (fmaxnum_ieee f64:$A, (fcanonicalize f64:$B))),
2759          (f64 (XSMAXDP $A, $B))>;
2760def : Pat<(f64 (fmaxnum_ieee (fcanonicalize f64:$A), (fcanonicalize f64:$B))),
2761          (f64 (XSMAXDP $A, $B))>;
2762
2763def : Pat<(int_ppc_vsx_stxvd2x_be v2f64:$rS, ForceXForm:$dst),
2764            (STXVD2X $rS, ForceXForm:$dst)>;
2765def : Pat<(int_ppc_vsx_stxvw4x_be v4i32:$rS, ForceXForm:$dst),
2766            (STXVW4X $rS, ForceXForm:$dst)>;
2767def : Pat<(v4i32 (int_ppc_vsx_lxvw4x_be ForceXForm:$src)), (LXVW4X ForceXForm:$src)>;
2768def : Pat<(v2f64 (int_ppc_vsx_lxvd2x_be ForceXForm:$src)), (LXVD2X ForceXForm:$src)>;
2769
2770// Rounding for single precision.
2771def : Pat<(f32 (any_fround f32:$S)),
2772          (f32 (COPY_TO_REGCLASS (XSRDPI
2773                                   (COPY_TO_REGCLASS $S, VSFRC)), VSSRC))>;
2774def : Pat<(f32 (fnearbyint f32:$S)),
2775          (f32 (COPY_TO_REGCLASS (XSRDPIC
2776                                   (COPY_TO_REGCLASS $S, VSFRC)), VSSRC))>;
2777def : Pat<(f32 (any_ffloor f32:$S)),
2778          (f32 (COPY_TO_REGCLASS (XSRDPIM
2779                                   (COPY_TO_REGCLASS $S, VSFRC)), VSSRC))>;
2780def : Pat<(f32 (any_fceil f32:$S)),
2781          (f32 (COPY_TO_REGCLASS (XSRDPIP
2782                                   (COPY_TO_REGCLASS $S, VSFRC)), VSSRC))>;
2783def : Pat<(f32 (any_ftrunc f32:$S)),
2784          (f32 (COPY_TO_REGCLASS (XSRDPIZ
2785                                   (COPY_TO_REGCLASS $S, VSFRC)), VSSRC))>;
2786def : Pat<(f32 (any_frint f32:$S)),
2787          (f32 (COPY_TO_REGCLASS (XSRDPIC
2788                                   (COPY_TO_REGCLASS $S, VSFRC)), VSSRC))>;
2789def : Pat<(v4f32 (any_frint v4f32:$S)), (v4f32 (XVRSPIC $S))>;
2790
2791// Rounding for double precision.
2792def : Pat<(f64 (any_frint f64:$S)), (f64 (XSRDPIC $S))>;
2793def : Pat<(v2f64 (any_frint v2f64:$S)), (v2f64 (XVRDPIC $S))>;
2794
2795// Materialize a zero-vector of long long
2796def : Pat<(v2i64 immAllZerosV),
2797          (v2i64 (XXLXORz))>;
2798
2799// Build vectors of floating point converted to i32.
2800def : Pat<(v4i32 (build_vector DblToInt.A, DblToInt.A,
2801                               DblToInt.A, DblToInt.A)),
2802          (v4i32 (XXSPLTW (SUBREG_TO_REG (i64 1), (XSCVDPSXWS $A), sub_64), 1))>;
2803def : Pat<(v4i32 (build_vector DblToUInt.A, DblToUInt.A,
2804                               DblToUInt.A, DblToUInt.A)),
2805          (v4i32 (XXSPLTW (SUBREG_TO_REG (i64 1), (XSCVDPUXWS $A), sub_64), 1))>;
2806def : Pat<(v2i64 (build_vector DblToLong.A, DblToLong.A)),
2807          (v2i64 (XXPERMDI (SUBREG_TO_REG (i64 1), (XSCVDPSXDS $A), sub_64),
2808                           (SUBREG_TO_REG (i64 1), (XSCVDPSXDS $A), sub_64), 0))>;
2809def : Pat<(v2i64 (build_vector DblToULong.A, DblToULong.A)),
2810          (v2i64 (XXPERMDI (SUBREG_TO_REG (i64 1), (XSCVDPUXDS $A), sub_64),
2811                           (SUBREG_TO_REG (i64 1), (XSCVDPUXDS $A), sub_64), 0))>;
2812defm : ScalToVecWPermute<
2813  v4i32, FltToIntLoad.A,
2814  (XXSPLTW (SUBREG_TO_REG (i64 1), (XSCVDPSXWSs (XFLOADf32 ForceXForm:$A)), sub_64), 1),
2815  (SUBREG_TO_REG (i64 1), (XSCVDPSXWSs (XFLOADf32 ForceXForm:$A)), sub_64)>;
2816defm : ScalToVecWPermute<
2817  v4i32, FltToUIntLoad.A,
2818  (XXSPLTW (SUBREG_TO_REG (i64 1), (XSCVDPUXWSs (XFLOADf32 ForceXForm:$A)), sub_64), 1),
2819  (SUBREG_TO_REG (i64 1), (XSCVDPUXWSs (XFLOADf32 ForceXForm:$A)), sub_64)>;
2820def : Pat<(v4f32 (build_vector (f32 (fpround f64:$A)), (f32 (fpround f64:$A)),
2821                               (f32 (fpround f64:$A)), (f32 (fpround f64:$A)))),
2822          (v4f32 (XXSPLTW (SUBREG_TO_REG (i64 1), (XSCVDPSP f64:$A), sub_64), 0))>;
2823
2824def : Pat<(v4f32 (build_vector f32:$A, f32:$A, f32:$A, f32:$A)),
2825          (v4f32 (XXSPLTW (v4f32 (XSCVDPSPN $A)), 0))>;
2826def : Pat<(v2f64 (PPCldsplat ForceXForm:$A)),
2827          (v2f64 (LXVDSX ForceXForm:$A))>;
2828def : Pat<(v2i64 (PPCldsplat ForceXForm:$A)),
2829          (v2i64 (LXVDSX ForceXForm:$A))>;
2830
2831// Build vectors of floating point converted to i64.
2832def : Pat<(v2i64 (build_vector FltToLong.A, FltToLong.A)),
2833          (v2i64 (XXPERMDIs
2834                   (COPY_TO_REGCLASS (XSCVDPSXDSs $A), VSFRC), 0))>;
2835def : Pat<(v2i64 (build_vector FltToULong.A, FltToULong.A)),
2836          (v2i64 (XXPERMDIs
2837                   (COPY_TO_REGCLASS (XSCVDPUXDSs $A), VSFRC), 0))>;
2838defm : ScalToVecWPermute<
2839  v2i64, DblToLongLoad.A,
2840  (XVCVDPSXDS (LXVDSX ForceXForm:$A)), (XVCVDPSXDS (LXVDSX ForceXForm:$A))>;
2841defm : ScalToVecWPermute<
2842  v2i64, DblToULongLoad.A,
2843  (XVCVDPUXDS (LXVDSX ForceXForm:$A)), (XVCVDPUXDS (LXVDSX ForceXForm:$A))>;
2844
2845// Doubleword vector predicate comparisons without Power8.
2846let AddedComplexity = 0 in {
2847def : Pat<(v2i64 (PPCvcmp_rec v2i64:$vA, v2i64:$vB, 967)),
2848          (VCMPGTUB_rec DblwdCmp.MRGSGT, (v2i64 (XXLXORz)))>;
2849def : Pat<(v2i64 (PPCvcmp_rec v2i64:$vA, v2i64:$vB, 711)),
2850          (VCMPGTUB_rec DblwdCmp.MRGUGT, (v2i64 (XXLXORz)))>;
2851def : Pat<(v2i64 (PPCvcmp_rec v2i64:$vA, v2i64:$vB, 199)),
2852          (VCMPGTUB_rec DblwdCmp.MRGEQ, (v2i64 (XXLXORz)))>;
2853} // AddedComplexity = 0
2854
2855// XL Compat builtins.
2856def : Pat<(int_ppc_fmsub f64:$A, f64:$B, f64:$C), (XSMSUBMDP $A, $B, $C)>;
2857def : Pat<(int_ppc_fnmsub f64:$A, f64:$B, f64:$C), (XSNMSUBMDP $A, $B, $C)>;
2858def : Pat<(int_ppc_fnmadd f64:$A, f64:$B, f64:$C), (XSNMADDMDP $A, $B, $C)>;
2859def : Pat<(int_ppc_fre f64:$A), (XSREDP $A)>;
2860def : Pat<(int_ppc_frsqrte vsfrc:$XB), (XSRSQRTEDP $XB)>;
2861} // HasVSX
2862
2863// Any big endian VSX subtarget.
2864let Predicates = [HasVSX, IsBigEndian] in {
2865def : Pat<(v2f64 (scalar_to_vector f64:$A)),
2866          (v2f64 (SUBREG_TO_REG (i64 1), $A, sub_64))>;
2867
2868def : Pat<(f64 (extractelt v2f64:$S, 0)),
2869          (f64 (EXTRACT_SUBREG $S, sub_64))>;
2870def : Pat<(f64 (extractelt v2f64:$S, 1)),
2871          (f64 (EXTRACT_SUBREG (XXPERMDI $S, $S, 2), sub_64))>;
2872def : Pat<(f64 (PPCfcfid (PPCmtvsra (i64 (vector_extract v2i64:$S, 0))))),
2873          (f64 (XSCVSXDDP (COPY_TO_REGCLASS $S, VSFRC)))>;
2874def : Pat<(f64 (PPCfcfid (PPCmtvsra (i64 (vector_extract v2i64:$S, 1))))),
2875          (f64 (XSCVSXDDP (COPY_TO_REGCLASS (XXPERMDI $S, $S, 2), VSFRC)))>;
2876def : Pat<(f64 (PPCfcfidu (PPCmtvsra (i64 (vector_extract v2i64:$S, 0))))),
2877          (f64 (XSCVUXDDP (COPY_TO_REGCLASS $S, VSFRC)))>;
2878def : Pat<(f64 (PPCfcfidu (PPCmtvsra (i64 (vector_extract v2i64:$S, 1))))),
2879          (f64 (XSCVUXDDP (COPY_TO_REGCLASS (XXPERMDI $S, $S, 2), VSFRC)))>;
2880
2881def : Pat<(f64 (vector_extract v2f64:$S, i64:$Idx)),
2882          (f64 VectorExtractions.BE_VARIABLE_DOUBLE)>;
2883
2884def : Pat<(v2f64 (build_vector f64:$A, f64:$B)),
2885          (v2f64 (XXPERMDI
2886                    (SUBREG_TO_REG (i64 1), $A, sub_64),
2887                    (SUBREG_TO_REG (i64 1), $B, sub_64), 0))>;
2888// Using VMRGEW to assemble the final vector would be a lower latency
2889// solution. However, we choose to go with the slightly higher latency
2890// XXPERMDI for 2 reasons:
2891// 1. This is likely to occur in unrolled loops where regpressure is high,
2892//    so we want to use the latter as it has access to all 64 VSX registers.
2893// 2. Using Altivec instructions in this sequence would likely cause the
2894//    allocation of Altivec registers even for the loads which in turn would
2895//    force the use of LXSIWZX for the loads, adding a cycle of latency to
2896//    each of the loads which would otherwise be able to use LFIWZX.
2897def : Pat<(v4f32 (build_vector LoadFP.A, LoadFP.B, LoadFP.C, LoadFP.D)),
2898          (v4f32 (XXPERMDI (XXMRGHW MrgFP.LD32A, MrgFP.LD32B),
2899                           (XXMRGHW MrgFP.LD32C, MrgFP.LD32D), 3))>;
2900def : Pat<(v4f32 (build_vector f32:$A, f32:$B, f32:$C, f32:$D)),
2901          (VMRGEW MrgFP.AC, MrgFP.BD)>;
2902def : Pat<(v4f32 (build_vector DblToFlt.A0, DblToFlt.A1,
2903                               DblToFlt.B0, DblToFlt.B1)),
2904          (v4f32 (VMRGEW MrgFP.ABhToFlt, MrgFP.ABlToFlt))>;
2905
2906// Convert 4 doubles to a vector of ints.
2907def : Pat<(v4i32 (build_vector DblToInt.A, DblToInt.B,
2908                               DblToInt.C, DblToInt.D)),
2909          (v4i32 (VMRGEW MrgWords.CVACS, MrgWords.CVBDS))>;
2910def : Pat<(v4i32 (build_vector DblToUInt.A, DblToUInt.B,
2911                               DblToUInt.C, DblToUInt.D)),
2912          (v4i32 (VMRGEW MrgWords.CVACU, MrgWords.CVBDU))>;
2913def : Pat<(v4i32 (build_vector ExtDbl.A0S, ExtDbl.A1S,
2914                               ExtDbl.B0S, ExtDbl.B1S)),
2915          (v4i32 (VMRGEW MrgWords.CVA0B0S, MrgWords.CVA1B1S))>;
2916def : Pat<(v4i32 (build_vector ExtDbl.A0U, ExtDbl.A1U,
2917                               ExtDbl.B0U, ExtDbl.B1U)),
2918          (v4i32 (VMRGEW MrgWords.CVA0B0U, MrgWords.CVA1B1U))>;
2919def : Pat<(v2f64 (build_vector (f64 (fpextend (extractelt v4f32:$A, 0))),
2920                               (f64 (fpextend (extractelt v4f32:$A, 1))))),
2921          (v2f64 (XVCVSPDP (XXMRGHW $A, $A)))>;
2922def : Pat<(v2f64 (build_vector (f64 (fpextend (extractelt v4f32:$A, 1))),
2923                               (f64 (fpextend (extractelt v4f32:$A, 0))))),
2924          (v2f64 (XXPERMDI (XVCVSPDP (XXMRGHW $A, $A)),
2925                           (XVCVSPDP (XXMRGHW $A, $A)), 2))>;
2926def : Pat<(v2f64 (build_vector (f64 (fpextend (extractelt v4f32:$A, 0))),
2927                               (f64 (fpextend (extractelt v4f32:$A, 2))))),
2928          (v2f64 (XVCVSPDP $A))>;
2929def : Pat<(v2f64 (build_vector (f64 (fpextend (extractelt v4f32:$A, 1))),
2930                               (f64 (fpextend (extractelt v4f32:$A, 3))))),
2931          (v2f64 (XVCVSPDP (XXSLDWI $A, $A, 3)))>;
2932def : Pat<(v2f64 (build_vector (f64 (fpextend (extractelt v4f32:$A, 2))),
2933                               (f64 (fpextend (extractelt v4f32:$A, 3))))),
2934          (v2f64 (XVCVSPDP (XXMRGLW $A, $A)))>;
2935def : Pat<(v2f64 (build_vector (f64 (fpextend (extractelt v4f32:$A, 3))),
2936                               (f64 (fpextend (extractelt v4f32:$A, 2))))),
2937          (v2f64 (XXPERMDI (XVCVSPDP (XXMRGLW $A, $A)),
2938                           (XVCVSPDP (XXMRGLW $A, $A)), 2))>;
2939def : Pat<(v2f64 (build_vector (f64 (fpextend (extractelt v4f32:$A, 0))),
2940                               (f64 (fpextend (extractelt v4f32:$B, 0))))),
2941          (v2f64 (XVCVSPDP (XXPERMDI $A, $B, 0)))>;
2942def : Pat<(v2f64 (build_vector (f64 (fpextend (extractelt v4f32:$A, 3))),
2943                               (f64 (fpextend (extractelt v4f32:$B, 3))))),
2944          (v2f64 (XVCVSPDP (XXSLDWI (XXPERMDI $A, $B, 3),
2945                                    (XXPERMDI $A, $B, 3), 1)))>;
2946def : Pat<(v2i64 (fp_to_sint
2947                   (build_vector (f64 (fpextend (extractelt v4f32:$A, 0))),
2948                                 (f64 (fpextend (extractelt v4f32:$A, 2)))))),
2949          (v2i64 (XVCVSPSXDS $A))>;
2950def : Pat<(v2i64 (fp_to_uint
2951                   (build_vector (f64 (fpextend (extractelt v4f32:$A, 0))),
2952                                 (f64 (fpextend (extractelt v4f32:$A, 2)))))),
2953          (v2i64 (XVCVSPUXDS $A))>;
2954def : Pat<(v2i64 (fp_to_sint
2955                   (build_vector (f64 (fpextend (extractelt v4f32:$A, 1))),
2956                                 (f64 (fpextend (extractelt v4f32:$A, 3)))))),
2957          (v2i64 (XVCVSPSXDS (XXSLDWI $A, $A, 1)))>;
2958def : Pat<(v2i64 (fp_to_uint
2959                   (build_vector (f64 (fpextend (extractelt v4f32:$A, 1))),
2960                                 (f64 (fpextend (extractelt v4f32:$A, 3)))))),
2961          (v2i64 (XVCVSPUXDS (XXSLDWI $A, $A, 1)))>;
2962def : Pat<WToDPExtractConv.BV02S,
2963          (v2f64 (XVCVSXWDP $A))>;
2964def : Pat<WToDPExtractConv.BV13S,
2965          (v2f64 (XVCVSXWDP (XXSLDWI $A, $A, 3)))>;
2966def : Pat<WToDPExtractConv.BV02U,
2967          (v2f64 (XVCVUXWDP $A))>;
2968def : Pat<WToDPExtractConv.BV13U,
2969          (v2f64 (XVCVUXWDP (XXSLDWI $A, $A, 3)))>;
2970def : Pat<(v2f64 (insertelt v2f64:$A, f64:$B, 0)),
2971          (v2f64 (XXPERMDI (SUBREG_TO_REG (i64 1), $B, sub_64), $A, 1))>;
2972def : Pat<(v2f64 (insertelt v2f64:$A, f64:$B, 1)),
2973          (v2f64 (XXPERMDI $A, (SUBREG_TO_REG (i64 1), $B, sub_64), 0))>;
2974} // HasVSX, IsBigEndian
2975
2976// Any little endian VSX subtarget.
2977let Predicates = [HasVSX, IsLittleEndian] in {
2978defm : ScalToVecWPermute<v2f64, (f64 f64:$A),
2979                         (XXPERMDI (SUBREG_TO_REG (i64 1), $A, sub_64),
2980                                   (SUBREG_TO_REG (i64 1), $A, sub_64), 0),
2981                         (SUBREG_TO_REG (i64 1), $A, sub_64)>;
2982
2983def : Pat<(f64 (extractelt (v2f64 (bitconvert (v16i8
2984                 (PPCvperm v16i8:$A, v16i8:$B, v16i8:$C)))), 0)),
2985          (f64 (EXTRACT_SUBREG (VPERM $B, $A, $C), sub_64))>;
2986def : Pat<(f64 (extractelt v2f64:$S, 0)),
2987          (f64 (EXTRACT_SUBREG (XXPERMDI $S, $S, 2), sub_64))>;
2988def : Pat<(f64 (extractelt v2f64:$S, 1)),
2989          (f64 (EXTRACT_SUBREG $S, sub_64))>;
2990
2991def : Pat<(v2f64 (PPCld_vec_be ForceXForm:$src)), (LXVD2X ForceXForm:$src)>;
2992def : Pat<(PPCst_vec_be v2f64:$rS, ForceXForm:$dst), (STXVD2X $rS, ForceXForm:$dst)>;
2993def : Pat<(v4f32 (PPCld_vec_be ForceXForm:$src)), (LXVW4X ForceXForm:$src)>;
2994def : Pat<(PPCst_vec_be v4f32:$rS, ForceXForm:$dst), (STXVW4X $rS, ForceXForm:$dst)>;
2995def : Pat<(v2i64 (PPCld_vec_be ForceXForm:$src)), (LXVD2X ForceXForm:$src)>;
2996def : Pat<(PPCst_vec_be v2i64:$rS, ForceXForm:$dst), (STXVD2X $rS, ForceXForm:$dst)>;
2997def : Pat<(v4i32 (PPCld_vec_be ForceXForm:$src)), (LXVW4X ForceXForm:$src)>;
2998def : Pat<(PPCst_vec_be v4i32:$rS, ForceXForm:$dst), (STXVW4X $rS, ForceXForm:$dst)>;
2999def : Pat<(f64 (PPCfcfid (PPCmtvsra (i64 (vector_extract v2i64:$S, 0))))),
3000          (f64 (XSCVSXDDP (COPY_TO_REGCLASS (XXPERMDI $S, $S, 2), VSFRC)))>;
3001def : Pat<(f64 (PPCfcfid (PPCmtvsra (i64 (vector_extract v2i64:$S, 1))))),
3002          (f64 (XSCVSXDDP (COPY_TO_REGCLASS (f64 (COPY_TO_REGCLASS $S, VSRC)), VSFRC)))>;
3003def : Pat<(f64 (PPCfcfidu (PPCmtvsra (i64 (vector_extract v2i64:$S, 0))))),
3004          (f64 (XSCVUXDDP (COPY_TO_REGCLASS (XXPERMDI $S, $S, 2), VSFRC)))>;
3005def : Pat<(f64 (PPCfcfidu (PPCmtvsra (i64 (vector_extract v2i64:$S, 1))))),
3006          (f64 (XSCVUXDDP (COPY_TO_REGCLASS (f64 (COPY_TO_REGCLASS $S, VSRC)), VSFRC)))>;
3007
3008def : Pat<(f64 (vector_extract v2f64:$S, i64:$Idx)),
3009          (f64 VectorExtractions.LE_VARIABLE_DOUBLE)>;
3010
3011// Little endian, available on all targets with VSX
3012def : Pat<(v2f64 (build_vector f64:$A, f64:$B)),
3013          (v2f64 (XXPERMDI
3014                    (SUBREG_TO_REG (i64 1), $B, sub_64),
3015                    (SUBREG_TO_REG (i64 1), $A, sub_64), 0))>;
3016// Using VMRGEW to assemble the final vector would be a lower latency
3017// solution. However, we choose to go with the slightly higher latency
3018// XXPERMDI for 2 reasons:
3019// 1. This is likely to occur in unrolled loops where regpressure is high,
3020//    so we want to use the latter as it has access to all 64 VSX registers.
3021// 2. Using Altivec instructions in this sequence would likely cause the
3022//    allocation of Altivec registers even for the loads which in turn would
3023//    force the use of LXSIWZX for the loads, adding a cycle of latency to
3024//    each of the loads which would otherwise be able to use LFIWZX.
3025def : Pat<(v4f32 (build_vector LoadFP.A, LoadFP.B, LoadFP.C, LoadFP.D)),
3026          (v4f32 (XXPERMDI (XXMRGHW MrgFP.LD32D, MrgFP.LD32C),
3027                           (XXMRGHW MrgFP.LD32B, MrgFP.LD32A), 3))>;
3028def : Pat<(v4f32 (build_vector f32:$D, f32:$C, f32:$B, f32:$A)),
3029          (VMRGEW MrgFP.AC, MrgFP.BD)>;
3030def : Pat<(v4f32 (build_vector DblToFlt.A0, DblToFlt.A1,
3031                               DblToFlt.B0, DblToFlt.B1)),
3032          (v4f32 (VMRGEW MrgFP.BAhToFlt, MrgFP.BAlToFlt))>;
3033
3034// Convert 4 doubles to a vector of ints.
3035def : Pat<(v4i32 (build_vector DblToInt.A, DblToInt.B,
3036                               DblToInt.C, DblToInt.D)),
3037          (v4i32 (VMRGEW MrgWords.CVDBS, MrgWords.CVCAS))>;
3038def : Pat<(v4i32 (build_vector DblToUInt.A, DblToUInt.B,
3039                               DblToUInt.C, DblToUInt.D)),
3040          (v4i32 (VMRGEW MrgWords.CVDBU, MrgWords.CVCAU))>;
3041def : Pat<(v4i32 (build_vector ExtDbl.A0S, ExtDbl.A1S,
3042                               ExtDbl.B0S, ExtDbl.B1S)),
3043          (v4i32 (VMRGEW MrgWords.CVB1A1S, MrgWords.CVB0A0S))>;
3044def : Pat<(v4i32 (build_vector ExtDbl.A0U, ExtDbl.A1U,
3045                               ExtDbl.B0U, ExtDbl.B1U)),
3046          (v4i32 (VMRGEW MrgWords.CVB1A1U, MrgWords.CVB0A0U))>;
3047def : Pat<(v2f64 (build_vector (f64 (fpextend (extractelt v4f32:$A, 0))),
3048                               (f64 (fpextend (extractelt v4f32:$A, 1))))),
3049          (v2f64 (XVCVSPDP (XXMRGLW $A, $A)))>;
3050def : Pat<(v2f64 (build_vector (f64 (fpextend (extractelt v4f32:$A, 1))),
3051                               (f64 (fpextend (extractelt v4f32:$A, 0))))),
3052          (v2f64 (XXPERMDI (XVCVSPDP (XXMRGLW $A, $A)),
3053                           (XVCVSPDP (XXMRGLW $A, $A)), 2))>;
3054def : Pat<(v2f64 (build_vector (f64 (fpextend (extractelt v4f32:$A, 0))),
3055                               (f64 (fpextend (extractelt v4f32:$A, 2))))),
3056          (v2f64 (XVCVSPDP (XXSLDWI $A, $A, 1)))>;
3057def : Pat<(v2f64 (build_vector (f64 (fpextend (extractelt v4f32:$A, 1))),
3058                               (f64 (fpextend (extractelt v4f32:$A, 3))))),
3059          (v2f64 (XVCVSPDP $A))>;
3060def : Pat<(v2f64 (build_vector (f64 (fpextend (extractelt v4f32:$A, 2))),
3061                               (f64 (fpextend (extractelt v4f32:$A, 3))))),
3062          (v2f64 (XVCVSPDP (XXMRGHW $A, $A)))>;
3063def : Pat<(v2f64 (build_vector (f64 (fpextend (extractelt v4f32:$A, 3))),
3064                               (f64 (fpextend (extractelt v4f32:$A, 2))))),
3065          (v2f64 (XXPERMDI (XVCVSPDP (XXMRGHW $A, $A)),
3066                           (XVCVSPDP (XXMRGHW $A, $A)), 2))>;
3067def : Pat<(v2f64 (build_vector (f64 (fpextend (extractelt v4f32:$A, 0))),
3068                               (f64 (fpextend (extractelt v4f32:$B, 0))))),
3069          (v2f64 (XVCVSPDP (XXSLDWI (XXPERMDI $B, $A, 3),
3070                                    (XXPERMDI $B, $A, 3), 1)))>;
3071def : Pat<(v2f64 (build_vector (f64 (fpextend (extractelt v4f32:$A, 3))),
3072                               (f64 (fpextend (extractelt v4f32:$B, 3))))),
3073          (v2f64 (XVCVSPDP (XXPERMDI $B, $A, 0)))>;
3074def : Pat<(v2i64 (fp_to_sint
3075                   (build_vector (f64 (fpextend (extractelt v4f32:$A, 1))),
3076                                 (f64 (fpextend (extractelt v4f32:$A, 3)))))),
3077          (v2i64 (XVCVSPSXDS $A))>;
3078def : Pat<(v2i64 (fp_to_uint
3079                   (build_vector (f64 (fpextend (extractelt v4f32:$A, 1))),
3080                                 (f64 (fpextend (extractelt v4f32:$A, 3)))))),
3081          (v2i64 (XVCVSPUXDS $A))>;
3082def : Pat<(v2i64 (fp_to_sint
3083                   (build_vector (f64 (fpextend (extractelt v4f32:$A, 0))),
3084                                 (f64 (fpextend (extractelt v4f32:$A, 2)))))),
3085          (v2i64 (XVCVSPSXDS (XXSLDWI $A, $A, 1)))>;
3086def : Pat<(v2i64 (fp_to_uint
3087                   (build_vector (f64 (fpextend (extractelt v4f32:$A, 0))),
3088                                 (f64 (fpextend (extractelt v4f32:$A, 2)))))),
3089          (v2i64 (XVCVSPUXDS (XXSLDWI $A, $A, 1)))>;
3090def : Pat<WToDPExtractConv.BV02S,
3091          (v2f64 (XVCVSXWDP (XXSLDWI $A, $A, 1)))>;
3092def : Pat<WToDPExtractConv.BV13S,
3093          (v2f64 (XVCVSXWDP $A))>;
3094def : Pat<WToDPExtractConv.BV02U,
3095          (v2f64 (XVCVUXWDP (XXSLDWI $A, $A, 1)))>;
3096def : Pat<WToDPExtractConv.BV13U,
3097          (v2f64 (XVCVUXWDP $A))>;
3098def : Pat<(v2f64 (insertelt v2f64:$A, f64:$B, 0)),
3099          (v2f64 (XXPERMDI $A, (SUBREG_TO_REG (i64 1), $B, sub_64), 0))>;
3100def : Pat<(v2f64 (insertelt v2f64:$A, f64:$B, 1)),
3101          (v2f64 (XXPERMDI (SUBREG_TO_REG (i64 1), $B, sub_64), $A, 1))>;
3102} // HasVSX, IsLittleEndian
3103
3104// Any pre-Power9 VSX subtarget.
3105let Predicates = [HasVSX, NoP9Vector] in {
3106def : Pat<(PPCstore_scal_int_from_vsr
3107            (f64 (PPCcv_fp_to_sint_in_vsr f64:$src)), ForceXForm:$dst, 8),
3108          (STXSDX (XSCVDPSXDS f64:$src), ForceXForm:$dst)>;
3109def : Pat<(PPCstore_scal_int_from_vsr
3110            (f64 (PPCcv_fp_to_uint_in_vsr f64:$src)), ForceXForm:$dst, 8),
3111          (STXSDX (XSCVDPUXDS f64:$src), ForceXForm:$dst)>;
3112
3113// Load-and-splat with fp-to-int conversion (using X-Form VSX/FP loads).
3114defm : ScalToVecWPermute<
3115  v4i32, DblToIntLoad.A,
3116  (XXSPLTW (SUBREG_TO_REG (i64 1), (XSCVDPSXWS (XFLOADf64 ForceXForm:$A)), sub_64), 1),
3117  (SUBREG_TO_REG (i64 1), (XSCVDPSXWS (XFLOADf64 ForceXForm:$A)), sub_64)>;
3118defm : ScalToVecWPermute<
3119  v4i32, DblToUIntLoad.A,
3120  (XXSPLTW (SUBREG_TO_REG (i64 1), (XSCVDPUXWS (XFLOADf64 ForceXForm:$A)), sub_64), 1),
3121  (SUBREG_TO_REG (i64 1), (XSCVDPUXWS (XFLOADf64 ForceXForm:$A)), sub_64)>;
3122defm : ScalToVecWPermute<
3123  v2i64, FltToLongLoad.A,
3124  (XXPERMDIs (XSCVDPSXDS (COPY_TO_REGCLASS (XFLOADf32 ForceXForm:$A), VSFRC)), 0),
3125  (SUBREG_TO_REG (i64 1), (XSCVDPSXDS (COPY_TO_REGCLASS (XFLOADf32 ForceXForm:$A),
3126                                                        VSFRC)), sub_64)>;
3127defm : ScalToVecWPermute<
3128  v2i64, FltToULongLoad.A,
3129  (XXPERMDIs (XSCVDPUXDS (COPY_TO_REGCLASS (XFLOADf32 ForceXForm:$A), VSFRC)), 0),
3130  (SUBREG_TO_REG (i64 1), (XSCVDPUXDS (COPY_TO_REGCLASS (XFLOADf32 ForceXForm:$A),
3131                                                        VSFRC)), sub_64)>;
3132} // HasVSX, NoP9Vector
3133
3134// Any little endian pre-Power9 VSX subtarget.
3135let Predicates = [HasVSX, NoP9Vector, IsLittleEndian] in {
3136// Load-and-splat using only X-Form VSX loads.
3137defm : ScalToVecWPermute<
3138  v2i64, (i64 (load ForceXForm:$src)),
3139  (XXPERMDIs (XFLOADf64 ForceXForm:$src), 2),
3140  (SUBREG_TO_REG (i64 1), (XFLOADf64 ForceXForm:$src), sub_64)>;
3141defm : ScalToVecWPermute<
3142  v2f64, (f64 (load ForceXForm:$src)),
3143  (XXPERMDIs (XFLOADf64 ForceXForm:$src), 2),
3144  (SUBREG_TO_REG (i64 1), (XFLOADf64 ForceXForm:$src), sub_64)>;
3145} // HasVSX, NoP9Vector, IsLittleEndian
3146
3147let Predicates = [HasVSX, NoP9Vector, IsBigEndian] in {
3148  def : Pat<(v2f64 (int_ppc_vsx_lxvd2x ForceXForm:$src)),
3149            (LXVD2X ForceXForm:$src)>;
3150  def : Pat<(int_ppc_vsx_stxvd2x v2f64:$rS, ForceXForm:$dst),
3151            (STXVD2X $rS, ForceXForm:$dst)>;
3152} // HasVSX, NoP9Vector, IsBigEndian
3153
3154// Any VSX subtarget that only has loads and stores that load in big endian
3155// order regardless of endianness. This is really pre-Power9 subtargets.
3156let Predicates = [HasVSX, HasOnlySwappingMemOps] in {
3157  def : Pat<(v2f64 (PPClxvd2x ForceXForm:$src)), (LXVD2X ForceXForm:$src)>;
3158
3159  // Stores.
3160  def : Pat<(PPCstxvd2x v2f64:$rS, ForceXForm:$dst), (STXVD2X $rS, ForceXForm:$dst)>;
3161} // HasVSX, HasOnlySwappingMemOps
3162
3163// Big endian VSX subtarget that only has loads and stores that always
3164// load in big endian order. Really big endian pre-Power9 subtargets.
3165let Predicates = [HasVSX, HasOnlySwappingMemOps, IsBigEndian] in {
3166  def : Pat<(v2f64 (load ForceXForm:$src)), (LXVD2X ForceXForm:$src)>;
3167  def : Pat<(v2i64 (load ForceXForm:$src)), (LXVD2X ForceXForm:$src)>;
3168  def : Pat<(v4i32 (load ForceXForm:$src)), (LXVW4X ForceXForm:$src)>;
3169  def : Pat<(v4i32 (int_ppc_vsx_lxvw4x ForceXForm:$src)), (LXVW4X ForceXForm:$src)>;
3170  def : Pat<(store v2f64:$rS, ForceXForm:$dst), (STXVD2X $rS, ForceXForm:$dst)>;
3171  def : Pat<(store v2i64:$rS, ForceXForm:$dst), (STXVD2X $rS, ForceXForm:$dst)>;
3172  def : Pat<(store v4i32:$XT, ForceXForm:$dst), (STXVW4X $XT, ForceXForm:$dst)>;
3173  def : Pat<(int_ppc_vsx_stxvw4x v4i32:$rS, ForceXForm:$dst),
3174            (STXVW4X $rS, ForceXForm:$dst)>;
3175  def : Pat<(v2i64 (scalar_to_vector (i64 (load ForceXForm:$src)))),
3176           (SUBREG_TO_REG (i64 1), (XFLOADf64 ForceXForm:$src), sub_64)>;
3177} // HasVSX, HasOnlySwappingMemOps, IsBigEndian
3178
3179// Any Power8 VSX subtarget.
3180let Predicates = [HasVSX, HasP8Vector] in {
3181def : Pat<(int_ppc_vsx_xxleqv v4i32:$A, v4i32:$B),
3182          (XXLEQV $A, $B)>;
3183def : Pat<(f64 (extloadf32 XForm:$src)),
3184          (COPY_TO_REGCLASS (XFLOADf32 XForm:$src), VSFRC)>;
3185def : Pat<(f32 (fpround (f64 (extloadf32 ForceXForm:$src)))),
3186          (f32 (XFLOADf32 ForceXForm:$src))>;
3187def : Pat<(f64 (any_fpextend f32:$src)),
3188          (COPY_TO_REGCLASS $src, VSFRC)>;
3189
3190def : Pat<(f32 (selectcc i1:$lhs, i1:$rhs, f32:$tval, f32:$fval, SETLT)),
3191          (SELECT_VSSRC (CRANDC $lhs, $rhs), $tval, $fval)>;
3192def : Pat<(f32 (selectcc i1:$lhs, i1:$rhs, f32:$tval, f32:$fval, SETULT)),
3193          (SELECT_VSSRC (CRANDC $rhs, $lhs), $tval, $fval)>;
3194def : Pat<(f32 (selectcc i1:$lhs, i1:$rhs, f32:$tval, f32:$fval, SETLE)),
3195          (SELECT_VSSRC (CRORC  $lhs, $rhs), $tval, $fval)>;
3196def : Pat<(f32 (selectcc i1:$lhs, i1:$rhs, f32:$tval, f32:$fval, SETULE)),
3197          (SELECT_VSSRC (CRORC  $rhs, $lhs), $tval, $fval)>;
3198def : Pat<(f32 (selectcc i1:$lhs, i1:$rhs, f32:$tval, f32:$fval, SETEQ)),
3199          (SELECT_VSSRC (CREQV $lhs, $rhs), $tval, $fval)>;
3200def : Pat<(f32 (selectcc i1:$lhs, i1:$rhs, f32:$tval, f32:$fval, SETGE)),
3201          (SELECT_VSSRC (CRORC  $rhs, $lhs), $tval, $fval)>;
3202def : Pat<(f32 (selectcc i1:$lhs, i1:$rhs, f32:$tval, f32:$fval, SETUGE)),
3203          (SELECT_VSSRC (CRORC  $lhs, $rhs), $tval, $fval)>;
3204def : Pat<(f32 (selectcc i1:$lhs, i1:$rhs, f32:$tval, f32:$fval, SETGT)),
3205          (SELECT_VSSRC (CRANDC $rhs, $lhs), $tval, $fval)>;
3206def : Pat<(f32 (selectcc i1:$lhs, i1:$rhs, f32:$tval, f32:$fval, SETUGT)),
3207          (SELECT_VSSRC (CRANDC $lhs, $rhs), $tval, $fval)>;
3208def : Pat<(f32 (selectcc i1:$lhs, i1:$rhs, f32:$tval, f32:$fval, SETNE)),
3209          (SELECT_VSSRC (CRXOR $lhs, $rhs), $tval, $fval)>;
3210
3211// Additional fnmsub pattern for PPC specific ISD opcode
3212def : Pat<(PPCfnmsub f32:$A, f32:$B, f32:$C),
3213          (XSNMSUBASP $C, $A, $B)>;
3214def : Pat<(fneg (PPCfnmsub f32:$A, f32:$B, f32:$C)),
3215          (XSMSUBASP $C, $A, $B)>;
3216def : Pat<(PPCfnmsub f32:$A, f32:$B, (fneg f32:$C)),
3217          (XSNMADDASP $C, $A, $B)>;
3218
3219// f32 neg
3220// Although XSNEGDP is available in P7, we want to select it starting from P8,
3221// so that FNMSUBS can be selected for fneg-fmsub pattern on P7. (VSX version,
3222// XSNMSUBASP, is available since P8)
3223def : Pat<(f32 (fneg f32:$S)),
3224          (f32 (COPY_TO_REGCLASS (XSNEGDP
3225               (COPY_TO_REGCLASS $S, VSFRC)), VSSRC))>;
3226
3227// Instructions for converting float to i32 feeding a store.
3228def : Pat<(PPCstore_scal_int_from_vsr
3229            (f64 (PPCcv_fp_to_sint_in_vsr f64:$src)), ForceXForm:$dst, 4),
3230          (STIWX (XSCVDPSXWS f64:$src), ForceXForm:$dst)>;
3231def : Pat<(PPCstore_scal_int_from_vsr
3232            (f64 (PPCcv_fp_to_uint_in_vsr f64:$src)), ForceXForm:$dst, 4),
3233          (STIWX (XSCVDPUXWS f64:$src), ForceXForm:$dst)>;
3234
3235def : Pat<(v2i64 (smax v2i64:$src1, v2i64:$src2)),
3236          (v2i64 (VMAXSD (COPY_TO_REGCLASS $src1, VRRC),
3237                         (COPY_TO_REGCLASS $src2, VRRC)))>;
3238def : Pat<(v2i64 (umax v2i64:$src1, v2i64:$src2)),
3239          (v2i64 (VMAXUD (COPY_TO_REGCLASS $src1, VRRC),
3240                         (COPY_TO_REGCLASS $src2, VRRC)))>;
3241def : Pat<(v2i64 (smin v2i64:$src1, v2i64:$src2)),
3242          (v2i64 (VMINSD (COPY_TO_REGCLASS $src1, VRRC),
3243                         (COPY_TO_REGCLASS $src2, VRRC)))>;
3244def : Pat<(v2i64 (umin v2i64:$src1, v2i64:$src2)),
3245          (v2i64 (VMINUD (COPY_TO_REGCLASS $src1, VRRC),
3246                         (COPY_TO_REGCLASS $src2, VRRC)))>;
3247
3248def : Pat<(v1i128 (bitconvert (v16i8 immAllOnesV))),
3249          (v1i128 (COPY_TO_REGCLASS(XXLEQVOnes), VSRC))>;
3250def : Pat<(v2i64 (bitconvert (v16i8 immAllOnesV))),
3251          (v2i64 (COPY_TO_REGCLASS(XXLEQVOnes), VSRC))>;
3252def : Pat<(v8i16 (bitconvert (v16i8 immAllOnesV))),
3253          (v8i16 (COPY_TO_REGCLASS(XXLEQVOnes), VSRC))>;
3254def : Pat<(v16i8 (bitconvert (v16i8 immAllOnesV))),
3255          (v16i8 (COPY_TO_REGCLASS(XXLEQVOnes), VSRC))>;
3256
3257// XL Compat builtins.
3258def : Pat<(int_ppc_fmsubs f32:$A, f32:$B, f32:$C), (XSMSUBMSP $A, $B, $C)>;
3259def : Pat<(int_ppc_fnmsubs f32:$A, f32:$B, f32:$C), (XSNMSUBMSP $A, $B, $C)>;
3260def : Pat<(int_ppc_fnmadds f32:$A, f32:$B, f32:$C), (XSNMADDMSP $A, $B, $C)>;
3261def : Pat<(int_ppc_fres f32:$A), (XSRESP $A)>;
3262def : Pat<(i32 (int_ppc_extract_exp f64:$A)),
3263          (EXTRACT_SUBREG (XSXEXPDP (COPY_TO_REGCLASS $A, VSFRC)), sub_32)>;
3264def : Pat<(int_ppc_extract_sig f64:$A),
3265          (XSXSIGDP (COPY_TO_REGCLASS $A, VSFRC))>;
3266def : Pat<(f64 (int_ppc_insert_exp f64:$A, i64:$B)),
3267          (COPY_TO_REGCLASS (XSIEXPDP (COPY_TO_REGCLASS $A, G8RC), $B), F8RC)>;
3268
3269def : Pat<(int_ppc_stfiw ForceXForm:$dst, f64:$XT),
3270          (STXSIWX f64:$XT, ForceXForm:$dst)>;
3271def : Pat<(int_ppc_frsqrtes vssrc:$XB), (XSRSQRTESP $XB)>;
3272} // HasVSX, HasP8Vector
3273
3274// Any big endian Power8 VSX subtarget.
3275let Predicates = [HasVSX, HasP8Vector, IsBigEndian] in {
3276def : Pat<DWToSPExtractConv.El0SS1,
3277          (f32 (XSCVSXDSP (COPY_TO_REGCLASS $S1, VSFRC)))>;
3278def : Pat<DWToSPExtractConv.El1SS1,
3279          (f32 (XSCVSXDSP (COPY_TO_REGCLASS (XXPERMDI $S1, $S1, 2), VSFRC)))>;
3280def : Pat<DWToSPExtractConv.El0US1,
3281          (f32 (XSCVUXDSP (COPY_TO_REGCLASS $S1, VSFRC)))>;
3282def : Pat<DWToSPExtractConv.El1US1,
3283          (f32 (XSCVUXDSP (COPY_TO_REGCLASS (XXPERMDI $S1, $S1, 2), VSFRC)))>;
3284
3285// v4f32 scalar <-> vector conversions (BE)
3286defm : ScalToVecWPermute<v4f32, (f32 f32:$A), (XSCVDPSPN $A), (XSCVDPSPN $A)>;
3287def : Pat<(f32 (vector_extract v4f32:$S, 0)),
3288          (f32 (XSCVSPDPN $S))>;
3289def : Pat<(f32 (vector_extract v4f32:$S, 1)),
3290          (f32 (XSCVSPDPN (XXSLDWI $S, $S, 1)))>;
3291def : Pat<(f32 (vector_extract v4f32:$S, 2)),
3292          (f32 (XSCVSPDPN (XXPERMDI $S, $S, 2)))>;
3293def : Pat<(f32 (vector_extract v4f32:$S, 3)),
3294          (f32 (XSCVSPDPN (XXSLDWI $S, $S, 3)))>;
3295
3296def : Pat<(f32 (PPCfcfids (f64 (PPCmtvsra (i32 (extractelt v4i32:$A, 0)))))),
3297          (f32 (XSCVSPDPN (XVCVSXWSP (XXSPLTW $A, 0))))>;
3298def : Pat<(f32 (PPCfcfids (f64 (PPCmtvsra (i32 (extractelt v4i32:$A, 1)))))),
3299          (f32 (XSCVSPDPN (XVCVSXWSP (XXSPLTW $A, 1))))>;
3300def : Pat<(f32 (PPCfcfids (f64 (PPCmtvsra (i32 (extractelt v4i32:$A, 2)))))),
3301          (f32 (XSCVSPDPN (XVCVSXWSP (XXSPLTW $A, 2))))>;
3302def : Pat<(f32 (PPCfcfids (f64 (PPCmtvsra (i32 (extractelt v4i32:$A, 3)))))),
3303          (f32 (XSCVSPDPN (XVCVSXWSP (XXSPLTW $A, 3))))>;
3304def : Pat<(f64 (PPCfcfid (f64 (PPCmtvsra (i32 (extractelt v4i32:$A, 0)))))),
3305          (f64 (COPY_TO_REGCLASS (XVCVSXWDP (XXSPLTW $A, 0)), VSFRC))>;
3306def : Pat<(f64 (PPCfcfid (f64 (PPCmtvsra (i32 (extractelt v4i32:$A, 1)))))),
3307          (f64 (COPY_TO_REGCLASS (XVCVSXWDP (XXSPLTW $A, 1)), VSFRC))>;
3308def : Pat<(f64 (PPCfcfid (f64 (PPCmtvsra (i32 (extractelt v4i32:$A, 2)))))),
3309          (f64 (COPY_TO_REGCLASS (XVCVSXWDP (XXSPLTW $A, 2)), VSFRC))>;
3310def : Pat<(f64 (PPCfcfid (f64 (PPCmtvsra (i32 (extractelt v4i32:$A, 3)))))),
3311          (f64 (COPY_TO_REGCLASS (XVCVSXWDP (XXSPLTW $A, 3)), VSFRC))>;
3312
3313def : Pat<(f32 (vector_extract v4f32:$S, i32:$Idx)),
3314          (f32 VectorExtractions.BE_32B_VARIABLE_FLOAT)>;
3315
3316def : Pat<(f64 (vector_extract v2f64:$S, i32:$Idx)),
3317          (f64 VectorExtractions.BE_32B_VARIABLE_DOUBLE)>;
3318} // HasVSX, HasP8Vector, IsBigEndian
3319
3320// Big endian Power8 64Bit VSX subtarget.
3321let Predicates = [HasVSX, HasP8Vector, IsBigEndian, IsPPC64] in {
3322def : Pat<(f32 (vector_extract v4f32:$S, i64:$Idx)),
3323          (f32 VectorExtractions.BE_VARIABLE_FLOAT)>;
3324
3325// LIWAX - This instruction is used for sign extending i32 -> i64.
3326// LIWZX - This instruction will be emitted for i32, f32, and when
3327//         zero-extending i32 to i64 (zext i32 -> i64).
3328def : Pat<(v2i64 (scalar_to_vector (i64 (sextloadi32 ForceXForm:$src)))),
3329          (v2i64 (SUBREG_TO_REG (i64 1), (LIWAX ForceXForm:$src), sub_64))>;
3330def : Pat<(v2i64 (scalar_to_vector (i64 (zextloadi32 ForceXForm:$src)))),
3331          (v2i64 (SUBREG_TO_REG (i64 1), (LIWZX ForceXForm:$src), sub_64))>;
3332defm : ScalToVecWPermute<
3333  v4i32, (i32 (load ForceXForm:$src)),
3334  (XXSLDWIs (LIWZX ForceXForm:$src), 1),
3335  (SUBREG_TO_REG (i64 1), (LIWZX ForceXForm:$src), sub_64)>;
3336defm : ScalToVecWPermute<
3337  v4f32, (f32 (load ForceXForm:$src)),
3338  (XXSLDWIs (LIWZX ForceXForm:$src), 1),
3339  (SUBREG_TO_REG (i64 1), (LIWZX ForceXForm:$src), sub_64)>;
3340
3341def : Pat<DWToSPExtractConv.BVU,
3342          (v4f32 (VPKUDUM (XXSLDWI (XVCVUXDSP $S1), (XVCVUXDSP $S1), 3),
3343                          (XXSLDWI (XVCVUXDSP $S2), (XVCVUXDSP $S2), 3)))>;
3344def : Pat<DWToSPExtractConv.BVS,
3345          (v4f32 (VPKUDUM (XXSLDWI (XVCVSXDSP $S1), (XVCVSXDSP $S1), 3),
3346                          (XXSLDWI (XVCVSXDSP $S2), (XVCVSXDSP $S2), 3)))>;
3347def : Pat<(store (i32 (extractelt v4i32:$A, 1)), ForceXForm:$src),
3348          (STIWX (EXTRACT_SUBREG $A, sub_64), ForceXForm:$src)>;
3349def : Pat<(store (f32 (extractelt v4f32:$A, 1)), ForceXForm:$src),
3350          (STIWX (EXTRACT_SUBREG $A, sub_64), ForceXForm:$src)>;
3351
3352// Elements in a register on a BE system are in order <0, 1, 2, 3>.
3353// The store instructions store the second word from the left.
3354// So to align element zero, we need to modulo-left-shift by 3 words.
3355// Similar logic applies for elements 2 and 3.
3356foreach Idx = [ [0,3], [2,1], [3,2] ] in {
3357  def : Pat<(store (i32 (extractelt v4i32:$A, !head(Idx))), ForceXForm:$src),
3358            (STIWX (EXTRACT_SUBREG (XXSLDWI $A, $A, !head(!tail(Idx))),
3359                                   sub_64), ForceXForm:$src)>;
3360  def : Pat<(store (f32 (extractelt v4f32:$A, !head(Idx))), ForceXForm:$src),
3361            (STIWX (EXTRACT_SUBREG (XXSLDWI $A, $A, !head(!tail(Idx))),
3362                                   sub_64), ForceXForm:$src)>;
3363}
3364} // HasVSX, HasP8Vector, IsBigEndian, IsPPC64
3365
3366// Little endian Power8 VSX subtarget.
3367let Predicates = [HasVSX, HasP8Vector, IsLittleEndian] in {
3368def : Pat<DWToSPExtractConv.El0SS1,
3369          (f32 (XSCVSXDSP (COPY_TO_REGCLASS (XXPERMDI $S1, $S1, 2), VSFRC)))>;
3370def : Pat<DWToSPExtractConv.El1SS1,
3371          (f32 (XSCVSXDSP (COPY_TO_REGCLASS
3372                            (f64 (COPY_TO_REGCLASS $S1, VSRC)), VSFRC)))>;
3373def : Pat<DWToSPExtractConv.El0US1,
3374          (f32 (XSCVUXDSP (COPY_TO_REGCLASS (XXPERMDI $S1, $S1, 2), VSFRC)))>;
3375def : Pat<DWToSPExtractConv.El1US1,
3376          (f32 (XSCVUXDSP (COPY_TO_REGCLASS
3377                            (f64 (COPY_TO_REGCLASS $S1, VSRC)), VSFRC)))>;
3378
3379// v4f32 scalar <-> vector conversions (LE)
3380  defm : ScalToVecWPermute<v4f32, (f32 f32:$A),
3381                           (XXSLDWI (XSCVDPSPN $A), (XSCVDPSPN $A), 1),
3382                           (XSCVDPSPN $A)>;
3383def : Pat<(f32 (vector_extract v4f32:$S, 0)),
3384          (f32 (XSCVSPDPN (XXSLDWI $S, $S, 3)))>;
3385def : Pat<(f32 (vector_extract v4f32:$S, 1)),
3386          (f32 (XSCVSPDPN (XXPERMDI $S, $S, 2)))>;
3387def : Pat<(f32 (vector_extract v4f32:$S, 2)),
3388          (f32 (XSCVSPDPN (XXSLDWI $S, $S, 1)))>;
3389def : Pat<(f32 (vector_extract v4f32:$S, 3)),
3390          (f32 (XSCVSPDPN $S))>;
3391def : Pat<(f32 (vector_extract v4f32:$S, i64:$Idx)),
3392          (f32 VectorExtractions.LE_VARIABLE_FLOAT)>;
3393
3394def : Pat<(f32 (PPCfcfids (f64 (PPCmtvsra (i32 (extractelt v4i32:$A, 0)))))),
3395          (f32 (XSCVSPDPN (XVCVSXWSP (XXSPLTW $A, 3))))>;
3396def : Pat<(f32 (PPCfcfids (f64 (PPCmtvsra (i32 (extractelt v4i32:$A, 1)))))),
3397          (f32 (XSCVSPDPN (XVCVSXWSP (XXSPLTW $A, 2))))>;
3398def : Pat<(f32 (PPCfcfids (f64 (PPCmtvsra (i32 (extractelt v4i32:$A, 2)))))),
3399          (f32 (XSCVSPDPN (XVCVSXWSP (XXSPLTW $A, 1))))>;
3400def : Pat<(f32 (PPCfcfids (f64 (PPCmtvsra (i32 (extractelt v4i32:$A, 3)))))),
3401          (f32 (XSCVSPDPN (XVCVSXWSP (XXSPLTW $A, 0))))>;
3402def : Pat<(f64 (PPCfcfid (f64 (PPCmtvsra (i32 (extractelt v4i32:$A, 0)))))),
3403          (f64 (COPY_TO_REGCLASS (XVCVSXWDP (XXSPLTW $A, 3)), VSFRC))>;
3404def : Pat<(f64 (PPCfcfid (f64 (PPCmtvsra (i32 (extractelt v4i32:$A, 1)))))),
3405          (f64 (COPY_TO_REGCLASS (XVCVSXWDP (XXSPLTW $A, 2)), VSFRC))>;
3406def : Pat<(f64 (PPCfcfid (f64 (PPCmtvsra (i32 (extractelt v4i32:$A, 2)))))),
3407          (f64 (COPY_TO_REGCLASS (XVCVSXWDP (XXSPLTW $A, 1)), VSFRC))>;
3408def : Pat<(f64 (PPCfcfid (f64 (PPCmtvsra (i32 (extractelt v4i32:$A, 3)))))),
3409          (f64 (COPY_TO_REGCLASS (XVCVSXWDP (XXSPLTW $A, 0)), VSFRC))>;
3410
3411// LIWAX - This instruction is used for sign extending i32 -> i64.
3412// LIWZX - This instruction will be emitted for i32, f32, and when
3413//         zero-extending i32 to i64 (zext i32 -> i64).
3414defm : ScalToVecWPermute<
3415  v2i64, (i64 (sextloadi32 ForceXForm:$src)),
3416  (XXPERMDIs (LIWAX ForceXForm:$src), 2),
3417  (SUBREG_TO_REG (i64 1), (LIWAX ForceXForm:$src), sub_64)>;
3418
3419defm : ScalToVecWPermute<
3420  v2i64, (i64 (zextloadi32 ForceXForm:$src)),
3421  (XXPERMDIs (LIWZX ForceXForm:$src), 2),
3422  (SUBREG_TO_REG (i64 1), (LIWZX ForceXForm:$src), sub_64)>;
3423
3424defm : ScalToVecWPermute<
3425  v4i32, (i32 (load ForceXForm:$src)),
3426  (XXPERMDIs (LIWZX ForceXForm:$src), 2),
3427  (SUBREG_TO_REG (i64 1), (LIWZX ForceXForm:$src), sub_64)>;
3428
3429defm : ScalToVecWPermute<
3430  v4f32, (f32 (load ForceXForm:$src)),
3431  (XXPERMDIs (LIWZX ForceXForm:$src), 2),
3432  (SUBREG_TO_REG (i64 1), (LIWZX ForceXForm:$src), sub_64)>;
3433
3434def : Pat<DWToSPExtractConv.BVU,
3435          (v4f32 (VPKUDUM (XXSLDWI (XVCVUXDSP $S2), (XVCVUXDSP $S2), 3),
3436                          (XXSLDWI (XVCVUXDSP $S1), (XVCVUXDSP $S1), 3)))>;
3437def : Pat<DWToSPExtractConv.BVS,
3438          (v4f32 (VPKUDUM (XXSLDWI (XVCVSXDSP $S2), (XVCVSXDSP $S2), 3),
3439                          (XXSLDWI (XVCVSXDSP $S1), (XVCVSXDSP $S1), 3)))>;
3440def : Pat<(store (i32 (extractelt v4i32:$A, 2)), ForceXForm:$src),
3441          (STIWX (EXTRACT_SUBREG $A, sub_64), ForceXForm:$src)>;
3442def : Pat<(store (f32 (extractelt v4f32:$A, 2)), ForceXForm:$src),
3443          (STIWX (EXTRACT_SUBREG $A, sub_64), ForceXForm:$src)>;
3444
3445// Elements in a register on a LE system are in order <3, 2, 1, 0>.
3446// The store instructions store the second word from the left.
3447// So to align element 3, we need to modulo-left-shift by 3 words.
3448// Similar logic applies for elements 0 and 1.
3449foreach Idx = [ [0,2], [1,1], [3,3] ] in {
3450  def : Pat<(store (i32 (extractelt v4i32:$A, !head(Idx))), ForceXForm:$src),
3451            (STIWX (EXTRACT_SUBREG (XXSLDWI $A, $A, !head(!tail(Idx))),
3452                                   sub_64), ForceXForm:$src)>;
3453  def : Pat<(store (f32 (extractelt v4f32:$A, !head(Idx))), ForceXForm:$src),
3454            (STIWX (EXTRACT_SUBREG (XXSLDWI $A, $A, !head(!tail(Idx))),
3455                                   sub_64), ForceXForm:$src)>;
3456}
3457} // HasVSX, HasP8Vector, IsLittleEndian
3458
3459// Big endian pre-Power9 VSX subtarget.
3460let Predicates = [HasVSX, HasP8Vector, NoP9Vector, IsBigEndian, IsPPC64] in {
3461def : Pat<(store (i64 (extractelt v2i64:$A, 0)), ForceXForm:$src),
3462          (XFSTOREf64 (EXTRACT_SUBREG $A, sub_64), ForceXForm:$src)>;
3463def : Pat<(store (f64 (extractelt v2f64:$A, 0)), ForceXForm:$src),
3464          (XFSTOREf64 (EXTRACT_SUBREG $A, sub_64), ForceXForm:$src)>;
3465def : Pat<(store (i64 (extractelt v2i64:$A, 1)), ForceXForm:$src),
3466          (XFSTOREf64 (EXTRACT_SUBREG (XXPERMDI $A, $A, 2), sub_64),
3467                      ForceXForm:$src)>;
3468def : Pat<(store (f64 (extractelt v2f64:$A, 1)), ForceXForm:$src),
3469          (XFSTOREf64 (EXTRACT_SUBREG (XXPERMDI $A, $A, 2), sub_64),
3470                      ForceXForm:$src)>;
3471} // HasVSX, HasP8Vector, NoP9Vector, IsBigEndian, IsPPC64
3472
3473// Little endian pre-Power9 VSX subtarget.
3474let Predicates = [HasVSX, HasP8Vector, NoP9Vector, IsLittleEndian] in {
3475def : Pat<(store (i64 (extractelt v2i64:$A, 0)), ForceXForm:$src),
3476          (XFSTOREf64 (EXTRACT_SUBREG (XXPERMDI $A, $A, 2), sub_64),
3477                      ForceXForm:$src)>;
3478def : Pat<(store (f64 (extractelt v2f64:$A, 0)), ForceXForm:$src),
3479          (XFSTOREf64 (EXTRACT_SUBREG (XXPERMDI $A, $A, 2), sub_64),
3480                      ForceXForm:$src)>;
3481def : Pat<(store (i64 (extractelt v2i64:$A, 1)), ForceXForm:$src),
3482          (XFSTOREf64 (EXTRACT_SUBREG $A, sub_64), ForceXForm:$src)>;
3483def : Pat<(store (f64 (extractelt v2f64:$A, 1)), ForceXForm:$src),
3484          (XFSTOREf64 (EXTRACT_SUBREG $A, sub_64), ForceXForm:$src)>;
3485} // HasVSX, HasP8Vector, NoP9Vector, IsLittleEndian
3486
3487// Any VSX target with direct moves.
3488let Predicates = [HasVSX, HasDirectMove] in {
3489// bitconvert f32 -> i32
3490// (convert to 32-bit fp single, shift right 1 word, move to GPR)
3491def : Pat<(i32 (bitconvert f32:$A)), Bitcast.FltToInt>;
3492
3493// bitconvert i32 -> f32
3494// (move to FPR, shift left 1 word, convert to 64-bit fp single)
3495def : Pat<(f32 (bitconvert i32:$A)),
3496          (f32 (XSCVSPDPN
3497                 (XXSLDWI MovesToVSR.LE_WORD_1, MovesToVSR.LE_WORD_1, 1)))>;
3498
3499// bitconvert f64 -> i64
3500// (move to GPR, nothing else needed)
3501def : Pat<(i64 (bitconvert f64:$A)), Bitcast.DblToLong>;
3502
3503// bitconvert i64 -> f64
3504// (move to FPR, nothing else needed)
3505def : Pat<(f64 (bitconvert i64:$S)),
3506          (f64 (MTVSRD $S))>;
3507
3508// Rounding to integer.
3509def : Pat<(i64 (lrint f64:$S)),
3510          (i64 (MFVSRD (FCTID $S)))>;
3511def : Pat<(i64 (lrint f32:$S)),
3512          (i64 (MFVSRD (FCTID (COPY_TO_REGCLASS $S, F8RC))))>;
3513def : Pat<(i64 (llrint f64:$S)),
3514          (i64 (MFVSRD (FCTID $S)))>;
3515def : Pat<(i64 (llrint f32:$S)),
3516          (i64 (MFVSRD (FCTID (COPY_TO_REGCLASS $S, F8RC))))>;
3517def : Pat<(i64 (lround f64:$S)),
3518          (i64 (MFVSRD (FCTID (XSRDPI $S))))>;
3519def : Pat<(i64 (lround f32:$S)),
3520          (i64 (MFVSRD (FCTID (XSRDPI (COPY_TO_REGCLASS $S, VSFRC)))))>;
3521def : Pat<(i64 (llround f64:$S)),
3522          (i64 (MFVSRD (FCTID (XSRDPI $S))))>;
3523def : Pat<(i64 (llround f32:$S)),
3524          (i64 (MFVSRD (FCTID (XSRDPI (COPY_TO_REGCLASS $S, VSFRC)))))>;
3525
3526// Alternate patterns for PPCmtvsrz where the output is v8i16 or v16i8 instead
3527// of f64
3528def : Pat<(v8i16 (PPCmtvsrz i32:$A)),
3529          (v8i16 (SUBREG_TO_REG (i64 1), (MTVSRWZ $A), sub_64))>;
3530def : Pat<(v16i8 (PPCmtvsrz i32:$A)),
3531          (v16i8 (SUBREG_TO_REG (i64 1), (MTVSRWZ $A), sub_64))>;
3532
3533// Endianness-neutral constant splat on P8 and newer targets. The reason
3534// for this pattern is that on targets with direct moves, we don't expand
3535// BUILD_VECTOR nodes for v4i32.
3536def : Pat<(v4i32 (build_vector immSExt5NonZero:$A, immSExt5NonZero:$A,
3537                               immSExt5NonZero:$A, immSExt5NonZero:$A)),
3538          (v4i32 (VSPLTISW imm:$A))>;
3539} // HasVSX, HasDirectMove
3540
3541// Big endian VSX subtarget with direct moves.
3542let Predicates = [HasVSX, HasDirectMove, IsBigEndian] in {
3543// v16i8 scalar <-> vector conversions (BE)
3544defm : ScalToVecWPermute<
3545  v16i8, (i32 i32:$A),
3546  (SUBREG_TO_REG (i64 1), MovesToVSR.BE_BYTE_0, sub_64),
3547  (SUBREG_TO_REG (i64 1), (MTVSRWZ $A), sub_64)>;
3548defm : ScalToVecWPermute<
3549  v8i16, (i32 i32:$A),
3550  (SUBREG_TO_REG (i64 1), MovesToVSR.BE_BYTE_0, sub_64),
3551  (SUBREG_TO_REG (i64 1), (MTVSRWZ $A), sub_64)>;
3552defm : ScalToVecWPermute<
3553  v4i32, (i32 i32:$A),
3554  (SUBREG_TO_REG (i64 1), MovesToVSR.BE_WORD_0, sub_64),
3555  (SUBREG_TO_REG (i64 1), (MTVSRWZ $A), sub_64)>;
3556def : Pat<(v2i64 (scalar_to_vector i64:$A)),
3557          (v2i64 (SUBREG_TO_REG (i64 1), MovesToVSR.BE_DWORD_0, sub_64))>;
3558
3559// v2i64 scalar <-> vector conversions (BE)
3560def : Pat<(i64 (vector_extract v2i64:$S, 0)),
3561          (i64 VectorExtractions.LE_DWORD_1)>;
3562def : Pat<(i64 (vector_extract v2i64:$S, 1)),
3563          (i64 VectorExtractions.LE_DWORD_0)>;
3564def : Pat<(i64 (vector_extract v2i64:$S, i64:$Idx)),
3565          (i64 VectorExtractions.BE_VARIABLE_DWORD)>;
3566} // HasVSX, HasDirectMove, IsBigEndian
3567
3568// Little endian VSX subtarget with direct moves.
3569let Predicates = [HasVSX, HasDirectMove, IsLittleEndian] in {
3570  // v16i8 scalar <-> vector conversions (LE)
3571  defm : ScalToVecWPermute<v16i8, (i32 i32:$A),
3572                           (COPY_TO_REGCLASS MovesToVSR.LE_WORD_0, VSRC),
3573                           (COPY_TO_REGCLASS MovesToVSR.LE_WORD_1, VSRC)>;
3574  defm : ScalToVecWPermute<v8i16, (i32 i32:$A),
3575                           (COPY_TO_REGCLASS MovesToVSR.LE_WORD_0, VSRC),
3576                           (COPY_TO_REGCLASS MovesToVSR.LE_WORD_1, VSRC)>;
3577  defm : ScalToVecWPermute<v4i32, (i32 i32:$A), MovesToVSR.LE_WORD_0,
3578                           (SUBREG_TO_REG (i64 1), (MTVSRWZ $A), sub_64)>;
3579  defm : ScalToVecWPermute<v2i64, (i64 i64:$A), MovesToVSR.LE_DWORD_0,
3580                           MovesToVSR.LE_DWORD_1>;
3581
3582  // v2i64 scalar <-> vector conversions (LE)
3583  def : Pat<(i64 (vector_extract v2i64:$S, 0)),
3584            (i64 VectorExtractions.LE_DWORD_0)>;
3585  def : Pat<(i64 (vector_extract v2i64:$S, 1)),
3586            (i64 VectorExtractions.LE_DWORD_1)>;
3587  def : Pat<(i64 (vector_extract v2i64:$S, i64:$Idx)),
3588            (i64 VectorExtractions.LE_VARIABLE_DWORD)>;
3589} // HasVSX, HasDirectMove, IsLittleEndian
3590
3591// Big endian pre-P9 VSX subtarget with direct moves.
3592let Predicates = [HasVSX, HasDirectMove, NoP9Altivec, IsBigEndian] in {
3593def : Pat<(i32 (vector_extract v16i8:$S, 0)),
3594          (i32 VectorExtractions.LE_BYTE_15)>;
3595def : Pat<(i32 (vector_extract v16i8:$S, 1)),
3596          (i32 VectorExtractions.LE_BYTE_14)>;
3597def : Pat<(i32 (vector_extract v16i8:$S, 2)),
3598          (i32 VectorExtractions.LE_BYTE_13)>;
3599def : Pat<(i32 (vector_extract v16i8:$S, 3)),
3600          (i32 VectorExtractions.LE_BYTE_12)>;
3601def : Pat<(i32 (vector_extract v16i8:$S, 4)),
3602          (i32 VectorExtractions.LE_BYTE_11)>;
3603def : Pat<(i32 (vector_extract v16i8:$S, 5)),
3604          (i32 VectorExtractions.LE_BYTE_10)>;
3605def : Pat<(i32 (vector_extract v16i8:$S, 6)),
3606          (i32 VectorExtractions.LE_BYTE_9)>;
3607def : Pat<(i32 (vector_extract v16i8:$S, 7)),
3608          (i32 VectorExtractions.LE_BYTE_8)>;
3609def : Pat<(i32 (vector_extract v16i8:$S, 8)),
3610          (i32 VectorExtractions.LE_BYTE_7)>;
3611def : Pat<(i32 (vector_extract v16i8:$S, 9)),
3612          (i32 VectorExtractions.LE_BYTE_6)>;
3613def : Pat<(i32 (vector_extract v16i8:$S, 10)),
3614          (i32 VectorExtractions.LE_BYTE_5)>;
3615def : Pat<(i32 (vector_extract v16i8:$S, 11)),
3616          (i32 VectorExtractions.LE_BYTE_4)>;
3617def : Pat<(i32 (vector_extract v16i8:$S, 12)),
3618          (i32 VectorExtractions.LE_BYTE_3)>;
3619def : Pat<(i32 (vector_extract v16i8:$S, 13)),
3620          (i32 VectorExtractions.LE_BYTE_2)>;
3621def : Pat<(i32 (vector_extract v16i8:$S, 14)),
3622          (i32 VectorExtractions.LE_BYTE_1)>;
3623def : Pat<(i32 (vector_extract v16i8:$S, 15)),
3624          (i32 VectorExtractions.LE_BYTE_0)>;
3625def : Pat<(i32 (vector_extract v16i8:$S, i64:$Idx)),
3626          (i32 VectorExtractions.BE_VARIABLE_BYTE)>;
3627
3628// v8i16 scalar <-> vector conversions (BE)
3629def : Pat<(i32 (vector_extract v8i16:$S, 0)),
3630          (i32 VectorExtractions.LE_HALF_7)>;
3631def : Pat<(i32 (vector_extract v8i16:$S, 1)),
3632          (i32 VectorExtractions.LE_HALF_6)>;
3633def : Pat<(i32 (vector_extract v8i16:$S, 2)),
3634          (i32 VectorExtractions.LE_HALF_5)>;
3635def : Pat<(i32 (vector_extract v8i16:$S, 3)),
3636          (i32 VectorExtractions.LE_HALF_4)>;
3637def : Pat<(i32 (vector_extract v8i16:$S, 4)),
3638          (i32 VectorExtractions.LE_HALF_3)>;
3639def : Pat<(i32 (vector_extract v8i16:$S, 5)),
3640          (i32 VectorExtractions.LE_HALF_2)>;
3641def : Pat<(i32 (vector_extract v8i16:$S, 6)),
3642          (i32 VectorExtractions.LE_HALF_1)>;
3643def : Pat<(i32 (vector_extract v8i16:$S, 7)),
3644          (i32 VectorExtractions.LE_HALF_0)>;
3645def : Pat<(i32 (vector_extract v8i16:$S, i64:$Idx)),
3646          (i32 VectorExtractions.BE_VARIABLE_HALF)>;
3647
3648// v4i32 scalar <-> vector conversions (BE)
3649def : Pat<(i32 (vector_extract v4i32:$S, 0)),
3650          (i32 VectorExtractions.LE_WORD_3)>;
3651def : Pat<(i32 (vector_extract v4i32:$S, 1)),
3652          (i32 VectorExtractions.LE_WORD_2)>;
3653def : Pat<(i32 (vector_extract v4i32:$S, 2)),
3654          (i32 VectorExtractions.LE_WORD_1)>;
3655def : Pat<(i32 (vector_extract v4i32:$S, 3)),
3656          (i32 VectorExtractions.LE_WORD_0)>;
3657def : Pat<(i32 (vector_extract v4i32:$S, i64:$Idx)),
3658          (i32 VectorExtractions.BE_VARIABLE_WORD)>;
3659} // HasVSX, HasDirectMove, NoP9Altivec, IsBigEndian
3660
3661// Little endian pre-P9 VSX subtarget with direct moves.
3662let Predicates = [HasVSX, HasDirectMove, NoP9Altivec, IsLittleEndian] in {
3663def : Pat<(i32 (vector_extract v16i8:$S, 0)),
3664          (i32 VectorExtractions.LE_BYTE_0)>;
3665def : Pat<(i32 (vector_extract v16i8:$S, 1)),
3666          (i32 VectorExtractions.LE_BYTE_1)>;
3667def : Pat<(i32 (vector_extract v16i8:$S, 2)),
3668          (i32 VectorExtractions.LE_BYTE_2)>;
3669def : Pat<(i32 (vector_extract v16i8:$S, 3)),
3670          (i32 VectorExtractions.LE_BYTE_3)>;
3671def : Pat<(i32 (vector_extract v16i8:$S, 4)),
3672          (i32 VectorExtractions.LE_BYTE_4)>;
3673def : Pat<(i32 (vector_extract v16i8:$S, 5)),
3674          (i32 VectorExtractions.LE_BYTE_5)>;
3675def : Pat<(i32 (vector_extract v16i8:$S, 6)),
3676          (i32 VectorExtractions.LE_BYTE_6)>;
3677def : Pat<(i32 (vector_extract v16i8:$S, 7)),
3678          (i32 VectorExtractions.LE_BYTE_7)>;
3679def : Pat<(i32 (vector_extract v16i8:$S, 8)),
3680          (i32 VectorExtractions.LE_BYTE_8)>;
3681def : Pat<(i32 (vector_extract v16i8:$S, 9)),
3682          (i32 VectorExtractions.LE_BYTE_9)>;
3683def : Pat<(i32 (vector_extract v16i8:$S, 10)),
3684          (i32 VectorExtractions.LE_BYTE_10)>;
3685def : Pat<(i32 (vector_extract v16i8:$S, 11)),
3686          (i32 VectorExtractions.LE_BYTE_11)>;
3687def : Pat<(i32 (vector_extract v16i8:$S, 12)),
3688          (i32 VectorExtractions.LE_BYTE_12)>;
3689def : Pat<(i32 (vector_extract v16i8:$S, 13)),
3690          (i32 VectorExtractions.LE_BYTE_13)>;
3691def : Pat<(i32 (vector_extract v16i8:$S, 14)),
3692          (i32 VectorExtractions.LE_BYTE_14)>;
3693def : Pat<(i32 (vector_extract v16i8:$S, 15)),
3694          (i32 VectorExtractions.LE_BYTE_15)>;
3695def : Pat<(i32 (vector_extract v16i8:$S, i64:$Idx)),
3696          (i32 VectorExtractions.LE_VARIABLE_BYTE)>;
3697
3698// v8i16 scalar <-> vector conversions (LE)
3699def : Pat<(i32 (vector_extract v8i16:$S, 0)),
3700          (i32 VectorExtractions.LE_HALF_0)>;
3701def : Pat<(i32 (vector_extract v8i16:$S, 1)),
3702          (i32 VectorExtractions.LE_HALF_1)>;
3703def : Pat<(i32 (vector_extract v8i16:$S, 2)),
3704          (i32 VectorExtractions.LE_HALF_2)>;
3705def : Pat<(i32 (vector_extract v8i16:$S, 3)),
3706          (i32 VectorExtractions.LE_HALF_3)>;
3707def : Pat<(i32 (vector_extract v8i16:$S, 4)),
3708          (i32 VectorExtractions.LE_HALF_4)>;
3709def : Pat<(i32 (vector_extract v8i16:$S, 5)),
3710          (i32 VectorExtractions.LE_HALF_5)>;
3711def : Pat<(i32 (vector_extract v8i16:$S, 6)),
3712          (i32 VectorExtractions.LE_HALF_6)>;
3713def : Pat<(i32 (vector_extract v8i16:$S, 7)),
3714          (i32 VectorExtractions.LE_HALF_7)>;
3715def : Pat<(i32 (vector_extract v8i16:$S, i64:$Idx)),
3716          (i32 VectorExtractions.LE_VARIABLE_HALF)>;
3717
3718// v4i32 scalar <-> vector conversions (LE)
3719def : Pat<(i32 (vector_extract v4i32:$S, 0)),
3720          (i32 VectorExtractions.LE_WORD_0)>;
3721def : Pat<(i32 (vector_extract v4i32:$S, 1)),
3722          (i32 VectorExtractions.LE_WORD_1)>;
3723def : Pat<(i32 (vector_extract v4i32:$S, 2)),
3724          (i32 VectorExtractions.LE_WORD_2)>;
3725def : Pat<(i32 (vector_extract v4i32:$S, 3)),
3726          (i32 VectorExtractions.LE_WORD_3)>;
3727def : Pat<(i32 (vector_extract v4i32:$S, i64:$Idx)),
3728          (i32 VectorExtractions.LE_VARIABLE_WORD)>;
3729} // HasVSX, HasDirectMove, NoP9Altivec, IsLittleEndian
3730
3731// Big endian pre-Power9 64Bit VSX subtarget that has direct moves.
3732let Predicates = [HasVSX, HasDirectMove, NoP9Vector, IsBigEndian, IsPPC64] in {
3733// Big endian integer vectors using direct moves.
3734def : Pat<(v2i64 (build_vector i64:$A, i64:$B)),
3735          (v2i64 (XXPERMDI
3736                    (SUBREG_TO_REG (i64 1), (MTVSRD $A), sub_64),
3737                    (SUBREG_TO_REG (i64 1), (MTVSRD $B), sub_64), 0))>;
3738def : Pat<(v4i32 (build_vector i32:$A, i32:$B, i32:$C, i32:$D)),
3739          (XXPERMDI
3740            (SUBREG_TO_REG (i64 1),
3741              (MTVSRD (RLDIMI AnyExts.B, AnyExts.A, 32, 0)), sub_64),
3742            (SUBREG_TO_REG (i64 1),
3743              (MTVSRD (RLDIMI AnyExts.D, AnyExts.C, 32, 0)), sub_64), 0)>;
3744def : Pat<(v4i32 (build_vector i32:$A, i32:$A, i32:$A, i32:$A)),
3745          (XXSPLTW (SUBREG_TO_REG (i64 1), (MTVSRWZ $A), sub_64), 1)>;
3746} // HasVSX, HasDirectMove, NoP9Vector, IsBigEndian, IsPPC64
3747
3748// Little endian pre-Power9 VSX subtarget that has direct moves.
3749let Predicates = [HasVSX, HasDirectMove, NoP9Vector, IsLittleEndian] in {
3750// Little endian integer vectors using direct moves.
3751def : Pat<(v2i64 (build_vector i64:$A, i64:$B)),
3752          (v2i64 (XXPERMDI
3753                    (SUBREG_TO_REG (i64 1), (MTVSRD $B), sub_64),
3754                    (SUBREG_TO_REG (i64 1), (MTVSRD $A), sub_64), 0))>;
3755def : Pat<(v4i32 (build_vector i32:$A, i32:$B, i32:$C, i32:$D)),
3756          (XXPERMDI
3757            (SUBREG_TO_REG (i64 1),
3758              (MTVSRD (RLDIMI AnyExts.C, AnyExts.D, 32, 0)), sub_64),
3759            (SUBREG_TO_REG (i64 1),
3760              (MTVSRD (RLDIMI AnyExts.A, AnyExts.B, 32, 0)), sub_64), 0)>;
3761def : Pat<(v4i32 (build_vector i32:$A, i32:$A, i32:$A, i32:$A)),
3762          (XXSPLTW (SUBREG_TO_REG (i64 1), (MTVSRWZ $A), sub_64), 1)>;
3763}
3764
3765// Any Power9 VSX subtarget.
3766let Predicates = [HasVSX, HasP9Vector] in {
3767// Additional fnmsub pattern for PPC specific ISD opcode
3768def : Pat<(PPCfnmsub f128:$A, f128:$B, f128:$C),
3769          (XSNMSUBQP $C, $A, $B)>;
3770def : Pat<(fneg (PPCfnmsub f128:$A, f128:$B, f128:$C)),
3771          (XSMSUBQP $C, $A, $B)>;
3772def : Pat<(PPCfnmsub f128:$A, f128:$B, (fneg f128:$C)),
3773          (XSNMADDQP $C, $A, $B)>;
3774
3775def : Pat<(f128 (any_sint_to_fp i64:$src)),
3776          (f128 (XSCVSDQP (COPY_TO_REGCLASS $src, VFRC)))>;
3777def : Pat<(f128 (any_sint_to_fp (i64 (PPCmfvsr f64:$src)))),
3778          (f128 (XSCVSDQP $src))>;
3779def : Pat<(f128 (any_sint_to_fp (i32 (PPCmfvsr f64:$src)))),
3780          (f128 (XSCVSDQP (VEXTSW2Ds $src)))>;
3781def : Pat<(f128 (any_uint_to_fp i64:$src)),
3782          (f128 (XSCVUDQP (COPY_TO_REGCLASS $src, VFRC)))>;
3783def : Pat<(f128 (any_uint_to_fp (i64 (PPCmfvsr f64:$src)))),
3784          (f128 (XSCVUDQP $src))>;
3785
3786// Convert (Un)Signed Word -> QP.
3787def : Pat<(f128 (any_sint_to_fp i32:$src)),
3788          (f128 (XSCVSDQP (MTVSRWA $src)))>;
3789def : Pat<(f128 (any_sint_to_fp (i32 (load ForceXForm:$src)))),
3790          (f128 (XSCVSDQP (LIWAX ForceXForm:$src)))>;
3791def : Pat<(f128 (any_uint_to_fp i32:$src)),
3792          (f128 (XSCVUDQP (MTVSRWZ $src)))>;
3793def : Pat<(f128 (any_uint_to_fp (i32 (load ForceXForm:$src)))),
3794          (f128 (XSCVUDQP (LIWZX ForceXForm:$src)))>;
3795
3796// Pattern for matching Vector HP -> Vector SP intrinsic. Defined as a
3797// separate pattern so that it can convert the input register class from
3798// VRRC(v8i16) to VSRC.
3799def : Pat<(v4f32 (int_ppc_vsx_xvcvhpsp v8i16:$A)),
3800          (v4f32 (XVCVHPSP (COPY_TO_REGCLASS $A, VSRC)))>;
3801
3802// Use current rounding mode
3803def : Pat<(f128 (any_fnearbyint f128:$vB)), (f128 (XSRQPI 0, $vB, 3))>;
3804// Round to nearest, ties away from zero
3805def : Pat<(f128 (any_fround f128:$vB)), (f128 (XSRQPI 0, $vB, 0))>;
3806// Round towards Zero
3807def : Pat<(f128 (any_ftrunc f128:$vB)), (f128 (XSRQPI 1, $vB, 1))>;
3808// Round towards +Inf
3809def : Pat<(f128 (any_fceil f128:$vB)), (f128 (XSRQPI 1, $vB, 2))>;
3810// Round towards -Inf
3811def : Pat<(f128 (any_ffloor f128:$vB)), (f128 (XSRQPI 1, $vB, 3))>;
3812// Use current rounding mode, [with Inexact]
3813def : Pat<(f128 (any_frint f128:$vB)), (f128 (XSRQPIX 0, $vB, 3))>;
3814
3815def : Pat<(f128 (int_ppc_scalar_insert_exp_qp f128:$vA, i64:$vB)),
3816          (f128 (XSIEXPQP $vA, (MTVSRD $vB)))>;
3817
3818def : Pat<(i64 (int_ppc_scalar_extract_expq  f128:$vA)),
3819          (i64 (MFVSRD (EXTRACT_SUBREG
3820                          (v2i64 (XSXEXPQP $vA)), sub_64)))>;
3821
3822// Extra patterns expanding to vector Extract Word/Insert Word
3823def : Pat<(v4i32 (int_ppc_vsx_xxinsertw v4i32:$A, v2i64:$B, imm:$IMM)),
3824          (v4i32 (XXINSERTW $A, $B, imm:$IMM))>;
3825def : Pat<(v2i64 (int_ppc_vsx_xxextractuw v2i64:$A, imm:$IMM)),
3826          (v2i64 (COPY_TO_REGCLASS (XXEXTRACTUW $A, imm:$IMM), VSRC))>;
3827
3828// Vector Reverse
3829def : Pat<(v8i16 (bswap v8i16 :$A)),
3830          (v8i16 (COPY_TO_REGCLASS (XXBRH (COPY_TO_REGCLASS $A, VSRC)), VRRC))>;
3831def : Pat<(v1i128 (bswap v1i128 :$A)),
3832          (v1i128 (COPY_TO_REGCLASS (XXBRQ (COPY_TO_REGCLASS $A, VSRC)), VRRC))>;
3833
3834// D-Form Load/Store
3835foreach Ty = [v4i32, v4f32, v2i64, v2f64] in {
3836  def : Pat<(Ty (load DQForm:$src)), (LXV memrix16:$src)>;
3837  def : Pat<(Ty (load XForm:$src)), (LXVX XForm:$src)>;
3838  def : Pat<(store Ty:$rS, DQForm:$dst), (STXV $rS, memrix16:$dst)>;
3839  def : Pat<(store Ty:$rS, XForm:$dst), (STXVX $rS, XForm:$dst)>;
3840}
3841
3842def : Pat<(f128 (load DQForm:$src)),
3843          (COPY_TO_REGCLASS (LXV memrix16:$src), VRRC)>;
3844def : Pat<(f128 (load XForm:$src)),
3845          (COPY_TO_REGCLASS (LXVX XForm:$src), VRRC)>;
3846def : Pat<(v4i32 (int_ppc_vsx_lxvw4x DQForm:$src)), (LXV memrix16:$src)>;
3847def : Pat<(v2f64 (int_ppc_vsx_lxvd2x DQForm:$src)), (LXV memrix16:$src)>;
3848def : Pat<(v4i32 (int_ppc_vsx_lxvw4x XForm:$src)), (LXVX XForm:$src)>;
3849def : Pat<(v2f64 (int_ppc_vsx_lxvd2x XForm:$src)), (LXVX XForm:$src)>;
3850
3851def : Pat<(store f128:$rS, DQForm:$dst),
3852          (STXV (COPY_TO_REGCLASS $rS, VSRC), memrix16:$dst)>;
3853def : Pat<(store f128:$rS, XForm:$dst),
3854          (STXVX (COPY_TO_REGCLASS $rS, VSRC), XForm:$dst)>;
3855def : Pat<(int_ppc_vsx_stxvw4x v4i32:$rS, DQForm:$dst),
3856          (STXV $rS, memrix16:$dst)>;
3857def : Pat<(int_ppc_vsx_stxvd2x v2f64:$rS, DQForm:$dst),
3858          (STXV $rS, memrix16:$dst)>;
3859def : Pat<(int_ppc_vsx_stxvw4x v4i32:$rS, XForm:$dst),
3860          (STXVX $rS, XForm:$dst)>;
3861def : Pat<(int_ppc_vsx_stxvd2x v2f64:$rS, XForm:$dst),
3862          (STXVX $rS, XForm:$dst)>;
3863
3864// Build vectors from i8 loads
3865defm : ScalToVecWPermute<v8i16, ScalarLoads.ZELi8,
3866                         (VSPLTHs 3, (LXSIBZX ForceXForm:$src)),
3867                         (SUBREG_TO_REG (i64 1), (LXSIBZX ForceXForm:$src), sub_64)>;
3868defm : ScalToVecWPermute<v4i32, ScalarLoads.ZELi8,
3869                         (XXSPLTWs (LXSIBZX ForceXForm:$src), 1),
3870                         (SUBREG_TO_REG (i64 1), (LXSIBZX ForceXForm:$src), sub_64)>;
3871defm : ScalToVecWPermute<v2i64, ScalarLoads.ZELi8i64,
3872                         (XXPERMDIs (LXSIBZX ForceXForm:$src), 0),
3873                         (SUBREG_TO_REG (i64 1), (LXSIBZX ForceXForm:$src), sub_64)>;
3874defm : ScalToVecWPermute<
3875  v4i32, ScalarLoads.SELi8,
3876  (XXSPLTWs (VEXTSB2Ws (LXSIBZX ForceXForm:$src)), 1),
3877  (SUBREG_TO_REG (i64 1), (VEXTSB2Ws (LXSIBZX ForceXForm:$src)), sub_64)>;
3878defm : ScalToVecWPermute<
3879  v2i64, ScalarLoads.SELi8i64,
3880  (XXPERMDIs (VEXTSB2Ds (LXSIBZX ForceXForm:$src)), 0),
3881  (SUBREG_TO_REG (i64 1), (VEXTSB2Ds (LXSIBZX ForceXForm:$src)), sub_64)>;
3882
3883// Build vectors from i16 loads
3884defm : ScalToVecWPermute<
3885  v4i32, ScalarLoads.ZELi16,
3886  (XXSPLTWs (LXSIHZX ForceXForm:$src), 1),
3887  (SUBREG_TO_REG (i64 1), (LXSIHZX ForceXForm:$src), sub_64)>;
3888defm : ScalToVecWPermute<
3889  v2i64, ScalarLoads.ZELi16i64,
3890  (XXPERMDIs (LXSIHZX ForceXForm:$src), 0),
3891  (SUBREG_TO_REG (i64 1), (LXSIHZX ForceXForm:$src), sub_64)>;
3892defm : ScalToVecWPermute<
3893  v4i32, ScalarLoads.SELi16,
3894  (XXSPLTWs (VEXTSH2Ws (LXSIHZX ForceXForm:$src)), 1),
3895  (SUBREG_TO_REG (i64 1), (VEXTSH2Ws (LXSIHZX ForceXForm:$src)), sub_64)>;
3896defm : ScalToVecWPermute<
3897  v2i64, ScalarLoads.SELi16i64,
3898  (XXPERMDIs (VEXTSH2Ds (LXSIHZX ForceXForm:$src)), 0),
3899  (SUBREG_TO_REG (i64 1), (VEXTSH2Ds (LXSIHZX ForceXForm:$src)), sub_64)>;
3900
3901// Load/convert and convert/store patterns for f16.
3902def : Pat<(f64 (extloadf16 ForceXForm:$src)),
3903          (f64 (XSCVHPDP (LXSIHZX ForceXForm:$src)))>;
3904def : Pat<(truncstoref16 f64:$src, ForceXForm:$dst),
3905          (STXSIHX (XSCVDPHP $src), ForceXForm:$dst)>;
3906def : Pat<(f32 (extloadf16 ForceXForm:$src)),
3907          (f32 (COPY_TO_REGCLASS (XSCVHPDP (LXSIHZX ForceXForm:$src)), VSSRC))>;
3908def : Pat<(truncstoref16 f32:$src, ForceXForm:$dst),
3909          (STXSIHX (XSCVDPHP (COPY_TO_REGCLASS $src, VSFRC)), ForceXForm:$dst)>;
3910def : Pat<(f64 (f16_to_fp i32:$A)),
3911          (f64 (XSCVHPDP (MTVSRWZ $A)))>;
3912def : Pat<(f32 (f16_to_fp i32:$A)),
3913          (f32 (COPY_TO_REGCLASS (XSCVHPDP (MTVSRWZ $A)), VSSRC))>;
3914def : Pat<(i32 (fp_to_f16 f32:$A)),
3915          (i32 (MFVSRWZ (XSCVDPHP (COPY_TO_REGCLASS $A, VSFRC))))>;
3916def : Pat<(i32 (fp_to_f16 f64:$A)), (i32 (MFVSRWZ (XSCVDPHP $A)))>;
3917
3918// Vector sign extensions
3919def : Pat<(f64 (PPCVexts f64:$A, 1)),
3920          (f64 (COPY_TO_REGCLASS (VEXTSB2Ds $A), VSFRC))>;
3921def : Pat<(f64 (PPCVexts f64:$A, 2)),
3922          (f64 (COPY_TO_REGCLASS (VEXTSH2Ds $A), VSFRC))>;
3923
3924def : Pat<(f64 (extloadf32 DSForm:$src)),
3925          (COPY_TO_REGCLASS (DFLOADf32 DSForm:$src), VSFRC)>;
3926def : Pat<(f32 (fpround (f64 (extloadf32 DSForm:$src)))),
3927          (f32 (DFLOADf32 DSForm:$src))>;
3928
3929def : Pat<(v4f32 (PPCldvsxlh XForm:$src)),
3930          (SUBREG_TO_REG (i64 1), (XFLOADf64 XForm:$src), sub_64)>;
3931def : Pat<(v4f32 (PPCldvsxlh DSForm:$src)),
3932          (SUBREG_TO_REG (i64 1), (DFLOADf64 DSForm:$src), sub_64)>;
3933
3934// Convert (Un)Signed DWord in memory -> QP
3935def : Pat<(f128 (sint_to_fp (i64 (load XForm:$src)))),
3936          (f128 (XSCVSDQP (LXSDX XForm:$src)))>;
3937def : Pat<(f128 (sint_to_fp (i64 (load DSForm:$src)))),
3938          (f128 (XSCVSDQP (LXSD DSForm:$src)))>;
3939def : Pat<(f128 (uint_to_fp (i64 (load XForm:$src)))),
3940          (f128 (XSCVUDQP (LXSDX XForm:$src)))>;
3941def : Pat<(f128 (uint_to_fp (i64 (load DSForm:$src)))),
3942          (f128 (XSCVUDQP (LXSD DSForm:$src)))>;
3943
3944// Convert Unsigned HWord in memory -> QP
3945def : Pat<(f128 (uint_to_fp ScalarLoads.ZELi16)),
3946          (f128 (XSCVUDQP (LXSIHZX XForm:$src)))>;
3947
3948// Convert Unsigned Byte in memory -> QP
3949def : Pat<(f128 (uint_to_fp ScalarLoads.ZELi8)),
3950          (f128 (XSCVUDQP (LXSIBZX ForceXForm:$src)))>;
3951
3952// Truncate & Convert QP -> (Un)Signed (D)Word.
3953def : Pat<(i64 (any_fp_to_sint f128:$src)), (i64 (MFVRD (XSCVQPSDZ $src)))>;
3954def : Pat<(i64 (any_fp_to_uint f128:$src)), (i64 (MFVRD (XSCVQPUDZ $src)))>;
3955def : Pat<(i32 (any_fp_to_sint f128:$src)),
3956          (i32 (MFVSRWZ (COPY_TO_REGCLASS (XSCVQPSWZ $src), VFRC)))>;
3957def : Pat<(i32 (any_fp_to_uint f128:$src)),
3958          (i32 (MFVSRWZ (COPY_TO_REGCLASS (XSCVQPUWZ $src), VFRC)))>;
3959
3960// Instructions for store(fptosi).
3961// The 8-byte version is repeated here due to availability of D-Form STXSD.
3962def : Pat<(PPCstore_scal_int_from_vsr
3963            (f64 (PPCcv_fp_to_sint_in_vsr f128:$src)), XForm:$dst, 8),
3964          (STXSDX (COPY_TO_REGCLASS (XSCVQPSDZ f128:$src), VFRC),
3965                  XForm:$dst)>;
3966def : Pat<(PPCstore_scal_int_from_vsr
3967            (f64 (PPCcv_fp_to_sint_in_vsr f128:$src)), DSForm:$dst, 8),
3968          (STXSD (COPY_TO_REGCLASS (XSCVQPSDZ f128:$src), VFRC),
3969                 DSForm:$dst)>;
3970def : Pat<(PPCstore_scal_int_from_vsr
3971            (f64 (PPCcv_fp_to_sint_in_vsr f128:$src)), ForceXForm:$dst, 4),
3972          (STXSIWX (COPY_TO_REGCLASS (XSCVQPSWZ $src), VFRC), ForceXForm:$dst)>;
3973def : Pat<(PPCstore_scal_int_from_vsr
3974            (f64 (PPCcv_fp_to_sint_in_vsr f128:$src)), ForceXForm:$dst, 2),
3975          (STXSIHX (COPY_TO_REGCLASS (XSCVQPSWZ $src), VFRC), ForceXForm:$dst)>;
3976def : Pat<(PPCstore_scal_int_from_vsr
3977            (f64 (PPCcv_fp_to_sint_in_vsr f128:$src)), ForceXForm:$dst, 1),
3978          (STXSIBX (COPY_TO_REGCLASS (XSCVQPSWZ $src), VFRC), ForceXForm:$dst)>;
3979def : Pat<(PPCstore_scal_int_from_vsr
3980            (f64 (PPCcv_fp_to_sint_in_vsr f64:$src)), XForm:$dst, 8),
3981          (STXSDX (XSCVDPSXDS f64:$src), XForm:$dst)>;
3982def : Pat<(PPCstore_scal_int_from_vsr
3983            (f64 (PPCcv_fp_to_sint_in_vsr f64:$src)), DSForm:$dst, 8),
3984          (STXSD (XSCVDPSXDS f64:$src), DSForm:$dst)>;
3985def : Pat<(PPCstore_scal_int_from_vsr
3986            (f64 (PPCcv_fp_to_sint_in_vsr f64:$src)), ForceXForm:$dst, 2),
3987          (STXSIHX (XSCVDPSXWS f64:$src), ForceXForm:$dst)>;
3988def : Pat<(PPCstore_scal_int_from_vsr
3989            (f64 (PPCcv_fp_to_sint_in_vsr f64:$src)), ForceXForm:$dst, 1),
3990          (STXSIBX (XSCVDPSXWS f64:$src), ForceXForm:$dst)>;
3991
3992// Instructions for store(fptoui).
3993def : Pat<(PPCstore_scal_int_from_vsr
3994            (f64 (PPCcv_fp_to_uint_in_vsr f128:$src)), XForm:$dst, 8),
3995          (STXSDX (COPY_TO_REGCLASS (XSCVQPUDZ f128:$src), VFRC),
3996                  XForm:$dst)>;
3997def : Pat<(PPCstore_scal_int_from_vsr
3998            (f64 (PPCcv_fp_to_uint_in_vsr f128:$src)), DSForm:$dst, 8),
3999          (STXSD (COPY_TO_REGCLASS (XSCVQPUDZ f128:$src), VFRC),
4000                 DSForm:$dst)>;
4001def : Pat<(PPCstore_scal_int_from_vsr
4002            (f64 (PPCcv_fp_to_uint_in_vsr f128:$src)), ForceXForm:$dst, 4),
4003          (STXSIWX (COPY_TO_REGCLASS (XSCVQPUWZ $src), VFRC), ForceXForm:$dst)>;
4004def : Pat<(PPCstore_scal_int_from_vsr
4005            (f64 (PPCcv_fp_to_uint_in_vsr f128:$src)), ForceXForm:$dst, 2),
4006          (STXSIHX (COPY_TO_REGCLASS (XSCVQPUWZ $src), VFRC), ForceXForm:$dst)>;
4007def : Pat<(PPCstore_scal_int_from_vsr
4008            (f64 (PPCcv_fp_to_uint_in_vsr f128:$src)), ForceXForm:$dst, 1),
4009          (STXSIBX (COPY_TO_REGCLASS (XSCVQPUWZ $src), VFRC), ForceXForm:$dst)>;
4010def : Pat<(PPCstore_scal_int_from_vsr
4011            (f64 (PPCcv_fp_to_uint_in_vsr f64:$src)), XForm:$dst, 8),
4012          (STXSDX (XSCVDPUXDS f64:$src), XForm:$dst)>;
4013def : Pat<(PPCstore_scal_int_from_vsr
4014            (f64 (PPCcv_fp_to_uint_in_vsr f64:$src)), DSForm:$dst, 8),
4015          (STXSD (XSCVDPUXDS f64:$src), DSForm:$dst)>;
4016def : Pat<(PPCstore_scal_int_from_vsr
4017            (f64 (PPCcv_fp_to_uint_in_vsr f64:$src)), ForceXForm:$dst, 2),
4018          (STXSIHX (XSCVDPUXWS f64:$src), ForceXForm:$dst)>;
4019def : Pat<(PPCstore_scal_int_from_vsr
4020            (f64 (PPCcv_fp_to_uint_in_vsr f64:$src)), ForceXForm:$dst, 1),
4021          (STXSIBX (XSCVDPUXWS f64:$src), ForceXForm:$dst)>;
4022
4023// Round & Convert QP -> DP/SP
4024def : Pat<(f64 (any_fpround f128:$src)), (f64 (XSCVQPDP $src))>;
4025def : Pat<(f32 (any_fpround f128:$src)), (f32 (XSRSP (XSCVQPDPO $src)))>;
4026
4027// Convert SP -> QP
4028def : Pat<(f128 (any_fpextend f32:$src)),
4029          (f128 (XSCVDPQP (COPY_TO_REGCLASS $src, VFRC)))>;
4030
4031def : Pat<(f32 (PPCxsmaxc f32:$XA, f32:$XB)),
4032          (f32 (COPY_TO_REGCLASS (XSMAXCDP (COPY_TO_REGCLASS $XA, VSSRC),
4033                                           (COPY_TO_REGCLASS $XB, VSSRC)),
4034                                 VSSRC))>;
4035def : Pat<(f32 (PPCxsminc f32:$XA, f32:$XB)),
4036          (f32 (COPY_TO_REGCLASS (XSMINCDP (COPY_TO_REGCLASS $XA, VSSRC),
4037                                           (COPY_TO_REGCLASS $XB, VSSRC)),
4038                                 VSSRC))>;
4039
4040// Endianness-neutral patterns for const splats with ISA 3.0 instructions.
4041defm : ScalToVecWPermute<v4i32, (i32 i32:$A), (MTVSRWS $A),
4042                         (SUBREG_TO_REG (i64 1), (MTVSRWZ $A), sub_64)>;
4043def : Pat<(v4i32 (build_vector i32:$A, i32:$A, i32:$A, i32:$A)),
4044          (v4i32 (MTVSRWS $A))>;
4045def : Pat<(v16i8 (build_vector immNonAllOneAnyExt8:$A, immNonAllOneAnyExt8:$A,
4046                               immNonAllOneAnyExt8:$A, immNonAllOneAnyExt8:$A,
4047                               immNonAllOneAnyExt8:$A, immNonAllOneAnyExt8:$A,
4048                               immNonAllOneAnyExt8:$A, immNonAllOneAnyExt8:$A,
4049                               immNonAllOneAnyExt8:$A, immNonAllOneAnyExt8:$A,
4050                               immNonAllOneAnyExt8:$A, immNonAllOneAnyExt8:$A,
4051                               immNonAllOneAnyExt8:$A, immNonAllOneAnyExt8:$A,
4052                               immNonAllOneAnyExt8:$A, immNonAllOneAnyExt8:$A)),
4053          (v16i8 (COPY_TO_REGCLASS (XXSPLTIB imm:$A), VSRC))>;
4054defm : ScalToVecWPermute<
4055  v4i32, FltToIntLoad.A,
4056  (XVCVSPSXWS (LXVWSX ForceXForm:$A)),
4057  (XVCVSPSXWS (SUBREG_TO_REG (i64 1), (LIWZX ForceXForm:$A), sub_64))>;
4058defm : ScalToVecWPermute<
4059  v4i32, FltToUIntLoad.A,
4060  (XVCVSPUXWS (LXVWSX ForceXForm:$A)),
4061  (XVCVSPUXWS (SUBREG_TO_REG (i64 1), (LIWZX ForceXForm:$A), sub_64))>;
4062defm : ScalToVecWPermute<
4063  v4i32, DblToIntLoadP9.A,
4064  (XXSPLTW (SUBREG_TO_REG (i64 1), (XSCVDPSXWS (DFLOADf64 DSForm:$A)), sub_64), 1),
4065  (SUBREG_TO_REG (i64 1), (XSCVDPSXWS (DFLOADf64 DSForm:$A)), sub_64)>;
4066defm : ScalToVecWPermute<
4067  v4i32, DblToUIntLoadP9.A,
4068  (XXSPLTW (SUBREG_TO_REG (i64 1), (XSCVDPUXWS (DFLOADf64 DSForm:$A)), sub_64), 1),
4069  (SUBREG_TO_REG (i64 1), (XSCVDPUXWS (DFLOADf64 DSForm:$A)), sub_64)>;
4070defm : ScalToVecWPermute<
4071  v2i64, FltToLongLoadP9.A,
4072  (XXPERMDIs (XSCVDPSXDS (COPY_TO_REGCLASS (DFLOADf32 DSForm:$A), VSFRC)), 0),
4073  (SUBREG_TO_REG
4074     (i64 1),
4075     (XSCVDPSXDS (COPY_TO_REGCLASS (DFLOADf32 DSForm:$A), VSFRC)), sub_64)>;
4076defm : ScalToVecWPermute<
4077  v2i64, FltToULongLoadP9.A,
4078  (XXPERMDIs (XSCVDPUXDS (COPY_TO_REGCLASS (DFLOADf32 DSForm:$A), VSFRC)), 0),
4079  (SUBREG_TO_REG
4080     (i64 1),
4081     (XSCVDPUXDS (COPY_TO_REGCLASS (DFLOADf32 DSForm:$A), VSFRC)), sub_64)>;
4082def : Pat<(v4f32 (PPCldsplat ForceXForm:$A)),
4083          (v4f32 (LXVWSX ForceXForm:$A))>;
4084def : Pat<(v4i32 (PPCldsplat ForceXForm:$A)),
4085          (v4i32 (LXVWSX ForceXForm:$A))>;
4086} // HasVSX, HasP9Vector
4087
4088// Any Power9 VSX subtarget with equivalent length but better Power10 VSX
4089// patterns.
4090// Two identical blocks are required due to the slightly different predicates:
4091// One without P10 instructions, the other is BigEndian only with P10 instructions.
4092let Predicates = [HasVSX, HasP9Vector, NoP10Vector] in {
4093// Little endian Power10 subtargets produce a shorter pattern but require a
4094// COPY_TO_REGCLASS. The COPY_TO_REGCLASS makes it appear to need two instructions
4095// to perform the operation, when only one instruction is produced in practice.
4096// The NoP10Vector predicate excludes these patterns from Power10 VSX subtargets.
4097defm : ScalToVecWPermute<
4098  v16i8, ScalarLoads.Li8,
4099  (VSPLTBs 7, (LXSIBZX ForceXForm:$src)),
4100  (SUBREG_TO_REG (i64 1), (LXSIBZX ForceXForm:$src), sub_64)>;
4101// Build vectors from i16 loads
4102defm : ScalToVecWPermute<
4103  v8i16, ScalarLoads.Li16,
4104  (VSPLTHs 3, (LXSIHZX ForceXForm:$src)),
4105  (SUBREG_TO_REG (i64 1), (LXSIHZX ForceXForm:$src), sub_64)>;
4106} // HasVSX, HasP9Vector, NoP10Vector
4107
4108// Any big endian Power9 VSX subtarget
4109let Predicates = [HasVSX, HasP9Vector, IsBigEndian] in {
4110// Power10 VSX subtargets produce a shorter pattern for little endian targets
4111// but this is still the best pattern for Power9 and Power10 VSX big endian
4112// Build vectors from i8 loads
4113defm : ScalToVecWPermute<
4114  v16i8, ScalarLoads.Li8,
4115  (VSPLTBs 7, (LXSIBZX ForceXForm:$src)),
4116  (SUBREG_TO_REG (i64 1), (LXSIBZX ForceXForm:$src), sub_64)>;
4117// Build vectors from i16 loads
4118defm : ScalToVecWPermute<
4119  v8i16, ScalarLoads.Li16,
4120  (VSPLTHs 3, (LXSIHZX ForceXForm:$src)),
4121  (SUBREG_TO_REG (i64 1), (LXSIHZX ForceXForm:$src), sub_64)>;
4122
4123def : Pat<(f32 (PPCfcfidus (f64 (PPCmtvsrz (i32 (extractelt v4i32:$A, 0)))))),
4124          (f32 (XSCVUXDSP (XXEXTRACTUW $A, 0)))>;
4125def : Pat<(f32 (PPCfcfidus (f64 (PPCmtvsrz (i32 (extractelt v4i32:$A, 1)))))),
4126          (f32 (XSCVUXDSP (XXEXTRACTUW $A, 4)))>;
4127def : Pat<(f32 (PPCfcfidus (f64 (PPCmtvsrz (i32 (extractelt v4i32:$A, 2)))))),
4128          (f32 (XSCVUXDSP (XXEXTRACTUW $A, 8)))>;
4129def : Pat<(f32 (PPCfcfidus (f64 (PPCmtvsrz (i32 (extractelt v4i32:$A, 3)))))),
4130          (f32 (XSCVUXDSP (XXEXTRACTUW $A, 12)))>;
4131def : Pat<(f64 (PPCfcfidu (f64 (PPCmtvsrz (i32 (extractelt v4i32:$A, 0)))))),
4132          (f64 (XSCVUXDDP (XXEXTRACTUW $A, 0)))>;
4133def : Pat<(f64 (PPCfcfidu (f64 (PPCmtvsrz (i32 (extractelt v4i32:$A, 1)))))),
4134          (f64 (XSCVUXDDP (XXEXTRACTUW $A, 4)))>;
4135def : Pat<(f64 (PPCfcfidu (f64 (PPCmtvsrz (i32 (extractelt v4i32:$A, 2)))))),
4136          (f64 (XSCVUXDDP (XXEXTRACTUW $A, 8)))>;
4137def : Pat<(f64 (PPCfcfidu (f64 (PPCmtvsrz (i32 (extractelt v4i32:$A, 3)))))),
4138          (f64 (XSCVUXDDP (XXEXTRACTUW $A, 12)))>;
4139def : Pat<(v4i32 (insertelt v4i32:$A, i32:$B, 0)),
4140          (v4i32 (XXINSERTW v4i32:$A, AlignValues.I32_TO_BE_WORD1, 0))>;
4141def : Pat<(v4i32 (insertelt v4i32:$A, i32:$B, 1)),
4142          (v4i32 (XXINSERTW v4i32:$A, AlignValues.I32_TO_BE_WORD1, 4))>;
4143def : Pat<(v4i32 (insertelt v4i32:$A, i32:$B, 2)),
4144          (v4i32 (XXINSERTW v4i32:$A, AlignValues.I32_TO_BE_WORD1, 8))>;
4145def : Pat<(v4i32 (insertelt v4i32:$A, i32:$B, 3)),
4146          (v4i32 (XXINSERTW v4i32:$A, AlignValues.I32_TO_BE_WORD1, 12))>;
4147def : Pat<(v4f32 (insertelt v4f32:$A, f32:$B, 0)),
4148          (v4f32 (XXINSERTW v4f32:$A, AlignValues.F32_TO_BE_WORD1, 0))>;
4149def : Pat<(v4f32 (insertelt v4f32:$A, f32:$B, 1)),
4150          (v4f32 (XXINSERTW v4f32:$A, AlignValues.F32_TO_BE_WORD1, 4))>;
4151def : Pat<(v4f32 (insertelt v4f32:$A, f32:$B, 2)),
4152          (v4f32 (XXINSERTW v4f32:$A, AlignValues.F32_TO_BE_WORD1, 8))>;
4153def : Pat<(v4f32 (insertelt v4f32:$A, f32:$B, 3)),
4154          (v4f32 (XXINSERTW v4f32:$A, AlignValues.F32_TO_BE_WORD1, 12))>;
4155
4156def : Pat<(v4f32 (insertelt v4f32:$A, (f32 (fpround f64:$B)), 0)),
4157          (v4f32 (XXINSERTW v4f32:$A,
4158                  (SUBREG_TO_REG (i64 1), (XSCVDPSP f64:$B), sub_64), 0))>;
4159def : Pat<(v4f32 (insertelt v4f32:$A, (f32 (fpround f64:$B)), 1)),
4160          (v4f32 (XXINSERTW v4f32:$A,
4161                  (SUBREG_TO_REG (i64 1), (XSCVDPSP f64:$B), sub_64), 4))>;
4162def : Pat<(v4f32 (insertelt v4f32:$A, (f32 (fpround f64:$B)), 2)),
4163          (v4f32 (XXINSERTW v4f32:$A,
4164                  (SUBREG_TO_REG (i64 1), (XSCVDPSP f64:$B), sub_64), 8))>;
4165def : Pat<(v4f32 (insertelt v4f32:$A, (f32 (fpround f64:$B)), 3)),
4166          (v4f32 (XXINSERTW v4f32:$A,
4167                  (SUBREG_TO_REG (i64 1), (XSCVDPSP f64:$B), sub_64), 12))>;
4168
4169// Scalar stores of i8
4170def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 0)), ForceXForm:$dst),
4171          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 9)), VSRC), ForceXForm:$dst)>;
4172def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 1)), ForceXForm:$dst),
4173          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 10)), VSRC), ForceXForm:$dst)>;
4174def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 2)), ForceXForm:$dst),
4175          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 11)), VSRC), ForceXForm:$dst)>;
4176def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 3)), ForceXForm:$dst),
4177          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 12)), VSRC), ForceXForm:$dst)>;
4178def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 4)), ForceXForm:$dst),
4179          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 13)), VSRC), ForceXForm:$dst)>;
4180def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 5)), ForceXForm:$dst),
4181          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 14)), VSRC), ForceXForm:$dst)>;
4182def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 6)), ForceXForm:$dst),
4183          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 15)), VSRC), ForceXForm:$dst)>;
4184def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 7)), ForceXForm:$dst),
4185          (STXSIBXv (COPY_TO_REGCLASS $S, VSRC), ForceXForm:$dst)>;
4186def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 8)), ForceXForm:$dst),
4187          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 1)), VSRC), ForceXForm:$dst)>;
4188def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 9)), ForceXForm:$dst),
4189          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 2)), VSRC), ForceXForm:$dst)>;
4190def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 10)), ForceXForm:$dst),
4191          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 3)), VSRC), ForceXForm:$dst)>;
4192def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 11)), ForceXForm:$dst),
4193          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 4)), VSRC), ForceXForm:$dst)>;
4194def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 12)), ForceXForm:$dst),
4195          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 5)), VSRC), ForceXForm:$dst)>;
4196def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 13)), ForceXForm:$dst),
4197          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 6)), VSRC), ForceXForm:$dst)>;
4198def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 14)), ForceXForm:$dst),
4199          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 7)), VSRC), ForceXForm:$dst)>;
4200def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 15)), ForceXForm:$dst),
4201          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 8)), VSRC), ForceXForm:$dst)>;
4202
4203// Scalar stores of i16
4204def : Pat<(truncstorei16 (i32 (vector_extract v8i16:$S, 0)), ForceXForm:$dst),
4205          (STXSIHXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 10)), VSRC), ForceXForm:$dst)>;
4206def : Pat<(truncstorei16 (i32 (vector_extract v8i16:$S, 1)), ForceXForm:$dst),
4207          (STXSIHXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 12)), VSRC), ForceXForm:$dst)>;
4208def : Pat<(truncstorei16 (i32 (vector_extract v8i16:$S, 2)), ForceXForm:$dst),
4209          (STXSIHXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 14)), VSRC), ForceXForm:$dst)>;
4210def : Pat<(truncstorei16 (i32 (vector_extract v8i16:$S, 3)), ForceXForm:$dst),
4211          (STXSIHXv (COPY_TO_REGCLASS $S, VSRC), ForceXForm:$dst)>;
4212def : Pat<(truncstorei16 (i32 (vector_extract v8i16:$S, 4)), ForceXForm:$dst),
4213          (STXSIHXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 2)), VSRC), ForceXForm:$dst)>;
4214def : Pat<(truncstorei16 (i32 (vector_extract v8i16:$S, 5)), ForceXForm:$dst),
4215          (STXSIHXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 4)), VSRC), ForceXForm:$dst)>;
4216def : Pat<(truncstorei16 (i32 (vector_extract v8i16:$S, 6)), ForceXForm:$dst),
4217          (STXSIHXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 6)), VSRC), ForceXForm:$dst)>;
4218def : Pat<(truncstorei16 (i32 (vector_extract v8i16:$S, 7)), ForceXForm:$dst),
4219          (STXSIHXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 8)), VSRC), ForceXForm:$dst)>;
4220} // HasVSX, HasP9Vector, IsBigEndian
4221
4222// Big endian 64Bit Power9 subtarget.
4223let Predicates = [HasVSX, HasP9Vector, IsBigEndian, IsPPC64] in {
4224def : Pat<(v2i64 (scalar_to_vector (i64 (load DSForm:$src)))),
4225          (v2i64 (SUBREG_TO_REG (i64 1), (DFLOADf64 DSForm:$src), sub_64))>;
4226def : Pat<(v2i64 (scalar_to_vector (i64 (load XForm:$src)))),
4227          (v2i64 (SUBREG_TO_REG (i64 1), (XFLOADf64 XForm:$src), sub_64))>;
4228
4229def : Pat<(v2f64 (scalar_to_vector (f64 (load DSForm:$src)))),
4230          (v2f64 (SUBREG_TO_REG (i64 1), (DFLOADf64 DSForm:$src), sub_64))>;
4231def : Pat<(v2f64 (scalar_to_vector (f64 (load XForm:$src)))),
4232          (v2f64 (SUBREG_TO_REG (i64 1), (XFLOADf64 XForm:$src), sub_64))>;
4233def : Pat<(store (i64 (extractelt v2i64:$A, 1)), XForm:$src),
4234          (XFSTOREf64 (EXTRACT_SUBREG (XXPERMDI $A, $A, 2),
4235                       sub_64), XForm:$src)>;
4236def : Pat<(store (f64 (extractelt v2f64:$A, 1)), XForm:$src),
4237          (XFSTOREf64 (EXTRACT_SUBREG (XXPERMDI $A, $A, 2),
4238                       sub_64), XForm:$src)>;
4239def : Pat<(store (i64 (extractelt v2i64:$A, 0)), XForm:$src),
4240          (XFSTOREf64 (EXTRACT_SUBREG $A, sub_64), XForm:$src)>;
4241def : Pat<(store (f64 (extractelt v2f64:$A, 0)), XForm:$src),
4242          (XFSTOREf64 (EXTRACT_SUBREG $A, sub_64), XForm:$src)>;
4243def : Pat<(store (i64 (extractelt v2i64:$A, 1)), DSForm:$src),
4244          (DFSTOREf64 (EXTRACT_SUBREG (XXPERMDI $A, $A, 2),
4245                       sub_64), DSForm:$src)>;
4246def : Pat<(store (f64 (extractelt v2f64:$A, 1)), DSForm:$src),
4247          (DFSTOREf64 (EXTRACT_SUBREG (XXPERMDI $A, $A, 2),
4248                       sub_64), DSForm:$src)>;
4249def : Pat<(store (i64 (extractelt v2i64:$A, 0)), DSForm:$src),
4250          (DFSTOREf64 (EXTRACT_SUBREG $A, sub_64), DSForm:$src)>;
4251def : Pat<(store (f64 (extractelt v2f64:$A, 0)), DSForm:$src),
4252          (DFSTOREf64 (EXTRACT_SUBREG $A, sub_64), DSForm:$src)>;
4253
4254// (Un)Signed DWord vector extract -> QP
4255def : Pat<(f128 (sint_to_fp (i64 (extractelt v2i64:$src, 0)))),
4256          (f128 (XSCVSDQP (COPY_TO_REGCLASS $src, VFRC)))>;
4257def : Pat<(f128 (sint_to_fp (i64 (extractelt v2i64:$src, 1)))),
4258          (f128 (XSCVSDQP
4259                  (EXTRACT_SUBREG (XXPERMDI $src, $src, 3), sub_64)))>;
4260def : Pat<(f128 (uint_to_fp (i64 (extractelt v2i64:$src, 0)))),
4261          (f128 (XSCVUDQP (COPY_TO_REGCLASS $src, VFRC)))>;
4262def : Pat<(f128 (uint_to_fp (i64 (extractelt v2i64:$src, 1)))),
4263          (f128 (XSCVUDQP
4264                  (EXTRACT_SUBREG (XXPERMDI $src, $src, 3), sub_64)))>;
4265
4266// (Un)Signed Word vector extract -> QP
4267def : Pat<(f128 (sint_to_fp (i32 (extractelt v4i32:$src, 1)))),
4268          (f128 (XSCVSDQP (EXTRACT_SUBREG (VEXTSW2D $src), sub_64)))>;
4269foreach Idx = [0,2,3] in {
4270  def : Pat<(f128 (sint_to_fp (i32 (extractelt v4i32:$src, Idx)))),
4271            (f128 (XSCVSDQP (EXTRACT_SUBREG
4272                            (VEXTSW2D (VSPLTW Idx, $src)), sub_64)))>;
4273}
4274foreach Idx = 0-3 in {
4275  def : Pat<(f128 (uint_to_fp (i32 (extractelt v4i32:$src, Idx)))),
4276            (f128 (XSCVUDQP (XXEXTRACTUW $src, !shl(Idx, 2))))>;
4277}
4278
4279// (Un)Signed HWord vector extract -> QP/DP/SP
4280foreach Idx = 0-7 in {
4281  def : Pat<(f128 (sint_to_fp
4282                    (i32 (sext_inreg
4283                           (vector_extract v8i16:$src, Idx), i16)))),
4284          (f128 (XSCVSDQP (EXTRACT_SUBREG
4285                            (VEXTSH2D (VEXTRACTUH !add(Idx, Idx), $src)),
4286                            sub_64)))>;
4287  // The SDAG adds the `and` since an `i16` is being extracted as an `i32`.
4288  def : Pat<(f128 (uint_to_fp
4289                    (and (i32 (vector_extract v8i16:$src, Idx)), 65535))),
4290            (f128 (XSCVUDQP (EXTRACT_SUBREG
4291                              (VEXTRACTUH !add(Idx, Idx), $src), sub_64)))>;
4292  def : Pat<(f32 (PPCfcfidus
4293                   (f64 (PPCmtvsrz (and (i32 (vector_extract v8i16:$src, Idx)),
4294                                        65535))))),
4295            (f32 (XSCVUXDSP (EXTRACT_SUBREG
4296                              (VEXTRACTUH !add(Idx, Idx), $src), sub_64)))>;
4297  def : Pat<(f32 (PPCfcfids
4298                   (f64 (PPCmtvsra
4299                          (i32 (sext_inreg (vector_extract v8i16:$src, Idx),
4300                               i16)))))),
4301          (f32 (XSCVSXDSP (EXTRACT_SUBREG
4302                            (VEXTSH2D (VEXTRACTUH !add(Idx, Idx), $src)),
4303                            sub_64)))>;
4304  def : Pat<(f64 (PPCfcfidu
4305                   (f64 (PPCmtvsrz
4306                          (and (i32 (vector_extract v8i16:$src, Idx)),
4307                               65535))))),
4308            (f64 (XSCVUXDDP (EXTRACT_SUBREG
4309                              (VEXTRACTUH !add(Idx, Idx), $src), sub_64)))>;
4310  def : Pat<(f64 (PPCfcfid
4311                   (f64 (PPCmtvsra
4312                          (i32 (sext_inreg (vector_extract v8i16:$src, Idx),
4313                               i16)))))),
4314          (f64 (XSCVSXDDP (EXTRACT_SUBREG
4315                            (VEXTSH2D (VEXTRACTUH !add(Idx, Idx), $src)),
4316                            sub_64)))>;
4317}
4318
4319// (Un)Signed Byte vector extract -> QP
4320foreach Idx = 0-15 in {
4321  def : Pat<(f128 (sint_to_fp
4322                    (i32 (sext_inreg (vector_extract v16i8:$src, Idx),
4323                                     i8)))),
4324            (f128 (XSCVSDQP (EXTRACT_SUBREG
4325                              (VEXTSB2D (VEXTRACTUB Idx, $src)), sub_64)))>;
4326  def : Pat<(f128 (uint_to_fp
4327                    (and (i32 (vector_extract v16i8:$src, Idx)), 255))),
4328            (f128 (XSCVUDQP
4329                    (EXTRACT_SUBREG (VEXTRACTUB Idx, $src), sub_64)))>;
4330
4331  def : Pat<(f32 (PPCfcfidus
4332                   (f64 (PPCmtvsrz
4333                          (and (i32 (vector_extract v16i8:$src, Idx)),
4334                               255))))),
4335            (f32 (XSCVUXDSP (EXTRACT_SUBREG
4336                              (VEXTRACTUB !add(Idx, Idx), $src), sub_64)))>;
4337  def : Pat<(f32 (PPCfcfids
4338                   (f64 (PPCmtvsra
4339                          (i32 (sext_inreg (vector_extract v16i8:$src, Idx),
4340                               i8)))))),
4341          (f32 (XSCVSXDSP (EXTRACT_SUBREG
4342                            (VEXTSH2D (VEXTRACTUB !add(Idx, Idx), $src)),
4343                            sub_64)))>;
4344  def : Pat<(f64 (PPCfcfidu
4345                   (f64 (PPCmtvsrz
4346                          (and (i32 (vector_extract v16i8:$src, Idx)),
4347                          255))))),
4348            (f64 (XSCVUXDDP (EXTRACT_SUBREG
4349                              (VEXTRACTUB !add(Idx, Idx), $src), sub_64)))>;
4350  def : Pat<(f64 (PPCfcfid
4351                   (f64 (PPCmtvsra
4352                          (i32 (sext_inreg (vector_extract v16i8:$src, Idx),
4353                               i8)))))),
4354          (f64 (XSCVSXDDP (EXTRACT_SUBREG
4355                            (VEXTSH2D (VEXTRACTUB !add(Idx, Idx), $src)),
4356                            sub_64)))>;
4357}
4358
4359// Unsiged int in vsx register -> QP
4360def : Pat<(f128 (uint_to_fp (i32 (PPCmfvsr f64:$src)))),
4361          (f128 (XSCVUDQP
4362                  (XXEXTRACTUW (SUBREG_TO_REG (i64 1), $src, sub_64), 4)))>;
4363} // HasVSX, HasP9Vector, IsBigEndian, IsPPC64
4364
4365// Little endian Power9 subtarget.
4366let Predicates = [HasVSX, HasP9Vector, IsLittleEndian] in {
4367def : Pat<(f32 (PPCfcfidus (f64 (PPCmtvsrz (i32 (extractelt v4i32:$A, 0)))))),
4368          (f32 (XSCVUXDSP (XXEXTRACTUW $A, 12)))>;
4369def : Pat<(f32 (PPCfcfidus (f64 (PPCmtvsrz (i32 (extractelt v4i32:$A, 1)))))),
4370          (f32 (XSCVUXDSP (XXEXTRACTUW $A, 8)))>;
4371def : Pat<(f32 (PPCfcfidus (f64 (PPCmtvsrz (i32 (extractelt v4i32:$A, 2)))))),
4372          (f32 (XSCVUXDSP (XXEXTRACTUW $A, 4)))>;
4373def : Pat<(f32 (PPCfcfidus (f64 (PPCmtvsrz (i32 (extractelt v4i32:$A, 3)))))),
4374          (f32 (XSCVUXDSP (XXEXTRACTUW $A, 0)))>;
4375def : Pat<(f64 (PPCfcfidu (f64 (PPCmtvsrz (i32 (extractelt v4i32:$A, 0)))))),
4376          (f64 (XSCVUXDDP (XXEXTRACTUW $A, 12)))>;
4377def : Pat<(f64 (PPCfcfidu (f64 (PPCmtvsrz (i32 (extractelt v4i32:$A, 1)))))),
4378          (f64 (XSCVUXDDP (XXEXTRACTUW $A, 8)))>;
4379def : Pat<(f64 (PPCfcfidu (f64 (PPCmtvsrz (i32 (extractelt v4i32:$A, 2)))))),
4380          (f64 (XSCVUXDDP (XXEXTRACTUW $A, 4)))>;
4381def : Pat<(f64 (PPCfcfidu (f64 (PPCmtvsrz (i32 (extractelt v4i32:$A, 3)))))),
4382          (f64 (XSCVUXDDP (XXEXTRACTUW $A, 0)))>;
4383def : Pat<(v4i32 (insertelt v4i32:$A, i32:$B, 0)),
4384          (v4i32 (XXINSERTW v4i32:$A, AlignValues.I32_TO_BE_WORD1, 12))>;
4385def : Pat<(v4i32 (insertelt v4i32:$A, i32:$B, 1)),
4386          (v4i32 (XXINSERTW v4i32:$A, AlignValues.I32_TO_BE_WORD1, 8))>;
4387def : Pat<(v4i32 (insertelt v4i32:$A, i32:$B, 2)),
4388          (v4i32 (XXINSERTW v4i32:$A, AlignValues.I32_TO_BE_WORD1, 4))>;
4389def : Pat<(v4i32 (insertelt v4i32:$A, i32:$B, 3)),
4390          (v4i32 (XXINSERTW v4i32:$A, AlignValues.I32_TO_BE_WORD1, 0))>;
4391def : Pat<(v4f32 (insertelt v4f32:$A, f32:$B, 0)),
4392          (v4f32 (XXINSERTW v4f32:$A, AlignValues.F32_TO_BE_WORD1, 12))>;
4393def : Pat<(v4f32 (insertelt v4f32:$A, f32:$B, 1)),
4394          (v4f32 (XXINSERTW v4f32:$A, AlignValues.F32_TO_BE_WORD1, 8))>;
4395def : Pat<(v4f32 (insertelt v4f32:$A, f32:$B, 2)),
4396          (v4f32 (XXINSERTW v4f32:$A, AlignValues.F32_TO_BE_WORD1, 4))>;
4397def : Pat<(v4f32 (insertelt v4f32:$A, f32:$B, 3)),
4398          (v4f32 (XXINSERTW v4f32:$A, AlignValues.F32_TO_BE_WORD1, 0))>;
4399
4400def : Pat<(v4f32 (insertelt v4f32:$A, (f32 (fpround f64:$B)), 0)),
4401          (v4f32 (XXINSERTW v4f32:$A,
4402                  (SUBREG_TO_REG (i64 1), (XSCVDPSP f64:$B), sub_64), 12))>;
4403def : Pat<(v4f32 (insertelt v4f32:$A, (f32 (fpround f64:$B)), 1)),
4404          (v4f32 (XXINSERTW v4f32:$A,
4405                  (SUBREG_TO_REG (i64 1), (XSCVDPSP f64:$B), sub_64), 8))>;
4406def : Pat<(v4f32 (insertelt v4f32:$A, (f32 (fpround f64:$B)), 2)),
4407          (v4f32 (XXINSERTW v4f32:$A,
4408                  (SUBREG_TO_REG (i64 1), (XSCVDPSP f64:$B), sub_64), 4))>;
4409def : Pat<(v4f32 (insertelt v4f32:$A, (f32 (fpround f64:$B)), 3)),
4410          (v4f32 (XXINSERTW v4f32:$A,
4411                  (SUBREG_TO_REG (i64 1), (XSCVDPSP f64:$B), sub_64), 0))>;
4412
4413def : Pat<(v8i16 (PPCld_vec_be ForceXForm:$src)),
4414          (COPY_TO_REGCLASS (LXVH8X ForceXForm:$src), VRRC)>;
4415def : Pat<(PPCst_vec_be v8i16:$rS, ForceXForm:$dst),
4416          (STXVH8X (COPY_TO_REGCLASS $rS, VSRC), ForceXForm:$dst)>;
4417
4418def : Pat<(v16i8 (PPCld_vec_be ForceXForm:$src)),
4419          (COPY_TO_REGCLASS (LXVB16X ForceXForm:$src), VRRC)>;
4420def : Pat<(PPCst_vec_be v16i8:$rS, ForceXForm:$dst),
4421          (STXVB16X (COPY_TO_REGCLASS $rS, VSRC), ForceXForm:$dst)>;
4422
4423// Scalar stores of i8
4424def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 0)), ForceXForm:$dst),
4425          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 8)), VSRC), ForceXForm:$dst)>;
4426def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 1)), ForceXForm:$dst),
4427          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 7)), VSRC), ForceXForm:$dst)>;
4428def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 2)), ForceXForm:$dst),
4429          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 6)), VSRC), ForceXForm:$dst)>;
4430def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 3)), ForceXForm:$dst),
4431          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 5)), VSRC), ForceXForm:$dst)>;
4432def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 4)), ForceXForm:$dst),
4433          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 4)), VSRC), ForceXForm:$dst)>;
4434def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 5)), ForceXForm:$dst),
4435          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 3)), VSRC), ForceXForm:$dst)>;
4436def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 6)), ForceXForm:$dst),
4437          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 2)), VSRC), ForceXForm:$dst)>;
4438def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 7)), ForceXForm:$dst),
4439          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 1)), VSRC), ForceXForm:$dst)>;
4440def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 8)), ForceXForm:$dst),
4441          (STXSIBXv (COPY_TO_REGCLASS $S, VSRC), ForceXForm:$dst)>;
4442def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 9)), ForceXForm:$dst),
4443          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 15)), VSRC), ForceXForm:$dst)>;
4444def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 10)), ForceXForm:$dst),
4445          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 14)), VSRC), ForceXForm:$dst)>;
4446def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 11)), ForceXForm:$dst),
4447          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 13)), VSRC), ForceXForm:$dst)>;
4448def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 12)), ForceXForm:$dst),
4449          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 12)), VSRC), ForceXForm:$dst)>;
4450def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 13)), ForceXForm:$dst),
4451          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 11)), VSRC), ForceXForm:$dst)>;
4452def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 14)), ForceXForm:$dst),
4453          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 10)), VSRC), ForceXForm:$dst)>;
4454def : Pat<(truncstorei8 (i32 (vector_extract v16i8:$S, 15)), ForceXForm:$dst),
4455          (STXSIBXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 9)), VSRC), ForceXForm:$dst)>;
4456
4457// Scalar stores of i16
4458def : Pat<(truncstorei16 (i32 (vector_extract v8i16:$S, 0)), ForceXForm:$dst),
4459          (STXSIHXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 8)), VSRC), ForceXForm:$dst)>;
4460def : Pat<(truncstorei16 (i32 (vector_extract v8i16:$S, 1)), ForceXForm:$dst),
4461          (STXSIHXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 6)), VSRC), ForceXForm:$dst)>;
4462def : Pat<(truncstorei16 (i32 (vector_extract v8i16:$S, 2)), ForceXForm:$dst),
4463          (STXSIHXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 4)), VSRC), ForceXForm:$dst)>;
4464def : Pat<(truncstorei16 (i32 (vector_extract v8i16:$S, 3)), ForceXForm:$dst),
4465          (STXSIHXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 2)), VSRC), ForceXForm:$dst)>;
4466def : Pat<(truncstorei16 (i32 (vector_extract v8i16:$S, 4)), ForceXForm:$dst),
4467          (STXSIHXv (COPY_TO_REGCLASS $S, VSRC), ForceXForm:$dst)>;
4468def : Pat<(truncstorei16 (i32 (vector_extract v8i16:$S, 5)), ForceXForm:$dst),
4469          (STXSIHXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 14)), VSRC), ForceXForm:$dst)>;
4470def : Pat<(truncstorei16 (i32 (vector_extract v8i16:$S, 6)), ForceXForm:$dst),
4471          (STXSIHXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 12)), VSRC), ForceXForm:$dst)>;
4472def : Pat<(truncstorei16 (i32 (vector_extract v8i16:$S, 7)), ForceXForm:$dst),
4473          (STXSIHXv (COPY_TO_REGCLASS (v16i8 (VSLDOI $S, $S, 10)), VSRC), ForceXForm:$dst)>;
4474
4475defm : ScalToVecWPermute<
4476  v2i64, (i64 (load DSForm:$src)),
4477  (XXPERMDIs (DFLOADf64 DSForm:$src), 2),
4478  (SUBREG_TO_REG (i64 1), (DFLOADf64 DSForm:$src), sub_64)>;
4479defm : ScalToVecWPermute<
4480  v2i64, (i64 (load XForm:$src)),
4481  (XXPERMDIs (XFLOADf64 XForm:$src), 2),
4482  (SUBREG_TO_REG (i64 1), (XFLOADf64 XForm:$src), sub_64)>;
4483defm : ScalToVecWPermute<
4484  v2f64, (f64 (load DSForm:$src)),
4485  (XXPERMDIs (DFLOADf64 DSForm:$src), 2),
4486  (SUBREG_TO_REG (i64 1), (DFLOADf64 DSForm:$src), sub_64)>;
4487defm : ScalToVecWPermute<
4488  v2f64, (f64 (load XForm:$src)),
4489  (XXPERMDIs (XFLOADf64 XForm:$src), 2),
4490  (SUBREG_TO_REG (i64 1), (XFLOADf64 XForm:$src), sub_64)>;
4491
4492def : Pat<(store (i64 (extractelt v2i64:$A, 0)), XForm:$src),
4493          (XFSTOREf64 (EXTRACT_SUBREG (XXPERMDI $A, $A, 2),
4494                       sub_64), XForm:$src)>;
4495def : Pat<(store (f64 (extractelt v2f64:$A, 0)), XForm:$src),
4496          (XFSTOREf64 (EXTRACT_SUBREG (XXPERMDI $A, $A, 2),
4497                       sub_64), XForm:$src)>;
4498def : Pat<(store (i64 (extractelt v2i64:$A, 1)), XForm:$src),
4499          (XFSTOREf64 (EXTRACT_SUBREG $A, sub_64), XForm:$src)>;
4500def : Pat<(store (f64 (extractelt v2f64:$A, 1)), XForm:$src),
4501          (XFSTOREf64 (EXTRACT_SUBREG $A, sub_64), XForm:$src)>;
4502def : Pat<(store (i64 (extractelt v2i64:$A, 0)), DSForm:$src),
4503          (DFSTOREf64 (EXTRACT_SUBREG (XXPERMDI $A, $A, 2),
4504                       sub_64), DSForm:$src)>;
4505def : Pat<(store (f64 (extractelt v2f64:$A, 0)), DSForm:$src),
4506          (DFSTOREf64 (EXTRACT_SUBREG (XXPERMDI $A, $A, 2), sub_64),
4507                      DSForm:$src)>;
4508def : Pat<(store (i64 (extractelt v2i64:$A, 1)), DSForm:$src),
4509          (DFSTOREf64 (EXTRACT_SUBREG $A, sub_64), DSForm:$src)>;
4510def : Pat<(store (f64 (extractelt v2f64:$A, 1)), DSForm:$src),
4511          (DFSTOREf64 (EXTRACT_SUBREG $A, sub_64), DSForm:$src)>;
4512
4513// (Un)Signed DWord vector extract -> QP
4514def : Pat<(f128 (sint_to_fp (i64 (extractelt v2i64:$src, 0)))),
4515          (f128 (XSCVSDQP
4516                  (EXTRACT_SUBREG (XXPERMDI $src, $src, 3), sub_64)))>;
4517def : Pat<(f128 (sint_to_fp (i64 (extractelt v2i64:$src, 1)))),
4518          (f128 (XSCVSDQP (COPY_TO_REGCLASS $src, VFRC)))>;
4519def : Pat<(f128 (uint_to_fp (i64 (extractelt v2i64:$src, 0)))),
4520          (f128 (XSCVUDQP
4521                  (EXTRACT_SUBREG (XXPERMDI $src, $src, 3), sub_64)))>;
4522def : Pat<(f128 (uint_to_fp (i64 (extractelt v2i64:$src, 1)))),
4523          (f128 (XSCVUDQP (COPY_TO_REGCLASS $src, VFRC)))>;
4524
4525// (Un)Signed Word vector extract -> QP
4526foreach Idx = [[0,3],[1,2],[3,0]] in {
4527  def : Pat<(f128 (sint_to_fp (i32 (extractelt v4i32:$src, !head(Idx))))),
4528            (f128 (XSCVSDQP (EXTRACT_SUBREG
4529                              (VEXTSW2D (VSPLTW !head(!tail(Idx)), $src)),
4530                              sub_64)))>;
4531}
4532def : Pat<(f128 (sint_to_fp (i32 (extractelt v4i32:$src, 2)))),
4533          (f128 (XSCVSDQP (EXTRACT_SUBREG (VEXTSW2D $src), sub_64)))>;
4534
4535foreach Idx = [[0,12],[1,8],[2,4],[3,0]] in {
4536  def : Pat<(f128 (uint_to_fp (i32 (extractelt v4i32:$src, !head(Idx))))),
4537            (f128 (XSCVUDQP (XXEXTRACTUW $src, !head(!tail(Idx)))))>;
4538}
4539
4540// (Un)Signed HWord vector extract -> QP/DP/SP
4541// The Nested foreach lists identifies the vector element and corresponding
4542// register byte location.
4543foreach Idx = [[0,14],[1,12],[2,10],[3,8],[4,6],[5,4],[6,2],[7,0]] in {
4544  def : Pat<(f128 (sint_to_fp
4545                    (i32 (sext_inreg
4546                           (vector_extract v8i16:$src, !head(Idx)), i16)))),
4547            (f128 (XSCVSDQP
4548                    (EXTRACT_SUBREG (VEXTSH2D
4549                                      (VEXTRACTUH !head(!tail(Idx)), $src)),
4550                                    sub_64)))>;
4551  def : Pat<(f128 (uint_to_fp
4552                    (and (i32 (vector_extract v8i16:$src, !head(Idx))),
4553                         65535))),
4554            (f128 (XSCVUDQP (EXTRACT_SUBREG
4555                              (VEXTRACTUH !head(!tail(Idx)), $src), sub_64)))>;
4556  def : Pat<(f32 (PPCfcfidus
4557                   (f64 (PPCmtvsrz
4558                          (and (i32 (vector_extract v8i16:$src, !head(Idx))),
4559                          65535))))),
4560            (f32 (XSCVUXDSP (EXTRACT_SUBREG
4561                              (VEXTRACTUH !head(!tail(Idx)), $src), sub_64)))>;
4562  def : Pat<(f32 (PPCfcfids
4563                   (f64 (PPCmtvsra
4564                          (i32 (sext_inreg (vector_extract v8i16:$src,
4565                                           !head(Idx)), i16)))))),
4566            (f32 (XSCVSXDSP
4567                    (EXTRACT_SUBREG
4568                     (VEXTSH2D (VEXTRACTUH !head(!tail(Idx)), $src)),
4569                     sub_64)))>;
4570  def : Pat<(f64 (PPCfcfidu
4571                   (f64 (PPCmtvsrz
4572                          (and (i32 (vector_extract v8i16:$src, !head(Idx))),
4573                          65535))))),
4574            (f64 (XSCVUXDDP (EXTRACT_SUBREG
4575                              (VEXTRACTUH !head(!tail(Idx)), $src), sub_64)))>;
4576  def : Pat<(f64 (PPCfcfid
4577                   (f64 (PPCmtvsra
4578                        (i32 (sext_inreg
4579                            (vector_extract v8i16:$src, !head(Idx)), i16)))))),
4580            (f64 (XSCVSXDDP
4581                    (EXTRACT_SUBREG (VEXTSH2D
4582                                      (VEXTRACTUH !head(!tail(Idx)), $src)),
4583                                    sub_64)))>;
4584}
4585
4586// (Un)Signed Byte vector extract -> QP/DP/SP
4587foreach Idx = [[0,15],[1,14],[2,13],[3,12],[4,11],[5,10],[6,9],[7,8],[8,7],
4588               [9,6],[10,5],[11,4],[12,3],[13,2],[14,1],[15,0]] in {
4589  def : Pat<(f128 (sint_to_fp
4590                    (i32 (sext_inreg
4591                           (vector_extract v16i8:$src, !head(Idx)), i8)))),
4592            (f128 (XSCVSDQP
4593                    (EXTRACT_SUBREG
4594                      (VEXTSB2D (VEXTRACTUB !head(!tail(Idx)), $src)),
4595                      sub_64)))>;
4596  def : Pat<(f128 (uint_to_fp
4597                    (and (i32 (vector_extract v16i8:$src, !head(Idx))),
4598                         255))),
4599            (f128 (XSCVUDQP
4600                    (EXTRACT_SUBREG
4601                      (VEXTRACTUB !head(!tail(Idx)), $src), sub_64)))>;
4602
4603  def : Pat<(f32 (PPCfcfidus
4604                   (f64 (PPCmtvsrz
4605                          (and (i32 (vector_extract v16i8:$src, !head(Idx))),
4606                          255))))),
4607            (f32 (XSCVUXDSP (EXTRACT_SUBREG
4608                              (VEXTRACTUB !head(!tail(Idx)), $src), sub_64)))>;
4609  def : Pat<(f32 (PPCfcfids
4610                   (f64 (PPCmtvsra
4611                          (i32 (sext_inreg
4612                            (vector_extract v16i8:$src, !head(Idx)), i8)))))),
4613            (f32 (XSCVSXDSP
4614                    (EXTRACT_SUBREG (VEXTSH2D
4615                                      (VEXTRACTUB !head(!tail(Idx)), $src)),
4616                                    sub_64)))>;
4617  def : Pat<(f64 (PPCfcfidu
4618                   (f64 (PPCmtvsrz
4619                          (and (i32
4620                            (vector_extract v16i8:$src, !head(Idx))), 255))))),
4621            (f64 (XSCVUXDDP (EXTRACT_SUBREG
4622                              (VEXTRACTUB !head(!tail(Idx)), $src), sub_64)))>;
4623  def : Pat<(f64 (PPCfcfidu
4624                   (f64 (PPCmtvsra
4625                        (i32 (sext_inreg
4626                            (vector_extract v16i8:$src, !head(Idx)), i8)))))),
4627            (f64 (XSCVSXDDP
4628                    (EXTRACT_SUBREG (VEXTSH2D
4629                                      (VEXTRACTUB !head(!tail(Idx)), $src)),
4630                                    sub_64)))>;
4631
4632  def : Pat<(f64 (PPCfcfid
4633                   (f64 (PPCmtvsra
4634                        (i32 (sext_inreg
4635                          (vector_extract v16i8:$src, !head(Idx)), i8)))))),
4636            (f64 (XSCVSXDDP
4637                    (EXTRACT_SUBREG (VEXTSH2D
4638                                      (VEXTRACTUH !head(!tail(Idx)), $src)),
4639                                    sub_64)))>;
4640}
4641
4642// Unsiged int in vsx register -> QP
4643def : Pat<(f128 (uint_to_fp (i32 (PPCmfvsr f64:$src)))),
4644          (f128 (XSCVUDQP
4645                  (XXEXTRACTUW (SUBREG_TO_REG (i64 1), $src, sub_64), 8)))>;
4646} // HasVSX, HasP9Vector, IsLittleEndian
4647
4648// Any Power9 VSX subtarget that supports Power9 Altivec.
4649let Predicates = [HasVSX, HasP9Altivec] in {
4650// Put this P9Altivec related definition here since it's possible to be
4651// selected to VSX instruction xvnegsp, avoid possible undef.
4652def : Pat<(v4i32 (PPCvabsd v4i32:$A, v4i32:$B, (i32 0))),
4653          (v4i32 (VABSDUW $A, $B))>;
4654
4655def : Pat<(v8i16 (PPCvabsd v8i16:$A, v8i16:$B, (i32 0))),
4656          (v8i16 (VABSDUH $A, $B))>;
4657
4658def : Pat<(v16i8 (PPCvabsd v16i8:$A, v16i8:$B, (i32 0))),
4659          (v16i8 (VABSDUB $A, $B))>;
4660
4661// As PPCVABSD description, the last operand indicates whether do the
4662// sign bit flip.
4663def : Pat<(v4i32 (PPCvabsd v4i32:$A, v4i32:$B, (i32 1))),
4664          (v4i32 (VABSDUW (XVNEGSP $A), (XVNEGSP $B)))>;
4665} // HasVSX, HasP9Altivec
4666
4667// Big endian Power9 64Bit VSX subtargets with P9 Altivec support.
4668let Predicates = [HasVSX, HasP9Altivec, IsBigEndian, IsPPC64] in {
4669def : Pat<(i64 (anyext (i32 (vector_extract v16i8:$S, i64:$Idx)))),
4670          (VEXTUBLX $Idx, $S)>;
4671
4672def : Pat<(i64 (anyext (i32 (vector_extract v8i16:$S, i64:$Idx)))),
4673          (VEXTUHLX (RLWINM8 $Idx, 1, 28, 30), $S)>;
4674def : Pat<(i64 (anyext (i32 (vector_extract v8i16:$S, 0)))),
4675          (VEXTUHLX (LI8 0), $S)>;
4676def : Pat<(i64 (anyext (i32 (vector_extract v8i16:$S, 1)))),
4677          (VEXTUHLX (LI8 2), $S)>;
4678def : Pat<(i64 (anyext (i32 (vector_extract v8i16:$S, 2)))),
4679          (VEXTUHLX (LI8 4), $S)>;
4680def : Pat<(i64 (anyext (i32 (vector_extract v8i16:$S, 3)))),
4681          (VEXTUHLX (LI8 6), $S)>;
4682def : Pat<(i64 (anyext (i32 (vector_extract v8i16:$S, 4)))),
4683          (VEXTUHLX (LI8 8), $S)>;
4684def : Pat<(i64 (anyext (i32 (vector_extract v8i16:$S, 5)))),
4685          (VEXTUHLX (LI8 10), $S)>;
4686def : Pat<(i64 (anyext (i32 (vector_extract v8i16:$S, 6)))),
4687          (VEXTUHLX (LI8 12), $S)>;
4688def : Pat<(i64 (anyext (i32 (vector_extract v8i16:$S, 7)))),
4689          (VEXTUHLX (LI8 14), $S)>;
4690
4691def : Pat<(i64 (zext (i32 (vector_extract v4i32:$S, i64:$Idx)))),
4692          (VEXTUWLX (RLWINM8 $Idx, 2, 28, 29), $S)>;
4693def : Pat<(i64 (zext (i32 (vector_extract v4i32:$S, 0)))),
4694          (VEXTUWLX (LI8 0), $S)>;
4695
4696// For extracting BE word 1, MFVSRWZ is better than VEXTUWLX
4697def : Pat<(i64 (zext (i32 (vector_extract v4i32:$S, 1)))),
4698          (INSERT_SUBREG (i64 (IMPLICIT_DEF)),
4699          (i32 VectorExtractions.LE_WORD_2), sub_32)>;
4700def : Pat<(i64 (zext (i32 (vector_extract v4i32:$S, 2)))),
4701          (VEXTUWLX (LI8 8), $S)>;
4702def : Pat<(i64 (zext (i32 (vector_extract v4i32:$S, 3)))),
4703          (VEXTUWLX (LI8 12), $S)>;
4704
4705def : Pat<(i64 (sext (i32 (vector_extract v4i32:$S, i64:$Idx)))),
4706          (EXTSW (VEXTUWLX (RLWINM8 $Idx, 2, 28, 29), $S))>;
4707def : Pat<(i64 (sext (i32 (vector_extract v4i32:$S, 0)))),
4708          (EXTSW (VEXTUWLX (LI8 0), $S))>;
4709// For extracting BE word 1, MFVSRWZ is better than VEXTUWLX
4710def : Pat<(i64 (sext (i32 (vector_extract v4i32:$S, 1)))),
4711          (EXTSW (INSERT_SUBREG (i64 (IMPLICIT_DEF)),
4712          (i32 VectorExtractions.LE_WORD_2), sub_32))>;
4713def : Pat<(i64 (sext (i32 (vector_extract v4i32:$S, 2)))),
4714          (EXTSW (VEXTUWLX (LI8 8), $S))>;
4715def : Pat<(i64 (sext (i32 (vector_extract v4i32:$S, 3)))),
4716          (EXTSW (VEXTUWLX (LI8 12), $S))>;
4717
4718def : Pat<(i32 (vector_extract v16i8:$S, i64:$Idx)),
4719          (i32 (EXTRACT_SUBREG (VEXTUBLX $Idx, $S), sub_32))>;
4720def : Pat<(i32 (vector_extract v16i8:$S, 0)),
4721          (i32 (EXTRACT_SUBREG (VEXTUBLX (LI8 0), $S), sub_32))>;
4722def : Pat<(i32 (vector_extract v16i8:$S, 1)),
4723          (i32 (EXTRACT_SUBREG (VEXTUBLX (LI8 1), $S), sub_32))>;
4724def : Pat<(i32 (vector_extract v16i8:$S, 2)),
4725          (i32 (EXTRACT_SUBREG (VEXTUBLX (LI8 2), $S), sub_32))>;
4726def : Pat<(i32 (vector_extract v16i8:$S, 3)),
4727          (i32 (EXTRACT_SUBREG (VEXTUBLX (LI8 3), $S), sub_32))>;
4728def : Pat<(i32 (vector_extract v16i8:$S, 4)),
4729          (i32 (EXTRACT_SUBREG (VEXTUBLX (LI8 4), $S), sub_32))>;
4730def : Pat<(i32 (vector_extract v16i8:$S, 5)),
4731          (i32 (EXTRACT_SUBREG (VEXTUBLX (LI8 5), $S), sub_32))>;
4732def : Pat<(i32 (vector_extract v16i8:$S, 6)),
4733          (i32 (EXTRACT_SUBREG (VEXTUBLX (LI8 6), $S), sub_32))>;
4734def : Pat<(i32 (vector_extract v16i8:$S, 7)),
4735          (i32 (EXTRACT_SUBREG (VEXTUBLX (LI8 7), $S), sub_32))>;
4736def : Pat<(i32 (vector_extract v16i8:$S, 8)),
4737          (i32 (EXTRACT_SUBREG (VEXTUBLX (LI8 8), $S), sub_32))>;
4738def : Pat<(i32 (vector_extract v16i8:$S, 9)),
4739          (i32 (EXTRACT_SUBREG (VEXTUBLX (LI8 9), $S), sub_32))>;
4740def : Pat<(i32 (vector_extract v16i8:$S, 10)),
4741          (i32 (EXTRACT_SUBREG (VEXTUBLX (LI8 10), $S), sub_32))>;
4742def : Pat<(i32 (vector_extract v16i8:$S, 11)),
4743          (i32 (EXTRACT_SUBREG (VEXTUBLX (LI8 11), $S), sub_32))>;
4744def : Pat<(i32 (vector_extract v16i8:$S, 12)),
4745          (i32 (EXTRACT_SUBREG (VEXTUBLX (LI8 12), $S), sub_32))>;
4746def : Pat<(i32 (vector_extract v16i8:$S, 13)),
4747          (i32 (EXTRACT_SUBREG (VEXTUBLX (LI8 13), $S), sub_32))>;
4748def : Pat<(i32 (vector_extract v16i8:$S, 14)),
4749          (i32 (EXTRACT_SUBREG (VEXTUBLX (LI8 14), $S), sub_32))>;
4750def : Pat<(i32 (vector_extract v16i8:$S, 15)),
4751          (i32 (EXTRACT_SUBREG (VEXTUBLX (LI8 15), $S), sub_32))>;
4752
4753def : Pat<(i32 (vector_extract v8i16:$S, i64:$Idx)),
4754          (i32 (EXTRACT_SUBREG (VEXTUHLX
4755          (RLWINM8 $Idx, 1, 28, 30), $S), sub_32))>;
4756def : Pat<(i32 (vector_extract v8i16:$S, 0)),
4757          (i32 (EXTRACT_SUBREG (VEXTUHLX (LI8 0), $S), sub_32))>;
4758def : Pat<(i32 (vector_extract v8i16:$S, 1)),
4759          (i32 (EXTRACT_SUBREG (VEXTUHLX (LI8 2), $S), sub_32))>;
4760def : Pat<(i32 (vector_extract v8i16:$S, 2)),
4761          (i32 (EXTRACT_SUBREG (VEXTUHLX (LI8 4), $S), sub_32))>;
4762def : Pat<(i32 (vector_extract v8i16:$S, 3)),
4763          (i32 (EXTRACT_SUBREG (VEXTUHLX (LI8 6), $S), sub_32))>;
4764def : Pat<(i32 (vector_extract v8i16:$S, 4)),
4765          (i32 (EXTRACT_SUBREG (VEXTUHLX (LI8 8), $S), sub_32))>;
4766def : Pat<(i32 (vector_extract v8i16:$S, 5)),
4767          (i32 (EXTRACT_SUBREG (VEXTUHLX (LI8 10), $S), sub_32))>;
4768def : Pat<(i32 (vector_extract v8i16:$S, 6)),
4769          (i32 (EXTRACT_SUBREG (VEXTUHLX (LI8 12), $S), sub_32))>;
4770def : Pat<(i32 (vector_extract v8i16:$S, 6)),
4771          (i32 (EXTRACT_SUBREG (VEXTUHLX (LI8 14), $S), sub_32))>;
4772
4773def : Pat<(i32 (vector_extract v4i32:$S, i64:$Idx)),
4774          (i32 (EXTRACT_SUBREG (VEXTUWLX
4775          (RLWINM8 $Idx, 2, 28, 29), $S), sub_32))>;
4776def : Pat<(i32 (vector_extract v4i32:$S, 0)),
4777          (i32 (EXTRACT_SUBREG (VEXTUWLX (LI8 0), $S), sub_32))>;
4778// For extracting BE word 1, MFVSRWZ is better than VEXTUWLX
4779def : Pat<(i32 (vector_extract v4i32:$S, 1)),
4780          (i32 VectorExtractions.LE_WORD_2)>;
4781def : Pat<(i32 (vector_extract v4i32:$S, 2)),
4782          (i32 (EXTRACT_SUBREG (VEXTUWLX (LI8 8), $S), sub_32))>;
4783def : Pat<(i32 (vector_extract v4i32:$S, 3)),
4784          (i32 (EXTRACT_SUBREG (VEXTUWLX (LI8 12), $S), sub_32))>;
4785
4786// P9 Altivec instructions that can be used to build vectors.
4787// Adding them to PPCInstrVSX.td rather than PPCAltivecVSX.td to compete
4788// with complexities of existing build vector patterns in this file.
4789def : Pat<(v2i64 (build_vector WordToDWord.BE_A0, WordToDWord.BE_A1)),
4790          (v2i64 (VEXTSW2D $A))>;
4791def : Pat<(v2i64 (build_vector HWordToDWord.BE_A0, HWordToDWord.BE_A1)),
4792          (v2i64 (VEXTSH2D $A))>;
4793def : Pat<(v4i32 (build_vector HWordToWord.BE_A0, HWordToWord.BE_A1,
4794                  HWordToWord.BE_A2, HWordToWord.BE_A3)),
4795          (v4i32 (VEXTSH2W $A))>;
4796def : Pat<(v4i32 (build_vector ByteToWord.BE_A0, ByteToWord.BE_A1,
4797                  ByteToWord.BE_A2, ByteToWord.BE_A3)),
4798          (v4i32 (VEXTSB2W $A))>;
4799def : Pat<(v2i64 (build_vector ByteToDWord.BE_A0, ByteToDWord.BE_A1)),
4800          (v2i64 (VEXTSB2D $A))>;
4801} // HasVSX, HasP9Altivec, IsBigEndian, IsPPC64
4802
4803// Little endian Power9 VSX subtargets with P9 Altivec support.
4804let Predicates = [HasVSX, HasP9Altivec, IsLittleEndian] in {
4805def : Pat<(i64 (anyext (i32 (vector_extract v16i8:$S, i64:$Idx)))),
4806          (VEXTUBRX $Idx, $S)>;
4807
4808def : Pat<(i64 (anyext (i32 (vector_extract v8i16:$S, i64:$Idx)))),
4809          (VEXTUHRX (RLWINM8 $Idx, 1, 28, 30), $S)>;
4810def : Pat<(i64 (anyext (i32 (vector_extract v8i16:$S, 0)))),
4811          (VEXTUHRX (LI8 0), $S)>;
4812def : Pat<(i64 (anyext (i32 (vector_extract v8i16:$S, 1)))),
4813          (VEXTUHRX (LI8 2), $S)>;
4814def : Pat<(i64 (anyext (i32 (vector_extract v8i16:$S, 2)))),
4815          (VEXTUHRX (LI8 4), $S)>;
4816def : Pat<(i64 (anyext (i32 (vector_extract v8i16:$S, 3)))),
4817          (VEXTUHRX (LI8 6), $S)>;
4818def : Pat<(i64 (anyext (i32 (vector_extract v8i16:$S, 4)))),
4819          (VEXTUHRX (LI8 8), $S)>;
4820def : Pat<(i64 (anyext (i32 (vector_extract v8i16:$S, 5)))),
4821          (VEXTUHRX (LI8 10), $S)>;
4822def : Pat<(i64 (anyext (i32 (vector_extract v8i16:$S, 6)))),
4823          (VEXTUHRX (LI8 12), $S)>;
4824def : Pat<(i64 (anyext (i32 (vector_extract v8i16:$S, 7)))),
4825          (VEXTUHRX (LI8 14), $S)>;
4826
4827def : Pat<(i64 (zext (i32 (vector_extract v4i32:$S, i64:$Idx)))),
4828          (VEXTUWRX (RLWINM8 $Idx, 2, 28, 29), $S)>;
4829def : Pat<(i64 (zext (i32 (vector_extract v4i32:$S, 0)))),
4830          (VEXTUWRX (LI8 0), $S)>;
4831def : Pat<(i64 (zext (i32 (vector_extract v4i32:$S, 1)))),
4832          (VEXTUWRX (LI8 4), $S)>;
4833// For extracting LE word 2, MFVSRWZ is better than VEXTUWRX
4834def : Pat<(i64 (zext (i32 (vector_extract v4i32:$S, 2)))),
4835          (INSERT_SUBREG (i64 (IMPLICIT_DEF)),
4836          (i32 VectorExtractions.LE_WORD_2), sub_32)>;
4837def : Pat<(i64 (zext (i32 (vector_extract v4i32:$S, 3)))),
4838          (VEXTUWRX (LI8 12), $S)>;
4839
4840def : Pat<(i64 (sext (i32 (vector_extract v4i32:$S, i64:$Idx)))),
4841          (EXTSW (VEXTUWRX (RLWINM8 $Idx, 2, 28, 29), $S))>;
4842def : Pat<(i64 (sext (i32 (vector_extract v4i32:$S, 0)))),
4843          (EXTSW (VEXTUWRX (LI8 0), $S))>;
4844def : Pat<(i64 (sext (i32 (vector_extract v4i32:$S, 1)))),
4845          (EXTSW (VEXTUWRX (LI8 4), $S))>;
4846// For extracting LE word 2, MFVSRWZ is better than VEXTUWRX
4847def : Pat<(i64 (sext (i32 (vector_extract v4i32:$S, 2)))),
4848          (EXTSW (INSERT_SUBREG (i64 (IMPLICIT_DEF)),
4849          (i32 VectorExtractions.LE_WORD_2), sub_32))>;
4850def : Pat<(i64 (sext (i32 (vector_extract v4i32:$S, 3)))),
4851          (EXTSW (VEXTUWRX (LI8 12), $S))>;
4852
4853def : Pat<(i32 (vector_extract v16i8:$S, i64:$Idx)),
4854          (i32 (EXTRACT_SUBREG (VEXTUBRX $Idx, $S), sub_32))>;
4855def : Pat<(i32 (vector_extract v16i8:$S, 0)),
4856          (i32 (EXTRACT_SUBREG (VEXTUBRX (LI8 0), $S), sub_32))>;
4857def : Pat<(i32 (vector_extract v16i8:$S, 1)),
4858          (i32 (EXTRACT_SUBREG (VEXTUBRX (LI8 1), $S), sub_32))>;
4859def : Pat<(i32 (vector_extract v16i8:$S, 2)),
4860          (i32 (EXTRACT_SUBREG (VEXTUBRX (LI8 2), $S), sub_32))>;
4861def : Pat<(i32 (vector_extract v16i8:$S, 3)),
4862          (i32 (EXTRACT_SUBREG (VEXTUBRX (LI8 3), $S), sub_32))>;
4863def : Pat<(i32 (vector_extract v16i8:$S, 4)),
4864          (i32 (EXTRACT_SUBREG (VEXTUBRX (LI8 4), $S), sub_32))>;
4865def : Pat<(i32 (vector_extract v16i8:$S, 5)),
4866          (i32 (EXTRACT_SUBREG (VEXTUBRX (LI8 5), $S), sub_32))>;
4867def : Pat<(i32 (vector_extract v16i8:$S, 6)),
4868          (i32 (EXTRACT_SUBREG (VEXTUBRX (LI8 6), $S), sub_32))>;
4869def : Pat<(i32 (vector_extract v16i8:$S, 7)),
4870          (i32 (EXTRACT_SUBREG (VEXTUBRX (LI8 7), $S), sub_32))>;
4871def : Pat<(i32 (vector_extract v16i8:$S, 8)),
4872          (i32 (EXTRACT_SUBREG (VEXTUBRX (LI8 8), $S), sub_32))>;
4873def : Pat<(i32 (vector_extract v16i8:$S, 9)),
4874          (i32 (EXTRACT_SUBREG (VEXTUBRX (LI8 9), $S), sub_32))>;
4875def : Pat<(i32 (vector_extract v16i8:$S, 10)),
4876          (i32 (EXTRACT_SUBREG (VEXTUBRX (LI8 10), $S), sub_32))>;
4877def : Pat<(i32 (vector_extract v16i8:$S, 11)),
4878          (i32 (EXTRACT_SUBREG (VEXTUBRX (LI8 11), $S), sub_32))>;
4879def : Pat<(i32 (vector_extract v16i8:$S, 12)),
4880          (i32 (EXTRACT_SUBREG (VEXTUBRX (LI8 12), $S), sub_32))>;
4881def : Pat<(i32 (vector_extract v16i8:$S, 13)),
4882          (i32 (EXTRACT_SUBREG (VEXTUBRX (LI8 13), $S), sub_32))>;
4883def : Pat<(i32 (vector_extract v16i8:$S, 14)),
4884          (i32 (EXTRACT_SUBREG (VEXTUBRX (LI8 14), $S), sub_32))>;
4885def : Pat<(i32 (vector_extract v16i8:$S, 15)),
4886          (i32 (EXTRACT_SUBREG (VEXTUBRX (LI8 15), $S), sub_32))>;
4887
4888def : Pat<(i32 (vector_extract v8i16:$S, i64:$Idx)),
4889          (i32 (EXTRACT_SUBREG (VEXTUHRX
4890          (RLWINM8 $Idx, 1, 28, 30), $S), sub_32))>;
4891def : Pat<(i32 (vector_extract v8i16:$S, 0)),
4892          (i32 (EXTRACT_SUBREG (VEXTUHRX (LI8 0), $S), sub_32))>;
4893def : Pat<(i32 (vector_extract v8i16:$S, 1)),
4894          (i32 (EXTRACT_SUBREG (VEXTUHRX (LI8 2), $S), sub_32))>;
4895def : Pat<(i32 (vector_extract v8i16:$S, 2)),
4896          (i32 (EXTRACT_SUBREG (VEXTUHRX (LI8 4), $S), sub_32))>;
4897def : Pat<(i32 (vector_extract v8i16:$S, 3)),
4898          (i32 (EXTRACT_SUBREG (VEXTUHRX (LI8 6), $S), sub_32))>;
4899def : Pat<(i32 (vector_extract v8i16:$S, 4)),
4900          (i32 (EXTRACT_SUBREG (VEXTUHRX (LI8 8), $S), sub_32))>;
4901def : Pat<(i32 (vector_extract v8i16:$S, 5)),
4902          (i32 (EXTRACT_SUBREG (VEXTUHRX (LI8 10), $S), sub_32))>;
4903def : Pat<(i32 (vector_extract v8i16:$S, 6)),
4904          (i32 (EXTRACT_SUBREG (VEXTUHRX (LI8 12), $S), sub_32))>;
4905def : Pat<(i32 (vector_extract v8i16:$S, 6)),
4906          (i32 (EXTRACT_SUBREG (VEXTUHRX (LI8 14), $S), sub_32))>;
4907
4908def : Pat<(i32 (vector_extract v4i32:$S, i64:$Idx)),
4909          (i32 (EXTRACT_SUBREG (VEXTUWRX
4910          (RLWINM8 $Idx, 2, 28, 29), $S), sub_32))>;
4911def : Pat<(i32 (vector_extract v4i32:$S, 0)),
4912          (i32 (EXTRACT_SUBREG (VEXTUWRX (LI8 0), $S), sub_32))>;
4913def : Pat<(i32 (vector_extract v4i32:$S, 1)),
4914          (i32 (EXTRACT_SUBREG (VEXTUWRX (LI8 4), $S), sub_32))>;
4915// For extracting LE word 2, MFVSRWZ is better than VEXTUWRX
4916def : Pat<(i32 (vector_extract v4i32:$S, 2)),
4917          (i32 VectorExtractions.LE_WORD_2)>;
4918def : Pat<(i32 (vector_extract v4i32:$S, 3)),
4919          (i32 (EXTRACT_SUBREG (VEXTUWRX (LI8 12), $S), sub_32))>;
4920
4921// P9 Altivec instructions that can be used to build vectors.
4922// Adding them to PPCInstrVSX.td rather than PPCAltivecVSX.td to compete
4923// with complexities of existing build vector patterns in this file.
4924def : Pat<(v2i64 (build_vector WordToDWord.LE_A0, WordToDWord.LE_A1)),
4925          (v2i64 (VEXTSW2D $A))>;
4926def : Pat<(v2i64 (build_vector HWordToDWord.LE_A0, HWordToDWord.LE_A1)),
4927          (v2i64 (VEXTSH2D $A))>;
4928def : Pat<(v4i32 (build_vector HWordToWord.LE_A0, HWordToWord.LE_A1,
4929                  HWordToWord.LE_A2, HWordToWord.LE_A3)),
4930          (v4i32 (VEXTSH2W $A))>;
4931def : Pat<(v4i32 (build_vector ByteToWord.LE_A0, ByteToWord.LE_A1,
4932                  ByteToWord.LE_A2, ByteToWord.LE_A3)),
4933          (v4i32 (VEXTSB2W $A))>;
4934def : Pat<(v2i64 (build_vector ByteToDWord.LE_A0, ByteToDWord.LE_A1)),
4935          (v2i64 (VEXTSB2D $A))>;
4936} // HasVSX, HasP9Altivec, IsLittleEndian
4937
4938// Big endian 64Bit VSX subtarget that supports additional direct moves from
4939// ISA3.0.
4940let Predicates = [HasVSX, IsISA3_0, HasDirectMove, IsBigEndian, IsPPC64] in {
4941def : Pat<(i64 (extractelt v2i64:$A, 1)),
4942          (i64 (MFVSRLD $A))>;
4943// Better way to build integer vectors if we have MTVSRDD. Big endian.
4944def : Pat<(v2i64 (build_vector i64:$rB, i64:$rA)),
4945          (v2i64 (MTVSRDD $rB, $rA))>;
4946def : Pat<(v4i32 (build_vector i32:$A, i32:$B, i32:$C, i32:$D)),
4947          (MTVSRDD
4948            (RLDIMI AnyExts.B, AnyExts.A, 32, 0),
4949            (RLDIMI AnyExts.D, AnyExts.C, 32, 0))>;
4950
4951def : Pat<(f128 (PPCbuild_fp128 i64:$rB, i64:$rA)),
4952          (f128 (COPY_TO_REGCLASS (MTVSRDD $rB, $rA), VRRC))>;
4953} // HasVSX, IsISA3_0, HasDirectMove, IsBigEndian, IsPPC64
4954
4955// Little endian VSX subtarget that supports direct moves from ISA3.0.
4956let Predicates = [HasVSX, IsISA3_0, HasDirectMove, IsLittleEndian] in {
4957def : Pat<(i64 (extractelt v2i64:$A, 0)),
4958          (i64 (MFVSRLD $A))>;
4959// Better way to build integer vectors if we have MTVSRDD. Little endian.
4960def : Pat<(v2i64 (build_vector i64:$rA, i64:$rB)),
4961          (v2i64 (MTVSRDD $rB, $rA))>;
4962def : Pat<(v4i32 (build_vector i32:$A, i32:$B, i32:$C, i32:$D)),
4963          (MTVSRDD
4964            (RLDIMI AnyExts.C, AnyExts.D, 32, 0),
4965            (RLDIMI AnyExts.A, AnyExts.B, 32, 0))>;
4966
4967def : Pat<(f128 (PPCbuild_fp128 i64:$rA, i64:$rB)),
4968          (f128 (COPY_TO_REGCLASS (MTVSRDD $rB, $rA), VRRC))>;
4969} // HasVSX, IsISA3_0, HasDirectMove, IsLittleEndian
4970} // AddedComplexity = 400
4971
4972//---------------------------- Instruction aliases ---------------------------//
4973def : InstAlias<"xvmovdp $XT, $XB",
4974                (XVCPSGNDP vsrc:$XT, vsrc:$XB, vsrc:$XB)>;
4975def : InstAlias<"xvmovsp $XT, $XB",
4976                (XVCPSGNSP vsrc:$XT, vsrc:$XB, vsrc:$XB)>;
4977
4978// Certain versions of the AIX assembler may missassemble these mnemonics.
4979let Predicates = [ModernAs] in {
4980  def : InstAlias<"xxspltd $XT, $XB, 0",
4981                  (XXPERMDI vsrc:$XT, vsrc:$XB, vsrc:$XB, 0)>;
4982  def : InstAlias<"xxspltd $XT, $XB, 1",
4983                  (XXPERMDI vsrc:$XT, vsrc:$XB, vsrc:$XB, 3)>;
4984  def : InstAlias<"xxspltd $XT, $XB, 0",
4985                  (XXPERMDIs vsrc:$XT, vsfrc:$XB, 0)>;
4986  def : InstAlias<"xxspltd $XT, $XB, 1",
4987                  (XXPERMDIs vsrc:$XT, vsfrc:$XB, 3)>;
4988}
4989
4990def : InstAlias<"xxmrghd $XT, $XA, $XB",
4991                (XXPERMDI vsrc:$XT, vsrc:$XA, vsrc:$XB, 0)>;
4992def : InstAlias<"xxmrgld $XT, $XA, $XB",
4993                (XXPERMDI vsrc:$XT, vsrc:$XA, vsrc:$XB, 3)>;
4994def : InstAlias<"xxswapd $XT, $XB",
4995                (XXPERMDI vsrc:$XT, vsrc:$XB, vsrc:$XB, 2)>;
4996def : InstAlias<"xxswapd $XT, $XB",
4997                (XXPERMDIs vsrc:$XT, vsfrc:$XB, 2)>;
4998def : InstAlias<"mfvrd $rA, $XT",
4999                (MFVRD g8rc:$rA, vrrc:$XT), 0>;
5000def : InstAlias<"mffprd $rA, $src",
5001                (MFVSRD g8rc:$rA, f8rc:$src)>;
5002def : InstAlias<"mtvrd $XT, $rA",
5003                (MTVRD vrrc:$XT, g8rc:$rA), 0>;
5004def : InstAlias<"mtfprd $dst, $rA",
5005                (MTVSRD f8rc:$dst, g8rc:$rA)>;
5006def : InstAlias<"mfvrwz $rA, $XT",
5007                (MFVRWZ gprc:$rA, vrrc:$XT), 0>;
5008def : InstAlias<"mffprwz $rA, $src",
5009                (MFVSRWZ gprc:$rA, f8rc:$src)>;
5010def : InstAlias<"mtvrwa $XT, $rA",
5011                (MTVRWA vrrc:$XT, gprc:$rA), 0>;
5012def : InstAlias<"mtfprwa $dst, $rA",
5013                (MTVSRWA f8rc:$dst, gprc:$rA)>;
5014def : InstAlias<"mtvrwz $XT, $rA",
5015                (MTVRWZ vrrc:$XT, gprc:$rA), 0>;
5016def : InstAlias<"mtfprwz $dst, $rA",
5017                (MTVSRWZ f8rc:$dst, gprc:$rA)>;
5018