- Various '#if 0' cleanups.
[oota-llvm.git] / lib / Target / CellSPU / SPUInstrInfo.td
1 //==- SPUInstrInfo.td - Describe the Cell SPU Instructions -*- tablegen -*-==//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 // Cell SPU Instructions:
10 //===----------------------------------------------------------------------===//
11
12 //===----------------------------------------------------------------------===//
13 // TODO Items (not urgent today, but would be nice, low priority)
14 //
15 // ANDBI, ORBI: SPU constructs a 4-byte constant for these instructions by
16 // concatenating the byte argument b as "bbbb". Could recognize this bit pattern
17 // in 16-bit and 32-bit constants and reduce instruction count.
18 //===----------------------------------------------------------------------===//
19
20 //===----------------------------------------------------------------------===//
21 // Pseudo instructions:
22 //===----------------------------------------------------------------------===//
23
24 let hasCtrlDep = 1, Defs = [R1], Uses = [R1] in {
25   def ADJCALLSTACKDOWN : Pseudo<(outs), (ins u16imm_i32:$amt),
26                                 "${:comment} ADJCALLSTACKDOWN",
27                                 [(callseq_start timm:$amt)]>;
28   def ADJCALLSTACKUP   : Pseudo<(outs), (ins u16imm_i32:$amt),
29                                 "${:comment} ADJCALLSTACKUP",
30                                 [(callseq_end timm:$amt)]>;
31 }
32
33 //===----------------------------------------------------------------------===//
34 // DWARF debugging Pseudo Instructions
35 //===----------------------------------------------------------------------===//
36
37 def DWARF_LOC        : Pseudo<(outs), (ins i32imm:$line, i32imm:$col, i32imm:$file),
38                               "${:comment} .loc $file, $line, $col",
39                       [(dwarf_loc (i32 imm:$line), (i32 imm:$col),
40                                   (i32 imm:$file))]>;
41
42 //===----------------------------------------------------------------------===//
43 // Loads:
44 // NB: The ordering is actually important, since the instruction selection
45 // will try each of the instructions in sequence, i.e., the D-form first with
46 // the 10-bit displacement, then the A-form with the 16 bit displacement, and
47 // finally the X-form with the register-register.
48 //===----------------------------------------------------------------------===//
49
50 let canFoldAsLoad = 1 in {
51   class LoadDFormVec<ValueType vectype>
52     : RI10Form<0b00101100, (outs VECREG:$rT), (ins dformaddr:$src),
53                "lqd\t$rT, $src",
54                LoadStore,
55                [(set (vectype VECREG:$rT), (load dform_addr:$src))]>
56   { }
57
58   class LoadDForm<RegisterClass rclass>
59     : RI10Form<0b00101100, (outs rclass:$rT), (ins dformaddr:$src),
60                "lqd\t$rT, $src",
61                LoadStore,
62                [(set rclass:$rT, (load dform_addr:$src))]>
63   { }
64
65   multiclass LoadDForms
66   {
67     def v16i8: LoadDFormVec<v16i8>;
68     def v8i16: LoadDFormVec<v8i16>;
69     def v4i32: LoadDFormVec<v4i32>;
70     def v2i64: LoadDFormVec<v2i64>;
71     def v4f32: LoadDFormVec<v4f32>;
72     def v2f64: LoadDFormVec<v2f64>;
73
74     def r128:  LoadDForm<GPRC>;
75     def r64:   LoadDForm<R64C>;
76     def r32:   LoadDForm<R32C>;
77     def f32:   LoadDForm<R32FP>;
78     def f64:   LoadDForm<R64FP>;
79     def r16:   LoadDForm<R16C>;
80     def r8:    LoadDForm<R8C>;
81   }
82
83   class LoadAFormVec<ValueType vectype>
84     : RI16Form<0b100001100, (outs VECREG:$rT), (ins addr256k:$src),
85                "lqa\t$rT, $src",
86                LoadStore,
87                [(set (vectype VECREG:$rT), (load aform_addr:$src))]>
88   { }
89
90   class LoadAForm<RegisterClass rclass>
91     : RI16Form<0b100001100, (outs rclass:$rT), (ins addr256k:$src),
92                "lqa\t$rT, $src",
93                LoadStore,
94                [(set rclass:$rT, (load aform_addr:$src))]>
95   { }
96
97   multiclass LoadAForms
98   {
99     def v16i8: LoadAFormVec<v16i8>;
100     def v8i16: LoadAFormVec<v8i16>;
101     def v4i32: LoadAFormVec<v4i32>;
102     def v2i64: LoadAFormVec<v2i64>;
103     def v4f32: LoadAFormVec<v4f32>;
104     def v2f64: LoadAFormVec<v2f64>;
105
106     def r128:  LoadAForm<GPRC>;
107     def r64:   LoadAForm<R64C>;
108     def r32:   LoadAForm<R32C>;
109     def f32:   LoadAForm<R32FP>;
110     def f64:   LoadAForm<R64FP>;
111     def r16:   LoadAForm<R16C>;
112     def r8:    LoadAForm<R8C>;
113   }
114
115   class LoadXFormVec<ValueType vectype>
116     : RRForm<0b00100011100, (outs VECREG:$rT), (ins memrr:$src),
117              "lqx\t$rT, $src",
118              LoadStore,
119              [(set (vectype VECREG:$rT), (load xform_addr:$src))]>
120   { }
121
122   class LoadXForm<RegisterClass rclass>
123     : RRForm<0b00100011100, (outs rclass:$rT), (ins memrr:$src),
124              "lqx\t$rT, $src",
125              LoadStore,
126              [(set rclass:$rT, (load xform_addr:$src))]>
127   { }
128
129   multiclass LoadXForms
130   {
131     def v16i8: LoadXFormVec<v16i8>;
132     def v8i16: LoadXFormVec<v8i16>;
133     def v4i32: LoadXFormVec<v4i32>;
134     def v2i64: LoadXFormVec<v2i64>;
135     def v4f32: LoadXFormVec<v4f32>;
136     def v2f64: LoadXFormVec<v2f64>;
137
138     def r128:  LoadXForm<GPRC>;
139     def r64:   LoadXForm<R64C>;
140     def r32:   LoadXForm<R32C>;
141     def f32:   LoadXForm<R32FP>;
142     def f64:   LoadXForm<R64FP>;
143     def r16:   LoadXForm<R16C>;
144     def r8:    LoadXForm<R8C>;
145   }
146
147   defm LQA : LoadAForms;
148   defm LQD : LoadDForms;
149   defm LQX : LoadXForms;
150
151 /* Load quadword, PC relative: Not much use at this point in time.
152    Might be of use later for relocatable code. It's effectively the
153    same as LQA, but uses PC-relative addressing.
154   def LQR : RI16Form<0b111001100, (outs VECREG:$rT), (ins s16imm:$disp),
155                      "lqr\t$rT, $disp", LoadStore,
156                      [(set VECREG:$rT, (load iaddr:$disp))]>;
157  */
158 }
159
160 //===----------------------------------------------------------------------===//
161 // Stores:
162 //===----------------------------------------------------------------------===//
163 class StoreDFormVec<ValueType vectype>
164   : RI10Form<0b00100100, (outs), (ins VECREG:$rT, dformaddr:$src),
165              "stqd\t$rT, $src",
166              LoadStore,
167              [(store (vectype VECREG:$rT), dform_addr:$src)]>
168 { }
169
170 class StoreDForm<RegisterClass rclass>
171   : RI10Form<0b00100100, (outs), (ins rclass:$rT, dformaddr:$src),
172              "stqd\t$rT, $src",
173              LoadStore,
174              [(store rclass:$rT, dform_addr:$src)]>
175 { }
176
177 multiclass StoreDForms
178 {
179   def v16i8: StoreDFormVec<v16i8>;
180   def v8i16: StoreDFormVec<v8i16>;
181   def v4i32: StoreDFormVec<v4i32>;
182   def v2i64: StoreDFormVec<v2i64>;
183   def v4f32: StoreDFormVec<v4f32>;
184   def v2f64: StoreDFormVec<v2f64>;
185
186   def r128:  StoreDForm<GPRC>;
187   def r64:   StoreDForm<R64C>;
188   def r32:   StoreDForm<R32C>;
189   def f32:   StoreDForm<R32FP>;
190   def f64:   StoreDForm<R64FP>;
191   def r16:   StoreDForm<R16C>;
192   def r8:    StoreDForm<R8C>;
193 }
194
195 class StoreAFormVec<ValueType vectype>
196   : RI16Form<0b0010010, (outs), (ins VECREG:$rT, addr256k:$src),
197              "stqa\t$rT, $src",
198              LoadStore,
199              [(store (vectype VECREG:$rT), aform_addr:$src)]>;
200
201 class StoreAForm<RegisterClass rclass>
202   : RI16Form<0b001001, (outs), (ins rclass:$rT, addr256k:$src),
203              "stqa\t$rT, $src",
204              LoadStore,
205              [(store rclass:$rT, aform_addr:$src)]>;
206
207 multiclass StoreAForms
208 {
209   def v16i8: StoreAFormVec<v16i8>;
210   def v8i16: StoreAFormVec<v8i16>;
211   def v4i32: StoreAFormVec<v4i32>;
212   def v2i64: StoreAFormVec<v2i64>;
213   def v4f32: StoreAFormVec<v4f32>;
214   def v2f64: StoreAFormVec<v2f64>;
215
216   def r128:  StoreAForm<GPRC>;
217   def r64:   StoreAForm<R64C>;
218   def r32:   StoreAForm<R32C>;
219   def f32:   StoreAForm<R32FP>;
220   def f64:   StoreAForm<R64FP>;
221   def r16:   StoreAForm<R16C>;
222   def r8:    StoreAForm<R8C>;
223 }
224
225 class StoreXFormVec<ValueType vectype>
226   : RRForm<0b00100100, (outs), (ins VECREG:$rT, memrr:$src),
227            "stqx\t$rT, $src",
228            LoadStore,
229            [(store (vectype VECREG:$rT), xform_addr:$src)]>
230 { }
231
232 class StoreXForm<RegisterClass rclass>
233   : RRForm<0b00100100, (outs), (ins rclass:$rT, memrr:$src),
234            "stqx\t$rT, $src",
235            LoadStore,
236            [(store rclass:$rT, xform_addr:$src)]>
237 { }
238
239 multiclass StoreXForms
240 {
241   def v16i8: StoreXFormVec<v16i8>;
242   def v8i16: StoreXFormVec<v8i16>;
243   def v4i32: StoreXFormVec<v4i32>;
244   def v2i64: StoreXFormVec<v2i64>;
245   def v4f32: StoreXFormVec<v4f32>;
246   def v2f64: StoreXFormVec<v2f64>;
247
248   def r128:  StoreXForm<GPRC>;
249   def r64:   StoreXForm<R64C>;
250   def r32:   StoreXForm<R32C>;
251   def f32:   StoreXForm<R32FP>;
252   def f64:   StoreXForm<R64FP>;
253   def r16:   StoreXForm<R16C>;
254   def r8:    StoreXForm<R8C>;
255 }
256
257 defm STQD : StoreDForms;
258 defm STQA : StoreAForms;
259 defm STQX : StoreXForms;
260
261 /* Store quadword, PC relative: Not much use at this point in time. Might
262    be useful for relocatable code.
263 def STQR : RI16Form<0b111000100, (outs), (ins VECREG:$rT, s16imm:$disp),
264                    "stqr\t$rT, $disp", LoadStore,
265                    [(store VECREG:$rT, iaddr:$disp)]>;
266 */
267
268 //===----------------------------------------------------------------------===//
269 // Generate Controls for Insertion:
270 //===----------------------------------------------------------------------===//
271
272 def CBD: RI7Form<0b10101111100, (outs VECREG:$rT), (ins shufaddr:$src),
273     "cbd\t$rT, $src", ShuffleOp,
274     [(set (v16i8 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
275
276 def CBX: RRForm<0b00101011100, (outs VECREG:$rT), (ins memrr:$src),
277     "cbx\t$rT, $src", ShuffleOp,
278     [(set (v16i8 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
279
280 def CHD: RI7Form<0b10101111100, (outs VECREG:$rT), (ins shufaddr:$src),
281     "chd\t$rT, $src", ShuffleOp,
282     [(set (v8i16 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
283
284 def CHX: RRForm<0b10101011100, (outs VECREG:$rT), (ins memrr:$src),
285     "chx\t$rT, $src", ShuffleOp,
286     [(set (v8i16 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
287
288 def CWD: RI7Form<0b01101111100, (outs VECREG:$rT), (ins shufaddr:$src),
289     "cwd\t$rT, $src", ShuffleOp,
290     [(set (v4i32 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
291
292 def CWX: RRForm<0b01101011100, (outs VECREG:$rT), (ins memrr:$src),
293     "cwx\t$rT, $src", ShuffleOp,
294     [(set (v4i32 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
295
296 def CWDf32: RI7Form<0b01101111100, (outs VECREG:$rT), (ins shufaddr:$src),
297     "cwd\t$rT, $src", ShuffleOp,
298     [(set (v4f32 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
299
300 def CWXf32: RRForm<0b01101011100, (outs VECREG:$rT), (ins memrr:$src),
301     "cwx\t$rT, $src", ShuffleOp,
302     [(set (v4f32 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
303
304 def CDD: RI7Form<0b11101111100, (outs VECREG:$rT), (ins shufaddr:$src),
305     "cdd\t$rT, $src", ShuffleOp,
306     [(set (v2i64 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
307
308 def CDX: RRForm<0b11101011100, (outs VECREG:$rT), (ins memrr:$src),
309     "cdx\t$rT, $src", ShuffleOp,
310     [(set (v2i64 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
311
312 def CDDf64: RI7Form<0b11101111100, (outs VECREG:$rT), (ins shufaddr:$src),
313     "cdd\t$rT, $src", ShuffleOp,
314     [(set (v2f64 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
315
316 def CDXf64: RRForm<0b11101011100, (outs VECREG:$rT), (ins memrr:$src),
317     "cdx\t$rT, $src", ShuffleOp,
318     [(set (v2f64 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
319
320 //===----------------------------------------------------------------------===//
321 // Constant formation:
322 //===----------------------------------------------------------------------===//
323
324 def ILHv8i16:
325   RI16Form<0b110000010, (outs VECREG:$rT), (ins s16imm:$val),
326     "ilh\t$rT, $val", ImmLoad,
327     [(set (v8i16 VECREG:$rT), (v8i16 v8i16SExt16Imm:$val))]>;
328
329 def ILHr16:
330   RI16Form<0b110000010, (outs R16C:$rT), (ins s16imm:$val),
331     "ilh\t$rT, $val", ImmLoad,
332     [(set R16C:$rT, immSExt16:$val)]>;
333
334 // Cell SPU doesn't have a native 8-bit immediate load, but ILH works ("with
335 // the right constant")
336 def ILHr8:
337   RI16Form<0b110000010, (outs R8C:$rT), (ins s16imm_i8:$val),
338     "ilh\t$rT, $val", ImmLoad,
339     [(set R8C:$rT, immSExt8:$val)]>;
340
341 // IL does sign extension!
342
343 class ILInst<dag OOL, dag IOL, list<dag> pattern>:
344   RI16Form<0b100000010, OOL, IOL, "il\t$rT, $val",
345            ImmLoad, pattern>;
346
347 class ILVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
348   ILInst<(outs VECREG:$rT), (ins immtype:$val),
349          [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
350
351 class ILRegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
352   ILInst<(outs rclass:$rT), (ins immtype:$val),
353          [(set rclass:$rT, xform:$val)]>;
354
355 multiclass ImmediateLoad
356 {
357   def v2i64: ILVecInst<v2i64, s16imm_i64, v2i64SExt16Imm>;
358   def v4i32: ILVecInst<v4i32, s16imm_i32, v4i32SExt16Imm>;
359
360   // TODO: Need v2f64, v4f32
361
362   def r64: ILRegInst<R64C, s16imm_i64, immSExt16>;
363   def r32: ILRegInst<R32C, s16imm_i32, immSExt16>;
364   def f32: ILRegInst<R32FP, s16imm_f32, fpimmSExt16>;
365   def f64: ILRegInst<R64FP, s16imm_f64, fpimmSExt16>;
366 }
367
368 defm IL : ImmediateLoad;
369
370 class ILHUInst<dag OOL, dag IOL, list<dag> pattern>:
371   RI16Form<0b010000010, OOL, IOL, "ilhu\t$rT, $val",
372            ImmLoad, pattern>;
373
374 class ILHUVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
375   ILHUInst<(outs VECREG:$rT), (ins immtype:$val),
376            [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
377
378 class ILHURegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
379   ILHUInst<(outs rclass:$rT), (ins immtype:$val),
380            [(set rclass:$rT, xform:$val)]>;
381
382 multiclass ImmLoadHalfwordUpper
383 {
384   def v2i64: ILHUVecInst<v2i64, u16imm_i64, immILHUvec_i64>;
385   def v4i32: ILHUVecInst<v4i32, u16imm_i32, immILHUvec>;
386
387   def r64: ILHURegInst<R64C, u16imm_i64, hi16>;
388   def r32: ILHURegInst<R32C, u16imm_i32, hi16>;
389
390   // Loads the high portion of an address
391   def hi: ILHURegInst<R32C, symbolHi, hi16>;
392
393   // Used in custom lowering constant SFP loads:
394   def f32: ILHURegInst<R32FP, f16imm, hi16_f32>;
395 }
396
397 defm ILHU : ImmLoadHalfwordUpper;
398
399 // Immediate load address (can also be used to load 18-bit unsigned constants,
400 // see the zext 16->32 pattern)
401
402 class ILAInst<dag OOL, dag IOL, list<dag> pattern>:
403   RI18Form<0b1000010, OOL, IOL, "ila\t$rT, $val",
404            LoadNOP, pattern>;
405
406 class ILAVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
407   ILAInst<(outs VECREG:$rT), (ins immtype:$val),
408           [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
409
410 class ILARegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
411   ILAInst<(outs rclass:$rT), (ins immtype:$val),
412           [(set rclass:$rT, xform:$val)]>;
413
414 multiclass ImmLoadAddress
415 {
416   def v2i64: ILAVecInst<v2i64, u18imm, v2i64Uns18Imm>;
417   def v4i32: ILAVecInst<v4i32, u18imm, v4i32Uns18Imm>;
418
419   def r64: ILARegInst<R64C, u18imm_i64, imm18>;
420   def r32: ILARegInst<R32C, u18imm, imm18>;
421   def f32: ILARegInst<R32FP, f18imm, fpimm18>;
422   def f64: ILARegInst<R64FP, f18imm_f64, fpimm18>;
423
424   def hi: ILARegInst<R32C, symbolHi, imm18>;
425   def lo: ILARegInst<R32C, symbolLo, imm18>;
426
427   def lsa: ILAInst<(outs R32C:$rT), (ins symbolLSA:$val),
428                    [/* no pattern */]>;
429 }
430
431 defm ILA : ImmLoadAddress;
432
433 // Immediate OR, Halfword Lower: The "other" part of loading large constants
434 // into 32-bit registers. See the anonymous pattern Pat<(i32 imm:$imm), ...>
435 // Note that these are really two operand instructions, but they're encoded
436 // as three operands with the first two arguments tied-to each other.
437
438 class IOHLInst<dag OOL, dag IOL, list<dag> pattern>:
439   RI16Form<0b100000110, OOL, IOL, "iohl\t$rT, $val",
440            ImmLoad, pattern>,
441   RegConstraint<"$rS = $rT">,
442   NoEncode<"$rS">;
443
444 class IOHLVecInst<ValueType vectype, Operand immtype /* , PatLeaf xform */>:
445   IOHLInst<(outs VECREG:$rT), (ins VECREG:$rS, immtype:$val),
446            [/* no pattern */]>;
447
448 class IOHLRegInst<RegisterClass rclass, Operand immtype /* , PatLeaf xform */>:
449   IOHLInst<(outs rclass:$rT), (ins rclass:$rS, immtype:$val),
450            [/* no pattern */]>;
451
452 multiclass ImmOrHalfwordLower
453 {
454   def v2i64: IOHLVecInst<v2i64, u16imm_i64>;
455   def v4i32: IOHLVecInst<v4i32, u16imm_i32>;
456
457   def r32: IOHLRegInst<R32C, i32imm>;
458   def f32: IOHLRegInst<R32FP, f32imm>;
459
460   def lo: IOHLRegInst<R32C, symbolLo>;
461 }
462
463 defm IOHL: ImmOrHalfwordLower;
464
465 // Form select mask for bytes using immediate, used in conjunction with the
466 // SELB instruction:
467
468 class FSMBIVec<ValueType vectype>:
469   RI16Form<0b101001100, (outs VECREG:$rT), (ins u16imm:$val),
470           "fsmbi\t$rT, $val",
471           SelectOp,
472           [(set (vectype VECREG:$rT), (SPUselmask (i16 immU16:$val)))]>;
473
474 multiclass FormSelectMaskBytesImm
475 {
476   def v16i8: FSMBIVec<v16i8>;
477   def v8i16: FSMBIVec<v8i16>;
478   def v4i32: FSMBIVec<v4i32>;
479   def v2i64: FSMBIVec<v2i64>;
480 }
481
482 defm FSMBI : FormSelectMaskBytesImm;
483
484 // fsmb: Form select mask for bytes. N.B. Input operand, $rA, is 16-bits
485 class FSMBInst<dag OOL, dag IOL, list<dag> pattern>:
486     RRForm_1<0b01101101100, OOL, IOL, "fsmb\t$rT, $rA", SelectOp,
487              pattern>;
488
489 class FSMBRegInst<RegisterClass rclass, ValueType vectype>:
490     FSMBInst<(outs VECREG:$rT), (ins rclass:$rA),
491              [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
492
493 class FSMBVecInst<ValueType vectype>:
494     FSMBInst<(outs VECREG:$rT), (ins VECREG:$rA),
495              [(set (vectype VECREG:$rT),
496                    (SPUselmask (vectype VECREG:$rA)))]>;
497
498 multiclass FormSelectMaskBits {
499   def v16i8_r16: FSMBRegInst<R16C, v16i8>;
500   def v16i8:     FSMBVecInst<v16i8>;
501 }
502
503 defm FSMB: FormSelectMaskBits;
504
505 // fsmh: Form select mask for halfwords. N.B., Input operand, $rA, is
506 // only 8-bits wide (even though it's input as 16-bits here)
507
508 class FSMHInst<dag OOL, dag IOL, list<dag> pattern>:
509     RRForm_1<0b10101101100, OOL, IOL, "fsmh\t$rT, $rA", SelectOp,
510              pattern>;
511
512 class FSMHRegInst<RegisterClass rclass, ValueType vectype>:
513     FSMHInst<(outs VECREG:$rT), (ins rclass:$rA),
514              [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
515
516 class FSMHVecInst<ValueType vectype>:
517     FSMHInst<(outs VECREG:$rT), (ins VECREG:$rA),
518              [(set (vectype VECREG:$rT),
519                    (SPUselmask (vectype VECREG:$rA)))]>;
520
521 multiclass FormSelectMaskHalfword {
522   def v8i16_r16: FSMHRegInst<R16C, v8i16>;
523   def v8i16:     FSMHVecInst<v8i16>;
524 }
525
526 defm FSMH: FormSelectMaskHalfword;
527
528 // fsm: Form select mask for words. Like the other fsm* instructions,
529 // only the lower 4 bits of $rA are significant.
530
531 class FSMInst<dag OOL, dag IOL, list<dag> pattern>:
532     RRForm_1<0b00101101100, OOL, IOL, "fsm\t$rT, $rA", SelectOp,
533              pattern>;
534
535 class FSMRegInst<ValueType vectype, RegisterClass rclass>:
536     FSMInst<(outs VECREG:$rT), (ins rclass:$rA),
537             [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
538
539 class FSMVecInst<ValueType vectype>:
540     FSMInst<(outs VECREG:$rT), (ins VECREG:$rA),
541             [(set (vectype VECREG:$rT), (SPUselmask (vectype VECREG:$rA)))]>;
542
543 multiclass FormSelectMaskWord {
544   def v4i32: FSMVecInst<v4i32>;
545
546   def r32 :  FSMRegInst<v4i32, R32C>;
547   def r16 :  FSMRegInst<v4i32, R16C>;
548 }
549
550 defm FSM : FormSelectMaskWord;
551
552 // Special case when used for i64 math operations
553 multiclass FormSelectMaskWord64 {
554   def r32 : FSMRegInst<v2i64, R32C>;
555   def r16 : FSMRegInst<v2i64, R16C>;
556 }
557
558 defm FSM64 : FormSelectMaskWord64;
559
560 //===----------------------------------------------------------------------===//
561 // Integer and Logical Operations:
562 //===----------------------------------------------------------------------===//
563
564 def AHv8i16:
565   RRForm<0b00010011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
566     "ah\t$rT, $rA, $rB", IntegerOp,
567     [(set (v8i16 VECREG:$rT), (int_spu_si_ah VECREG:$rA, VECREG:$rB))]>;
568
569 def : Pat<(add (v8i16 VECREG:$rA), (v8i16 VECREG:$rB)),
570           (AHv8i16 VECREG:$rA, VECREG:$rB)>;
571
572 def AHr16:
573   RRForm<0b00010011000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
574     "ah\t$rT, $rA, $rB", IntegerOp,
575     [(set R16C:$rT, (add R16C:$rA, R16C:$rB))]>;
576
577 def AHIvec:
578     RI10Form<0b10111000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
579       "ahi\t$rT, $rA, $val", IntegerOp,
580       [(set (v8i16 VECREG:$rT), (add (v8i16 VECREG:$rA),
581                                      v8i16SExt10Imm:$val))]>;
582
583 def AHIr16:
584   RI10Form<0b10111000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
585     "ahi\t$rT, $rA, $val", IntegerOp,
586     [(set R16C:$rT, (add R16C:$rA, v8i16SExt10Imm:$val))]>;
587
588 class AInst<dag OOL, dag IOL, list<dag> pattern>:
589   RRForm<0b00000011000, OOL, IOL,
590          "a\t$rT, $rA, $rB", IntegerOp,
591          pattern>;
592
593 class AVecInst<ValueType vectype>:
594   AInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
595         [(set (vectype VECREG:$rT), (add (vectype VECREG:$rA),
596                                          (vectype VECREG:$rB)))]>;
597
598 class ARegInst<RegisterClass rclass>:
599   AInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
600         [(set rclass:$rT, (add rclass:$rA, rclass:$rB))]>;
601         
602 multiclass AddInstruction {
603   def v4i32: AVecInst<v4i32>;
604   def v16i8: AVecInst<v16i8>;
605   
606   def r32:   ARegInst<R32C>;
607   def r8:    AInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB), [/* no pattern */]>; 
608 }
609
610 defm A : AddInstruction;
611
612 def AIvec:
613     RI10Form<0b00111000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
614       "ai\t$rT, $rA, $val", IntegerOp,
615       [(set (v4i32 VECREG:$rT), (add (v4i32 VECREG:$rA),
616                                       v4i32SExt10Imm:$val))]>;
617
618 def AIr32:
619     RI10Form<0b00111000, (outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
620       "ai\t$rT, $rA, $val", IntegerOp,
621       [(set R32C:$rT, (add R32C:$rA, i32ImmSExt10:$val))]>;
622
623 def SFHvec:
624     RRForm<0b00010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
625       "sfh\t$rT, $rA, $rB", IntegerOp,
626       [(set (v8i16 VECREG:$rT), (sub (v8i16 VECREG:$rA),
627                                      (v8i16 VECREG:$rB)))]>;
628
629 def SFHr16:
630     RRForm<0b00010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
631       "sfh\t$rT, $rA, $rB", IntegerOp,
632       [(set R16C:$rT, (sub R16C:$rA, R16C:$rB))]>;
633
634 def SFHIvec:
635     RI10Form<0b10110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
636       "sfhi\t$rT, $rA, $val", IntegerOp,
637       [(set (v8i16 VECREG:$rT), (sub v8i16SExt10Imm:$val,
638                                      (v8i16 VECREG:$rA)))]>;
639
640 def SFHIr16 : RI10Form<0b10110000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
641   "sfhi\t$rT, $rA, $val", IntegerOp,
642   [(set R16C:$rT, (sub i16ImmSExt10:$val, R16C:$rA))]>;
643
644 def SFvec : RRForm<0b00000010000, (outs VECREG:$rT),
645                                   (ins VECREG:$rA, VECREG:$rB),
646   "sf\t$rT, $rA, $rB", IntegerOp,
647   [(set (v4i32 VECREG:$rT), (sub (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
648
649 def SFr32 : RRForm<0b00000010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
650   "sf\t$rT, $rA, $rB", IntegerOp,
651   [(set R32C:$rT, (sub R32C:$rA, R32C:$rB))]>;
652
653 def SFIvec:
654     RI10Form<0b00110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
655       "sfi\t$rT, $rA, $val", IntegerOp,
656       [(set (v4i32 VECREG:$rT), (sub v4i32SExt10Imm:$val,
657                                      (v4i32 VECREG:$rA)))]>;
658
659 def SFIr32 : RI10Form<0b00110000, (outs R32C:$rT),
660                                   (ins R32C:$rA, s10imm_i32:$val),
661   "sfi\t$rT, $rA, $val", IntegerOp,
662   [(set R32C:$rT, (sub i32ImmSExt10:$val, R32C:$rA))]>;
663
664 // ADDX: only available in vector form, doesn't match a pattern.
665 class ADDXInst<dag OOL, dag IOL, list<dag> pattern>:
666     RRForm<0b00000010110, OOL, IOL,
667       "addx\t$rT, $rA, $rB",
668       IntegerOp, pattern>;
669
670 class ADDXVecInst<ValueType vectype>:
671     ADDXInst<(outs VECREG:$rT),
672              (ins VECREG:$rA, VECREG:$rB, VECREG:$rCarry),
673              [(set (vectype VECREG:$rT),
674                    (SPUaddx (vectype VECREG:$rA), (vectype VECREG:$rB),
675                             (vectype VECREG:$rCarry)))]>,
676     RegConstraint<"$rCarry = $rT">,
677     NoEncode<"$rCarry">;
678
679 class ADDXRegInst<RegisterClass rclass>:
680     ADDXInst<(outs rclass:$rT),
681              (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
682              [(set rclass:$rT,
683                    (SPUaddx rclass:$rA, rclass:$rB, rclass:$rCarry))]>,
684     RegConstraint<"$rCarry = $rT">,
685     NoEncode<"$rCarry">;
686
687 multiclass AddExtended {
688   def v2i64 : ADDXVecInst<v2i64>;
689   def v4i32 : ADDXVecInst<v4i32>;
690   def r64 : ADDXRegInst<R64C>;
691   def r32 : ADDXRegInst<R32C>;
692 }
693
694 defm ADDX : AddExtended;
695
696 // CG: Generate carry for add
697 class CGInst<dag OOL, dag IOL, list<dag> pattern>:
698     RRForm<0b01000011000, OOL, IOL,
699       "cg\t$rT, $rA, $rB",
700       IntegerOp, pattern>;
701
702 class CGVecInst<ValueType vectype>:
703     CGInst<(outs VECREG:$rT),
704            (ins VECREG:$rA, VECREG:$rB),
705              [(set (vectype VECREG:$rT),
706                    (SPUcarry_gen (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
707
708 class CGRegInst<RegisterClass rclass>:
709     CGInst<(outs rclass:$rT),
710            (ins rclass:$rA, rclass:$rB),
711              [(set rclass:$rT,
712                    (SPUcarry_gen rclass:$rA, rclass:$rB))]>;
713
714 multiclass CarryGenerate {
715   def v2i64 : CGVecInst<v2i64>;
716   def v4i32 : CGVecInst<v4i32>;
717   def r64 : CGRegInst<R64C>;
718   def r32 : CGRegInst<R32C>;
719 }
720
721 defm CG : CarryGenerate;
722
723 // SFX: Subract from, extended. This is used in conjunction with BG to subtract
724 // with carry (borrow, in this case)
725 class SFXInst<dag OOL, dag IOL, list<dag> pattern>:
726     RRForm<0b10000010110, OOL, IOL,
727       "sfx\t$rT, $rA, $rB",
728       IntegerOp, pattern>;
729
730 class SFXVecInst<ValueType vectype>:
731     SFXInst<(outs VECREG:$rT),
732             (ins VECREG:$rA, VECREG:$rB, VECREG:$rCarry),
733              [(set (vectype VECREG:$rT),
734                    (SPUsubx (vectype VECREG:$rA), (vectype VECREG:$rB),
735                             (vectype VECREG:$rCarry)))]>,
736     RegConstraint<"$rCarry = $rT">,
737     NoEncode<"$rCarry">;
738
739 class SFXRegInst<RegisterClass rclass>:
740     SFXInst<(outs rclass:$rT),
741             (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
742              [(set rclass:$rT,
743                    (SPUsubx rclass:$rA, rclass:$rB, rclass:$rCarry))]>,
744     RegConstraint<"$rCarry = $rT">,
745     NoEncode<"$rCarry">;
746
747 multiclass SubtractExtended {
748   def v2i64 : SFXVecInst<v2i64>;
749   def v4i32 : SFXVecInst<v4i32>;
750   def r64 : SFXRegInst<R64C>;
751   def r32 : SFXRegInst<R32C>;
752 }
753
754 defm SFX : SubtractExtended;
755
756 // BG: only available in vector form, doesn't match a pattern.
757 class BGInst<dag OOL, dag IOL, list<dag> pattern>:
758     RRForm<0b01000010000, OOL, IOL,
759       "bg\t$rT, $rA, $rB",
760       IntegerOp, pattern>;
761
762 class BGVecInst<ValueType vectype>:
763     BGInst<(outs VECREG:$rT),
764            (ins VECREG:$rA, VECREG:$rB),
765            [(set (vectype VECREG:$rT),
766                  (SPUborrow_gen (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
767
768 class BGRegInst<RegisterClass rclass>:
769     BGInst<(outs rclass:$rT),
770            (ins rclass:$rA, rclass:$rB),
771            [(set rclass:$rT,
772                  (SPUborrow_gen rclass:$rA, rclass:$rB))]>;
773
774 multiclass BorrowGenerate {
775   def v4i32 : BGVecInst<v4i32>;
776   def v2i64 : BGVecInst<v2i64>;
777   def r64 : BGRegInst<R64C>;
778   def r32 : BGRegInst<R32C>;
779 }
780
781 defm BG : BorrowGenerate;
782
783 // BGX: Borrow generate, extended.
784 def BGXvec:
785     RRForm<0b11000010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB,
786                                 VECREG:$rCarry),
787       "bgx\t$rT, $rA, $rB", IntegerOp,
788       []>,
789     RegConstraint<"$rCarry = $rT">,
790     NoEncode<"$rCarry">;
791
792 // Halfword multiply variants:
793 // N.B: These can be used to build up larger quantities (16x16 -> 32)
794
795 def MPYv8i16:
796   RRForm<0b00100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
797     "mpy\t$rT, $rA, $rB", IntegerMulDiv,
798     [(set (v8i16 VECREG:$rT), (SPUmpy_vec (v8i16 VECREG:$rA),
799                                           (v8i16 VECREG:$rB)))]>;
800
801 def MPYr16:
802   RRForm<0b00100011110, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
803     "mpy\t$rT, $rA, $rB", IntegerMulDiv,
804     [(set R16C:$rT, (mul R16C:$rA, R16C:$rB))]>;
805
806 // Unsigned 16-bit multiply:
807
808 class MPYUInst<dag OOL, dag IOL, list<dag> pattern>:
809     RRForm<0b00110011110, OOL, IOL,
810       "mpyu\t$rT, $rA, $rB", IntegerMulDiv,
811       pattern>;
812
813 def MPYUv4i32:
814   MPYUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
815            [(set (v4i32 VECREG:$rT),
816                  (SPUmpyu_vec (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
817
818 def MPYUr16:
819   MPYUInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB),
820            [(set R32C:$rT, (mul (zext R16C:$rA), (zext R16C:$rB)))]>;
821
822 def MPYUr32:
823   MPYUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
824            [(set R32C:$rT, (SPUmpyu_int R32C:$rA, R32C:$rB))]>;
825
826 // mpyi: multiply 16 x s10imm -> 32 result.
827
828 class MPYIInst<dag OOL, dag IOL, list<dag> pattern>:
829   RI10Form<0b00101110, OOL, IOL,
830     "mpyi\t$rT, $rA, $val", IntegerMulDiv,
831     pattern>;
832
833 def MPYIvec:
834   MPYIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
835            [(set (v8i16 VECREG:$rT),
836                  (mul (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
837
838 def MPYIr16:
839   MPYIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
840            [(set R16C:$rT, (mul R16C:$rA, i16ImmSExt10:$val))]>;
841
842 // mpyui: same issues as other multiplies, plus, this doesn't match a
843 // pattern... but may be used during target DAG selection or lowering
844
845 class MPYUIInst<dag OOL, dag IOL, list<dag> pattern>:
846   RI10Form<0b10101110, OOL, IOL,
847            "mpyui\t$rT, $rA, $val", IntegerMulDiv,
848            pattern>;
849     
850 def MPYUIvec:
851   MPYUIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
852             []>;
853
854 def MPYUIr16:
855   MPYUIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
856             []>;
857
858 // mpya: 16 x 16 + 16 -> 32 bit result
859 class MPYAInst<dag OOL, dag IOL, list<dag> pattern>:
860   RRRForm<0b0011, OOL, IOL,
861           "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
862           pattern>;
863           
864 def MPYAvec:
865   MPYAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
866            [(set (v4i32 VECREG:$rT),
867                  (add (v4i32 (bitconvert (mul (v8i16 VECREG:$rA),
868                                               (v8i16 VECREG:$rB)))),
869                       (v4i32 VECREG:$rC)))]>;
870
871 def MPYAr32:
872   MPYAInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
873            [(set R32C:$rT, (add (sext (mul R16C:$rA, R16C:$rB)),
874                                 R32C:$rC))]>;
875                                 
876 def MPYAr32_sext:
877   MPYAInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
878            [(set R32C:$rT, (add (mul (sext R16C:$rA), (sext R16C:$rB)),
879                                 R32C:$rC))]>;
880
881 def MPYAr32_sextinreg:
882   MPYAInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB, R32C:$rC),
883            [(set R32C:$rT, (add (mul (sext_inreg R32C:$rA, i16),
884                                      (sext_inreg R32C:$rB, i16)),
885                                 R32C:$rC))]>;
886
887 // mpyh: multiply high, used to synthesize 32-bit multiplies
888 class MPYHInst<dag OOL, dag IOL, list<dag> pattern>:
889   RRForm<0b10100011110, OOL, IOL,
890          "mpyh\t$rT, $rA, $rB", IntegerMulDiv,
891          pattern>;
892          
893 def MPYHv4i32:
894     MPYHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
895              [(set (v4i32 VECREG:$rT),
896                    (SPUmpyh_vec (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
897
898 def MPYHr32:
899     MPYHInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
900              [(set R32C:$rT, (SPUmpyh_int R32C:$rA, R32C:$rB))]>;
901
902 // mpys: multiply high and shift right (returns the top half of
903 // a 16-bit multiply, sign extended to 32 bits.)
904 def MPYSvec:
905     RRForm<0b11100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
906       "mpys\t$rT, $rA, $rB", IntegerMulDiv,
907       []>;
908
909 def MPYSr16:
910     RRForm<0b11100011110, (outs R32C:$rT), (ins R16C:$rA, R16C:$rB),
911       "mpys\t$rT, $rA, $rB", IntegerMulDiv,
912       []>;
913
914 // mpyhh: multiply high-high (returns the 32-bit result from multiplying
915 // the top 16 bits of the $rA, $rB)
916 def MPYHHv8i16:
917     RRForm<0b01100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
918       "mpyhh\t$rT, $rA, $rB", IntegerMulDiv,
919       [(set (v8i16 VECREG:$rT),
920             (SPUmpyhh_vec (v8i16 VECREG:$rA), (v8i16 VECREG:$rB)))]>;
921
922 def MPYHHr32:
923     RRForm<0b01100011110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
924       "mpyhh\t$rT, $rA, $rB", IntegerMulDiv,
925       []>;
926
927 // mpyhha: Multiply high-high, add to $rT:
928 def MPYHHAvec:
929     RRForm<0b01100010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
930       "mpyhha\t$rT, $rA, $rB", IntegerMulDiv,
931       []>;
932
933 def MPYHHAr32:
934     RRForm<0b01100010110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
935       "mpyhha\t$rT, $rA, $rB", IntegerMulDiv,
936       []>;
937
938 // mpyhhu: Multiply high-high, unsigned
939 def MPYHHUvec:
940     RRForm<0b01110011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
941       "mpyhhu\t$rT, $rA, $rB", IntegerMulDiv,
942       []>;
943
944 def MPYHHUr32:
945     RRForm<0b01110011110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
946       "mpyhhu\t$rT, $rA, $rB", IntegerMulDiv,
947       []>;
948
949 // mpyhhau: Multiply high-high, unsigned
950 def MPYHHAUvec:
951     RRForm<0b01110010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
952       "mpyhhau\t$rT, $rA, $rB", IntegerMulDiv,
953       []>;
954
955 def MPYHHAUr32:
956     RRForm<0b01110010110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
957       "mpyhhau\t$rT, $rA, $rB", IntegerMulDiv,
958       []>;
959
960 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
961 // v4i32, i32 multiply instruction sequence:
962 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
963 def MPYv4i32:
964   Pat<(mul (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)),
965       (Av4i32
966         (Av4i32 (MPYHv4i32 VECREG:$rA, VECREG:$rB),
967                 (MPYHv4i32 VECREG:$rB, VECREG:$rA)),
968         (MPYUv4i32 VECREG:$rA, VECREG:$rB))>;
969
970 def MPYi32:
971   Pat<(mul R32C:$rA, R32C:$rB),
972       (Ar32
973         (Ar32 (MPYHr32 R32C:$rA, R32C:$rB),
974               (MPYHr32 R32C:$rB, R32C:$rA)),
975         (MPYUr32 R32C:$rA, R32C:$rB))>;
976
977 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
978 // clz: Count leading zeroes
979 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
980 class CLZInst<dag OOL, dag IOL, list<dag> pattern>:
981     RRForm_1<0b10100101010, OOL, IOL, "clz\t$rT, $rA",
982              IntegerOp, pattern>;
983
984 class CLZRegInst<RegisterClass rclass>:
985     CLZInst<(outs rclass:$rT), (ins rclass:$rA),
986             [(set rclass:$rT, (ctlz rclass:$rA))]>;
987
988 class CLZVecInst<ValueType vectype>:
989     CLZInst<(outs VECREG:$rT), (ins VECREG:$rA),
990             [(set (vectype VECREG:$rT), (ctlz (vectype VECREG:$rA)))]>;
991
992 multiclass CountLeadingZeroes {
993   def v4i32 : CLZVecInst<v4i32>;
994   def r32   : CLZRegInst<R32C>;
995 }
996
997 defm CLZ : CountLeadingZeroes;
998
999 // cntb: Count ones in bytes (aka "population count")
1000 //
1001 // NOTE: This instruction is really a vector instruction, but the custom
1002 // lowering code uses it in unorthodox ways to support CTPOP for other
1003 // data types!
1004
1005 def CNTBv16i8:
1006     RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1007       "cntb\t$rT, $rA", IntegerOp,
1008       [(set (v16i8 VECREG:$rT), (SPUcntb (v16i8 VECREG:$rA)))]>;
1009
1010 def CNTBv8i16 :
1011     RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1012       "cntb\t$rT, $rA", IntegerOp,
1013       [(set (v8i16 VECREG:$rT), (SPUcntb (v8i16 VECREG:$rA)))]>;
1014
1015 def CNTBv4i32 :
1016     RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1017       "cntb\t$rT, $rA", IntegerOp,
1018       [(set (v4i32 VECREG:$rT), (SPUcntb (v4i32 VECREG:$rA)))]>;
1019
1020 // gbb: Gather the low order bits from each byte in $rA into a single 16-bit
1021 // quantity stored into $rT's slot 0, upper 16 bits are zeroed, as are
1022 // slots 1-3.
1023 //
1024 // Note: This instruction "pairs" with the fsmb instruction for all of the
1025 // various types defined here.
1026 //
1027 // Note 2: The "VecInst" and "RegInst" forms refer to the result being either
1028 // a vector or register.
1029
1030 class GBBInst<dag OOL, dag IOL, list<dag> pattern>:
1031   RRForm_1<0b01001101100, OOL, IOL, "gbb\t$rT, $rA", GatherOp, pattern>;
1032
1033 class GBBRegInst<RegisterClass rclass, ValueType vectype>:
1034   GBBInst<(outs rclass:$rT), (ins VECREG:$rA),
1035           [(set rclass:$rT, (SPUgatherbits (vectype VECREG:$rA)))]>;
1036
1037 class GBBVecInst<ValueType vectype>:
1038   GBBInst<(outs VECREG:$rT), (ins VECREG:$rA),
1039           [(set (vectype VECREG:$rT), (SPUgatherbits (vectype VECREG:$rA)))]>;
1040
1041 multiclass GatherBitsFromBytes {
1042   def v16i8_r32: GBBRegInst<R32C, v16i8>;
1043   def v16i8_r16: GBBRegInst<R16C, v16i8>;
1044   def v16i8:     GBBVecInst<v16i8>;
1045 }
1046
1047 defm GBB: GatherBitsFromBytes;
1048
1049 // gbh: Gather all low order bits from each halfword in $rA into a single
1050 // 8-bit quantity stored in $rT's slot 0, with the upper bits of $rT set to 0
1051 // and slots 1-3 also set to 0.
1052 //
1053 // See notes for GBBInst, above.
1054
1055 class GBHInst<dag OOL, dag IOL, list<dag> pattern>:
1056     RRForm_1<0b10001101100, OOL, IOL, "gbh\t$rT, $rA", GatherOp,
1057              pattern>;
1058
1059 class GBHRegInst<RegisterClass rclass, ValueType vectype>:
1060     GBHInst<(outs rclass:$rT), (ins VECREG:$rA),
1061             [(set rclass:$rT, (SPUgatherbits (vectype VECREG:$rA)))]>;
1062
1063 class GBHVecInst<ValueType vectype>:
1064     GBHInst<(outs VECREG:$rT), (ins VECREG:$rA),
1065             [(set (vectype VECREG:$rT),
1066                   (SPUgatherbits (vectype VECREG:$rA)))]>;
1067
1068 multiclass GatherBitsHalfword {
1069   def v8i16_r32: GBHRegInst<R32C, v8i16>;
1070   def v8i16_r16: GBHRegInst<R16C, v8i16>;
1071   def v8i16:     GBHVecInst<v8i16>;
1072 }
1073
1074 defm GBH: GatherBitsHalfword;
1075
1076 // gb: Gather all low order bits from each word in $rA into a single
1077 // 4-bit quantity stored in $rT's slot 0, upper bits in $rT set to 0,
1078 // as well as slots 1-3.
1079 //
1080 // See notes for gbb, above.
1081
1082 class GBInst<dag OOL, dag IOL, list<dag> pattern>:
1083     RRForm_1<0b00001101100, OOL, IOL, "gb\t$rT, $rA", GatherOp,
1084              pattern>;
1085
1086 class GBRegInst<RegisterClass rclass, ValueType vectype>:
1087     GBInst<(outs rclass:$rT), (ins VECREG:$rA),
1088            [(set rclass:$rT, (SPUgatherbits (vectype VECREG:$rA)))]>;
1089
1090 class GBVecInst<ValueType vectype>:
1091     GBInst<(outs VECREG:$rT), (ins VECREG:$rA),
1092            [(set (vectype VECREG:$rT),
1093                  (SPUgatherbits (vectype VECREG:$rA)))]>;
1094
1095 multiclass GatherBitsWord {
1096   def v4i32_r32: GBRegInst<R32C, v4i32>;
1097   def v4i32_r16: GBRegInst<R16C, v4i32>;
1098   def v4i32:     GBVecInst<v4i32>;
1099 }
1100
1101 defm GB: GatherBitsWord;
1102
1103 // avgb: average bytes
1104 def AVGB:
1105     RRForm<0b11001011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1106       "avgb\t$rT, $rA, $rB", ByteOp,
1107       []>;
1108
1109 // absdb: absolute difference of bytes
1110 def ABSDB:
1111     RRForm<0b11001010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1112       "absdb\t$rT, $rA, $rB", ByteOp,
1113       []>;
1114
1115 // sumb: sum bytes into halfwords
1116 def SUMB:
1117     RRForm<0b11001010010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1118       "sumb\t$rT, $rA, $rB", ByteOp,
1119       []>;
1120
1121 // Sign extension operations:
1122 class XSBHInst<dag OOL, dag IOL, list<dag> pattern>:
1123     RRForm_1<0b01101101010, OOL, IOL,
1124       "xsbh\t$rDst, $rSrc",
1125       IntegerOp, pattern>;
1126
1127 class XSBHVecInst<ValueType vectype>:
1128     XSBHInst<(outs VECREG:$rDst), (ins VECREG:$rSrc),
1129       [(set (v8i16 VECREG:$rDst), (sext (vectype VECREG:$rSrc)))]>;
1130
1131 class XSBHInRegInst<RegisterClass rclass>:
1132     XSBHInst<(outs rclass:$rDst), (ins rclass:$rSrc),
1133       [(set rclass:$rDst, (sext_inreg rclass:$rSrc, i8))]>;
1134
1135 multiclass ExtendByteHalfword {
1136   def v16i8: XSBHVecInst<v8i16>;
1137   def r16:   XSBHInRegInst<R16C>;
1138   def r8:    XSBHInst<(outs R16C:$rDst), (ins R8C:$rSrc),
1139                       [(set R16C:$rDst, (sext R8C:$rSrc))]>;
1140
1141   // 32-bit form for XSBH: used to sign extend 8-bit quantities to 16-bit
1142   // quantities to 32-bit quantities via a 32-bit register (see the sext 8->32
1143   // pattern below). Intentionally doesn't match a pattern because we want the
1144   // sext 8->32 pattern to do the work for us, namely because we need the extra
1145   // XSHWr32.
1146   def r32:   XSBHInRegInst<R32C>;
1147 }
1148
1149 defm XSBH : ExtendByteHalfword;
1150
1151 // Sign extend halfwords to words:
1152 def XSHWvec:
1153     RRForm_1<0b01101101010, (outs VECREG:$rDest), (ins VECREG:$rSrc),
1154       "xshw\t$rDest, $rSrc", IntegerOp,
1155       [(set (v4i32 VECREG:$rDest), (sext (v8i16 VECREG:$rSrc)))]>;
1156
1157 def XSHWr32:
1158     RRForm_1<0b01101101010, (outs R32C:$rDst), (ins R32C:$rSrc),
1159       "xshw\t$rDst, $rSrc", IntegerOp,
1160       [(set R32C:$rDst, (sext_inreg R32C:$rSrc, i16))]>;
1161
1162 def XSHWr16:
1163     RRForm_1<0b01101101010, (outs R32C:$rDst), (ins R16C:$rSrc),
1164       "xshw\t$rDst, $rSrc", IntegerOp,
1165       [(set R32C:$rDst, (sext R16C:$rSrc))]>;
1166
1167 def XSWDvec:
1168     RRForm_1<0b01100101010, (outs VECREG:$rDst), (ins VECREG:$rSrc),
1169       "xswd\t$rDst, $rSrc", IntegerOp,
1170       [(set (v2i64 VECREG:$rDst), (sext (v4i32 VECREG:$rSrc)))]>;
1171
1172 def XSWDr64:
1173     RRForm_1<0b01100101010, (outs R64C:$rDst), (ins R64C:$rSrc),
1174       "xswd\t$rDst, $rSrc", IntegerOp,
1175       [(set R64C:$rDst, (sext_inreg R64C:$rSrc, i32))]>;
1176
1177 def XSWDr32:
1178     RRForm_1<0b01100101010, (outs R64C:$rDst), (ins R32C:$rSrc),
1179       "xswd\t$rDst, $rSrc", IntegerOp,
1180       [(set R64C:$rDst, (SPUsext32_to_64 R32C:$rSrc))]>;
1181
1182 def : Pat<(sext R32C:$inp),
1183           (XSWDr32 R32C:$inp)>;
1184
1185 // AND operations
1186
1187 class ANDInst<dag OOL, dag IOL, list<dag> pattern> :
1188     RRForm<0b10000011000, OOL, IOL, "and\t$rT, $rA, $rB",
1189            IntegerOp, pattern>;
1190
1191 class ANDVecInst<ValueType vectype>:
1192     ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1193              [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
1194                                               (vectype VECREG:$rB)))]>;
1195
1196 class ANDRegInst<RegisterClass rclass>:
1197     ANDInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1198              [(set rclass:$rT, (and rclass:$rA, rclass:$rB))]>;
1199
1200 multiclass BitwiseAnd
1201 {
1202   def v16i8: ANDVecInst<v16i8>;
1203   def v8i16: ANDVecInst<v8i16>;
1204   def v4i32: ANDVecInst<v4i32>;
1205   def v2i64: ANDVecInst<v2i64>;
1206
1207   def r128:  ANDRegInst<GPRC>;
1208   def r64:   ANDRegInst<R64C>;
1209   def r32:   ANDRegInst<R32C>;
1210   def r16:   ANDRegInst<R16C>;
1211   def r8:    ANDRegInst<R8C>;
1212
1213   //===---------------------------------------------
1214   // Special instructions to perform the fabs instruction
1215   def fabs32: ANDInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1216                       [/* Intentionally does not match a pattern */]>;
1217
1218   def fabs64: ANDInst<(outs R64FP:$rT), (ins R64FP:$rA, VECREG:$rB),
1219                       [/* Intentionally does not match a pattern */]>;
1220
1221   // Could use v4i32, but won't for clarity
1222   def fabsvec: ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1223                        [/* Intentionally does not match a pattern */]>;
1224
1225   //===---------------------------------------------
1226
1227   // Hacked form of AND to zero-extend 16-bit quantities to 32-bit
1228   // quantities -- see 16->32 zext pattern.
1229   //
1230   // This pattern is somewhat artificial, since it might match some
1231   // compiler generated pattern but it is unlikely to do so.
1232
1233   def i16i32: ANDInst<(outs R32C:$rT), (ins R16C:$rA, R32C:$rB),
1234                       [(set R32C:$rT, (and (zext R16C:$rA), R32C:$rB))]>;
1235 }
1236
1237 defm AND : BitwiseAnd;
1238
1239 // N.B.: vnot_conv is one of those special target selection pattern fragments,
1240 // in which we expect there to be a bit_convert on the constant. Bear in mind
1241 // that llvm translates "not <reg>" to "xor <reg>, -1" (or in this case, a
1242 // constant -1 vector.)
1243
1244 class ANDCInst<dag OOL, dag IOL, list<dag> pattern>:
1245     RRForm<0b10000011010, OOL, IOL, "andc\t$rT, $rA, $rB",
1246            IntegerOp, pattern>;
1247
1248 class ANDCVecInst<ValueType vectype>:
1249     ANDCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1250              [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
1251                                               (vnot (vectype VECREG:$rB))))]>;
1252
1253 class ANDCRegInst<RegisterClass rclass>:
1254     ANDCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1255              [(set rclass:$rT, (and rclass:$rA, (not rclass:$rB)))]>;
1256
1257 multiclass AndComplement
1258 {
1259   def v16i8: ANDCVecInst<v16i8>;
1260   def v8i16: ANDCVecInst<v8i16>;
1261   def v4i32: ANDCVecInst<v4i32>;
1262   def v2i64: ANDCVecInst<v2i64>;
1263
1264   def r128: ANDCRegInst<GPRC>;
1265   def r64:  ANDCRegInst<R64C>;
1266   def r32:  ANDCRegInst<R32C>;
1267   def r16:  ANDCRegInst<R16C>;
1268   def r8:   ANDCRegInst<R8C>;
1269 }
1270
1271 defm ANDC : AndComplement;
1272
1273 class ANDBIInst<dag OOL, dag IOL, list<dag> pattern>:
1274     RI10Form<0b01101000, OOL, IOL, "andbi\t$rT, $rA, $val",
1275              ByteOp, pattern>;
1276
1277 multiclass AndByteImm
1278 {
1279   def v16i8: ANDBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1280                        [(set (v16i8 VECREG:$rT),
1281                              (and (v16i8 VECREG:$rA),
1282                                   (v16i8 v16i8U8Imm:$val)))]>;
1283
1284   def r8: ANDBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1285                     [(set R8C:$rT, (and R8C:$rA, immU8:$val))]>;
1286 }
1287
1288 defm ANDBI : AndByteImm;
1289
1290 class ANDHIInst<dag OOL, dag IOL, list<dag> pattern> :
1291     RI10Form<0b10101000, OOL, IOL, "andhi\t$rT, $rA, $val",
1292              ByteOp, pattern>;
1293
1294 multiclass AndHalfwordImm
1295 {
1296   def v8i16: ANDHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1297                        [(set (v8i16 VECREG:$rT),
1298                              (and (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
1299
1300   def r16: ANDHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1301                      [(set R16C:$rT, (and R16C:$rA, i16ImmUns10:$val))]>;
1302
1303   // Zero-extend i8 to i16:
1304   def i8i16: ANDHIInst<(outs R16C:$rT), (ins R8C:$rA, u10imm:$val),
1305                       [(set R16C:$rT, (and (zext R8C:$rA), i16ImmUns10:$val))]>;
1306 }
1307
1308 defm ANDHI : AndHalfwordImm;
1309
1310 class ANDIInst<dag OOL, dag IOL, list<dag> pattern> :
1311     RI10Form<0b00101000, OOL, IOL, "andi\t$rT, $rA, $val",
1312              IntegerOp, pattern>;
1313
1314 multiclass AndWordImm
1315 {
1316   def v4i32: ANDIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1317                       [(set (v4i32 VECREG:$rT),
1318                             (and (v4i32 VECREG:$rA), v4i32SExt10Imm:$val))]>;
1319
1320   def r32: ANDIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1321                     [(set R32C:$rT, (and R32C:$rA, i32ImmSExt10:$val))]>;
1322
1323   // Hacked form of ANDI to zero-extend i8 quantities to i32. See the zext 8->32
1324   // pattern below.
1325   def i8i32: ANDIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1326                       [(set R32C:$rT,
1327                             (and (zext R8C:$rA), i32ImmSExt10:$val))]>;
1328
1329   // Hacked form of ANDI to zero-extend i16 quantities to i32. See the
1330   // zext 16->32 pattern below.
1331   //
1332   // Note that this pattern is somewhat artificial, since it might match
1333   // something the compiler generates but is unlikely to occur in practice.
1334   def i16i32: ANDIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1335                        [(set R32C:$rT,
1336                              (and (zext R16C:$rA), i32ImmSExt10:$val))]>;
1337 }
1338
1339 defm ANDI : AndWordImm;
1340
1341 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1342 // Bitwise OR group:
1343 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1344
1345 // Bitwise "or" (N.B.: These are also register-register copy instructions...)
1346 class ORInst<dag OOL, dag IOL, list<dag> pattern>:
1347     RRForm<0b10000010000, OOL, IOL, "or\t$rT, $rA, $rB",
1348            IntegerOp, pattern>;
1349
1350 class ORVecInst<ValueType vectype>:
1351     ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1352            [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1353                                            (vectype VECREG:$rB)))]>;
1354
1355 class ORRegInst<RegisterClass rclass>:
1356     ORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1357            [(set rclass:$rT, (or rclass:$rA, rclass:$rB))]>;
1358
1359 // ORCvtForm: OR conversion form
1360 //
1361 // This is used to "convert" the preferred slot to its vector equivalent, as
1362 // well as convert a vector back to its preferred slot.
1363 //
1364 // These are effectively no-ops, but need to exist for proper type conversion
1365 // and type coercion.
1366
1367 class ORCvtForm<dag OOL, dag IOL>
1368           : SPUInstr<OOL, IOL, "or\t$rT, $rA, $rA", IntegerOp> {
1369   bits<7> RA;
1370   bits<7> RT;
1371
1372   let Pattern = [/* no pattern */];
1373
1374   let Inst{0-10} = 0b10000010000;
1375   let Inst{11-17} = RA;
1376   let Inst{18-24} = RA;
1377   let Inst{25-31} = RT;
1378 }
1379
1380 class ORPromoteScalar<RegisterClass rclass>:
1381     ORCvtForm<(outs VECREG:$rT), (ins rclass:$rA)>;
1382
1383 class ORExtractElt<RegisterClass rclass>:
1384     ORCvtForm<(outs rclass:$rT), (ins VECREG:$rA)>;
1385
1386 class ORCvtRegGPRC<RegisterClass rclass>:
1387     ORCvtForm<(outs GPRC:$rT), (ins rclass:$rA)>;
1388
1389 class ORCvtVecGPRC:
1390     ORCvtForm<(outs GPRC:$rT), (ins VECREG:$rA)>;
1391
1392 class ORCvtGPRCReg<RegisterClass rclass>:
1393     ORCvtForm<(outs rclass:$rT), (ins GPRC:$rA)>;
1394
1395 class ORCvtGPRCVec:
1396     ORCvtForm<(outs VECREG:$rT), (ins GPRC:$rA)>;
1397
1398 multiclass BitwiseOr
1399 {
1400   def v16i8: ORVecInst<v16i8>;
1401   def v8i16: ORVecInst<v8i16>;
1402   def v4i32: ORVecInst<v4i32>;
1403   def v2i64: ORVecInst<v2i64>;
1404
1405   def v4f32: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1406                     [(set (v4f32 VECREG:$rT),
1407                           (v4f32 (bitconvert (or (v4i32 VECREG:$rA),
1408                                                  (v4i32 VECREG:$rB)))))]>;
1409
1410   def v2f64: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1411                     [(set (v2f64 VECREG:$rT),
1412                           (v2f64 (bitconvert (or (v2i64 VECREG:$rA),
1413                                                  (v2i64 VECREG:$rB)))))]>;
1414
1415   def r64: ORRegInst<R64C>;
1416   def r32: ORRegInst<R32C>;
1417   def r16: ORRegInst<R16C>;
1418   def r8:  ORRegInst<R8C>;
1419
1420   // OR instructions used to copy f32 and f64 registers.
1421   def f32: ORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
1422                   [/* no pattern */]>;
1423
1424   def f64: ORInst<(outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
1425                   [/* no pattern */]>;
1426
1427   // scalar->vector promotion:
1428   def v16i8_i8:  ORPromoteScalar<R8C>;
1429   def v8i16_i16: ORPromoteScalar<R16C>;
1430   def v4i32_i32: ORPromoteScalar<R32C>;
1431   def v2i64_i64: ORPromoteScalar<R64C>;
1432   def v4f32_f32: ORPromoteScalar<R32FP>;
1433   def v2f64_f64: ORPromoteScalar<R64FP>;
1434
1435   // extract element 0:
1436   def i8_v16i8:  ORExtractElt<R8C>;
1437   def i16_v8i16: ORExtractElt<R16C>;
1438   def i32_v4i32: ORExtractElt<R32C>;
1439   def i64_v2i64: ORExtractElt<R64C>;
1440   def f32_v4f32: ORExtractElt<R32FP>;
1441   def f64_v2f64: ORExtractElt<R64FP>;
1442
1443   // Conversion from GPRC to register
1444   def i128_r64:  ORCvtRegGPRC<R64C>;
1445   def i128_f64:  ORCvtRegGPRC<R64FP>;
1446   def i128_r32:  ORCvtRegGPRC<R32C>;
1447   def i128_f32:  ORCvtRegGPRC<R32FP>;
1448   def i128_r16:  ORCvtRegGPRC<R16C>;
1449   def i128_r8:   ORCvtRegGPRC<R8C>;
1450
1451   // Conversion from GPRC to vector
1452   def i128_vec:  ORCvtVecGPRC;
1453
1454   // Conversion from register to GPRC
1455   def r64_i128:  ORCvtGPRCReg<R64C>;
1456   def f64_i128:  ORCvtGPRCReg<R64FP>;
1457   def r32_i128:  ORCvtGPRCReg<R32C>;
1458   def f32_i128:  ORCvtGPRCReg<R32FP>;
1459   def r16_i128:  ORCvtGPRCReg<R16C>;
1460   def r8_i128:   ORCvtGPRCReg<R8C>;
1461
1462   // Conversion from vector to GPRC
1463   def vec_i128:  ORCvtGPRCVec;
1464 }
1465
1466 defm OR : BitwiseOr;
1467
1468 // scalar->vector promotion patterns (preferred slot to vector):
1469 def : Pat<(v16i8 (SPUprefslot2vec R8C:$rA)),
1470           (ORv16i8_i8 R8C:$rA)>;
1471
1472 def : Pat<(v8i16 (SPUprefslot2vec R16C:$rA)),
1473           (ORv8i16_i16 R16C:$rA)>;
1474
1475 def : Pat<(v4i32 (SPUprefslot2vec R32C:$rA)),
1476           (ORv4i32_i32 R32C:$rA)>;
1477
1478 def : Pat<(v2i64 (SPUprefslot2vec R64C:$rA)),
1479           (ORv2i64_i64 R64C:$rA)>;
1480
1481 def : Pat<(v4f32 (SPUprefslot2vec R32FP:$rA)),
1482           (ORv4f32_f32 R32FP:$rA)>;
1483
1484 def : Pat<(v2f64 (SPUprefslot2vec R64FP:$rA)),
1485           (ORv2f64_f64 R64FP:$rA)>;
1486
1487 // ORi*_v*: Used to extract vector element 0 (the preferred slot), otherwise
1488 // known as converting the vector back to its preferred slot
1489
1490 def : Pat<(SPUvec2prefslot (v16i8 VECREG:$rA)),
1491           (ORi8_v16i8 VECREG:$rA)>;
1492
1493 def : Pat<(SPUvec2prefslot (v8i16 VECREG:$rA)),
1494           (ORi16_v8i16 VECREG:$rA)>;
1495
1496 def : Pat<(SPUvec2prefslot (v4i32 VECREG:$rA)),
1497           (ORi32_v4i32 VECREG:$rA)>;
1498
1499 def : Pat<(SPUvec2prefslot (v2i64 VECREG:$rA)),
1500           (ORi64_v2i64 VECREG:$rA)>;
1501
1502 def : Pat<(SPUvec2prefslot (v4f32 VECREG:$rA)),
1503           (ORf32_v4f32 VECREG:$rA)>;
1504
1505 def : Pat<(SPUvec2prefslot (v2f64 VECREG:$rA)),
1506           (ORf64_v2f64 VECREG:$rA)>;
1507
1508 // Load Register: This is an assembler alias for a bitwise OR of a register
1509 // against itself. It's here because it brings some clarity to assembly
1510 // language output.
1511
1512 let hasCtrlDep = 1 in {
1513     class LRInst<dag OOL, dag IOL>
1514               : SPUInstr<OOL, IOL, "lr\t$rT, $rA", IntegerOp> {
1515       bits<7> RA;
1516       bits<7> RT;
1517
1518       let Pattern = [/*no pattern*/];
1519
1520       let Inst{0-10} = 0b10000010000;   /* It's an OR operation */
1521       let Inst{11-17} = RA;
1522       let Inst{18-24} = RA;
1523       let Inst{25-31} = RT;
1524     }
1525
1526     class LRVecInst<ValueType vectype>:
1527         LRInst<(outs VECREG:$rT), (ins VECREG:$rA)>;
1528
1529     class LRRegInst<RegisterClass rclass>:
1530         LRInst<(outs rclass:$rT), (ins rclass:$rA)>;
1531
1532     multiclass LoadRegister {
1533       def v2i64: LRVecInst<v2i64>;
1534       def v2f64: LRVecInst<v2f64>;
1535       def v4i32: LRVecInst<v4i32>;
1536       def v4f32: LRVecInst<v4f32>;
1537       def v8i16: LRVecInst<v8i16>;
1538       def v16i8: LRVecInst<v16i8>;
1539
1540       def r128:  LRRegInst<GPRC>;
1541       def r64:   LRRegInst<R64C>;
1542       def f64:   LRRegInst<R64FP>;
1543       def r32:   LRRegInst<R32C>;
1544       def f32:   LRRegInst<R32FP>;
1545       def r16:   LRRegInst<R16C>;
1546       def r8:    LRRegInst<R8C>;
1547     }
1548
1549     defm LR: LoadRegister;
1550 }
1551
1552 // ORC: Bitwise "or" with complement (c = a | ~b)
1553
1554 class ORCInst<dag OOL, dag IOL, list<dag> pattern>:
1555     RRForm<0b10010010000, OOL, IOL, "orc\t$rT, $rA, $rB",
1556            IntegerOp, pattern>;
1557
1558 class ORCVecInst<ValueType vectype>:
1559     ORCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1560             [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1561                                             (vnot (vectype VECREG:$rB))))]>;
1562
1563 class ORCRegInst<RegisterClass rclass>:
1564   ORCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1565           [(set rclass:$rT, (or rclass:$rA, (not rclass:$rB)))]>;
1566
1567 multiclass BitwiseOrComplement
1568 {
1569   def v16i8: ORCVecInst<v16i8>;
1570   def v8i16: ORCVecInst<v8i16>;
1571   def v4i32: ORCVecInst<v4i32>;
1572   def v2i64: ORCVecInst<v2i64>;
1573
1574   def r64:   ORCRegInst<R64C>;
1575   def r32:   ORCRegInst<R32C>;
1576   def r16:   ORCRegInst<R16C>;
1577   def r8:    ORCRegInst<R8C>;
1578 }
1579
1580 defm ORC : BitwiseOrComplement;
1581
1582 // OR byte immediate
1583 class ORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1584     RI10Form<0b01100000, OOL, IOL, "orbi\t$rT, $rA, $val",
1585              IntegerOp, pattern>;
1586
1587 class ORBIVecInst<ValueType vectype, PatLeaf immpred>:
1588     ORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1589              [(set (v16i8 VECREG:$rT), (or (vectype VECREG:$rA),
1590                                            (vectype immpred:$val)))]>;
1591
1592 multiclass BitwiseOrByteImm
1593 {
1594   def v16i8: ORBIVecInst<v16i8, v16i8U8Imm>;
1595
1596   def r8: ORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1597                    [(set R8C:$rT, (or R8C:$rA, immU8:$val))]>;
1598 }
1599
1600 defm ORBI : BitwiseOrByteImm;
1601
1602 // OR halfword immediate
1603 class ORHIInst<dag OOL, dag IOL, list<dag> pattern>:
1604     RI10Form<0b10100000, OOL, IOL, "orhi\t$rT, $rA, $val",
1605              IntegerOp, pattern>;
1606
1607 class ORHIVecInst<ValueType vectype, PatLeaf immpred>:
1608     ORHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1609               [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1610                                               immpred:$val))]>;
1611
1612 multiclass BitwiseOrHalfwordImm
1613 {
1614   def v8i16: ORHIVecInst<v8i16, v8i16Uns10Imm>;
1615
1616   def r16: ORHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1617                     [(set R16C:$rT, (or R16C:$rA, i16ImmUns10:$val))]>;
1618
1619   // Specialized ORHI form used to promote 8-bit registers to 16-bit
1620   def i8i16: ORHIInst<(outs R16C:$rT), (ins R8C:$rA, s10imm:$val),
1621                       [(set R16C:$rT, (or (anyext R8C:$rA),
1622                                           i16ImmSExt10:$val))]>;
1623 }
1624
1625 defm ORHI : BitwiseOrHalfwordImm;
1626
1627 class ORIInst<dag OOL, dag IOL, list<dag> pattern>:
1628     RI10Form<0b00100000, OOL, IOL, "ori\t$rT, $rA, $val",
1629              IntegerOp, pattern>;
1630
1631 class ORIVecInst<ValueType vectype, PatLeaf immpred>:
1632     ORIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1633             [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1634                                             immpred:$val))]>;
1635
1636 // Bitwise "or" with immediate
1637 multiclass BitwiseOrImm
1638 {
1639   def v4i32: ORIVecInst<v4i32, v4i32Uns10Imm>;
1640
1641   def r32: ORIInst<(outs R32C:$rT), (ins R32C:$rA, u10imm_i32:$val),
1642                    [(set R32C:$rT, (or R32C:$rA, i32ImmUns10:$val))]>;
1643
1644   // i16i32: hacked version of the ori instruction to extend 16-bit quantities
1645   // to 32-bit quantities. used exclusively to match "anyext" conversions (vide
1646   // infra "anyext 16->32" pattern.)
1647   def i16i32: ORIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1648                       [(set R32C:$rT, (or (anyext R16C:$rA),
1649                                           i32ImmSExt10:$val))]>;
1650
1651   // i8i32: Hacked version of the ORI instruction to extend 16-bit quantities
1652   // to 32-bit quantities. Used exclusively to match "anyext" conversions (vide
1653   // infra "anyext 16->32" pattern.)
1654   def i8i32: ORIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1655                      [(set R32C:$rT, (or (anyext R8C:$rA),
1656                                          i32ImmSExt10:$val))]>;
1657 }
1658
1659 defm ORI : BitwiseOrImm;
1660
1661 // ORX: "or" across the vector: or's $rA's word slots leaving the result in
1662 // $rT[0], slots 1-3 are zeroed.
1663 //
1664 // FIXME: Needs to match an intrinsic pattern.
1665 def ORXv4i32:
1666     RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1667       "orx\t$rT, $rA, $rB", IntegerOp,
1668       []>;
1669
1670 // XOR:
1671
1672 class XORInst<dag OOL, dag IOL, list<dag> pattern> :
1673     RRForm<0b10010010000, OOL, IOL, "xor\t$rT, $rA, $rB",
1674            IntegerOp, pattern>;
1675
1676 class XORVecInst<ValueType vectype>:
1677     XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1678              [(set (vectype VECREG:$rT), (xor (vectype VECREG:$rA),
1679                                               (vectype VECREG:$rB)))]>;
1680
1681 class XORRegInst<RegisterClass rclass>:
1682     XORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1683              [(set rclass:$rT, (xor rclass:$rA, rclass:$rB))]>;
1684
1685 multiclass BitwiseExclusiveOr
1686 {
1687   def v16i8: XORVecInst<v16i8>;
1688   def v8i16: XORVecInst<v8i16>;
1689   def v4i32: XORVecInst<v4i32>;
1690   def v2i64: XORVecInst<v2i64>;
1691
1692   def r128:  XORRegInst<GPRC>;
1693   def r64:   XORRegInst<R64C>;
1694   def r32:   XORRegInst<R32C>;
1695   def r16:   XORRegInst<R16C>;
1696   def r8:    XORRegInst<R8C>;
1697
1698   // Special forms for floating point instructions.
1699   // fneg and fabs require bitwise logical ops to manipulate the sign bit.
1700
1701   def fneg32: XORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1702                       [/* no pattern */]>;
1703
1704   def fneg64: XORInst<(outs R64FP:$rT), (ins R64FP:$rA, VECREG:$rB),
1705                       [/* no pattern */]>;
1706
1707   def fnegvec: XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1708                        [/* no pattern, see fneg{32,64} */]>;
1709 }
1710
1711 defm XOR : BitwiseExclusiveOr;
1712
1713 //==----------------------------------------------------------
1714
1715 class XORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1716     RI10Form<0b01100000, OOL, IOL, "xorbi\t$rT, $rA, $val",
1717              IntegerOp, pattern>;
1718
1719 multiclass XorByteImm
1720 {
1721   def v16i8:
1722     XORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1723               [(set (v16i8 VECREG:$rT), (xor (v16i8 VECREG:$rA), v16i8U8Imm:$val))]>;
1724
1725   def r8:
1726     XORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1727               [(set R8C:$rT, (xor R8C:$rA, immU8:$val))]>;
1728 }
1729
1730 defm XORBI : XorByteImm;
1731
1732 def XORHIv8i16:
1733     RI10Form<0b10100000, (outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1734       "xorhi\t$rT, $rA, $val", IntegerOp,
1735       [(set (v8i16 VECREG:$rT), (xor (v8i16 VECREG:$rA),
1736                                       v8i16SExt10Imm:$val))]>;
1737
1738 def XORHIr16:
1739     RI10Form<0b10100000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
1740       "xorhi\t$rT, $rA, $val", IntegerOp,
1741       [(set R16C:$rT, (xor R16C:$rA, i16ImmSExt10:$val))]>;
1742
1743 def XORIv4i32:
1744     RI10Form<0b00100000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm_i32:$val),
1745       "xori\t$rT, $rA, $val", IntegerOp,
1746       [(set (v4i32 VECREG:$rT), (xor (v4i32 VECREG:$rA),
1747                                      v4i32SExt10Imm:$val))]>;
1748
1749 def XORIr32:
1750     RI10Form<0b00100000, (outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1751       "xori\t$rT, $rA, $val", IntegerOp,
1752       [(set R32C:$rT, (xor R32C:$rA, i32ImmSExt10:$val))]>;
1753
1754 // NAND:
1755 def NANDv16i8:
1756     RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1757       "nand\t$rT, $rA, $rB", IntegerOp,
1758       [(set (v16i8 VECREG:$rT), (vnot (and (v16i8 VECREG:$rA),
1759                                            (v16i8 VECREG:$rB))))]>;
1760
1761 def NANDv8i16:
1762     RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1763       "nand\t$rT, $rA, $rB", IntegerOp,
1764       [(set (v8i16 VECREG:$rT), (vnot (and (v8i16 VECREG:$rA),
1765                                            (v8i16 VECREG:$rB))))]>;
1766
1767 def NANDv4i32:
1768     RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1769       "nand\t$rT, $rA, $rB", IntegerOp,
1770       [(set (v4i32 VECREG:$rT), (vnot (and (v4i32 VECREG:$rA),
1771                                            (v4i32 VECREG:$rB))))]>;
1772
1773 def NANDr32:
1774     RRForm<0b10010010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1775       "nand\t$rT, $rA, $rB", IntegerOp,
1776       [(set R32C:$rT, (not (and R32C:$rA, R32C:$rB)))]>;
1777
1778 def NANDr16:
1779     RRForm<0b10010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1780       "nand\t$rT, $rA, $rB", IntegerOp,
1781       [(set R16C:$rT, (not (and R16C:$rA, R16C:$rB)))]>;
1782
1783 def NANDr8:
1784     RRForm<0b10010010000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
1785       "nand\t$rT, $rA, $rB", IntegerOp,
1786       [(set R8C:$rT, (not (and R8C:$rA, R8C:$rB)))]>;
1787
1788 // NOR:
1789 def NORv16i8:
1790     RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1791       "nor\t$rT, $rA, $rB", IntegerOp,
1792       [(set (v16i8 VECREG:$rT), (vnot (or (v16i8 VECREG:$rA),
1793                                           (v16i8 VECREG:$rB))))]>;
1794
1795 def NORv8i16:
1796     RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1797       "nor\t$rT, $rA, $rB", IntegerOp,
1798       [(set (v8i16 VECREG:$rT), (vnot (or (v8i16 VECREG:$rA),
1799                                           (v8i16 VECREG:$rB))))]>;
1800
1801 def NORv4i32:
1802     RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1803       "nor\t$rT, $rA, $rB", IntegerOp,
1804       [(set (v4i32 VECREG:$rT), (vnot (or (v4i32 VECREG:$rA),
1805                                           (v4i32 VECREG:$rB))))]>;
1806
1807 def NORr32:
1808     RRForm<0b10010010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1809       "nor\t$rT, $rA, $rB", IntegerOp,
1810       [(set R32C:$rT, (not (or R32C:$rA, R32C:$rB)))]>;
1811
1812 def NORr16:
1813     RRForm<0b10010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1814       "nor\t$rT, $rA, $rB", IntegerOp,
1815       [(set R16C:$rT, (not (or R16C:$rA, R16C:$rB)))]>;
1816
1817 def NORr8:
1818     RRForm<0b10010010000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
1819       "nor\t$rT, $rA, $rB", IntegerOp,
1820       [(set R8C:$rT, (not (or R8C:$rA, R8C:$rB)))]>;
1821
1822 // Select bits:
1823 class SELBInst<dag OOL, dag IOL, list<dag> pattern>:
1824     RRRForm<0b1000, OOL, IOL, "selb\t$rT, $rA, $rB, $rC",
1825             IntegerOp, pattern>;
1826
1827 class SELBVecInst<ValueType vectype>:
1828   SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1829            [(set (vectype VECREG:$rT),
1830                  (or (and (vectype VECREG:$rC), (vectype VECREG:$rB)),
1831                      (and (vnot (vectype VECREG:$rC)),
1832                           (vectype VECREG:$rA))))]>;
1833
1834 class SELBVecCondInst<ValueType vectype>:
1835   SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, R32C:$rC),
1836            [(set (vectype VECREG:$rT),
1837                  (select R32C:$rC,
1838                          (vectype VECREG:$rB),
1839                          (vectype VECREG:$rA)))]>;
1840
1841 class SELBRegInst<RegisterClass rclass>:
1842   SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rclass:$rC),
1843            [(set rclass:$rT,
1844                  (or (and rclass:$rB, rclass:$rC),
1845                      (and rclass:$rA, (not rclass:$rC))))]>;
1846
1847 class SELBRegCondInst<RegisterClass rcond, RegisterClass rclass>:
1848   SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rcond:$rC),
1849            [(set rclass:$rT,
1850                  (select rcond:$rC, rclass:$rB, rclass:$rA))]>;
1851
1852 multiclass SelectBits
1853 {
1854   def v16i8: SELBVecInst<v16i8>;
1855   def v8i16: SELBVecInst<v8i16>;
1856   def v4i32: SELBVecInst<v4i32>;
1857   def v2i64: SELBVecInst<v2i64>;
1858
1859   def r128:  SELBRegInst<GPRC>;
1860   def r64:   SELBRegInst<R64C>;
1861   def r32:   SELBRegInst<R32C>;
1862   def r16:   SELBRegInst<R16C>;
1863   def r8:    SELBRegInst<R8C>;
1864
1865   def v16i8_cond: SELBVecCondInst<v16i8>;
1866   def v8i16_cond: SELBVecCondInst<v8i16>;
1867   def v4i32_cond: SELBVecCondInst<v4i32>;
1868   def v2i64_cond: SELBVecCondInst<v2i64>;
1869
1870   // SELBr64_cond is defined further down, look for i64 comparisons
1871   def r32_cond:   SELBRegCondInst<R32C, R32C>;
1872   def r16_cond:   SELBRegCondInst<R16C, R16C>;
1873   def r8_cond:    SELBRegCondInst<R8C,  R8C>;
1874 }
1875
1876 defm SELB : SelectBits;
1877
1878 class SPUselbPatVec<ValueType vectype, SPUInstr inst>:
1879    Pat<(SPUselb (vectype VECREG:$rA), (vectype VECREG:$rB), (vectype VECREG:$rC)),
1880        (inst VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
1881
1882 def : SPUselbPatVec<v16i8, SELBv16i8>;
1883 def : SPUselbPatVec<v8i16, SELBv8i16>;
1884 def : SPUselbPatVec<v4i32, SELBv4i32>;
1885 def : SPUselbPatVec<v2i64, SELBv2i64>;
1886
1887 class SPUselbPatReg<RegisterClass rclass, SPUInstr inst>:
1888    Pat<(SPUselb rclass:$rA, rclass:$rB, rclass:$rC),
1889        (inst rclass:$rA, rclass:$rB, rclass:$rC)>;
1890
1891 def : SPUselbPatReg<R8C,   SELBr8>;
1892 def : SPUselbPatReg<R16C,  SELBr16>;
1893 def : SPUselbPatReg<R32C,  SELBr32>;
1894 def : SPUselbPatReg<R64C,  SELBr64>;
1895
1896 // EQV: Equivalence (1 for each same bit, otherwise 0)
1897 //
1898 // Note: There are a lot of ways to match this bit operator and these patterns
1899 // attempt to be as exhaustive as possible.
1900
1901 class EQVInst<dag OOL, dag IOL, list<dag> pattern>:
1902     RRForm<0b10010010000, OOL, IOL, "eqv\t$rT, $rA, $rB",
1903            IntegerOp, pattern>;
1904
1905 class EQVVecInst<ValueType vectype>:
1906     EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1907             [(set (vectype VECREG:$rT),
1908                   (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
1909                       (and (vnot (vectype VECREG:$rA)),
1910                            (vnot (vectype VECREG:$rB)))))]>;
1911
1912 class EQVRegInst<RegisterClass rclass>:
1913     EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1914             [(set rclass:$rT, (or (and rclass:$rA, rclass:$rB),
1915                                   (and (not rclass:$rA), (not rclass:$rB))))]>;
1916
1917 class EQVVecPattern1<ValueType vectype>:
1918   EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1919           [(set (vectype VECREG:$rT),
1920                 (xor (vectype VECREG:$rA), (vnot (vectype VECREG:$rB))))]>;
1921
1922 class EQVRegPattern1<RegisterClass rclass>:
1923   EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1924           [(set rclass:$rT, (xor rclass:$rA, (not rclass:$rB)))]>;
1925
1926 class EQVVecPattern2<ValueType vectype>:
1927   EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1928           [(set (vectype VECREG:$rT),
1929                 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
1930                     (vnot (or (vectype VECREG:$rA), (vectype VECREG:$rB)))))]>;
1931
1932 class EQVRegPattern2<RegisterClass rclass>:
1933   EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1934           [(set rclass:$rT,
1935                 (or (and rclass:$rA, rclass:$rB),
1936                     (not (or rclass:$rA, rclass:$rB))))]>;
1937
1938 class EQVVecPattern3<ValueType vectype>:
1939   EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1940           [(set (vectype VECREG:$rT),
1941                 (not (xor (vectype VECREG:$rA), (vectype VECREG:$rB))))]>;
1942
1943 class EQVRegPattern3<RegisterClass rclass>:
1944   EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1945           [(set rclass:$rT, (not (xor rclass:$rA, rclass:$rB)))]>;
1946
1947 multiclass BitEquivalence
1948 {
1949   def v16i8: EQVVecInst<v16i8>;
1950   def v8i16: EQVVecInst<v8i16>;
1951   def v4i32: EQVVecInst<v4i32>;
1952   def v2i64: EQVVecInst<v2i64>;
1953
1954   def v16i8_1: EQVVecPattern1<v16i8>;
1955   def v8i16_1: EQVVecPattern1<v8i16>;
1956   def v4i32_1: EQVVecPattern1<v4i32>;
1957   def v2i64_1: EQVVecPattern1<v2i64>;
1958
1959   def v16i8_2: EQVVecPattern2<v16i8>;
1960   def v8i16_2: EQVVecPattern2<v8i16>;
1961   def v4i32_2: EQVVecPattern2<v4i32>;
1962   def v2i64_2: EQVVecPattern2<v2i64>;
1963
1964   def v16i8_3: EQVVecPattern3<v16i8>;
1965   def v8i16_3: EQVVecPattern3<v8i16>;
1966   def v4i32_3: EQVVecPattern3<v4i32>;
1967   def v2i64_3: EQVVecPattern3<v2i64>;
1968
1969   def r128:  EQVRegInst<GPRC>;
1970   def r64:   EQVRegInst<R64C>;
1971   def r32:   EQVRegInst<R32C>;
1972   def r16:   EQVRegInst<R16C>;
1973   def r8:    EQVRegInst<R8C>;
1974
1975   def r128_1: EQVRegPattern1<GPRC>;
1976   def r64_1:  EQVRegPattern1<R64C>;
1977   def r32_1:  EQVRegPattern1<R32C>;
1978   def r16_1:  EQVRegPattern1<R16C>;
1979   def r8_1:   EQVRegPattern1<R8C>;
1980
1981   def r128_2: EQVRegPattern2<GPRC>;
1982   def r64_2:  EQVRegPattern2<R64C>;
1983   def r32_2:  EQVRegPattern2<R32C>;
1984   def r16_2:  EQVRegPattern2<R16C>;
1985   def r8_2:   EQVRegPattern2<R8C>;
1986
1987   def r128_3: EQVRegPattern3<GPRC>;
1988   def r64_3:  EQVRegPattern3<R64C>;
1989   def r32_3:  EQVRegPattern3<R32C>;
1990   def r16_3:  EQVRegPattern3<R16C>;
1991   def r8_3:   EQVRegPattern3<R8C>;
1992 }
1993
1994 defm EQV: BitEquivalence;
1995
1996 //===----------------------------------------------------------------------===//
1997 // Vector shuffle...
1998 //===----------------------------------------------------------------------===//
1999 // SPUshuffle is generated in LowerVECTOR_SHUFFLE and gets replaced with SHUFB.
2000 // See the SPUshuffle SDNode operand above, which sets up the DAG pattern
2001 // matcher to emit something when the LowerVECTOR_SHUFFLE generates a node with
2002 // the SPUISD::SHUFB opcode.
2003 //===----------------------------------------------------------------------===//
2004
2005 class SHUFBInst<dag OOL, dag IOL, list<dag> pattern>:
2006     RRRForm<0b1000, OOL, IOL, "shufb\t$rT, $rA, $rB, $rC",
2007             IntegerOp, pattern>;
2008
2009 class SHUFBVecInst<ValueType resultvec, ValueType maskvec>:
2010     SHUFBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
2011               [(set (resultvec VECREG:$rT),
2012                     (SPUshuffle (resultvec VECREG:$rA),
2013                                 (resultvec VECREG:$rB),
2014                                 (maskvec VECREG:$rC)))]>;
2015
2016 class SHUFBGPRCInst:
2017     SHUFBInst<(outs VECREG:$rT), (ins GPRC:$rA, GPRC:$rB, VECREG:$rC),
2018               [/* no pattern */]>;
2019
2020 multiclass ShuffleBytes
2021 {
2022   def v16i8     : SHUFBVecInst<v16i8, v16i8>;
2023   def v16i8_m32 : SHUFBVecInst<v16i8, v4i32>;
2024   def v8i16     : SHUFBVecInst<v8i16, v16i8>;
2025   def v8i16_m32 : SHUFBVecInst<v8i16, v4i32>;
2026   def v4i32     : SHUFBVecInst<v4i32, v16i8>;
2027   def v4i32_m32 : SHUFBVecInst<v4i32, v4i32>;
2028   def v2i64     : SHUFBVecInst<v2i64, v16i8>;
2029   def v2i64_m32 : SHUFBVecInst<v2i64, v4i32>;
2030
2031   def v4f32     : SHUFBVecInst<v4f32, v16i8>;
2032   def v4f32_m32 : SHUFBVecInst<v4f32, v4i32>;
2033
2034   def v2f64     : SHUFBVecInst<v2f64, v16i8>;
2035   def v2f64_m32 : SHUFBVecInst<v2f64, v4i32>;
2036
2037   def gprc      : SHUFBGPRCInst;
2038 }
2039
2040 defm SHUFB : ShuffleBytes;
2041
2042 //===----------------------------------------------------------------------===//
2043 // Shift and rotate group:
2044 //===----------------------------------------------------------------------===//
2045
2046 class SHLHInst<dag OOL, dag IOL, list<dag> pattern>:
2047     RRForm<0b11111010000, OOL, IOL, "shlh\t$rT, $rA, $rB",
2048            RotateShift, pattern>;
2049
2050 class SHLHVecInst<ValueType vectype>:
2051     SHLHInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2052              [(set (vectype VECREG:$rT),
2053                    (SPUvec_shl (vectype VECREG:$rA), R16C:$rB))]>;
2054
2055 // $rB gets promoted to 32-bit register type when confronted with
2056 // this llvm assembly code:
2057 //
2058 // define i16 @shlh_i16_1(i16 %arg1, i16 %arg2) {
2059 //      %A = shl i16 %arg1, %arg2
2060 //      ret i16 %A
2061 // }
2062
2063 multiclass ShiftLeftHalfword
2064 {
2065   def v8i16: SHLHVecInst<v8i16>;
2066   def r16:   SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2067                       [(set R16C:$rT, (shl R16C:$rA, R16C:$rB))]>;
2068   def r16_r32: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2069                         [(set R16C:$rT, (shl R16C:$rA, R32C:$rB))]>;
2070 }
2071
2072 defm SHLH : ShiftLeftHalfword;
2073
2074 //===----------------------------------------------------------------------===//
2075
2076 class SHLHIInst<dag OOL, dag IOL, list<dag> pattern>:
2077     RI7Form<0b11111010000, OOL, IOL, "shlhi\t$rT, $rA, $val",
2078             RotateShift, pattern>;
2079
2080 class SHLHIVecInst<ValueType vectype>:
2081     SHLHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2082               [(set (vectype VECREG:$rT),
2083                     (SPUvec_shl (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
2084
2085 multiclass ShiftLeftHalfwordImm
2086 {
2087   def v8i16: SHLHIVecInst<v8i16>;
2088   def r16: SHLHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2089                      [(set R16C:$rT, (shl R16C:$rA, (i16 uimm7:$val)))]>;
2090 }
2091
2092 defm SHLHI : ShiftLeftHalfwordImm;
2093
2094 def : Pat<(SPUvec_shl (v8i16 VECREG:$rA), (i32 uimm7:$val)),
2095           (SHLHIv8i16 VECREG:$rA, uimm7:$val)>;
2096
2097 def : Pat<(shl R16C:$rA, (i32 uimm7:$val)),
2098           (SHLHIr16 R16C:$rA, uimm7:$val)>;
2099
2100 //===----------------------------------------------------------------------===//
2101
2102 class SHLInst<dag OOL, dag IOL, list<dag> pattern>:
2103     RRForm<0b11111010000, OOL, IOL, "shl\t$rT, $rA, $rB",
2104            RotateShift, pattern>;
2105
2106 multiclass ShiftLeftWord
2107 {
2108   def v4i32:
2109       SHLInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2110               [(set (v4i32 VECREG:$rT),
2111                     (SPUvec_shl (v4i32 VECREG:$rA), R16C:$rB))]>;
2112   def r32:
2113       SHLInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2114               [(set R32C:$rT, (shl R32C:$rA, R32C:$rB))]>;
2115 }
2116
2117 defm SHL: ShiftLeftWord;
2118
2119 //===----------------------------------------------------------------------===//
2120
2121 class SHLIInst<dag OOL, dag IOL, list<dag> pattern>:
2122     RI7Form<0b11111010000, OOL, IOL, "shli\t$rT, $rA, $val",
2123             RotateShift, pattern>;
2124
2125 multiclass ShiftLeftWordImm
2126 {
2127   def v4i32:
2128     SHLIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2129              [(set (v4i32 VECREG:$rT),
2130                    (SPUvec_shl (v4i32 VECREG:$rA), (i32 uimm7:$val)))]>;
2131
2132   def r32:
2133     SHLIInst<(outs R32C:$rT), (ins R32C:$rA, u7imm_i32:$val),
2134              [(set R32C:$rT, (shl R32C:$rA, (i32 uimm7:$val)))]>;
2135 }
2136
2137 defm SHLI : ShiftLeftWordImm;
2138
2139 //===----------------------------------------------------------------------===//
2140 // SHLQBI vec form: Note that this will shift the entire vector (the 128-bit
2141 // register) to the left. Vector form is here to ensure type correctness.
2142 //
2143 // The shift count is in the lowest 3 bits (29-31) of $rB, so only a bit shift
2144 // of 7 bits is actually possible.
2145 //
2146 // Note also that SHLQBI/SHLQBII are used in conjunction with SHLQBY/SHLQBYI
2147 // to shift i64 and i128. SHLQBI is the residual left over after shifting by
2148 // bytes with SHLQBY.
2149
2150 class SHLQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2151     RRForm<0b11011011100, OOL, IOL, "shlqbi\t$rT, $rA, $rB",
2152            RotateShift, pattern>;
2153
2154 class SHLQBIVecInst<ValueType vectype>:
2155     SHLQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2156                [(set (vectype VECREG:$rT),
2157                      (SPUshlquad_l_bits (vectype VECREG:$rA), R32C:$rB))]>;
2158
2159 multiclass ShiftLeftQuadByBits
2160 {
2161   def v16i8: SHLQBIVecInst<v16i8>;
2162   def v8i16: SHLQBIVecInst<v8i16>;
2163   def v4i32: SHLQBIVecInst<v4i32>;
2164   def v4f32: SHLQBIVecInst<v4f32>;
2165   def v2i64: SHLQBIVecInst<v2i64>;
2166   def v2f64: SHLQBIVecInst<v2f64>;
2167 }
2168
2169 defm SHLQBI : ShiftLeftQuadByBits;
2170
2171 // See note above on SHLQBI. In this case, the predicate actually does then
2172 // enforcement, whereas with SHLQBI, we have to "take it on faith."
2173 class SHLQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2174     RI7Form<0b11011111100, OOL, IOL, "shlqbii\t$rT, $rA, $val",
2175             RotateShift, pattern>;
2176
2177 class SHLQBIIVecInst<ValueType vectype>:
2178     SHLQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2179                 [(set (vectype VECREG:$rT),
2180                       (SPUshlquad_l_bits (vectype VECREG:$rA), (i32 bitshift:$val)))]>;
2181
2182 multiclass ShiftLeftQuadByBitsImm
2183 {
2184   def v16i8 : SHLQBIIVecInst<v16i8>;
2185   def v8i16 : SHLQBIIVecInst<v8i16>;
2186   def v4i32 : SHLQBIIVecInst<v4i32>;
2187   def v4f32 : SHLQBIIVecInst<v4f32>;
2188   def v2i64 : SHLQBIIVecInst<v2i64>;
2189   def v2f64 : SHLQBIIVecInst<v2f64>;
2190 }
2191
2192 defm SHLQBII : ShiftLeftQuadByBitsImm;
2193
2194 // SHLQBY, SHLQBYI vector forms: Shift the entire vector to the left by bytes,
2195 // not by bits. See notes above on SHLQBI.
2196
2197 class SHLQBYInst<dag OOL, dag IOL, list<dag> pattern>:
2198     RI7Form<0b11111011100, OOL, IOL, "shlqby\t$rT, $rA, $rB",
2199             RotateShift, pattern>;
2200
2201 class SHLQBYVecInst<ValueType vectype>:
2202     SHLQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2203                [(set (vectype VECREG:$rT),
2204                      (SPUshlquad_l_bytes (vectype VECREG:$rA), R32C:$rB))]>;
2205
2206 multiclass ShiftLeftQuadBytes
2207 {
2208   def v16i8: SHLQBYVecInst<v16i8>;
2209   def v8i16: SHLQBYVecInst<v8i16>;
2210   def v4i32: SHLQBYVecInst<v4i32>;
2211   def v4f32: SHLQBYVecInst<v4f32>;
2212   def v2i64: SHLQBYVecInst<v2i64>;
2213   def v2f64: SHLQBYVecInst<v2f64>;
2214   def r128: SHLQBYInst<(outs GPRC:$rT), (ins GPRC:$rA, R32C:$rB),
2215                        [(set GPRC:$rT, (SPUshlquad_l_bytes GPRC:$rA, R32C:$rB))]>;
2216 }
2217
2218 defm SHLQBY: ShiftLeftQuadBytes;
2219
2220 class SHLQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2221     RI7Form<0b11111111100, OOL, IOL, "shlqbyi\t$rT, $rA, $val",
2222             RotateShift, pattern>;
2223
2224 class SHLQBYIVecInst<ValueType vectype>:
2225     SHLQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2226                 [(set (vectype VECREG:$rT),
2227                       (SPUshlquad_l_bytes (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
2228
2229 multiclass ShiftLeftQuadBytesImm
2230 {
2231   def v16i8: SHLQBYIVecInst<v16i8>;
2232   def v8i16: SHLQBYIVecInst<v8i16>;
2233   def v4i32: SHLQBYIVecInst<v4i32>;
2234   def v4f32: SHLQBYIVecInst<v4f32>;
2235   def v2i64: SHLQBYIVecInst<v2i64>;
2236   def v2f64: SHLQBYIVecInst<v2f64>;
2237   def r128:  SHLQBYIInst<(outs GPRC:$rT), (ins GPRC:$rA, u7imm_i32:$val),
2238                          [(set GPRC:$rT,
2239                                (SPUshlquad_l_bytes GPRC:$rA, (i32 uimm7:$val)))]>;
2240 }
2241
2242 defm SHLQBYI : ShiftLeftQuadBytesImm;
2243
2244 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2245 // Rotate halfword:
2246 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2247 class ROTHInst<dag OOL, dag IOL, list<dag> pattern>:
2248     RRForm<0b00111010000, OOL, IOL, "roth\t$rT, $rA, $rB",
2249            RotateShift, pattern>;
2250
2251 class ROTHVecInst<ValueType vectype>:
2252     ROTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2253              [(set (vectype VECREG:$rT),
2254                    (SPUvec_rotl VECREG:$rA, VECREG:$rB))]>;
2255
2256 class ROTHRegInst<RegisterClass rclass>:
2257     ROTHInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2258              [(set rclass:$rT, (rotl rclass:$rA, rclass:$rB))]>;
2259
2260 multiclass RotateLeftHalfword
2261 {
2262   def v8i16: ROTHVecInst<v8i16>;
2263   def r16: ROTHRegInst<R16C>;
2264 }
2265
2266 defm ROTH: RotateLeftHalfword;
2267
2268 def ROTHr16_r32: ROTHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2269                           [(set R16C:$rT, (rotl R16C:$rA, R32C:$rB))]>;
2270
2271 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2272 // Rotate halfword, immediate:
2273 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2274 class ROTHIInst<dag OOL, dag IOL, list<dag> pattern>:
2275     RI7Form<0b00111110000, OOL, IOL, "rothi\t$rT, $rA, $val",
2276             RotateShift, pattern>;
2277
2278 class ROTHIVecInst<ValueType vectype>:
2279     ROTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2280               [(set (vectype VECREG:$rT),
2281                     (SPUvec_rotl VECREG:$rA, (i16 uimm7:$val)))]>;
2282
2283 multiclass RotateLeftHalfwordImm
2284 {
2285   def v8i16: ROTHIVecInst<v8i16>;
2286   def r16: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2287                      [(set R16C:$rT, (rotl R16C:$rA, (i16 uimm7:$val)))]>;
2288   def r16_r32: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm_i32:$val),
2289                          [(set R16C:$rT, (rotl R16C:$rA, (i32 uimm7:$val)))]>;
2290 }
2291
2292 defm ROTHI: RotateLeftHalfwordImm;
2293
2294 def : Pat<(SPUvec_rotl VECREG:$rA, (i32 uimm7:$val)),
2295           (ROTHIv8i16 VECREG:$rA, imm:$val)>;
2296
2297 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2298 // Rotate word:
2299 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2300
2301 class ROTInst<dag OOL, dag IOL, list<dag> pattern>:
2302     RRForm<0b00011010000, OOL, IOL, "rot\t$rT, $rA, $rB",
2303            RotateShift, pattern>;
2304
2305 class ROTVecInst<ValueType vectype>:
2306     ROTInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2307             [(set (vectype VECREG:$rT),
2308                   (SPUvec_rotl (vectype VECREG:$rA), R32C:$rB))]>;
2309
2310 class ROTRegInst<RegisterClass rclass>:
2311     ROTInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2312             [(set rclass:$rT,
2313                   (rotl rclass:$rA, R32C:$rB))]>;
2314
2315 multiclass RotateLeftWord
2316 {
2317   def v4i32: ROTVecInst<v4i32>;
2318   def r32:   ROTRegInst<R32C>;
2319 }
2320
2321 defm ROT: RotateLeftWord;
2322
2323 // The rotate amount is in the same bits whether we've got an 8-bit, 16-bit or
2324 // 32-bit register
2325 def ROTr32_r16_anyext:
2326     ROTInst<(outs R32C:$rT), (ins R32C:$rA, R16C:$rB),
2327             [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R16C:$rB))))]>;
2328
2329 def : Pat<(rotl R32C:$rA, (i32 (zext R16C:$rB))),
2330           (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2331
2332 def : Pat<(rotl R32C:$rA, (i32 (sext R16C:$rB))),
2333           (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2334
2335 def ROTr32_r8_anyext:
2336     ROTInst<(outs R32C:$rT), (ins R32C:$rA, R8C:$rB),
2337             [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R8C:$rB))))]>;
2338
2339 def : Pat<(rotl R32C:$rA, (i32 (zext R8C:$rB))),
2340           (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2341
2342 def : Pat<(rotl R32C:$rA, (i32 (sext R8C:$rB))),
2343           (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2344
2345 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2346 // Rotate word, immediate
2347 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2348
2349 class ROTIInst<dag OOL, dag IOL, list<dag> pattern>:
2350     RI7Form<0b00011110000, OOL, IOL, "roti\t$rT, $rA, $val",
2351             RotateShift, pattern>;
2352
2353 class ROTIVecInst<ValueType vectype, Operand optype, ValueType inttype, PatLeaf pred>:
2354     ROTIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2355              [(set (vectype VECREG:$rT),
2356                    (SPUvec_rotl (vectype VECREG:$rA), (inttype pred:$val)))]>;
2357
2358 class ROTIRegInst<RegisterClass rclass, Operand optype, ValueType inttype, PatLeaf pred>:
2359     ROTIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2360              [(set rclass:$rT, (rotl rclass:$rA, (inttype pred:$val)))]>;
2361
2362 multiclass RotateLeftWordImm
2363 {
2364   def v4i32: ROTIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2365   def v4i32_i16: ROTIVecInst<v4i32, u7imm, i16, uimm7>;
2366   def v4i32_i8:  ROTIVecInst<v4i32, u7imm_i8, i8, uimm7>;
2367
2368   def r32:       ROTIRegInst<R32C, u7imm_i32, i32, uimm7>;
2369   def r32_i16:   ROTIRegInst<R32C, u7imm, i16, uimm7>;
2370   def r32_i8:    ROTIRegInst<R32C, u7imm_i8, i8, uimm7>;
2371 }
2372
2373 defm ROTI : RotateLeftWordImm;
2374
2375 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2376 // Rotate quad by byte (count)
2377 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2378
2379 class ROTQBYInst<dag OOL, dag IOL, list<dag> pattern>:
2380     RRForm<0b00111011100, OOL, IOL, "rotqby\t$rT, $rA, $rB",
2381            RotateShift, pattern>;
2382
2383 class ROTQBYVecInst<ValueType vectype>:
2384     ROTQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2385                [(set (vectype VECREG:$rT),
2386                      (SPUrotbytes_left (vectype VECREG:$rA), R32C:$rB))]>;
2387
2388 multiclass RotateQuadLeftByBytes
2389 {
2390   def v16i8: ROTQBYVecInst<v16i8>;
2391   def v8i16: ROTQBYVecInst<v8i16>;
2392   def v4i32: ROTQBYVecInst<v4i32>;
2393   def v4f32: ROTQBYVecInst<v4f32>;
2394   def v2i64: ROTQBYVecInst<v2i64>;
2395   def v2f64: ROTQBYVecInst<v2f64>;
2396 }
2397
2398 defm ROTQBY: RotateQuadLeftByBytes;
2399
2400 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2401 // Rotate quad by byte (count), immediate
2402 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2403
2404 class ROTQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2405     RI7Form<0b00111111100, OOL, IOL, "rotqbyi\t$rT, $rA, $val",
2406             RotateShift, pattern>;
2407
2408 class ROTQBYIVecInst<ValueType vectype>:
2409     ROTQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2410                 [(set (vectype VECREG:$rT),
2411                       (SPUrotbytes_left (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
2412
2413 multiclass RotateQuadByBytesImm
2414 {
2415   def v16i8: ROTQBYIVecInst<v16i8>;
2416   def v8i16: ROTQBYIVecInst<v8i16>;
2417   def v4i32: ROTQBYIVecInst<v4i32>;
2418   def v4f32: ROTQBYIVecInst<v4f32>;
2419   def v2i64: ROTQBYIVecInst<v2i64>;
2420   def vfi64: ROTQBYIVecInst<v2f64>;
2421 }
2422
2423 defm ROTQBYI: RotateQuadByBytesImm;
2424
2425 // See ROTQBY note above.
2426 class ROTQBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2427     RI7Form<0b00110011100, OOL, IOL,
2428       "rotqbybi\t$rT, $rA, $shift",
2429       RotateShift, pattern>;
2430
2431 class ROTQBYBIVecInst<ValueType vectype, RegisterClass rclass>:
2432     ROTQBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, rclass:$shift),
2433       [(set (vectype VECREG:$rT),
2434             (SPUrotbytes_left_bits (vectype VECREG:$rA), rclass:$shift))]>;
2435
2436 multiclass RotateQuadByBytesByBitshift {
2437   def v16i8_r32: ROTQBYBIVecInst<v16i8, R32C>;
2438   def v8i16_r32: ROTQBYBIVecInst<v8i16, R32C>;
2439   def v4i32_r32: ROTQBYBIVecInst<v4i32, R32C>;
2440   def v2i64_r32: ROTQBYBIVecInst<v2i64, R32C>;
2441 }
2442
2443 defm ROTQBYBI : RotateQuadByBytesByBitshift;
2444
2445 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2446 // See ROTQBY note above.
2447 //
2448 // Assume that the user of this instruction knows to shift the rotate count
2449 // into bit 29
2450 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2451
2452 class ROTQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2453     RRForm<0b00011011100, OOL, IOL, "rotqbi\t$rT, $rA, $rB",
2454            RotateShift, pattern>;
2455
2456 class ROTQBIVecInst<ValueType vectype>:
2457     ROTQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2458                [/* no pattern yet */]>;
2459
2460 class ROTQBIRegInst<RegisterClass rclass>:
2461     ROTQBIInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2462                [/* no pattern yet */]>;
2463
2464 multiclass RotateQuadByBitCount
2465 {
2466   def v16i8: ROTQBIVecInst<v16i8>;
2467   def v8i16: ROTQBIVecInst<v8i16>;
2468   def v4i32: ROTQBIVecInst<v4i32>;
2469   def v2i64: ROTQBIVecInst<v2i64>;
2470
2471   def r128:  ROTQBIRegInst<GPRC>;
2472   def r64:   ROTQBIRegInst<R64C>;
2473 }
2474
2475 defm ROTQBI: RotateQuadByBitCount;
2476
2477 class ROTQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2478     RI7Form<0b00011111100, OOL, IOL, "rotqbii\t$rT, $rA, $val",
2479             RotateShift, pattern>;
2480
2481 class ROTQBIIVecInst<ValueType vectype, Operand optype, ValueType inttype,
2482                      PatLeaf pred>:
2483     ROTQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2484                 [/* no pattern yet */]>;
2485
2486 class ROTQBIIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2487                      PatLeaf pred>:
2488     ROTQBIIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2489                 [/* no pattern yet */]>;
2490
2491 multiclass RotateQuadByBitCountImm
2492 {
2493   def v16i8: ROTQBIIVecInst<v16i8, u7imm_i32, i32, uimm7>;
2494   def v8i16: ROTQBIIVecInst<v8i16, u7imm_i32, i32, uimm7>;
2495   def v4i32: ROTQBIIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2496   def v2i64: ROTQBIIVecInst<v2i64, u7imm_i32, i32, uimm7>;
2497
2498   def r128:  ROTQBIIRegInst<GPRC, u7imm_i32, i32, uimm7>;
2499   def r64:   ROTQBIIRegInst<R64C, u7imm_i32, i32, uimm7>;
2500 }
2501
2502 defm ROTQBII : RotateQuadByBitCountImm;
2503
2504 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2505 // ROTHM v8i16 form:
2506 // NOTE(1): No vector rotate is generated by the C/C++ frontend (today),
2507 //          so this only matches a synthetically generated/lowered code
2508 //          fragment.
2509 // NOTE(2): $rB must be negated before the right rotate!
2510 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2511
2512 class ROTHMInst<dag OOL, dag IOL, list<dag> pattern>:
2513     RRForm<0b10111010000, OOL, IOL, "rothm\t$rT, $rA, $rB",
2514            RotateShift, pattern>;
2515
2516 def ROTHMv8i16:
2517     ROTHMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2518               [/* see patterns below - $rB must be negated */]>;
2519
2520 def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R32C:$rB),
2521           (ROTHMv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2522
2523 def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R16C:$rB),
2524           (ROTHMv8i16 VECREG:$rA,
2525                       (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2526
2527 def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R8C:$rB),
2528           (ROTHMv8i16 VECREG:$rA,
2529                       (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
2530
2531 // ROTHM r16 form: Rotate 16-bit quantity to right, zero fill at the left
2532 // Note: This instruction doesn't match a pattern because rB must be negated
2533 // for the instruction to work. Thus, the pattern below the instruction!
2534
2535 def ROTHMr16:
2536     ROTHMInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2537               [/* see patterns below - $rB must be negated! */]>;
2538
2539 def : Pat<(srl R16C:$rA, R32C:$rB),
2540           (ROTHMr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2541
2542 def : Pat<(srl R16C:$rA, R16C:$rB),
2543           (ROTHMr16 R16C:$rA,
2544                     (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2545
2546 def : Pat<(srl R16C:$rA, R8C:$rB),
2547           (ROTHMr16 R16C:$rA,
2548                     (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
2549
2550 // ROTHMI v8i16 form: See the comment for ROTHM v8i16. The difference here is
2551 // that the immediate can be complemented, so that the user doesn't have to
2552 // worry about it.
2553
2554 class ROTHMIInst<dag OOL, dag IOL, list<dag> pattern>:
2555     RI7Form<0b10111110000, OOL, IOL, "rothmi\t$rT, $rA, $val",
2556             RotateShift, pattern>;
2557
2558 def ROTHMIv8i16:
2559     ROTHMIInst<(outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2560                [/* no pattern */]>;
2561
2562 def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i32 imm:$val)),
2563           (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
2564
2565 def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i16 imm:$val)),
2566          (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
2567
2568 def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i8 imm:$val)),
2569          (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
2570
2571 def ROTHMIr16:
2572     ROTHMIInst<(outs R16C:$rT), (ins R16C:$rA, rothNeg7imm:$val),
2573                [/* no pattern */]>;
2574
2575 def: Pat<(srl R16C:$rA, (i32 uimm7:$val)),
2576          (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2577
2578 def: Pat<(srl R16C:$rA, (i16 uimm7:$val)),
2579          (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2580
2581 def: Pat<(srl R16C:$rA, (i8 uimm7:$val)),
2582          (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2583
2584 // ROTM v4i32 form: See the ROTHM v8i16 comments.
2585 class ROTMInst<dag OOL, dag IOL, list<dag> pattern>:
2586     RRForm<0b10011010000, OOL, IOL, "rotm\t$rT, $rA, $rB",
2587            RotateShift, pattern>;
2588
2589 def ROTMv4i32:
2590     ROTMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2591              [/* see patterns below - $rB must be negated */]>;
2592
2593 def : Pat<(SPUvec_srl VECREG:$rA, R32C:$rB),
2594           (ROTMv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2595
2596 def : Pat<(SPUvec_srl VECREG:$rA, R16C:$rB),
2597           (ROTMv4i32 VECREG:$rA,
2598                      (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2599
2600 def : Pat<(SPUvec_srl VECREG:$rA, R8C:$rB),
2601           (ROTMv4i32 VECREG:$rA,
2602                      (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2603
2604 def ROTMr32:
2605     ROTMInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2606              [/* see patterns below - $rB must be negated */]>;
2607
2608 def : Pat<(srl R32C:$rA, R32C:$rB),
2609           (ROTMr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2610
2611 def : Pat<(srl R32C:$rA, R16C:$rB),
2612           (ROTMr32 R32C:$rA,
2613                    (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2614
2615 def : Pat<(srl R32C:$rA, R8C:$rB),
2616           (ROTMr32 R32C:$rA,
2617                    (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2618
2619 // ROTMI v4i32 form: See the comment for ROTHM v8i16.
2620 def ROTMIv4i32:
2621     RI7Form<0b10011110000, (outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2622       "rotmi\t$rT, $rA, $val", RotateShift,
2623       [(set (v4i32 VECREG:$rT),
2624             (SPUvec_srl VECREG:$rA, (i32 uimm7:$val)))]>;
2625
2626 def : Pat<(SPUvec_srl VECREG:$rA, (i16 uimm7:$val)),
2627           (ROTMIv4i32 VECREG:$rA, uimm7:$val)>;
2628
2629 def : Pat<(SPUvec_srl VECREG:$rA, (i8 uimm7:$val)),
2630           (ROTMIv4i32 VECREG:$rA, uimm7:$val)>;
2631
2632 // ROTMI r32 form: know how to complement the immediate value.
2633 def ROTMIr32:
2634     RI7Form<0b10011110000, (outs R32C:$rT), (ins R32C:$rA, rotNeg7imm:$val),
2635       "rotmi\t$rT, $rA, $val", RotateShift,
2636       [(set R32C:$rT, (srl R32C:$rA, (i32 uimm7:$val)))]>;
2637
2638 def : Pat<(srl R32C:$rA, (i16 imm:$val)),
2639           (ROTMIr32 R32C:$rA, uimm7:$val)>;
2640
2641 def : Pat<(srl R32C:$rA, (i8 imm:$val)),
2642           (ROTMIr32 R32C:$rA, uimm7:$val)>;
2643
2644 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2645 // ROTQMBYvec: This is a vector form merely so that when used in an
2646 // instruction pattern, type checking will succeed. This instruction assumes
2647 // that the user knew to negate $rB.
2648 //
2649 // Using the SPUrotquad_rz_bytes target-specific DAG node, the patterns
2650 // ensure that $rB is negated.
2651 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2652
2653 class ROTQMBYInst<dag OOL, dag IOL, list<dag> pattern>:
2654     RRForm<0b10111011100, OOL, IOL, "rotqmby\t$rT, $rA, $rB",
2655            RotateShift, pattern>;
2656
2657 class ROTQMBYVecInst<ValueType vectype>:
2658     ROTQMBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2659                 [/* no pattern, $rB must be negated */]>;
2660
2661 class ROTQMBYRegInst<RegisterClass rclass>:
2662     ROTQMBYInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2663                 [(set rclass:$rT,
2664                       (SPUrotquad_rz_bytes rclass:$rA, R32C:$rB))]>;
2665
2666 multiclass RotateQuadBytes
2667 {
2668   def v16i8: ROTQMBYVecInst<v16i8>;
2669   def v8i16: ROTQMBYVecInst<v8i16>;
2670   def v4i32: ROTQMBYVecInst<v4i32>;
2671   def v2i64: ROTQMBYVecInst<v2i64>;
2672
2673   def r128: ROTQMBYRegInst<GPRC>;
2674   def r64:  ROTQMBYRegInst<R64C>;
2675 }
2676
2677 defm ROTQMBY : RotateQuadBytes;
2678
2679 def : Pat<(SPUrotquad_rz_bytes (v16i8 VECREG:$rA), R32C:$rB),
2680           (ROTQMBYv16i8 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2681 def : Pat<(SPUrotquad_rz_bytes (v8i16 VECREG:$rA), R32C:$rB),
2682           (ROTQMBYv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2683 def : Pat<(SPUrotquad_rz_bytes (v4i32 VECREG:$rA), R32C:$rB),
2684           (ROTQMBYv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2685 def : Pat<(SPUrotquad_rz_bytes (v2i64 VECREG:$rA), R32C:$rB),
2686           (ROTQMBYv2i64 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2687 def : Pat<(SPUrotquad_rz_bytes GPRC:$rA, R32C:$rB),
2688           (ROTQMBYr128 GPRC:$rA, (SFIr32 R32C:$rB, 0))>;
2689 def : Pat<(SPUrotquad_rz_bytes R64C:$rA, R32C:$rB),
2690           (ROTQMBYr64 R64C:$rA, (SFIr32 R32C:$rB, 0))>;
2691
2692 class ROTQMBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2693     RI7Form<0b10111111100, OOL, IOL, "rotqmbyi\t$rT, $rA, $val",
2694             RotateShift, pattern>;
2695
2696 class ROTQMBYIVecInst<ValueType vectype>:
2697     ROTQMBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2698                  [(set (vectype VECREG:$rT),
2699                        (SPUrotquad_rz_bytes (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
2700
2701 class ROTQMBYIRegInst<RegisterClass rclass, Operand optype, ValueType inttype, PatLeaf pred>:
2702     ROTQMBYIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2703                  [(set rclass:$rT,
2704                        (SPUrotquad_rz_bytes rclass:$rA, (inttype pred:$val)))]>;
2705
2706 multiclass RotateQuadBytesImm
2707 {
2708   def v16i8: ROTQMBYIVecInst<v16i8>;
2709   def v8i16: ROTQMBYIVecInst<v8i16>;
2710   def v4i32: ROTQMBYIVecInst<v4i32>;
2711   def v2i64: ROTQMBYIVecInst<v2i64>;
2712
2713   def r128:  ROTQMBYIRegInst<GPRC, rotNeg7imm, i32, uimm7>;
2714   def r64:   ROTQMBYIRegInst<R64C, rotNeg7imm, i32, uimm7>;
2715 }
2716
2717 defm ROTQMBYI : RotateQuadBytesImm;
2718
2719 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2720 // Rotate right and mask by bit count
2721 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2722
2723 class ROTQMBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2724     RRForm<0b10110011100, OOL, IOL, "rotqmbybi\t$rT, $rA, $rB",
2725            RotateShift, pattern>;
2726
2727 class ROTQMBYBIVecInst<ValueType vectype>:
2728     ROTQMBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2729                   [/* no pattern, intrinsic? */]>;
2730
2731 multiclass RotateMaskQuadByBitCount
2732 {
2733   def v16i8: ROTQMBYBIVecInst<v16i8>;
2734   def v8i16: ROTQMBYBIVecInst<v8i16>;
2735   def v4i32: ROTQMBYBIVecInst<v4i32>;
2736   def v2i64: ROTQMBYBIVecInst<v2i64>;
2737 }
2738
2739 defm ROTQMBYBI: RotateMaskQuadByBitCount;
2740
2741 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2742 // Rotate quad and mask by bits
2743 // Note that the rotate amount has to be negated
2744 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2745
2746 class ROTQMBIInst<dag OOL, dag IOL, list<dag> pattern>:
2747     RRForm<0b10011011100, OOL, IOL, "rotqmbi\t$rT, $rA, $rB",
2748            RotateShift, pattern>;
2749
2750 class ROTQMBIVecInst<ValueType vectype>:
2751     ROTQMBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2752                 [/* no pattern */]>;
2753
2754 class ROTQMBIRegInst<RegisterClass rclass>:
2755     ROTQMBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2756                 [/* no pattern */]>;
2757
2758 multiclass RotateMaskQuadByBits
2759 {
2760   def v16i8: ROTQMBIVecInst<v16i8>;
2761   def v8i16: ROTQMBIVecInst<v8i16>;
2762   def v4i32: ROTQMBIVecInst<v4i32>;
2763   def v2i64: ROTQMBIVecInst<v2i64>;
2764
2765   def r128:  ROTQMBIRegInst<GPRC>;
2766   def r64:   ROTQMBIRegInst<R64C>;
2767 }
2768
2769 defm ROTQMBI: RotateMaskQuadByBits;
2770
2771 def : Pat<(SPUrotquad_rz_bits (v16i8 VECREG:$rA), R32C:$rB),
2772           (ROTQMBIv16i8 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2773 def : Pat<(SPUrotquad_rz_bits (v8i16 VECREG:$rA), R32C:$rB),
2774           (ROTQMBIv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2775 def : Pat<(SPUrotquad_rz_bits (v4i32 VECREG:$rA), R32C:$rB),
2776           (ROTQMBIv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2777 def : Pat<(SPUrotquad_rz_bits (v2i64 VECREG:$rA), R32C:$rB),
2778           (ROTQMBIv2i64 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2779 def : Pat<(SPUrotquad_rz_bits GPRC:$rA, R32C:$rB),
2780           (ROTQMBIr128 GPRC:$rA, (SFIr32 R32C:$rB, 0))>;
2781 def : Pat<(SPUrotquad_rz_bits R64C:$rA, R32C:$rB),
2782           (ROTQMBIr64 R64C:$rA, (SFIr32 R32C:$rB, 0))>;
2783
2784 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2785 // Rotate quad and mask by bits, immediate
2786 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2787
2788 class ROTQMBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2789     RI7Form<0b10011111100, OOL, IOL, "rotqmbii\t$rT, $rA, $val",
2790             RotateShift, pattern>;
2791
2792 class ROTQMBIIVecInst<ValueType vectype>:
2793    ROTQMBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2794                  [(set (vectype VECREG:$rT),
2795                        (SPUrotquad_rz_bits (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
2796
2797 class ROTQMBIIRegInst<RegisterClass rclass>:
2798    ROTQMBIIInst<(outs rclass:$rT), (ins rclass:$rA, rotNeg7imm:$val),
2799                  [(set rclass:$rT,
2800                        (SPUrotquad_rz_bits rclass:$rA, (i32 uimm7:$val)))]>;
2801
2802 multiclass RotateMaskQuadByBitsImm
2803 {
2804   def v16i8: ROTQMBIIVecInst<v16i8>;
2805   def v8i16: ROTQMBIIVecInst<v8i16>;
2806   def v4i32: ROTQMBIIVecInst<v4i32>;
2807   def v2i64: ROTQMBIIVecInst<v2i64>;
2808
2809   def r128:  ROTQMBIIRegInst<GPRC>;
2810   def r64:   ROTQMBIIRegInst<R64C>;
2811 }
2812
2813 defm ROTQMBII: RotateMaskQuadByBitsImm;
2814
2815 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2816 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2817
2818 def ROTMAHv8i16:
2819     RRForm<0b01111010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2820       "rotmah\t$rT, $rA, $rB", RotateShift,
2821       [/* see patterns below - $rB must be negated */]>;
2822
2823 def : Pat<(SPUvec_sra VECREG:$rA, R32C:$rB),
2824           (ROTMAHv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2825
2826 def : Pat<(SPUvec_sra VECREG:$rA, R16C:$rB),
2827           (ROTMAHv8i16 VECREG:$rA,
2828                        (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2829
2830 def : Pat<(SPUvec_sra VECREG:$rA, R8C:$rB),
2831           (ROTMAHv8i16 VECREG:$rA,
2832                        (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2833
2834 def ROTMAHr16:
2835     RRForm<0b01111010000, (outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2836       "rotmah\t$rT, $rA, $rB", RotateShift,
2837       [/* see patterns below - $rB must be negated */]>;
2838
2839 def : Pat<(sra R16C:$rA, R32C:$rB),
2840           (ROTMAHr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2841
2842 def : Pat<(sra R16C:$rA, R16C:$rB),
2843           (ROTMAHr16 R16C:$rA,
2844                      (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2845
2846 def : Pat<(sra R16C:$rA, R8C:$rB),
2847           (ROTMAHr16 R16C:$rA,
2848                      (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2849
2850 def ROTMAHIv8i16:
2851     RRForm<0b01111110000, (outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2852       "rotmahi\t$rT, $rA, $val", RotateShift,
2853       [(set (v8i16 VECREG:$rT),
2854             (SPUvec_sra (v8i16 VECREG:$rA), (i32 uimm7:$val)))]>;
2855
2856 def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i16 uimm7:$val)),
2857           (ROTMAHIv8i16 (v8i16 VECREG:$rA), (i32 uimm7:$val))>;
2858
2859 def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i8 uimm7:$val)),
2860           (ROTMAHIv8i16 (v8i16 VECREG:$rA), (i32 uimm7:$val))>;
2861
2862 def ROTMAHIr16:
2863     RRForm<0b01111110000, (outs R16C:$rT), (ins R16C:$rA, rothNeg7imm_i16:$val),
2864       "rotmahi\t$rT, $rA, $val", RotateShift,
2865       [(set R16C:$rT, (sra R16C:$rA, (i16 uimm7:$val)))]>;
2866
2867 def : Pat<(sra R16C:$rA, (i32 imm:$val)),
2868           (ROTMAHIr16 R16C:$rA, uimm7:$val)>;
2869
2870 def : Pat<(sra R16C:$rA, (i8 imm:$val)),
2871           (ROTMAHIr16 R16C:$rA, uimm7:$val)>;
2872
2873 def ROTMAv4i32:
2874     RRForm<0b01011010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2875       "rotma\t$rT, $rA, $rB", RotateShift,
2876       [/* see patterns below - $rB must be negated */]>;
2877
2878 def : Pat<(SPUvec_sra VECREG:$rA, R32C:$rB),
2879           (ROTMAv4i32 (v4i32 VECREG:$rA), (SFIr32 R32C:$rB, 0))>;
2880
2881 def : Pat<(SPUvec_sra VECREG:$rA, R16C:$rB),
2882           (ROTMAv4i32 (v4i32 VECREG:$rA),
2883                       (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2884
2885 def : Pat<(SPUvec_sra VECREG:$rA, R8C:$rB),
2886           (ROTMAv4i32 (v4i32 VECREG:$rA),
2887                       (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2888
2889 def ROTMAr32:
2890     RRForm<0b01011010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2891       "rotma\t$rT, $rA, $rB", RotateShift,
2892       [/* see patterns below - $rB must be negated */]>;
2893
2894 def : Pat<(sra R32C:$rA, R32C:$rB),
2895           (ROTMAr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2896
2897 def : Pat<(sra R32C:$rA, R16C:$rB),
2898           (ROTMAr32 R32C:$rA,
2899                     (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2900
2901 def : Pat<(sra R32C:$rA, R8C:$rB),
2902           (ROTMAr32 R32C:$rA,
2903                     (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2904
2905 class ROTMAIInst<dag OOL, dag IOL, list<dag> pattern>:
2906     RRForm<0b01011110000, OOL, IOL,
2907       "rotmai\t$rT, $rA, $val",
2908       RotateShift, pattern>;
2909
2910 class ROTMAIVecInst<ValueType vectype, Operand intop, ValueType inttype>:
2911     ROTMAIInst<(outs VECREG:$rT), (ins VECREG:$rA, intop:$val),
2912       [(set (vectype VECREG:$rT),
2913             (SPUvec_sra VECREG:$rA, (inttype uimm7:$val)))]>;
2914
2915 class ROTMAIRegInst<RegisterClass rclass, Operand intop, ValueType inttype>:
2916     ROTMAIInst<(outs rclass:$rT), (ins rclass:$rA, intop:$val),
2917       [(set rclass:$rT, (sra rclass:$rA, (inttype uimm7:$val)))]>;
2918
2919 multiclass RotateMaskAlgebraicImm {
2920   def v2i64_i32 : ROTMAIVecInst<v2i64, rotNeg7imm, i32>;
2921   def v4i32_i32 : ROTMAIVecInst<v4i32, rotNeg7imm, i32>;
2922   def r64_i32 : ROTMAIRegInst<R64C, rotNeg7imm, i32>;
2923   def r32_i32 : ROTMAIRegInst<R32C, rotNeg7imm, i32>;
2924 }
2925
2926 defm ROTMAI : RotateMaskAlgebraicImm;
2927
2928 //===----------------------------------------------------------------------===//
2929 // Branch and conditionals:
2930 //===----------------------------------------------------------------------===//
2931
2932 let isTerminator = 1, isBarrier = 1 in {
2933   // Halt If Equal (r32 preferred slot only, no vector form)
2934   def HEQr32:
2935     RRForm_3<0b00011011110, (outs), (ins R32C:$rA, R32C:$rB),
2936       "heq\t$rA, $rB", BranchResolv,
2937       [/* no pattern to match */]>;
2938
2939   def HEQIr32 :
2940     RI10Form_2<0b11111110, (outs), (ins R32C:$rA, s10imm:$val),
2941       "heqi\t$rA, $val", BranchResolv,
2942       [/* no pattern to match */]>;
2943
2944   // HGT/HGTI: These instructions use signed arithmetic for the comparison,
2945   // contrasting with HLGT/HLGTI, which use unsigned comparison:
2946   def HGTr32:
2947     RRForm_3<0b00011010010, (outs), (ins R32C:$rA, R32C:$rB),
2948       "hgt\t$rA, $rB", BranchResolv,
2949       [/* no pattern to match */]>;
2950
2951   def HGTIr32:
2952     RI10Form_2<0b11110010, (outs), (ins R32C:$rA, s10imm:$val),
2953       "hgti\t$rA, $val", BranchResolv,
2954       [/* no pattern to match */]>;
2955
2956   def HLGTr32:
2957     RRForm_3<0b00011011010, (outs), (ins R32C:$rA, R32C:$rB),
2958       "hlgt\t$rA, $rB", BranchResolv,
2959       [/* no pattern to match */]>;
2960
2961   def HLGTIr32:
2962     RI10Form_2<0b11111010, (outs), (ins R32C:$rA, s10imm:$val),
2963       "hlgti\t$rA, $val", BranchResolv,
2964       [/* no pattern to match */]>;
2965 }
2966
2967 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2968 // Comparison operators for i8, i16 and i32:
2969 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2970
2971 class CEQBInst<dag OOL, dag IOL, list<dag> pattern> :
2972   RRForm<0b00001011110, OOL, IOL, "ceqb\t$rT, $rA, $rB",
2973          ByteOp, pattern>;
2974
2975 multiclass CmpEqualByte
2976 {
2977   def v16i8 :
2978     CEQBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2979       [(set (v16i8 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
2980                                        (v8i16 VECREG:$rB)))]>;
2981
2982   def r8 :
2983     CEQBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
2984              [(set R8C:$rT, (seteq R8C:$rA, R8C:$rB))]>;
2985 }
2986
2987 class CEQBIInst<dag OOL, dag IOL, list<dag> pattern> :
2988   RI10Form<0b01111110, OOL, IOL, "ceqbi\t$rT, $rA, $val",
2989            ByteOp, pattern>;
2990
2991 multiclass CmpEqualByteImm
2992 {
2993   def v16i8 :
2994     CEQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
2995               [(set (v16i8 VECREG:$rT), (seteq (v16i8 VECREG:$rA),
2996                                                v16i8SExt8Imm:$val))]>;
2997   def r8:
2998     CEQBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
2999              [(set R8C:$rT, (seteq R8C:$rA, immSExt8:$val))]>;
3000 }
3001
3002 class CEQHInst<dag OOL, dag IOL, list<dag> pattern> :
3003   RRForm<0b00010011110, OOL, IOL, "ceqh\t$rT, $rA, $rB",
3004          ByteOp, pattern>;
3005
3006 multiclass CmpEqualHalfword
3007 {
3008   def v8i16 : CEQHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3009                        [(set (v8i16 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
3010                                                         (v8i16 VECREG:$rB)))]>;
3011
3012   def r16 : CEQHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3013                      [(set R16C:$rT, (seteq R16C:$rA, R16C:$rB))]>;
3014 }
3015
3016 class CEQHIInst<dag OOL, dag IOL, list<dag> pattern> :
3017   RI10Form<0b10111110, OOL, IOL, "ceqhi\t$rT, $rA, $val",
3018            ByteOp, pattern>;
3019
3020 multiclass CmpEqualHalfwordImm
3021 {
3022   def v8i16 : CEQHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3023                         [(set (v8i16 VECREG:$rT),
3024                               (seteq (v8i16 VECREG:$rA),
3025                                      (v8i16 v8i16SExt10Imm:$val)))]>;
3026   def r16 : CEQHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3027                       [(set R16C:$rT, (seteq R16C:$rA, i16ImmSExt10:$val))]>;
3028 }
3029
3030 class CEQInst<dag OOL, dag IOL, list<dag> pattern> :
3031   RRForm<0b00000011110, OOL, IOL, "ceq\t$rT, $rA, $rB",
3032          ByteOp, pattern>;
3033
3034 multiclass CmpEqualWord
3035 {
3036   def v4i32 : CEQInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3037                       [(set (v4i32 VECREG:$rT),
3038                             (seteq (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3039
3040   def r32 : CEQInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3041                     [(set R32C:$rT, (seteq R32C:$rA, R32C:$rB))]>;
3042 }
3043
3044 class CEQIInst<dag OOL, dag IOL, list<dag> pattern> :
3045   RI10Form<0b00111110, OOL, IOL, "ceqi\t$rT, $rA, $val",
3046            ByteOp, pattern>;
3047
3048 multiclass CmpEqualWordImm
3049 {
3050   def v4i32 : CEQIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3051                        [(set (v4i32 VECREG:$rT),
3052                              (seteq (v4i32 VECREG:$rA),
3053                                     (v4i32 v4i32SExt16Imm:$val)))]>;
3054
3055   def r32: CEQIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3056                     [(set R32C:$rT, (seteq R32C:$rA, i32ImmSExt10:$val))]>;
3057 }
3058
3059 class CGTBInst<dag OOL, dag IOL, list<dag> pattern> :
3060   RRForm<0b00001010010, OOL, IOL, "cgtb\t$rT, $rA, $rB",
3061          ByteOp, pattern>;
3062
3063 multiclass CmpGtrByte
3064 {
3065   def v16i8 :
3066     CGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3067       [(set (v16i8 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3068                                        (v8i16 VECREG:$rB)))]>;
3069
3070   def r8 :
3071     CGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3072              [(set R8C:$rT, (setgt R8C:$rA, R8C:$rB))]>;
3073 }
3074
3075 class CGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
3076   RI10Form<0b01110010, OOL, IOL, "cgtbi\t$rT, $rA, $val",
3077            ByteOp, pattern>;
3078
3079 multiclass CmpGtrByteImm
3080 {
3081   def v16i8 :
3082     CGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3083               [(set (v16i8 VECREG:$rT), (setgt (v16i8 VECREG:$rA),
3084                                                v16i8SExt8Imm:$val))]>;
3085   def r8:
3086     CGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3087               [(set R8C:$rT, (setgt R8C:$rA, immSExt8:$val))]>;
3088 }
3089
3090 class CGTHInst<dag OOL, dag IOL, list<dag> pattern> :
3091   RRForm<0b00010010010, OOL, IOL, "cgth\t$rT, $rA, $rB",
3092          ByteOp, pattern>;
3093
3094 multiclass CmpGtrHalfword
3095 {
3096   def v8i16 : CGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3097                        [(set (v8i16 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3098                                                         (v8i16 VECREG:$rB)))]>;
3099
3100   def r16 : CGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3101                      [(set R16C:$rT, (setgt R16C:$rA, R16C:$rB))]>;
3102 }
3103
3104 class CGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
3105   RI10Form<0b10110010, OOL, IOL, "cgthi\t$rT, $rA, $val",
3106            ByteOp, pattern>;
3107
3108 multiclass CmpGtrHalfwordImm
3109 {
3110   def v8i16 : CGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3111                         [(set (v8i16 VECREG:$rT),
3112                               (setgt (v8i16 VECREG:$rA),
3113                                      (v8i16 v8i16SExt10Imm:$val)))]>;
3114   def r16 : CGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3115                       [(set R16C:$rT, (setgt R16C:$rA, i16ImmSExt10:$val))]>;
3116 }
3117
3118 class CGTInst<dag OOL, dag IOL, list<dag> pattern> :
3119   RRForm<0b00000010010, OOL, IOL, "cgt\t$rT, $rA, $rB",
3120          ByteOp, pattern>;
3121
3122 multiclass CmpGtrWord
3123 {
3124   def v4i32 : CGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3125                       [(set (v4i32 VECREG:$rT),
3126                             (setgt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3127
3128   def r32 : CGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3129                     [(set R32C:$rT, (setgt R32C:$rA, R32C:$rB))]>;
3130 }
3131
3132 class CGTIInst<dag OOL, dag IOL, list<dag> pattern> :
3133   RI10Form<0b00110010, OOL, IOL, "cgti\t$rT, $rA, $val",
3134            ByteOp, pattern>;
3135
3136 multiclass CmpGtrWordImm
3137 {
3138   def v4i32 : CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3139                        [(set (v4i32 VECREG:$rT),
3140                              (setgt (v4i32 VECREG:$rA),
3141                                     (v4i32 v4i32SExt16Imm:$val)))]>;
3142
3143   def r32: CGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3144                     [(set R32C:$rT, (setgt R32C:$rA, i32ImmSExt10:$val))]>;
3145 }
3146
3147 class CLGTBInst<dag OOL, dag IOL, list<dag> pattern> :
3148   RRForm<0b00001011010, OOL, IOL, "clgtb\t$rT, $rA, $rB",
3149          ByteOp, pattern>;
3150
3151 multiclass CmpLGtrByte
3152 {
3153   def v16i8 :
3154     CLGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3155       [(set (v16i8 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3156                                        (v8i16 VECREG:$rB)))]>;
3157
3158   def r8 :
3159     CLGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3160              [(set R8C:$rT, (setugt R8C:$rA, R8C:$rB))]>;
3161 }
3162
3163 class CLGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
3164   RI10Form<0b01111010, OOL, IOL, "clgtbi\t$rT, $rA, $val",
3165            ByteOp, pattern>;
3166
3167 multiclass CmpLGtrByteImm
3168 {
3169   def v16i8 :
3170     CLGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3171               [(set (v16i8 VECREG:$rT), (setugt (v16i8 VECREG:$rA),
3172                                                v16i8SExt8Imm:$val))]>;
3173   def r8:
3174     CLGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3175              [(set R8C:$rT, (setugt R8C:$rA, immSExt8:$val))]>;
3176 }
3177
3178 class CLGTHInst<dag OOL, dag IOL, list<dag> pattern> :
3179   RRForm<0b00010011010, OOL, IOL, "clgth\t$rT, $rA, $rB",
3180          ByteOp, pattern>;
3181
3182 multiclass CmpLGtrHalfword
3183 {
3184   def v8i16 : CLGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3185                        [(set (v8i16 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3186                                                         (v8i16 VECREG:$rB)))]>;
3187
3188   def r16 : CLGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3189                      [(set R16C:$rT, (setugt R16C:$rA, R16C:$rB))]>;
3190 }
3191
3192 class CLGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
3193   RI10Form<0b10111010, OOL, IOL, "clgthi\t$rT, $rA, $val",
3194            ByteOp, pattern>;
3195
3196 multiclass CmpLGtrHalfwordImm
3197 {
3198   def v8i16 : CLGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3199                          [(set (v8i16 VECREG:$rT),
3200                                (setugt (v8i16 VECREG:$rA),
3201                                        (v8i16 v8i16SExt10Imm:$val)))]>;
3202   def r16 : CLGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3203                        [(set R16C:$rT, (setugt R16C:$rA, i16ImmSExt10:$val))]>;
3204 }
3205
3206 class CLGTInst<dag OOL, dag IOL, list<dag> pattern> :
3207   RRForm<0b00000011010, OOL, IOL, "clgt\t$rT, $rA, $rB",
3208          ByteOp, pattern>;
3209
3210 multiclass CmpLGtrWord
3211 {
3212   def v4i32 : CLGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3213                       [(set (v4i32 VECREG:$rT),
3214                             (setugt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3215
3216   def r32 : CLGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3217                      [(set R32C:$rT, (setugt R32C:$rA, R32C:$rB))]>;
3218 }
3219
3220 class CLGTIInst<dag OOL, dag IOL, list<dag> pattern> :
3221   RI10Form<0b00111010, OOL, IOL, "clgti\t$rT, $rA, $val",
3222            ByteOp, pattern>;
3223
3224 multiclass CmpLGtrWordImm
3225 {
3226   def v4i32 : CLGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3227                        [(set (v4i32 VECREG:$rT),
3228                              (setugt (v4i32 VECREG:$rA),
3229                                     (v4i32 v4i32SExt16Imm:$val)))]>;
3230
3231   def r32: CLGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3232                      [(set R32C:$rT, (setugt R32C:$rA, i32ImmSExt10:$val))]>;
3233 }
3234
3235 defm CEQB   : CmpEqualByte;
3236 defm CEQBI  : CmpEqualByteImm;
3237 defm CEQH   : CmpEqualHalfword;
3238 defm CEQHI  : CmpEqualHalfwordImm;
3239 defm CEQ    : CmpEqualWord;
3240 defm CEQI   : CmpEqualWordImm;
3241 defm CGTB   : CmpGtrByte;
3242 defm CGTBI  : CmpGtrByteImm;
3243 defm CGTH   : CmpGtrHalfword;
3244 defm CGTHI  : CmpGtrHalfwordImm;
3245 defm CGT    : CmpGtrWord;
3246 defm CGTI   : CmpGtrWordImm;
3247 defm CLGTB  : CmpLGtrByte;
3248 defm CLGTBI : CmpLGtrByteImm;
3249 defm CLGTH  : CmpLGtrHalfword;
3250 defm CLGTHI : CmpLGtrHalfwordImm;
3251 defm CLGT   : CmpLGtrWord;
3252 defm CLGTI  : CmpLGtrWordImm;
3253
3254 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3255 // For SETCC primitives not supported above (setlt, setle, setge, etc.)
3256 // define a pattern to generate the right code, as a binary operator
3257 // (in a manner of speaking.)
3258 //
3259 // Notes:
3260 // 1. This only matches the setcc set of conditionals. Special pattern
3261 //    matching is used for select conditionals.
3262 //
3263 // 2. The "DAG" versions of these classes is almost exclusively used for
3264 //    i64 comparisons. See the tblgen fundamentals documentation for what
3265 //    ".ResultInstrs[0]" means; see TargetSelectionDAG.td and the Pattern
3266 //    class for where ResultInstrs originates.
3267 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3268
3269 class SETCCNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3270                       SPUInstr xorinst, SPUInstr cmpare>:
3271   Pat<(cond rclass:$rA, rclass:$rB),
3272       (xorinst (cmpare rclass:$rA, rclass:$rB), (inttype -1))>;
3273
3274 class SETCCNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3275                       PatLeaf immpred, SPUInstr xorinst, SPUInstr cmpare>:
3276   Pat<(cond rclass:$rA, (inttype immpred:$imm)),
3277       (xorinst (cmpare rclass:$rA, (inttype immpred:$imm)), (inttype -1))>;
3278
3279 def : SETCCNegCondReg<setne, R8C, i8, XORBIr8,  CEQBr8>;
3280 def : SETCCNegCondImm<setne, R8C, i8, immSExt8, XORBIr8, CEQBIr8>;
3281
3282 def : SETCCNegCondReg<setne, R16C, i16, XORHIr16,     CEQHr16>;
3283 def : SETCCNegCondImm<setne, R16C, i16, i16ImmSExt10, XORHIr16, CEQHIr16>;
3284
3285 def : SETCCNegCondReg<setne, R32C, i32, XORIr32, CEQr32>;
3286 def : SETCCNegCondImm<setne, R32C, i32, i32ImmSExt10, XORIr32, CEQIr32>;
3287
3288 class SETCCBinOpReg<PatFrag cond, RegisterClass rclass,
3289                     SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3290     Pat<(cond rclass:$rA, rclass:$rB),
3291         (binop (cmpOp1 rclass:$rA, rclass:$rB),
3292                (cmpOp2 rclass:$rA, rclass:$rB))>;
3293
3294 class SETCCBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3295                     ValueType immtype,
3296                     SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3297     Pat<(cond rclass:$rA, (immtype immpred:$imm)),
3298         (binop (cmpOp1 rclass:$rA, (immtype immpred:$imm)),
3299                (cmpOp2 rclass:$rA, (immtype immpred:$imm)))>;
3300
3301 def : SETCCBinOpReg<setge, R8C, ORr8, CGTBr8, CEQBr8>;
3302 def : SETCCBinOpImm<setge, R8C, immSExt8, i8, ORr8, CGTBIr8, CEQBIr8>;
3303 def : SETCCBinOpReg<setlt, R8C, NORr8, CGTBr8, CEQBr8>;
3304 def : SETCCBinOpImm<setlt, R8C, immSExt8, i8, NORr8, CGTBIr8, CEQBIr8>;
3305 def : Pat<(setle R8C:$rA, R8C:$rB),
3306           (XORBIr8 (CGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3307 def :  Pat<(setle R8C:$rA, immU8:$imm),
3308            (XORBIr8 (CGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
3309
3310 def : SETCCBinOpReg<setge, R16C, ORr16, CGTHr16, CEQHr16>;
3311 def : SETCCBinOpImm<setge, R16C, i16ImmSExt10, i16,
3312                     ORr16, CGTHIr16, CEQHIr16>;
3313 def : SETCCBinOpReg<setlt, R16C, NORr16, CGTHr16, CEQHr16>;
3314 def : SETCCBinOpImm<setlt, R16C, i16ImmSExt10, i16, NORr16, CGTHIr16, CEQHIr16>;
3315 def : Pat<(setle R16C:$rA, R16C:$rB),
3316           (XORHIr16 (CGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
3317 def : Pat<(setle R16C:$rA, i16ImmSExt10:$imm),
3318           (XORHIr16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
3319
3320 def : SETCCBinOpReg<setge, R32C, ORr32, CGTr32, CEQr32>;
3321 def : SETCCBinOpImm<setge, R32C, i32ImmSExt10, i32,
3322                     ORr32, CGTIr32, CEQIr32>;
3323 def : SETCCBinOpReg<setlt, R32C, NORr32, CGTr32, CEQr32>;
3324 def : SETCCBinOpImm<setlt, R32C, i32ImmSExt10, i32, NORr32, CGTIr32, CEQIr32>;
3325 def : Pat<(setle R32C:$rA, R32C:$rB),
3326           (XORIr32 (CGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3327 def : Pat<(setle R32C:$rA, i32ImmSExt10:$imm),
3328           (XORIr32 (CGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
3329
3330 def : SETCCBinOpReg<setuge, R8C, ORr8, CLGTBr8, CEQBr8>;
3331 def : SETCCBinOpImm<setuge, R8C, immSExt8, i8, ORr8, CLGTBIr8, CEQBIr8>;
3332 def : SETCCBinOpReg<setult, R8C, NORr8, CLGTBr8, CEQBr8>;
3333 def : SETCCBinOpImm<setult, R8C, immSExt8, i8, NORr8, CLGTBIr8, CEQBIr8>;
3334 def : Pat<(setule R8C:$rA, R8C:$rB),
3335           (XORBIr8 (CLGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3336 def :  Pat<(setule R8C:$rA, immU8:$imm),
3337            (XORBIr8 (CLGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
3338
3339 def : SETCCBinOpReg<setuge, R16C, ORr16, CLGTHr16, CEQHr16>;
3340 def : SETCCBinOpImm<setuge, R16C, i16ImmSExt10, i16,
3341                     ORr16, CLGTHIr16, CEQHIr16>;
3342 def : SETCCBinOpReg<setult, R16C, NORr16, CLGTHr16, CEQHr16>;
3343 def : SETCCBinOpImm<setult, R16C, i16ImmSExt10, i16, NORr16,
3344                     CLGTHIr16, CEQHIr16>;
3345 def : Pat<(setule R16C:$rA, R16C:$rB),
3346           (XORHIr16 (CLGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
3347 def :  Pat<(setule R16C:$rA, i16ImmSExt10:$imm),
3348            (XORHIr16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
3349
3350 def : SETCCBinOpReg<setuge, R32C, ORr32, CLGTr32, CEQr32>;
3351 def : SETCCBinOpImm<setuge, R32C, i32ImmSExt10, i32,
3352                     ORr32, CLGTIr32, CEQIr32>;
3353 def : SETCCBinOpReg<setult, R32C, NORr32, CLGTr32, CEQr32>;
3354 def : SETCCBinOpImm<setult, R32C, i32ImmSExt10, i32, NORr32, CLGTIr32, CEQIr32>;
3355 def : Pat<(setule R32C:$rA, R32C:$rB),
3356           (XORIr32 (CLGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3357 def : Pat<(setule R32C:$rA, i32ImmSExt10:$imm),
3358           (XORIr32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
3359
3360 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3361 // select conditional patterns:
3362 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3363
3364 class SELECTNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3365                        SPUInstr selinstr, SPUInstr cmpare>:
3366   Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
3367               rclass:$rTrue, rclass:$rFalse),
3368       (selinstr rclass:$rTrue, rclass:$rFalse,
3369                 (cmpare rclass:$rA, rclass:$rB))>;
3370
3371 class SELECTNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3372                        PatLeaf immpred, SPUInstr selinstr, SPUInstr cmpare>:
3373   Pat<(select (inttype (cond rclass:$rA, immpred:$imm)),
3374               rclass:$rTrue, rclass:$rFalse),
3375       (selinstr rclass:$rTrue, rclass:$rFalse,
3376                 (cmpare rclass:$rA, immpred:$imm))>;
3377
3378 def : SELECTNegCondReg<setne, R8C, i8, SELBr8, CEQBr8>;
3379 def : SELECTNegCondImm<setne, R8C, i8, immSExt8, SELBr8, CEQBIr8>;
3380 def : SELECTNegCondReg<setle, R8C, i8, SELBr8, CGTBr8>;
3381 def : SELECTNegCondImm<setle, R8C, i8, immSExt8, SELBr8, CGTBr8>;
3382 def : SELECTNegCondReg<setule, R8C, i8, SELBr8, CLGTBr8>;
3383 def : SELECTNegCondImm<setule, R8C, i8, immU8, SELBr8, CLGTBIr8>;
3384
3385 def : SELECTNegCondReg<setne, R16C, i16, SELBr16, CEQHr16>;
3386 def : SELECTNegCondImm<setne, R16C, i16, i16ImmSExt10, SELBr16, CEQHIr16>;
3387 def : SELECTNegCondReg<setle, R16C, i16, SELBr16, CGTHr16>;
3388 def : SELECTNegCondImm<setle, R16C, i16, i16ImmSExt10, SELBr16, CGTHIr16>;
3389 def : SELECTNegCondReg<setule, R16C, i16, SELBr16, CLGTHr16>;
3390 def : SELECTNegCondImm<setule, R16C, i16, i16ImmSExt10, SELBr16, CLGTHIr16>;
3391
3392 def : SELECTNegCondReg<setne, R32C, i32, SELBr32, CEQr32>;
3393 def : SELECTNegCondImm<setne, R32C, i32, i32ImmSExt10, SELBr32, CEQIr32>;
3394 def : SELECTNegCondReg<setle, R32C, i32, SELBr32, CGTr32>;
3395 def : SELECTNegCondImm<setle, R32C, i32, i32ImmSExt10, SELBr32, CGTIr32>;
3396 def : SELECTNegCondReg<setule, R32C, i32, SELBr32, CLGTr32>;
3397 def : SELECTNegCondImm<setule, R32C, i32, i32ImmSExt10, SELBr32, CLGTIr32>;
3398
3399 class SELECTBinOpReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3400                      SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3401                      SPUInstr cmpOp2>:
3402   Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
3403               rclass:$rTrue, rclass:$rFalse),
3404       (selinstr rclass:$rFalse, rclass:$rTrue,
3405                 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3406                        (cmpOp2 rclass:$rA, rclass:$rB)))>;
3407
3408 class SELECTBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3409                      ValueType inttype,
3410                      SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3411                      SPUInstr cmpOp2>:
3412     Pat<(select (inttype (cond rclass:$rA, (inttype immpred:$imm))),
3413                 rclass:$rTrue, rclass:$rFalse),
3414         (selinstr rclass:$rFalse, rclass:$rTrue,
3415                   (binop (cmpOp1 rclass:$rA, (inttype immpred:$imm)),
3416                          (cmpOp2 rclass:$rA, (inttype immpred:$imm))))>;
3417
3418 def : SELECTBinOpReg<setge, R8C, i8, SELBr8, ORr8, CGTBr8, CEQBr8>;
3419 def : SELECTBinOpImm<setge, R8C, immSExt8, i8,
3420                      SELBr8, ORr8, CGTBIr8, CEQBIr8>;
3421
3422 def : SELECTBinOpReg<setge, R16C, i16, SELBr16, ORr16, CGTHr16, CEQHr16>;
3423 def : SELECTBinOpImm<setge, R16C, i16ImmSExt10, i16,
3424                      SELBr16, ORr16, CGTHIr16, CEQHIr16>;
3425
3426 def : SELECTBinOpReg<setge, R32C, i32, SELBr32, ORr32, CGTr32, CEQr32>;
3427 def : SELECTBinOpImm<setge, R32C, i32ImmSExt10, i32,
3428                      SELBr32, ORr32, CGTIr32, CEQIr32>;
3429
3430 def : SELECTBinOpReg<setuge, R8C, i8, SELBr8, ORr8, CLGTBr8, CEQBr8>;
3431 def : SELECTBinOpImm<setuge, R8C, immSExt8, i8,
3432                      SELBr8, ORr8, CLGTBIr8, CEQBIr8>;
3433
3434 def : SELECTBinOpReg<setuge, R16C, i16, SELBr16, ORr16, CLGTHr16, CEQHr16>;
3435 def : SELECTBinOpImm<setuge, R16C, i16ImmUns10, i16,
3436                      SELBr16, ORr16, CLGTHIr16, CEQHIr16>;
3437
3438 def : SELECTBinOpReg<setuge, R32C, i32, SELBr32, ORr32, CLGTr32, CEQr32>;
3439 def : SELECTBinOpImm<setuge, R32C, i32ImmUns10, i32,
3440                      SELBr32, ORr32, CLGTIr32, CEQIr32>;
3441
3442 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3443
3444 let isCall = 1,
3445   // All calls clobber the non-callee-saved registers:
3446   Defs = [R0, R1, R2, R3, R4, R5, R6, R7, R8, R9,
3447           R10,R11,R12,R13,R14,R15,R16,R17,R18,R19,
3448           R20,R21,R22,R23,R24,R25,R26,R27,R28,R29,
3449           R30,R31,R32,R33,R34,R35,R36,R37,R38,R39,
3450           R40,R41,R42,R43,R44,R45,R46,R47,R48,R49,
3451           R50,R51,R52,R53,R54,R55,R56,R57,R58,R59,
3452           R60,R61,R62,R63,R64,R65,R66,R67,R68,R69,
3453           R70,R71,R72,R73,R74,R75,R76,R77,R78,R79],
3454   // All of these instructions use $lr (aka $0)
3455   Uses = [R0]  in {
3456   // Branch relative and set link: Used if we actually know that the target
3457   // is within [-32768, 32767] bytes of the target
3458   def BRSL:
3459     BranchSetLink<0b011001100, (outs), (ins relcalltarget:$func, variable_ops),
3460       "brsl\t$$lr, $func",
3461       [(SPUcall (SPUpcrel tglobaladdr:$func, 0))]>;
3462
3463   // Branch absolute and set link: Used if we actually know that the target
3464   // is an absolute address
3465   def BRASL:
3466     BranchSetLink<0b011001100, (outs), (ins calltarget:$func, variable_ops),
3467       "brasl\t$$lr, $func",
3468       [(SPUcall (SPUaform tglobaladdr:$func, 0))]>;
3469
3470   // Branch indirect and set link if external data. These instructions are not
3471   // actually generated, matched by an intrinsic:
3472   def BISLED_00: BISLEDForm<0b11, "bisled\t$$lr, $func", [/* empty pattern */]>;
3473   def BISLED_E0: BISLEDForm<0b10, "bisled\t$$lr, $func", [/* empty pattern */]>;
3474   def BISLED_0D: BISLEDForm<0b01, "bisled\t$$lr, $func", [/* empty pattern */]>;
3475   def BISLED_ED: BISLEDForm<0b00, "bisled\t$$lr, $func", [/* empty pattern */]>;
3476
3477   // Branch indirect and set link. This is the "X-form" address version of a
3478   // function call
3479   def BISL:
3480     BIForm<0b10010101100, "bisl\t$$lr, $func", [(SPUcall R32C:$func)]>;
3481 }
3482
3483 // Support calls to external symbols:      
3484 def : Pat<(SPUcall (SPUpcrel texternalsym:$func, 0)),
3485           (BRSL texternalsym:$func)>;
3486       
3487 def : Pat<(SPUcall (SPUaform texternalsym:$func, 0)),
3488           (BRASL texternalsym:$func)>;
3489
3490 // Unconditional branches:
3491 let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
3492   def BR :
3493     UncondBranch<0b001001100, (outs), (ins brtarget:$dest),
3494       "br\t$dest",
3495       [(br bb:$dest)]>;
3496
3497   // Unconditional, absolute address branch
3498   def BRA:
3499     UncondBranch<0b001100000, (outs), (ins brtarget:$dest),
3500       "bra\t$dest",
3501       [/* no pattern */]>;
3502
3503   // Indirect branch
3504   def BI:
3505     BIForm<0b00010101100, "bi\t$func", [(brind R32C:$func)]>;
3506
3507   // Various branches:
3508   class BRNZInst<dag IOL, list<dag> pattern>:
3509     RI16Form<0b010000100, (outs), IOL, "brnz\t$rCond,$dest",
3510              BranchResolv, pattern>;
3511
3512   class BRNZRegInst<RegisterClass rclass>:
3513     BRNZInst<(ins rclass:$rCond, brtarget:$dest),
3514              [(brcond rclass:$rCond, bb:$dest)]>;
3515
3516   class BRNZVecInst<ValueType vectype>:
3517     BRNZInst<(ins VECREG:$rCond, brtarget:$dest),
3518              [(brcond (vectype VECREG:$rCond), bb:$dest)]>;
3519
3520   multiclass BranchNotZero {
3521     def v4i32 : BRNZVecInst<v4i32>;
3522     def r32   : BRNZRegInst<R32C>;
3523   }
3524
3525   defm BRNZ : BranchNotZero;
3526
3527   class BRZInst<dag IOL, list<dag> pattern>:
3528     RI16Form<0b000000100, (outs), IOL, "brz\t$rT,$dest",
3529              BranchResolv, pattern>;
3530
3531   class BRZRegInst<RegisterClass rclass>:
3532     BRZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3533
3534   class BRZVecInst<ValueType vectype>:
3535     BRZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3536
3537   multiclass BranchZero {
3538     def v4i32: BRZVecInst<v4i32>;
3539     def r32:   BRZRegInst<R32C>;
3540   }
3541
3542   defm BRZ: BranchZero;
3543
3544   // Note: LLVM doesn't do branch conditional, indirect. Otherwise these would
3545   // be useful:
3546   /*
3547   class BINZInst<dag IOL, list<dag> pattern>:
3548    BICondForm<0b10010100100, (outs), IOL, "binz\t$rA, $dest", pattern>;
3549
3550   class BINZRegInst<RegisterClass rclass>:
3551     BINZInst<(ins rclass:$rA, brtarget:$dest),
3552              [(brcond rclass:$rA, R32C:$dest)]>;
3553
3554   class BINZVecInst<ValueType vectype>:
3555     BINZInst<(ins VECREG:$rA, R32C:$dest),
3556              [(brcond (vectype VECREG:$rA), R32C:$dest)]>;
3557
3558   multiclass BranchNotZeroIndirect {
3559     def v4i32: BINZVecInst<v4i32>;
3560     def r32:   BINZRegInst<R32C>;
3561   }
3562
3563   defm BINZ: BranchNotZeroIndirect;
3564
3565   class BIZInst<dag IOL, list<dag> pattern>:
3566     BICondForm<0b00010100100, (outs), IOL, "biz\t$rA, $func", pattern>;
3567
3568   class BIZRegInst<RegisterClass rclass>:
3569     BIZInst<(ins rclass:$rA, R32C:$func), [/* no pattern */]>;
3570
3571   class BIZVecInst<ValueType vectype>:
3572     BIZInst<(ins VECREG:$rA, R32C:$func), [/* no pattern */]>;
3573
3574   multiclass BranchZeroIndirect {
3575     def v4i32: BIZVecInst<v4i32>;
3576     def r32:   BIZRegInst<R32C>;
3577   }
3578
3579   defm BIZ: BranchZeroIndirect;
3580   */
3581
3582   class BRHNZInst<dag IOL, list<dag> pattern>:
3583     RI16Form<0b011000100, (outs), IOL, "brhnz\t$rCond,$dest", BranchResolv,
3584              pattern>;
3585
3586   class BRHNZRegInst<RegisterClass rclass>:
3587     BRHNZInst<(ins rclass:$rCond, brtarget:$dest),
3588               [(brcond rclass:$rCond, bb:$dest)]>;
3589
3590   class BRHNZVecInst<ValueType vectype>:
3591     BRHNZInst<(ins VECREG:$rCond, brtarget:$dest), [/* no pattern */]>;
3592
3593   multiclass BranchNotZeroHalfword {
3594     def v8i16: BRHNZVecInst<v8i16>;
3595     def r16:   BRHNZRegInst<R16C>;
3596   }
3597
3598   defm BRHNZ: BranchNotZeroHalfword;
3599
3600   class BRHZInst<dag IOL, list<dag> pattern>:
3601     RI16Form<0b001000100, (outs), IOL, "brhz\t$rT,$dest", BranchResolv,
3602              pattern>;
3603
3604   class BRHZRegInst<RegisterClass rclass>:
3605     BRHZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3606
3607   class BRHZVecInst<ValueType vectype>:
3608     BRHZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3609
3610   multiclass BranchZeroHalfword {
3611     def v8i16: BRHZVecInst<v8i16>;
3612     def r16:   BRHZRegInst<R16C>;
3613   }
3614
3615   defm BRHZ: BranchZeroHalfword;
3616 }
3617
3618 //===----------------------------------------------------------------------===//
3619 // setcc and brcond patterns:
3620 //===----------------------------------------------------------------------===//
3621
3622 def : Pat<(brcond (i16 (seteq R16C:$rA, 0)), bb:$dest),
3623           (BRHZr16 R16C:$rA, bb:$dest)>;
3624 def : Pat<(brcond (i16 (setne R16C:$rA, 0)), bb:$dest),
3625           (BRHNZr16 R16C:$rA, bb:$dest)>;
3626
3627 def : Pat<(brcond (i32 (seteq R32C:$rA, 0)), bb:$dest),
3628           (BRZr32 R32C:$rA, bb:$dest)>;
3629 def : Pat<(brcond (i32 (setne R32C:$rA, 0)), bb:$dest),
3630           (BRNZr32 R32C:$rA, bb:$dest)>;
3631
3632 multiclass BranchCondEQ<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3633 {
3634   def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3635                   (brinst16 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3636
3637   def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3638                 (brinst16 (CEQHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3639
3640   def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3641                    (brinst32 (CEQIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3642
3643   def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3644                 (brinst32 (CEQr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3645 }
3646
3647 defm BRCONDeq : BranchCondEQ<seteq, BRHZr16, BRZr32>;
3648 defm BRCONDne : BranchCondEQ<setne, BRHNZr16, BRNZr32>;
3649
3650 multiclass BranchCondLGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3651 {
3652   def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3653                    (brinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3654
3655   def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3656                 (brinst16 (CLGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3657
3658   def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3659                    (brinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3660
3661   def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3662                 (brinst32 (CLGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3663 }
3664
3665 defm BRCONDugt : BranchCondLGT<setugt, BRHNZr16, BRNZr32>;
3666 defm BRCONDule : BranchCondLGT<setule, BRHZr16, BRZr32>;
3667
3668 multiclass BranchCondLGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3669                            SPUInstr orinst32, SPUInstr brinst32>
3670 {
3671   def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3672                   (brinst16 (orinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3673                                       (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3674                             bb:$dest)>;
3675
3676   def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3677                (brinst16 (orinst16 (CLGTHr16 R16C:$rA, R16:$rB),
3678                                    (CEQHr16 R16C:$rA, R16:$rB)),
3679                          bb:$dest)>;
3680
3681   def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3682                    (brinst32 (orinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val),
3683                                        (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3684                              bb:$dest)>;
3685
3686   def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3687                 (brinst32 (orinst32 (CLGTr32 R32C:$rA, R32C:$rB),
3688                                     (CEQr32 R32C:$rA, R32C:$rB)),
3689                           bb:$dest)>;
3690 }
3691
3692 defm BRCONDuge : BranchCondLGTEQ<setuge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3693 defm BRCONDult : BranchCondLGTEQ<setult, ORr16, BRHZr16, ORr32, BRZr32>;
3694
3695 multiclass BranchCondGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3696 {
3697   def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3698                    (brinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3699
3700   def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3701                 (brinst16 (CGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3702
3703   def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3704                    (brinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3705
3706   def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3707                 (brinst32 (CGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3708 }
3709
3710 defm BRCONDgt : BranchCondGT<setgt, BRHNZr16, BRNZr32>;
3711 defm BRCONDle : BranchCondGT<setle, BRHZr16, BRZr32>;
3712
3713 multiclass BranchCondGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3714                           SPUInstr orinst32, SPUInstr brinst32>
3715 {
3716   def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3717                   (brinst16 (orinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3718                                       (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3719                             bb:$dest)>;
3720
3721   def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3722                (brinst16 (orinst16 (CGTHr16 R16C:$rA, R16:$rB),
3723                                    (CEQHr16 R16C:$rA, R16:$rB)),
3724                          bb:$dest)>;
3725
3726   def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3727                    (brinst32 (orinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val),
3728                                        (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3729                              bb:$dest)>;
3730
3731   def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3732                 (brinst32 (orinst32 (CGTr32 R32C:$rA, R32C:$rB),
3733                                     (CEQr32 R32C:$rA, R32C:$rB)),
3734                           bb:$dest)>;
3735 }
3736
3737 defm BRCONDge : BranchCondGTEQ<setge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3738 defm BRCONDlt : BranchCondGTEQ<setlt, ORr16, BRHZr16, ORr32, BRZr32>;
3739
3740 let isTerminator = 1, isBarrier = 1 in {
3741   let isReturn = 1 in {
3742     def RET:
3743         RETForm<"bi\t$$lr", [(retflag)]>;
3744   }
3745 }
3746
3747 //===----------------------------------------------------------------------===//
3748 // Single precision floating point instructions
3749 //===----------------------------------------------------------------------===//
3750
3751 class FAInst<dag OOL, dag IOL, list<dag> pattern>:
3752     RRForm<0b01011000100, OOL, IOL, "fa\t$rT, $rA, $rB",
3753            SPrecFP, pattern>;
3754
3755 class FAVecInst<ValueType vectype>:
3756     FAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3757              [(set (vectype VECREG:$rT),
3758                    (fadd (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
3759
3760 multiclass SFPAdd
3761 {
3762   def v4f32: FAVecInst<v4f32>;
3763   def r32:   FAInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3764                     [(set R32FP:$rT, (fadd R32FP:$rA, R32FP:$rB))]>;
3765 }
3766
3767 defm FA : SFPAdd;
3768
3769 class FSInst<dag OOL, dag IOL, list<dag> pattern>:
3770     RRForm<0b01011000100, OOL, IOL, "fs\t$rT, $rA, $rB",
3771            SPrecFP, pattern>;
3772
3773 class FSVecInst<ValueType vectype>:
3774     FSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3775            [(set (vectype VECREG:$rT),
3776                  (fsub (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
3777
3778 multiclass SFPSub
3779 {
3780   def v4f32: FSVecInst<v4f32>;
3781   def r32:   FSInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3782                     [(set R32FP:$rT, (fsub R32FP:$rA, R32FP:$rB))]>;
3783 }
3784
3785 defm FS : SFPSub;
3786
3787 // Floating point reciprocal estimate
3788 def FREv4f32 :
3789     RRForm_1<0b00011101100, (outs VECREG:$rT), (ins VECREG:$rA),
3790       "frest\t$rT, $rA", SPrecFP,
3791       [(set (v4f32 VECREG:$rT), (SPUreciprocalEst (v4f32 VECREG:$rA)))]>;
3792
3793 def FREf32 :
3794     RRForm_1<0b00011101100, (outs R32FP:$rT), (ins R32FP:$rA),
3795       "frest\t$rT, $rA", SPrecFP,
3796       [(set R32FP:$rT, (SPUreciprocalEst R32FP:$rA))]>;
3797
3798 // Floating point interpolate (used in conjunction with reciprocal estimate)
3799 def FIv4f32 :
3800     RRForm<0b00101011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3801       "fi\t$rT, $rA, $rB", SPrecFP,
3802       [(set (v4f32 VECREG:$rT), (SPUinterpolate (v4f32 VECREG:$rA),
3803                                                 (v4f32 VECREG:$rB)))]>;
3804
3805 def FIf32 :
3806     RRForm<0b00101011110, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3807       "fi\t$rT, $rA, $rB", SPrecFP,
3808       [(set R32FP:$rT, (SPUinterpolate R32FP:$rA, R32FP:$rB))]>;
3809
3810 //--------------------------------------------------------------------------
3811 // Basic single precision floating point comparisons:
3812 //
3813 // Note: There is no support on SPU for single precision NaN. Consequently,
3814 // ordered and unordered comparisons are the same.
3815 //--------------------------------------------------------------------------
3816
3817 def FCEQf32 :
3818     RRForm<0b01000011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3819       "fceq\t$rT, $rA, $rB", SPrecFP,
3820       [(set R32C:$rT, (setueq R32FP:$rA, R32FP:$rB))]>;
3821
3822 def : Pat<(setoeq R32FP:$rA, R32FP:$rB),
3823           (FCEQf32 R32FP:$rA, R32FP:$rB)>;
3824
3825 def FCMEQf32 :
3826     RRForm<0b01010011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3827       "fcmeq\t$rT, $rA, $rB", SPrecFP,
3828       [(set R32C:$rT, (setueq (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3829
3830 def : Pat<(setoeq (fabs R32FP:$rA), (fabs R32FP:$rB)),
3831           (FCMEQf32 R32FP:$rA, R32FP:$rB)>;
3832
3833 def FCGTf32 :
3834     RRForm<0b01000011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3835       "fcgt\t$rT, $rA, $rB", SPrecFP,
3836       [(set R32C:$rT, (setugt R32FP:$rA, R32FP:$rB))]>;
3837
3838 def : Pat<(setugt R32FP:$rA, R32FP:$rB),
3839           (FCGTf32 R32FP:$rA, R32FP:$rB)>;
3840
3841 def FCMGTf32 :
3842     RRForm<0b01010011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3843       "fcmgt\t$rT, $rA, $rB", SPrecFP,
3844       [(set R32C:$rT, (setugt (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3845
3846 def : Pat<(setugt (fabs R32FP:$rA), (fabs R32FP:$rB)),
3847           (FCMGTf32 R32FP:$rA, R32FP:$rB)>;
3848
3849 //--------------------------------------------------------------------------
3850 // Single precision floating point comparisons and SETCC equivalents:
3851 //--------------------------------------------------------------------------
3852
3853 def : SETCCNegCondReg<setune, R32FP, i32, XORIr32, FCEQf32>;
3854 def : SETCCNegCondReg<setone, R32FP, i32, XORIr32, FCEQf32>;
3855
3856 def : SETCCBinOpReg<setuge, R32FP, ORr32, FCGTf32, FCEQf32>;
3857 def : SETCCBinOpReg<setoge, R32FP, ORr32, FCGTf32, FCEQf32>;
3858
3859 def : SETCCBinOpReg<setult, R32FP, NORr32, FCGTf32, FCEQf32>;
3860 def : SETCCBinOpReg<setolt, R32FP, NORr32, FCGTf32, FCEQf32>;
3861
3862 def : Pat<(setule R32FP:$rA, R32FP:$rB),
3863           (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
3864 def : Pat<(setole R32FP:$rA, R32FP:$rB),
3865           (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
3866
3867 // FP Status and Control Register Write
3868 // Why isn't rT a don't care in the ISA?
3869 // Should we create a special RRForm_3 for this guy and zero out the rT?
3870 def FSCRWf32 :
3871     RRForm_1<0b01011101110, (outs R32FP:$rT), (ins R32FP:$rA),
3872       "fscrwr\t$rA", SPrecFP,
3873       [/* This instruction requires an intrinsic. Note: rT is unused. */]>;
3874
3875 // FP Status and Control Register Read
3876 def FSCRRf32 :
3877     RRForm_2<0b01011101110, (outs R32FP:$rT), (ins),
3878       "fscrrd\t$rT", SPrecFP,
3879       [/* This instruction requires an intrinsic */]>;
3880
3881 // llvm instruction space
3882 // How do these map onto cell instructions?
3883 // fdiv rA rB
3884 //   frest rC rB        # c = 1/b (both lines)
3885 //   fi rC rB rC
3886 //   fm rD rA rC        # d = a * 1/b
3887 //   fnms rB rD rB rA # b = - (d * b - a) --should == 0 in a perfect world
3888 //   fma rB rB rC rD            # b = b * c + d
3889 //                              = -(d *b -a) * c + d
3890 //                              = a * c - c ( a *b *c - a)
3891
3892 // fcopysign (???)
3893
3894 // Library calls:
3895 // These llvm instructions will actually map to library calls.
3896 // All that's needed, then, is to check that the appropriate library is
3897 // imported and do a brsl to the proper function name.
3898 // frem # fmod(x, y): x - (x/y) * y
3899 // (Note: fmod(double, double), fmodf(float,float)
3900 // fsqrt?
3901 // fsin?
3902 // fcos?
3903 // Unimplemented SPU instruction space
3904 // floating reciprocal absolute square root estimate (frsqest)
3905
3906 // The following are probably just intrinsics
3907 // status and control register write
3908 // status and control register read
3909
3910 //--------------------------------------
3911 // Floating point multiply instructions
3912 //--------------------------------------
3913
3914 def FMv4f32:
3915     RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3916       "fm\t$rT, $rA, $rB", SPrecFP,
3917       [(set (v4f32 VECREG:$rT), (fmul (v4f32 VECREG:$rA),
3918                                       (v4f32 VECREG:$rB)))]>;
3919
3920 def FMf32 :
3921     RRForm<0b01100011010, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3922       "fm\t$rT, $rA, $rB", SPrecFP,
3923       [(set R32FP:$rT, (fmul R32FP:$rA, R32FP:$rB))]>;
3924
3925 // Floating point multiply and add
3926 // e.g. d = c + (a * b)
3927 def FMAv4f32:
3928     RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3929       "fma\t$rT, $rA, $rB, $rC", SPrecFP,
3930       [(set (v4f32 VECREG:$rT),
3931             (fadd (v4f32 VECREG:$rC),
3932                   (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB))))]>;
3933
3934 def FMAf32:
3935     RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3936       "fma\t$rT, $rA, $rB, $rC", SPrecFP,
3937       [(set R32FP:$rT, (fadd R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
3938
3939 // FP multiply and subtract
3940 // Subtracts value in rC from product
3941 // res = a * b - c
3942 def FMSv4f32 :
3943     RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3944       "fms\t$rT, $rA, $rB, $rC", SPrecFP,
3945       [(set (v4f32 VECREG:$rT),
3946             (fsub (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB)),
3947                   (v4f32 VECREG:$rC)))]>;
3948
3949 def FMSf32 :
3950     RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3951       "fms\t$rT, $rA, $rB, $rC", SPrecFP,
3952       [(set R32FP:$rT,
3953             (fsub (fmul R32FP:$rA, R32FP:$rB), R32FP:$rC))]>;
3954
3955 // Floating Negative Mulitply and Subtract
3956 // Subtracts product from value in rC
3957 // res = fneg(fms a b c)
3958 //     = - (a * b - c)
3959 //     = c - a * b
3960 // NOTE: subtraction order
3961 // fsub a b = a - b
3962 // fs a b = b - a?
3963 def FNMSf32 :
3964     RRRForm<0b1101, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3965       "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
3966       [(set R32FP:$rT, (fsub R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
3967
3968 def FNMSv4f32 :
3969     RRRForm<0b1101, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3970       "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
3971       [(set (v4f32 VECREG:$rT),
3972             (fsub (v4f32 VECREG:$rC),
3973                   (fmul (v4f32 VECREG:$rA),
3974                         (v4f32 VECREG:$rB))))]>;
3975
3976 //--------------------------------------
3977 // Floating Point Conversions
3978 // Signed conversions:
3979 def CSiFv4f32:
3980     CVTIntFPForm<0b0101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3981       "csflt\t$rT, $rA, 0", SPrecFP,
3982       [(set (v4f32 VECREG:$rT), (sint_to_fp (v4i32 VECREG:$rA)))]>;
3983
3984 // Convert signed integer to floating point
3985 def CSiFf32 :
3986     CVTIntFPForm<0b0101101110, (outs R32FP:$rT), (ins R32C:$rA),
3987       "csflt\t$rT, $rA, 0", SPrecFP,
3988       [(set R32FP:$rT, (sint_to_fp R32C:$rA))]>;
3989
3990 // Convert unsigned into to float
3991 def CUiFv4f32 :
3992     CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3993       "cuflt\t$rT, $rA, 0", SPrecFP,
3994       [(set (v4f32 VECREG:$rT), (uint_to_fp (v4i32 VECREG:$rA)))]>;
3995
3996 def CUiFf32 :
3997     CVTIntFPForm<0b1101101110, (outs R32FP:$rT), (ins R32C:$rA),
3998       "cuflt\t$rT, $rA, 0", SPrecFP,
3999       [(set R32FP:$rT, (uint_to_fp R32C:$rA))]>;
4000
4001 // Convert float to unsigned int
4002 // Assume that scale = 0
4003
4004 def CFUiv4f32 :
4005     CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4006       "cfltu\t$rT, $rA, 0", SPrecFP,
4007       [(set (v4i32 VECREG:$rT), (fp_to_uint (v4f32 VECREG:$rA)))]>;
4008
4009 def CFUif32 :
4010     CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
4011       "cfltu\t$rT, $rA, 0", SPrecFP,
4012       [(set R32C:$rT, (fp_to_uint R32FP:$rA))]>;
4013
4014 // Convert float to signed int
4015 // Assume that scale = 0
4016
4017 def CFSiv4f32 :
4018     CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4019       "cflts\t$rT, $rA, 0", SPrecFP,
4020       [(set (v4i32 VECREG:$rT), (fp_to_sint (v4f32 VECREG:$rA)))]>;
4021
4022 def CFSif32 :
4023     CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
4024       "cflts\t$rT, $rA, 0", SPrecFP,
4025       [(set R32C:$rT, (fp_to_sint R32FP:$rA))]>;
4026
4027 //===----------------------------------------------------------------------==//
4028 // Single<->Double precision conversions
4029 //===----------------------------------------------------------------------==//
4030
4031 // NOTE: We use "vec" name suffix here to avoid confusion (e.g. input is a
4032 // v4f32, output is v2f64--which goes in the name?)
4033
4034 // Floating point extend single to double
4035 // NOTE: Not sure if passing in v4f32 to FESDvec is correct since it
4036 // operates on two double-word slots (i.e. 1st and 3rd fp numbers
4037 // are ignored).
4038 def FESDvec :
4039     RRForm_1<0b00011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4040       "fesd\t$rT, $rA", SPrecFP,
4041       [(set (v2f64 VECREG:$rT), (fextend (v4f32 VECREG:$rA)))]>;
4042
4043 def FESDf32 :
4044     RRForm_1<0b00011101110, (outs R64FP:$rT), (ins R32FP:$rA),
4045       "fesd\t$rT, $rA", SPrecFP,
4046       [(set R64FP:$rT, (fextend R32FP:$rA))]>;
4047
4048 // Floating point round double to single
4049 //def FRDSvec :
4050 //    RRForm_1<0b10011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4051 //      "frds\t$rT, $rA,", SPrecFP,
4052 //      [(set (v4f32 R32FP:$rT), (fround (v2f64 R64FP:$rA)))]>;
4053
4054 def FRDSf64 :
4055     RRForm_1<0b10011101110, (outs R32FP:$rT), (ins R64FP:$rA),
4056       "frds\t$rT, $rA", SPrecFP,
4057       [(set R32FP:$rT, (fround R64FP:$rA))]>;
4058
4059 //ToDo include anyextend?
4060
4061 //===----------------------------------------------------------------------==//
4062 // Double precision floating point instructions
4063 //===----------------------------------------------------------------------==//
4064 def FAf64 :
4065     RRForm<0b00110011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4066       "dfa\t$rT, $rA, $rB", DPrecFP,
4067       [(set R64FP:$rT, (fadd R64FP:$rA, R64FP:$rB))]>;
4068
4069 def FAv2f64 :
4070     RRForm<0b00110011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4071       "dfa\t$rT, $rA, $rB", DPrecFP,
4072       [(set (v2f64 VECREG:$rT), (fadd (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4073
4074 def FSf64 :
4075     RRForm<0b10100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4076       "dfs\t$rT, $rA, $rB", DPrecFP,
4077       [(set R64FP:$rT, (fsub R64FP:$rA, R64FP:$rB))]>;
4078
4079 def FSv2f64 :
4080     RRForm<0b10100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4081       "dfs\t$rT, $rA, $rB", DPrecFP,
4082       [(set (v2f64 VECREG:$rT),
4083             (fsub (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4084
4085 def FMf64 :
4086     RRForm<0b01100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4087       "dfm\t$rT, $rA, $rB", DPrecFP,
4088       [(set R64FP:$rT, (fmul R64FP:$rA, R64FP:$rB))]>;
4089
4090 def FMv2f64:
4091     RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4092       "dfm\t$rT, $rA, $rB", DPrecFP,
4093       [(set (v2f64 VECREG:$rT),
4094             (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4095
4096 def FMAf64:
4097     RRForm<0b00111010110, (outs R64FP:$rT),
4098                           (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4099       "dfma\t$rT, $rA, $rB", DPrecFP,
4100       [(set R64FP:$rT, (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
4101     RegConstraint<"$rC = $rT">,
4102     NoEncode<"$rC">;
4103
4104 def FMAv2f64:
4105     RRForm<0b00111010110, (outs VECREG:$rT),
4106                           (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4107       "dfma\t$rT, $rA, $rB", DPrecFP,
4108       [(set (v2f64 VECREG:$rT),
4109             (fadd (v2f64 VECREG:$rC),
4110                   (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB))))]>,
4111     RegConstraint<"$rC = $rT">,
4112     NoEncode<"$rC">;
4113
4114 def FMSf64 :
4115     RRForm<0b10111010110, (outs R64FP:$rT),
4116                           (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4117       "dfms\t$rT, $rA, $rB", DPrecFP,
4118       [(set R64FP:$rT, (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC))]>,
4119     RegConstraint<"$rC = $rT">,
4120     NoEncode<"$rC">;
4121
4122 def FMSv2f64 :
4123     RRForm<0b10111010110, (outs VECREG:$rT),
4124                           (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4125       "dfms\t$rT, $rA, $rB", DPrecFP,
4126       [(set (v2f64 VECREG:$rT),
4127             (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
4128                   (v2f64 VECREG:$rC)))]>;
4129
4130 // FNMS: - (a * b - c)
4131 // - (a * b) + c => c - (a * b)
4132 def FNMSf64 :
4133     RRForm<0b01111010110, (outs R64FP:$rT),
4134                           (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4135       "dfnms\t$rT, $rA, $rB", DPrecFP,
4136       [(set R64FP:$rT, (fsub R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
4137     RegConstraint<"$rC = $rT">,
4138     NoEncode<"$rC">;
4139
4140 def : Pat<(fneg (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC)),
4141           (FNMSf64 R64FP:$rA, R64FP:$rB, R64FP:$rC)>;
4142
4143 def FNMSv2f64 :
4144     RRForm<0b01111010110, (outs VECREG:$rT),
4145                           (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4146       "dfnms\t$rT, $rA, $rB", DPrecFP,
4147       [(set (v2f64 VECREG:$rT),
4148             (fsub (v2f64 VECREG:$rC),
4149                   (fmul (v2f64 VECREG:$rA),
4150                         (v2f64 VECREG:$rB))))]>,
4151     RegConstraint<"$rC = $rT">,
4152     NoEncode<"$rC">;
4153
4154 def : Pat<(fneg (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
4155                 (v2f64 VECREG:$rC))),
4156           (FNMSv2f64 VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
4157
4158 // - (a * b + c)
4159 // - (a * b) - c
4160 def FNMAf64 :
4161     RRForm<0b11111010110, (outs R64FP:$rT),
4162                           (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4163       "dfnma\t$rT, $rA, $rB", DPrecFP,
4164       [(set R64FP:$rT, (fneg (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB))))]>,
4165     RegConstraint<"$rC = $rT">,
4166     NoEncode<"$rC">;
4167
4168 def FNMAv2f64 :
4169     RRForm<0b11111010110, (outs VECREG:$rT),
4170                           (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4171       "dfnma\t$rT, $rA, $rB", DPrecFP,
4172       [(set (v2f64 VECREG:$rT),
4173             (fneg (fadd (v2f64 VECREG:$rC),
4174                         (fmul (v2f64 VECREG:$rA),
4175                               (v2f64 VECREG:$rB)))))]>,
4176     RegConstraint<"$rC = $rT">,
4177     NoEncode<"$rC">;
4178
4179 //===----------------------------------------------------------------------==//
4180 // Floating point negation and absolute value
4181 //===----------------------------------------------------------------------==//
4182
4183 def : Pat<(fneg (v4f32 VECREG:$rA)),
4184           (XORfnegvec (v4f32 VECREG:$rA),
4185                       (v4f32 (ILHUv4i32 0x8000)))>;
4186
4187 def : Pat<(fneg R32FP:$rA),
4188           (XORfneg32 R32FP:$rA, (ILHUr32 0x8000))>;
4189
4190 def : Pat<(fneg (v2f64 VECREG:$rA)),
4191           (XORfnegvec (v2f64 VECREG:$rA),
4192                       (v2f64 (ANDBIv16i8 (FSMBIv16i8 0x8080), 0x80)))>;
4193
4194 def : Pat<(fneg R64FP:$rA),
4195           (XORfneg64 R64FP:$rA,
4196                      (ANDBIv16i8 (FSMBIv16i8 0x8080), 0x80))>;
4197
4198 // Floating point absolute value
4199
4200 def : Pat<(fabs R32FP:$rA),
4201           (ANDfabs32 R32FP:$rA, (IOHLr32 (ILHUr32 0x7fff), 0xffff))>;
4202
4203 def : Pat<(fabs (v4f32 VECREG:$rA)),
4204           (ANDfabsvec (v4f32 VECREG:$rA),
4205                       (v4f32 (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f)))>;
4206
4207 def : Pat<(fabs R64FP:$rA),
4208           (ANDfabs64 R64FP:$rA, (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f))>;
4209
4210 def : Pat<(fabs (v2f64 VECREG:$rA)),
4211           (ANDfabsvec (v2f64 VECREG:$rA),
4212                       (v2f64 (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f)))>;
4213
4214 //===----------------------------------------------------------------------===//
4215 // Hint for branch instructions:
4216 //===----------------------------------------------------------------------===//
4217
4218 /* def HBR : SPUInstr<(outs), (ins), "hbr\t" */
4219
4220 //===----------------------------------------------------------------------===//
4221 // Execution, Load NOP (execute NOPs belong in even pipeline, load NOPs belong
4222 // in the odd pipeline)
4223 //===----------------------------------------------------------------------===//
4224
4225 def ENOP : SPUInstr<(outs), (ins), "enop", ExecNOP> {
4226   let Pattern = [];
4227
4228   let Inst{0-10} = 0b10000000010;
4229   let Inst{11-17} = 0;
4230   let Inst{18-24} = 0;
4231   let Inst{25-31} = 0;
4232 }
4233
4234 def LNOP : SPUInstr<(outs), (ins), "lnop", LoadNOP> {
4235   let Pattern = [];
4236
4237   let Inst{0-10} = 0b10000000000;
4238   let Inst{11-17} = 0;
4239   let Inst{18-24} = 0;
4240   let Inst{25-31} = 0;
4241 }
4242
4243 //===----------------------------------------------------------------------===//
4244 // Bit conversions (type conversions between vector/packed types)
4245 // NOTE: Promotions are handled using the XS* instructions. Truncation
4246 // is not handled.
4247 //===----------------------------------------------------------------------===//
4248 def : Pat<(v16i8 (bitconvert (v8i16 VECREG:$src))), (v16i8 VECREG:$src)>;
4249 def : Pat<(v16i8 (bitconvert (v4i32 VECREG:$src))), (v16i8 VECREG:$src)>;
4250 def : Pat<(v16i8 (bitconvert (v2i64 VECREG:$src))), (v16i8 VECREG:$src)>;
4251 def : Pat<(v16i8 (bitconvert (v4f32 VECREG:$src))), (v16i8 VECREG:$src)>;
4252 def : Pat<(v16i8 (bitconvert (v2f64 VECREG:$src))), (v16i8 VECREG:$src)>;
4253
4254 def : Pat<(v8i16 (bitconvert (v16i8 VECREG:$src))), (v8i16 VECREG:$src)>;
4255 def : Pat<(v8i16 (bitconvert (v4i32 VECREG:$src))), (v8i16 VECREG:$src)>;
4256 def : Pat<(v8i16 (bitconvert (v2i64 VECREG:$src))), (v8i16 VECREG:$src)>;
4257 def : Pat<(v8i16 (bitconvert (v4f32 VECREG:$src))), (v8i16 VECREG:$src)>;
4258 def : Pat<(v8i16 (bitconvert (v2f64 VECREG:$src))), (v8i16 VECREG:$src)>;
4259
4260 def : Pat<(v4i32 (bitconvert (v16i8 VECREG:$src))), (v4i32 VECREG:$src)>;
4261 def : Pat<(v4i32 (bitconvert (v8i16 VECREG:$src))), (v4i32 VECREG:$src)>;
4262 def : Pat<(v4i32 (bitconvert (v2i64 VECREG:$src))), (v4i32 VECREG:$src)>;
4263 def : Pat<(v4i32 (bitconvert (v4f32 VECREG:$src))), (v4i32 VECREG:$src)>;
4264 def : Pat<(v4i32 (bitconvert (v2f64 VECREG:$src))), (v4i32 VECREG:$src)>;
4265
4266 def : Pat<(v2i64 (bitconvert (v16i8 VECREG:$src))), (v2i64 VECREG:$src)>;
4267 def : Pat<(v2i64 (bitconvert (v8i16 VECREG:$src))), (v2i64 VECREG:$src)>;
4268 def : Pat<(v2i64 (bitconvert (v4i32 VECREG:$src))), (v2i64 VECREG:$src)>;
4269 def : Pat<(v2i64 (bitconvert (v4f32 VECREG:$src))), (v2i64 VECREG:$src)>;
4270 def : Pat<(v2i64 (bitconvert (v2f64 VECREG:$src))), (v2i64 VECREG:$src)>;
4271
4272 def : Pat<(v4f32 (bitconvert (v16i8 VECREG:$src))), (v4f32 VECREG:$src)>;
4273 def : Pat<(v4f32 (bitconvert (v8i16 VECREG:$src))), (v4f32 VECREG:$src)>;
4274 def : Pat<(v4f32 (bitconvert (v2i64 VECREG:$src))), (v4f32 VECREG:$src)>;
4275 def : Pat<(v4f32 (bitconvert (v4i32 VECREG:$src))), (v4f32 VECREG:$src)>;
4276 def : Pat<(v4f32 (bitconvert (v2f64 VECREG:$src))), (v4f32 VECREG:$src)>;
4277
4278 def : Pat<(v2f64 (bitconvert (v16i8 VECREG:$src))), (v2f64 VECREG:$src)>;
4279 def : Pat<(v2f64 (bitconvert (v8i16 VECREG:$src))), (v2f64 VECREG:$src)>;
4280 def : Pat<(v2f64 (bitconvert (v4i32 VECREG:$src))), (v2f64 VECREG:$src)>;
4281 def : Pat<(v2f64 (bitconvert (v2i64 VECREG:$src))), (v2f64 VECREG:$src)>;
4282 def : Pat<(v2f64 (bitconvert (v2f64 VECREG:$src))), (v2f64 VECREG:$src)>;
4283
4284 def : Pat<(f32 (bitconvert (i32 R32C:$src))), (f32 R32FP:$src)>;
4285 def : Pat<(f64 (bitconvert (i64 R64C:$src))), (f64 R64FP:$src)>;
4286
4287 //===----------------------------------------------------------------------===//
4288 // Instruction patterns:
4289 //===----------------------------------------------------------------------===//
4290
4291 // General 32-bit constants:
4292 def : Pat<(i32 imm:$imm),
4293           (IOHLr32 (ILHUr32 (HI16 imm:$imm)), (LO16 imm:$imm))>;
4294
4295 // Single precision float constants:
4296 def : Pat<(f32 fpimm:$imm),
4297           (IOHLf32 (ILHUf32 (HI16_f32 fpimm:$imm)), (LO16_f32 fpimm:$imm))>;
4298
4299 // General constant 32-bit vectors
4300 def : Pat<(v4i32 v4i32Imm:$imm),
4301           (IOHLv4i32 (v4i32 (ILHUv4i32 (HI16_vec v4i32Imm:$imm))),
4302                      (LO16_vec v4i32Imm:$imm))>;
4303
4304 // 8-bit constants
4305 def : Pat<(i8 imm:$imm),
4306           (ILHr8 imm:$imm)>;
4307
4308 //===----------------------------------------------------------------------===//
4309 // Call instruction patterns:
4310 //===----------------------------------------------------------------------===//
4311 // Return void
4312 def : Pat<(ret),
4313           (RET)>;
4314
4315 //===----------------------------------------------------------------------===//
4316 // Zero/Any/Sign extensions
4317 //===----------------------------------------------------------------------===//
4318
4319 // sext 8->32: Sign extend bytes to words
4320 def : Pat<(sext_inreg R32C:$rSrc, i8),
4321           (XSHWr32 (XSBHr32 R32C:$rSrc))>;
4322
4323 def : Pat<(i32 (sext R8C:$rSrc)),
4324           (XSHWr16 (XSBHr8 R8C:$rSrc))>;
4325
4326 // zext 8->16: Zero extend bytes to halfwords
4327 def : Pat<(i16 (zext R8C:$rSrc)),
4328           (ANDHIi8i16 R8C:$rSrc, 0xff)>;
4329
4330 // zext 8->32: Zero extend bytes to words
4331 def : Pat<(i32 (zext R8C:$rSrc)),
4332           (ANDIi8i32 R8C:$rSrc, 0xff)>;
4333
4334 // anyext 8->16: Extend 8->16 bits, irrespective of sign
4335 def : Pat<(i16 (anyext R8C:$rSrc)),
4336           (ORHIi8i16 R8C:$rSrc, 0)>;
4337
4338 // anyext 8->32: Extend 8->32 bits, irrespective of sign
4339 def : Pat<(i32 (anyext R8C:$rSrc)),
4340           (ORIi8i32 R8C:$rSrc, 0)>;
4341
4342 // zext 16->32: Zero extend halfwords to words
4343 def : Pat<(i32 (zext R16C:$rSrc)),
4344           (ANDi16i32 R16C:$rSrc, (ILAr32 0xffff))>;
4345
4346 def : Pat<(i32 (zext (and R16C:$rSrc, 0xf))),
4347           (ANDIi16i32 R16C:$rSrc, 0xf)>;
4348
4349 def : Pat<(i32 (zext (and R16C:$rSrc, 0xff))),
4350           (ANDIi16i32 R16C:$rSrc, 0xff)>;
4351
4352 def : Pat<(i32 (zext (and R16C:$rSrc, 0xfff))),
4353           (ANDIi16i32 R16C:$rSrc, 0xfff)>;
4354
4355 // anyext 16->32: Extend 16->32 bits, irrespective of sign
4356 def : Pat<(i32 (anyext R16C:$rSrc)),
4357           (ORIi16i32 R16C:$rSrc, 0)>;
4358
4359 //===----------------------------------------------------------------------===//
4360 // Truncates:
4361 // These truncates are for the SPU's supported types (i8, i16, i32). i64 and
4362 // above are custom lowered.
4363 //===----------------------------------------------------------------------===//
4364
4365 def : Pat<(i8 (trunc GPRC:$src)),
4366           (ORi8_v16i8
4367             (SHUFBgprc GPRC:$src, GPRC:$src,
4368                        (IOHLv4i32 (ILHUv4i32 0x0f0f), 0x0f0f)))>;
4369
4370 def : Pat<(i8 (trunc R64C:$src)),
4371           (ORi8_v16i8
4372             (SHUFBv2i64_m32
4373               (ORv2i64_i64 R64C:$src),
4374               (ORv2i64_i64 R64C:$src),
4375               (IOHLv4i32 (ILHUv4i32 0x0707), 0x0707)))>;
4376
4377 def : Pat<(i8 (trunc R32C:$src)),
4378           (ORi8_v16i8
4379             (SHUFBv4i32_m32
4380                (ORv4i32_i32 R32C:$src),
4381                (ORv4i32_i32 R32C:$src),
4382                (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4383
4384 def : Pat<(i8 (trunc R16C:$src)),
4385           (ORi8_v16i8
4386             (SHUFBv4i32_m32
4387                (ORv8i16_i16 R16C:$src),
4388                (ORv8i16_i16 R16C:$src),
4389                (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4390
4391 def : Pat<(i16 (trunc GPRC:$src)),
4392           (ORi16_v8i16
4393             (SHUFBgprc GPRC:$src, GPRC:$src,
4394                        (IOHLv4i32 (ILHUv4i32 0x0e0f), 0x0e0f)))>;
4395
4396 def : Pat<(i16 (trunc R64C:$src)),
4397           (ORi16_v8i16
4398             (SHUFBv2i64_m32
4399               (ORv2i64_i64 R64C:$src),
4400               (ORv2i64_i64 R64C:$src),
4401               (IOHLv4i32 (ILHUv4i32 0x0607), 0x0607)))>;
4402
4403 def : Pat<(i16 (trunc R32C:$src)),
4404           (ORi16_v8i16
4405             (SHUFBv4i32_m32
4406                (ORv4i32_i32 R32C:$src),
4407                (ORv4i32_i32 R32C:$src),
4408                (IOHLv4i32 (ILHUv4i32 0x0203), 0x0203)))>;
4409
4410 def : Pat<(i32 (trunc GPRC:$src)),
4411           (ORi32_v4i32
4412             (SHUFBgprc GPRC:$src, GPRC:$src,
4413                        (IOHLv4i32 (ILHUv4i32 0x0c0d), 0x0e0f)))>;
4414
4415 def : Pat<(i32 (trunc R64C:$src)),
4416           (ORi32_v4i32
4417             (SHUFBv2i64_m32
4418               (ORv2i64_i64 R64C:$src),
4419               (ORv2i64_i64 R64C:$src),
4420               (IOHLv4i32 (ILHUv4i32 0x0405), 0x0607)))>;
4421
4422 //===----------------------------------------------------------------------===//
4423 // Address generation: SPU, like PPC, has to split addresses into high and
4424 // low parts in order to load them into a register.
4425 //===----------------------------------------------------------------------===//
4426
4427 def : Pat<(SPUaform tglobaladdr:$in, 0),  (ILAlsa tglobaladdr:$in)>;
4428 def : Pat<(SPUaform texternalsym:$in, 0), (ILAlsa texternalsym:$in)>;
4429 def : Pat<(SPUaform tjumptable:$in, 0),   (ILAlsa tjumptable:$in)>;
4430 def : Pat<(SPUaform tconstpool:$in, 0),   (ILAlsa  tconstpool:$in)>;
4431
4432 def : Pat<(SPUindirect (SPUhi tglobaladdr:$in, 0),
4433                        (SPUlo tglobaladdr:$in, 0)),
4434           (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
4435
4436 def : Pat<(SPUindirect (SPUhi texternalsym:$in, 0),
4437                        (SPUlo texternalsym:$in, 0)),
4438           (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4439
4440 def : Pat<(SPUindirect (SPUhi tjumptable:$in, 0),
4441                        (SPUlo tjumptable:$in, 0)),
4442           (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
4443
4444 def : Pat<(SPUindirect (SPUhi tconstpool:$in, 0),
4445                        (SPUlo tconstpool:$in, 0)),
4446           (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
4447
4448 def : Pat<(SPUindirect R32C:$sp, i32ImmSExt10:$imm),
4449           (AIr32 R32C:$sp, i32ImmSExt10:$imm)>;
4450
4451 def : Pat<(SPUindirect R32C:$sp, imm:$imm),
4452           (Ar32 R32C:$sp,
4453                 (IOHLr32 (ILHUr32 (HI16 imm:$imm)), (LO16 imm:$imm)))>;
4454
4455 def : Pat<(add (SPUhi tglobaladdr:$in, 0), (SPUlo tglobaladdr:$in, 0)),
4456           (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
4457
4458 def : Pat<(add (SPUhi texternalsym:$in, 0), (SPUlo texternalsym:$in, 0)),
4459           (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4460
4461 def : Pat<(add (SPUhi tjumptable:$in, 0), (SPUlo tjumptable:$in, 0)),
4462           (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
4463
4464 def : Pat<(add (SPUhi tconstpool:$in, 0), (SPUlo tconstpool:$in, 0)),
4465           (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
4466
4467 // Instrinsics:
4468 include "CellSDKIntrinsics.td"
4469 // 64-bit "instructions"/support
4470 include "SPU64InstrInfo.td"