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