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