blob: eb9a819aa3cbd809583d04a180e16bb8ee8a84e6 [file] [log] [blame]
Akira Hatanaka44ebe002013-03-14 19:09:52 +00001//===-- MipsSEISelLowering.cpp - MipsSE DAG Lowering Interface --*- C++ -*-===//
Akira Hatanaka96ca1822013-03-13 00:54:29 +00002//
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//
10// Subclass of MipsTargetLowering specialized for mips32/64.
11//
12//===----------------------------------------------------------------------===//
13#include "MipsSEISelLowering.h"
14#include "MipsRegisterInfo.h"
15#include "MipsTargetMachine.h"
16#include "llvm/CodeGen/MachineInstrBuilder.h"
17#include "llvm/CodeGen/MachineRegisterInfo.h"
Akira Hatanakaa6bbde52013-04-13 02:13:30 +000018#include "llvm/IR/Intrinsics.h"
Akira Hatanaka96ca1822013-03-13 00:54:29 +000019#include "llvm/Support/CommandLine.h"
Daniel Sanders62aeab82013-10-30 13:31:27 +000020#include "llvm/Support/Debug.h"
Hans Wennborg3e9b1c12013-10-30 16:10:10 +000021#include "llvm/Support/raw_ostream.h"
Akira Hatanaka96ca1822013-03-13 00:54:29 +000022#include "llvm/Target/TargetInstrInfo.h"
23
24using namespace llvm;
25
Chandler Carruth84e68b22014-04-22 02:41:26 +000026#define DEBUG_TYPE "mips-isel"
27
Akira Hatanaka96ca1822013-03-13 00:54:29 +000028static cl::opt<bool>
29EnableMipsTailCalls("enable-mips-tail-calls", cl::Hidden,
30 cl::desc("MIPS: Enable tail calls."), cl::init(false));
31
Akira Hatanaka63791212013-09-07 00:52:30 +000032static cl::opt<bool> NoDPLoadStore("mno-ldc1-sdc1", cl::init(false),
33 cl::desc("Expand double precision loads and "
34 "stores to their single precision "
35 "counterparts"));
36
Akira Hatanaka96ca1822013-03-13 00:54:29 +000037MipsSETargetLowering::MipsSETargetLowering(MipsTargetMachine &TM)
38 : MipsTargetLowering(TM) {
39 // Set up the register classes
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +000040 addRegisterClass(MVT::i32, &Mips::GPR32RegClass);
Akira Hatanaka96ca1822013-03-13 00:54:29 +000041
Daniel Sanders5e94e682014-03-27 16:42:17 +000042 if (isGP64bit())
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +000043 addRegisterClass(MVT::i64, &Mips::GPR64RegClass);
Akira Hatanaka96ca1822013-03-13 00:54:29 +000044
Daniel Sanders36c671e2013-09-27 09:44:59 +000045 if (Subtarget->hasDSP() || Subtarget->hasMSA()) {
46 // Expand all truncating stores and extending loads.
47 unsigned FirstVT = (unsigned)MVT::FIRST_VECTOR_VALUETYPE;
48 unsigned LastVT = (unsigned)MVT::LAST_VECTOR_VALUETYPE;
49
50 for (unsigned VT0 = FirstVT; VT0 <= LastVT; ++VT0) {
51 for (unsigned VT1 = FirstVT; VT1 <= LastVT; ++VT1)
52 setTruncStoreAction((MVT::SimpleValueType)VT0,
53 (MVT::SimpleValueType)VT1, Expand);
54
55 setLoadExtAction(ISD::SEXTLOAD, (MVT::SimpleValueType)VT0, Expand);
56 setLoadExtAction(ISD::ZEXTLOAD, (MVT::SimpleValueType)VT0, Expand);
57 setLoadExtAction(ISD::EXTLOAD, (MVT::SimpleValueType)VT0, Expand);
58 }
59 }
60
Akira Hatanaka96ca1822013-03-13 00:54:29 +000061 if (Subtarget->hasDSP()) {
62 MVT::SimpleValueType VecTys[2] = {MVT::v2i16, MVT::v4i8};
63
64 for (unsigned i = 0; i < array_lengthof(VecTys); ++i) {
Akira Hatanaka654655f2013-08-14 00:53:38 +000065 addRegisterClass(VecTys[i], &Mips::DSPRRegClass);
Akira Hatanaka96ca1822013-03-13 00:54:29 +000066
67 // Expand all builtin opcodes.
68 for (unsigned Opc = 0; Opc < ISD::BUILTIN_OP_END; ++Opc)
69 setOperationAction(Opc, VecTys[i], Expand);
70
Akira Hatanaka2f088222013-04-13 00:55:41 +000071 setOperationAction(ISD::ADD, VecTys[i], Legal);
72 setOperationAction(ISD::SUB, VecTys[i], Legal);
Akira Hatanaka96ca1822013-03-13 00:54:29 +000073 setOperationAction(ISD::LOAD, VecTys[i], Legal);
74 setOperationAction(ISD::STORE, VecTys[i], Legal);
75 setOperationAction(ISD::BITCAST, VecTys[i], Legal);
76 }
Akira Hatanaka1ebb2a12013-04-19 23:21:32 +000077
78 setTargetDAGCombine(ISD::SHL);
79 setTargetDAGCombine(ISD::SRA);
80 setTargetDAGCombine(ISD::SRL);
Akira Hatanaka68741cc2013-04-30 22:37:26 +000081 setTargetDAGCombine(ISD::SETCC);
82 setTargetDAGCombine(ISD::VSELECT);
Akira Hatanaka96ca1822013-03-13 00:54:29 +000083 }
84
Akira Hatanaka2f088222013-04-13 00:55:41 +000085 if (Subtarget->hasDSPR2())
86 setOperationAction(ISD::MUL, MVT::v2i16, Legal);
87
Jack Carter3a2c2d42013-08-13 20:54:07 +000088 if (Subtarget->hasMSA()) {
Daniel Sandersc65f58a2013-09-11 10:15:48 +000089 addMSAIntType(MVT::v16i8, &Mips::MSA128BRegClass);
90 addMSAIntType(MVT::v8i16, &Mips::MSA128HRegClass);
91 addMSAIntType(MVT::v4i32, &Mips::MSA128WRegClass);
92 addMSAIntType(MVT::v2i64, &Mips::MSA128DRegClass);
93 addMSAFloatType(MVT::v8f16, &Mips::MSA128HRegClass);
94 addMSAFloatType(MVT::v4f32, &Mips::MSA128WRegClass);
95 addMSAFloatType(MVT::v2f64, &Mips::MSA128DRegClass);
Daniel Sandersf7456c72013-09-23 13:22:24 +000096
Daniel Sandersa4c8f3a2013-09-23 14:03:12 +000097 setTargetDAGCombine(ISD::AND);
Daniel Sanders53fe6c42013-10-30 13:51:01 +000098 setTargetDAGCombine(ISD::OR);
Daniel Sandersa4c8f3a2013-09-23 14:03:12 +000099 setTargetDAGCombine(ISD::SRA);
Daniel Sanderse1d24352013-09-24 12:04:44 +0000100 setTargetDAGCombine(ISD::VSELECT);
Daniel Sandersf7456c72013-09-23 13:22:24 +0000101 setTargetDAGCombine(ISD::XOR);
Jack Carter3a2c2d42013-08-13 20:54:07 +0000102 }
103
Reed Kotlerc03807a2013-08-30 19:40:56 +0000104 if (!Subtarget->mipsSEUsesSoftFloat()) {
Akira Hatanaka96ca1822013-03-13 00:54:29 +0000105 addRegisterClass(MVT::f32, &Mips::FGR32RegClass);
106
107 // When dealing with single precision only, use libcalls
108 if (!Subtarget->isSingleFloat()) {
Akira Hatanakabfb66242013-08-20 23:38:40 +0000109 if (Subtarget->isFP64bit())
Akira Hatanaka96ca1822013-03-13 00:54:29 +0000110 addRegisterClass(MVT::f64, &Mips::FGR64RegClass);
111 else
112 addRegisterClass(MVT::f64, &Mips::AFGR64RegClass);
113 }
114 }
115
Akira Hatanakabe8612f2013-03-30 01:36:35 +0000116 setOperationAction(ISD::SMUL_LOHI, MVT::i32, Custom);
117 setOperationAction(ISD::UMUL_LOHI, MVT::i32, Custom);
118 setOperationAction(ISD::MULHS, MVT::i32, Custom);
119 setOperationAction(ISD::MULHU, MVT::i32, Custom);
120
Kai Nacke93fe5e82014-03-20 11:51:58 +0000121 if (Subtarget->hasCnMips())
122 setOperationAction(ISD::MUL, MVT::i64, Legal);
Daniel Sanders3d849352014-04-14 15:44:42 +0000123 else if (isGP64bit())
Kai Nacke93fe5e82014-03-20 11:51:58 +0000124 setOperationAction(ISD::MUL, MVT::i64, Custom);
125
Daniel Sanders3d849352014-04-14 15:44:42 +0000126 if (isGP64bit()) {
Akira Hatanaka4f1130e2013-04-11 19:29:26 +0000127 setOperationAction(ISD::MULHS, MVT::i64, Custom);
128 setOperationAction(ISD::MULHU, MVT::i64, Custom);
Akira Hatanaka4f1130e2013-04-11 19:29:26 +0000129 }
Akira Hatanakabe8612f2013-03-30 01:36:35 +0000130
Akira Hatanakaa6bbde52013-04-13 02:13:30 +0000131 setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::i64, Custom);
132 setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::i64, Custom);
133
Akira Hatanakabe8612f2013-03-30 01:36:35 +0000134 setOperationAction(ISD::SDIVREM, MVT::i32, Custom);
135 setOperationAction(ISD::UDIVREM, MVT::i32, Custom);
136 setOperationAction(ISD::SDIVREM, MVT::i64, Custom);
137 setOperationAction(ISD::UDIVREM, MVT::i64, Custom);
Akira Hatanaka96ca1822013-03-13 00:54:29 +0000138 setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Custom);
139 setOperationAction(ISD::LOAD, MVT::i32, Custom);
140 setOperationAction(ISD::STORE, MVT::i32, Custom);
141
Akira Hatanaka9efcd762013-03-30 01:42:24 +0000142 setTargetDAGCombine(ISD::ADDE);
143 setTargetDAGCombine(ISD::SUBE);
Akira Hatanaka5832fc62013-06-26 18:48:17 +0000144 setTargetDAGCombine(ISD::MUL);
Akira Hatanaka9efcd762013-03-30 01:42:24 +0000145
Daniel Sandersce09d072013-08-28 12:14:50 +0000146 setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom);
Daniel Sanderse6ed5b72013-08-28 12:04:29 +0000147 setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::Other, Custom);
148 setOperationAction(ISD::INTRINSIC_VOID, MVT::Other, Custom);
149
Akira Hatanaka63791212013-09-07 00:52:30 +0000150 if (NoDPLoadStore) {
151 setOperationAction(ISD::LOAD, MVT::f64, Custom);
152 setOperationAction(ISD::STORE, MVT::f64, Custom);
153 }
154
Akira Hatanaka96ca1822013-03-13 00:54:29 +0000155 computeRegisterProperties();
156}
157
158const MipsTargetLowering *
159llvm::createMipsSETargetLowering(MipsTargetMachine &TM) {
160 return new MipsSETargetLowering(TM);
161}
162
Daniel Sanders7a289d02013-09-23 12:02:46 +0000163// Enable MSA support for the given integer type and Register class.
Daniel Sanders3c9a0ad2013-08-23 10:10:13 +0000164void MipsSETargetLowering::
Daniel Sandersc65f58a2013-09-11 10:15:48 +0000165addMSAIntType(MVT::SimpleValueType Ty, const TargetRegisterClass *RC) {
166 addRegisterClass(Ty, RC);
167
168 // Expand all builtin opcodes.
169 for (unsigned Opc = 0; Opc < ISD::BUILTIN_OP_END; ++Opc)
170 setOperationAction(Opc, Ty, Expand);
171
172 setOperationAction(ISD::BITCAST, Ty, Legal);
173 setOperationAction(ISD::LOAD, Ty, Legal);
174 setOperationAction(ISD::STORE, Ty, Legal);
Daniel Sandersa4c8f3a2013-09-23 14:03:12 +0000175 setOperationAction(ISD::EXTRACT_VECTOR_ELT, Ty, Custom);
176 setOperationAction(ISD::INSERT_VECTOR_ELT, Ty, Legal);
Daniel Sanders7a289d02013-09-23 12:02:46 +0000177 setOperationAction(ISD::BUILD_VECTOR, Ty, Custom);
Daniel Sandersc65f58a2013-09-11 10:15:48 +0000178
Daniel Sandersfa5ab1c2013-09-11 10:28:16 +0000179 setOperationAction(ISD::ADD, Ty, Legal);
Daniel Sanders8ca81e42013-09-23 12:57:42 +0000180 setOperationAction(ISD::AND, Ty, Legal);
Daniel Sandersfbcb5822013-09-11 11:58:30 +0000181 setOperationAction(ISD::CTLZ, Ty, Legal);
Daniel Sanders766cb692013-09-23 13:40:21 +0000182 setOperationAction(ISD::CTPOP, Ty, Legal);
Daniel Sandersfbcb5822013-09-11 11:58:30 +0000183 setOperationAction(ISD::MUL, Ty, Legal);
Daniel Sanders8ca81e42013-09-23 12:57:42 +0000184 setOperationAction(ISD::OR, Ty, Legal);
Daniel Sanders607952b2013-09-11 10:38:58 +0000185 setOperationAction(ISD::SDIV, Ty, Legal);
Daniel Sanders0210dd42013-10-01 10:22:35 +0000186 setOperationAction(ISD::SREM, Ty, Legal);
Daniel Sandersfbcb5822013-09-11 11:58:30 +0000187 setOperationAction(ISD::SHL, Ty, Legal);
188 setOperationAction(ISD::SRA, Ty, Legal);
189 setOperationAction(ISD::SRL, Ty, Legal);
190 setOperationAction(ISD::SUB, Ty, Legal);
Daniel Sanders607952b2013-09-11 10:38:58 +0000191 setOperationAction(ISD::UDIV, Ty, Legal);
Daniel Sanders0210dd42013-10-01 10:22:35 +0000192 setOperationAction(ISD::UREM, Ty, Legal);
Daniel Sanderse5087042013-09-24 14:02:15 +0000193 setOperationAction(ISD::VECTOR_SHUFFLE, Ty, Custom);
Daniel Sanderse1d24352013-09-24 12:04:44 +0000194 setOperationAction(ISD::VSELECT, Ty, Legal);
Daniel Sanders8ca81e42013-09-23 12:57:42 +0000195 setOperationAction(ISD::XOR, Ty, Legal);
Daniel Sandersfd538dc2013-09-24 10:46:19 +0000196
Daniel Sanders015972b2013-10-11 10:00:06 +0000197 if (Ty == MVT::v4i32 || Ty == MVT::v2i64) {
198 setOperationAction(ISD::FP_TO_SINT, Ty, Legal);
199 setOperationAction(ISD::FP_TO_UINT, Ty, Legal);
200 setOperationAction(ISD::SINT_TO_FP, Ty, Legal);
201 setOperationAction(ISD::UINT_TO_FP, Ty, Legal);
202 }
203
Daniel Sandersfd538dc2013-09-24 10:46:19 +0000204 setOperationAction(ISD::SETCC, Ty, Legal);
205 setCondCodeAction(ISD::SETNE, Ty, Expand);
206 setCondCodeAction(ISD::SETGE, Ty, Expand);
207 setCondCodeAction(ISD::SETGT, Ty, Expand);
208 setCondCodeAction(ISD::SETUGE, Ty, Expand);
209 setCondCodeAction(ISD::SETUGT, Ty, Expand);
Daniel Sandersc65f58a2013-09-11 10:15:48 +0000210}
211
Daniel Sanders7a289d02013-09-23 12:02:46 +0000212// Enable MSA support for the given floating-point type and Register class.
Daniel Sandersc65f58a2013-09-11 10:15:48 +0000213void MipsSETargetLowering::
214addMSAFloatType(MVT::SimpleValueType Ty, const TargetRegisterClass *RC) {
Daniel Sanders3c9a0ad2013-08-23 10:10:13 +0000215 addRegisterClass(Ty, RC);
Jack Carterbabdcc82013-08-15 12:24:57 +0000216
217 // Expand all builtin opcodes.
218 for (unsigned Opc = 0; Opc < ISD::BUILTIN_OP_END; ++Opc)
219 setOperationAction(Opc, Ty, Expand);
220
221 setOperationAction(ISD::LOAD, Ty, Legal);
222 setOperationAction(ISD::STORE, Ty, Legal);
223 setOperationAction(ISD::BITCAST, Ty, Legal);
Daniel Sandersa4c8f3a2013-09-23 14:03:12 +0000224 setOperationAction(ISD::EXTRACT_VECTOR_ELT, Ty, Legal);
Daniel Sandersa5150702013-09-27 12:31:32 +0000225 setOperationAction(ISD::INSERT_VECTOR_ELT, Ty, Legal);
Daniel Sanders1dfddc72013-10-15 13:14:41 +0000226 setOperationAction(ISD::BUILD_VECTOR, Ty, Custom);
Daniel Sandersf5bd9372013-09-11 10:51:30 +0000227
228 if (Ty != MVT::v8f16) {
Daniel Sanders4f3ff1b2013-09-24 13:02:08 +0000229 setOperationAction(ISD::FABS, Ty, Legal);
Daniel Sandersf5bd9372013-09-11 10:51:30 +0000230 setOperationAction(ISD::FADD, Ty, Legal);
231 setOperationAction(ISD::FDIV, Ty, Legal);
Daniel Sandersa9521602013-10-23 10:36:52 +0000232 setOperationAction(ISD::FEXP2, Ty, Legal);
Daniel Sandersf5bd9372013-09-11 10:51:30 +0000233 setOperationAction(ISD::FLOG2, Ty, Legal);
Daniel Sandersd7103f32013-10-11 10:14:25 +0000234 setOperationAction(ISD::FMA, Ty, Legal);
Daniel Sandersf5bd9372013-09-11 10:51:30 +0000235 setOperationAction(ISD::FMUL, Ty, Legal);
236 setOperationAction(ISD::FRINT, Ty, Legal);
237 setOperationAction(ISD::FSQRT, Ty, Legal);
238 setOperationAction(ISD::FSUB, Ty, Legal);
Daniel Sanderse1d24352013-09-24 12:04:44 +0000239 setOperationAction(ISD::VSELECT, Ty, Legal);
Daniel Sandersfd538dc2013-09-24 10:46:19 +0000240
241 setOperationAction(ISD::SETCC, Ty, Legal);
242 setCondCodeAction(ISD::SETOGE, Ty, Expand);
243 setCondCodeAction(ISD::SETOGT, Ty, Expand);
244 setCondCodeAction(ISD::SETUGE, Ty, Expand);
245 setCondCodeAction(ISD::SETUGT, Ty, Expand);
246 setCondCodeAction(ISD::SETGE, Ty, Expand);
247 setCondCodeAction(ISD::SETGT, Ty, Expand);
Daniel Sandersf5bd9372013-09-11 10:51:30 +0000248 }
Jack Carterbabdcc82013-08-15 12:24:57 +0000249}
Akira Hatanaka96ca1822013-03-13 00:54:29 +0000250
251bool
Matt Arsenault25793a32014-02-05 23:15:53 +0000252MipsSETargetLowering::allowsUnalignedMemoryAccesses(EVT VT,
253 unsigned,
254 bool *Fast) const {
Akira Hatanaka96ca1822013-03-13 00:54:29 +0000255 MVT::SimpleValueType SVT = VT.getSimpleVT().SimpleTy;
256
257 switch (SVT) {
258 case MVT::i64:
259 case MVT::i32:
260 if (Fast)
261 *Fast = true;
262 return true;
263 default:
264 return false;
265 }
266}
267
Akira Hatanakabe8612f2013-03-30 01:36:35 +0000268SDValue MipsSETargetLowering::LowerOperation(SDValue Op,
269 SelectionDAG &DAG) const {
270 switch(Op.getOpcode()) {
Akira Hatanaka63791212013-09-07 00:52:30 +0000271 case ISD::LOAD: return lowerLOAD(Op, DAG);
272 case ISD::STORE: return lowerSTORE(Op, DAG);
Akira Hatanakabe8612f2013-03-30 01:36:35 +0000273 case ISD::SMUL_LOHI: return lowerMulDiv(Op, MipsISD::Mult, true, true, DAG);
274 case ISD::UMUL_LOHI: return lowerMulDiv(Op, MipsISD::Multu, true, true, DAG);
275 case ISD::MULHS: return lowerMulDiv(Op, MipsISD::Mult, false, true, DAG);
276 case ISD::MULHU: return lowerMulDiv(Op, MipsISD::Multu, false, true, DAG);
277 case ISD::MUL: return lowerMulDiv(Op, MipsISD::Mult, true, false, DAG);
278 case ISD::SDIVREM: return lowerMulDiv(Op, MipsISD::DivRem, true, true, DAG);
Akira Hatanakad8fb0322013-04-22 20:13:37 +0000279 case ISD::UDIVREM: return lowerMulDiv(Op, MipsISD::DivRemU, true, true,
280 DAG);
Akira Hatanakaa6bbde52013-04-13 02:13:30 +0000281 case ISD::INTRINSIC_WO_CHAIN: return lowerINTRINSIC_WO_CHAIN(Op, DAG);
282 case ISD::INTRINSIC_W_CHAIN: return lowerINTRINSIC_W_CHAIN(Op, DAG);
Daniel Sanderse6ed5b72013-08-28 12:04:29 +0000283 case ISD::INTRINSIC_VOID: return lowerINTRINSIC_VOID(Op, DAG);
Daniel Sandersa4c8f3a2013-09-23 14:03:12 +0000284 case ISD::EXTRACT_VECTOR_ELT: return lowerEXTRACT_VECTOR_ELT(Op, DAG);
Daniel Sanders7a289d02013-09-23 12:02:46 +0000285 case ISD::BUILD_VECTOR: return lowerBUILD_VECTOR(Op, DAG);
Daniel Sanderse5087042013-09-24 14:02:15 +0000286 case ISD::VECTOR_SHUFFLE: return lowerVECTOR_SHUFFLE(Op, DAG);
Akira Hatanakabe8612f2013-03-30 01:36:35 +0000287 }
288
289 return MipsTargetLowering::LowerOperation(Op, DAG);
290}
291
Akira Hatanaka9efcd762013-03-30 01:42:24 +0000292// selectMADD -
293// Transforms a subgraph in CurDAG if the following pattern is found:
294// (addc multLo, Lo0), (adde multHi, Hi0),
295// where,
296// multHi/Lo: product of multiplication
297// Lo0: initial value of Lo register
298// Hi0: initial value of Hi register
299// Return true if pattern matching was successful.
300static bool selectMADD(SDNode *ADDENode, SelectionDAG *CurDAG) {
301 // ADDENode's second operand must be a flag output of an ADDC node in order
302 // for the matching to be successful.
303 SDNode *ADDCNode = ADDENode->getOperand(2).getNode();
304
305 if (ADDCNode->getOpcode() != ISD::ADDC)
306 return false;
307
308 SDValue MultHi = ADDENode->getOperand(0);
309 SDValue MultLo = ADDCNode->getOperand(0);
310 SDNode *MultNode = MultHi.getNode();
311 unsigned MultOpc = MultHi.getOpcode();
312
313 // MultHi and MultLo must be generated by the same node,
314 if (MultLo.getNode() != MultNode)
315 return false;
316
317 // and it must be a multiplication.
318 if (MultOpc != ISD::SMUL_LOHI && MultOpc != ISD::UMUL_LOHI)
319 return false;
320
321 // MultLo amd MultHi must be the first and second output of MultNode
322 // respectively.
323 if (MultHi.getResNo() != 1 || MultLo.getResNo() != 0)
324 return false;
325
326 // Transform this to a MADD only if ADDENode and ADDCNode are the only users
327 // of the values of MultNode, in which case MultNode will be removed in later
328 // phases.
329 // If there exist users other than ADDENode or ADDCNode, this function returns
330 // here, which will result in MultNode being mapped to a single MULT
331 // instruction node rather than a pair of MULT and MADD instructions being
332 // produced.
333 if (!MultHi.hasOneUse() || !MultLo.hasOneUse())
334 return false;
335
Andrew Trickef9de2a2013-05-25 02:42:55 +0000336 SDLoc DL(ADDENode);
Akira Hatanaka9efcd762013-03-30 01:42:24 +0000337
338 // Initialize accumulator.
Akira Hatanakad98c99f2013-10-15 01:12:50 +0000339 SDValue ACCIn = CurDAG->getNode(MipsISD::MTLOHI, DL, MVT::Untyped,
Akira Hatanaka9efcd762013-03-30 01:42:24 +0000340 ADDCNode->getOperand(1),
341 ADDENode->getOperand(1));
342
343 // create MipsMAdd(u) node
344 MultOpc = MultOpc == ISD::UMUL_LOHI ? MipsISD::MAddu : MipsISD::MAdd;
345
346 SDValue MAdd = CurDAG->getNode(MultOpc, DL, MVT::Untyped,
347 MultNode->getOperand(0),// Factor 0
348 MultNode->getOperand(1),// Factor 1
349 ACCIn);
350
351 // replace uses of adde and addc here
352 if (!SDValue(ADDCNode, 0).use_empty()) {
Akira Hatanakad98c99f2013-10-15 01:12:50 +0000353 SDValue LoOut = CurDAG->getNode(MipsISD::MFLO, DL, MVT::i32, MAdd);
Akira Hatanaka9efcd762013-03-30 01:42:24 +0000354 CurDAG->ReplaceAllUsesOfValueWith(SDValue(ADDCNode, 0), LoOut);
355 }
356 if (!SDValue(ADDENode, 0).use_empty()) {
Akira Hatanakad98c99f2013-10-15 01:12:50 +0000357 SDValue HiOut = CurDAG->getNode(MipsISD::MFHI, DL, MVT::i32, MAdd);
Akira Hatanaka9efcd762013-03-30 01:42:24 +0000358 CurDAG->ReplaceAllUsesOfValueWith(SDValue(ADDENode, 0), HiOut);
359 }
360
361 return true;
362}
363
364// selectMSUB -
365// Transforms a subgraph in CurDAG if the following pattern is found:
366// (addc Lo0, multLo), (sube Hi0, multHi),
367// where,
368// multHi/Lo: product of multiplication
369// Lo0: initial value of Lo register
370// Hi0: initial value of Hi register
371// Return true if pattern matching was successful.
372static bool selectMSUB(SDNode *SUBENode, SelectionDAG *CurDAG) {
373 // SUBENode's second operand must be a flag output of an SUBC node in order
374 // for the matching to be successful.
375 SDNode *SUBCNode = SUBENode->getOperand(2).getNode();
376
377 if (SUBCNode->getOpcode() != ISD::SUBC)
378 return false;
379
380 SDValue MultHi = SUBENode->getOperand(1);
381 SDValue MultLo = SUBCNode->getOperand(1);
382 SDNode *MultNode = MultHi.getNode();
383 unsigned MultOpc = MultHi.getOpcode();
384
385 // MultHi and MultLo must be generated by the same node,
386 if (MultLo.getNode() != MultNode)
387 return false;
388
389 // and it must be a multiplication.
390 if (MultOpc != ISD::SMUL_LOHI && MultOpc != ISD::UMUL_LOHI)
391 return false;
392
393 // MultLo amd MultHi must be the first and second output of MultNode
394 // respectively.
395 if (MultHi.getResNo() != 1 || MultLo.getResNo() != 0)
396 return false;
397
398 // Transform this to a MSUB only if SUBENode and SUBCNode are the only users
399 // of the values of MultNode, in which case MultNode will be removed in later
400 // phases.
401 // If there exist users other than SUBENode or SUBCNode, this function returns
402 // here, which will result in MultNode being mapped to a single MULT
403 // instruction node rather than a pair of MULT and MSUB instructions being
404 // produced.
405 if (!MultHi.hasOneUse() || !MultLo.hasOneUse())
406 return false;
407
Andrew Trickef9de2a2013-05-25 02:42:55 +0000408 SDLoc DL(SUBENode);
Akira Hatanaka9efcd762013-03-30 01:42:24 +0000409
410 // Initialize accumulator.
Akira Hatanakad98c99f2013-10-15 01:12:50 +0000411 SDValue ACCIn = CurDAG->getNode(MipsISD::MTLOHI, DL, MVT::Untyped,
Akira Hatanaka9efcd762013-03-30 01:42:24 +0000412 SUBCNode->getOperand(0),
413 SUBENode->getOperand(0));
414
415 // create MipsSub(u) node
416 MultOpc = MultOpc == ISD::UMUL_LOHI ? MipsISD::MSubu : MipsISD::MSub;
417
418 SDValue MSub = CurDAG->getNode(MultOpc, DL, MVT::Glue,
419 MultNode->getOperand(0),// Factor 0
420 MultNode->getOperand(1),// Factor 1
421 ACCIn);
422
423 // replace uses of sube and subc here
424 if (!SDValue(SUBCNode, 0).use_empty()) {
Akira Hatanakad98c99f2013-10-15 01:12:50 +0000425 SDValue LoOut = CurDAG->getNode(MipsISD::MFLO, DL, MVT::i32, MSub);
Akira Hatanaka9efcd762013-03-30 01:42:24 +0000426 CurDAG->ReplaceAllUsesOfValueWith(SDValue(SUBCNode, 0), LoOut);
427 }
428 if (!SDValue(SUBENode, 0).use_empty()) {
Akira Hatanakad98c99f2013-10-15 01:12:50 +0000429 SDValue HiOut = CurDAG->getNode(MipsISD::MFHI, DL, MVT::i32, MSub);
Akira Hatanaka9efcd762013-03-30 01:42:24 +0000430 CurDAG->ReplaceAllUsesOfValueWith(SDValue(SUBENode, 0), HiOut);
431 }
432
433 return true;
434}
435
436static SDValue performADDECombine(SDNode *N, SelectionDAG &DAG,
437 TargetLowering::DAGCombinerInfo &DCI,
438 const MipsSubtarget *Subtarget) {
439 if (DCI.isBeforeLegalize())
440 return SDValue();
441
442 if (Subtarget->hasMips32() && N->getValueType(0) == MVT::i32 &&
443 selectMADD(N, &DAG))
444 return SDValue(N, 0);
445
446 return SDValue();
447}
448
Daniel Sandersa4c8f3a2013-09-23 14:03:12 +0000449// Fold zero extensions into MipsISD::VEXTRACT_[SZ]EXT_ELT
450//
451// Performs the following transformations:
452// - Changes MipsISD::VEXTRACT_[SZ]EXT_ELT to zero extension if its
453// sign/zero-extension is completely overwritten by the new one performed by
454// the ISD::AND.
455// - Removes redundant zero extensions performed by an ISD::AND.
456static SDValue performANDCombine(SDNode *N, SelectionDAG &DAG,
457 TargetLowering::DAGCombinerInfo &DCI,
458 const MipsSubtarget *Subtarget) {
459 if (!Subtarget->hasMSA())
460 return SDValue();
461
462 SDValue Op0 = N->getOperand(0);
463 SDValue Op1 = N->getOperand(1);
464 unsigned Op0Opcode = Op0->getOpcode();
465
466 // (and (MipsVExtract[SZ]Ext $a, $b, $c), imm:$d)
467 // where $d + 1 == 2^n and n == 32
468 // or $d + 1 == 2^n and n <= 32 and ZExt
469 // -> (MipsVExtractZExt $a, $b, $c)
470 if (Op0Opcode == MipsISD::VEXTRACT_SEXT_ELT ||
471 Op0Opcode == MipsISD::VEXTRACT_ZEXT_ELT) {
472 ConstantSDNode *Mask = dyn_cast<ConstantSDNode>(Op1);
473
474 if (!Mask)
475 return SDValue();
476
477 int32_t Log2IfPositive = (Mask->getAPIntValue() + 1).exactLogBase2();
478
479 if (Log2IfPositive <= 0)
480 return SDValue(); // Mask+1 is not a power of 2
481
482 SDValue Op0Op2 = Op0->getOperand(2);
483 EVT ExtendTy = cast<VTSDNode>(Op0Op2)->getVT();
484 unsigned ExtendTySize = ExtendTy.getSizeInBits();
485 unsigned Log2 = Log2IfPositive;
486
487 if ((Op0Opcode == MipsISD::VEXTRACT_ZEXT_ELT && Log2 >= ExtendTySize) ||
488 Log2 == ExtendTySize) {
489 SDValue Ops[] = { Op0->getOperand(0), Op0->getOperand(1), Op0Op2 };
490 DAG.MorphNodeTo(Op0.getNode(), MipsISD::VEXTRACT_ZEXT_ELT,
Craig Topper131de822014-04-27 19:21:16 +0000491 Op0->getVTList(),
Craig Topper2d2aa0c2014-04-30 07:17:30 +0000492 makeArrayRef(Ops, Op0->getNumOperands()));
Daniel Sandersa4c8f3a2013-09-23 14:03:12 +0000493 return Op0;
494 }
495 }
496
497 return SDValue();
498}
499
Daniel Sanders53fe6c42013-10-30 13:51:01 +0000500// Determine if the specified node is a constant vector splat.
501//
502// Returns true and sets Imm if:
503// * N is a ISD::BUILD_VECTOR representing a constant splat
504//
505// This function is quite similar to MipsSEDAGToDAGISel::selectVSplat. The
506// differences are that it assumes the MSA has already been checked and the
507// arbitrary requirement for a maximum of 32-bit integers isn't applied (and
508// must not be in order for binsri.d to be selectable).
509static bool isVSplat(SDValue N, APInt &Imm, bool IsLittleEndian) {
510 BuildVectorSDNode *Node = dyn_cast<BuildVectorSDNode>(N.getNode());
511
Craig Topper062a2ba2014-04-25 05:30:21 +0000512 if (!Node)
Daniel Sanders53fe6c42013-10-30 13:51:01 +0000513 return false;
514
515 APInt SplatValue, SplatUndef;
516 unsigned SplatBitSize;
517 bool HasAnyUndefs;
518
519 if (!Node->isConstantSplat(SplatValue, SplatUndef, SplatBitSize, HasAnyUndefs,
520 8, !IsLittleEndian))
521 return false;
522
523 Imm = SplatValue;
524
525 return true;
526}
527
Daniel Sandersab94b532013-10-30 15:20:38 +0000528// Test whether the given node is an all-ones build_vector.
529static bool isVectorAllOnes(SDValue N) {
530 // Look through bitcasts. Endianness doesn't matter because we are looking
531 // for an all-ones value.
532 if (N->getOpcode() == ISD::BITCAST)
533 N = N->getOperand(0);
534
535 BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N);
536
537 if (!BVN)
538 return false;
539
540 APInt SplatValue, SplatUndef;
541 unsigned SplatBitSize;
542 bool HasAnyUndefs;
543
544 // Endianness doesn't matter in this context because we are looking for
545 // an all-ones value.
546 if (BVN->isConstantSplat(SplatValue, SplatUndef, SplatBitSize, HasAnyUndefs))
547 return SplatValue.isAllOnesValue();
548
549 return false;
550}
551
552// Test whether N is the bitwise inverse of OfNode.
553static bool isBitwiseInverse(SDValue N, SDValue OfNode) {
554 if (N->getOpcode() != ISD::XOR)
555 return false;
556
557 if (isVectorAllOnes(N->getOperand(0)))
558 return N->getOperand(1) == OfNode;
559
560 if (isVectorAllOnes(N->getOperand(1)))
561 return N->getOperand(0) == OfNode;
562
563 return false;
564}
565
Daniel Sanders53fe6c42013-10-30 13:51:01 +0000566// Perform combines where ISD::OR is the root node.
567//
568// Performs the following transformations:
569// - (or (and $a, $mask), (and $b, $inv_mask)) => (vselect $mask, $a, $b)
570// where $inv_mask is the bitwise inverse of $mask and the 'or' has a 128-bit
571// vector type.
572static SDValue performORCombine(SDNode *N, SelectionDAG &DAG,
573 TargetLowering::DAGCombinerInfo &DCI,
574 const MipsSubtarget *Subtarget) {
575 if (!Subtarget->hasMSA())
576 return SDValue();
577
578 EVT Ty = N->getValueType(0);
579
580 if (!Ty.is128BitVector())
581 return SDValue();
582
583 SDValue Op0 = N->getOperand(0);
584 SDValue Op1 = N->getOperand(1);
585
586 if (Op0->getOpcode() == ISD::AND && Op1->getOpcode() == ISD::AND) {
587 SDValue Op0Op0 = Op0->getOperand(0);
588 SDValue Op0Op1 = Op0->getOperand(1);
589 SDValue Op1Op0 = Op1->getOperand(0);
590 SDValue Op1Op1 = Op1->getOperand(1);
591 bool IsLittleEndian = !Subtarget->isLittle();
592
593 SDValue IfSet, IfClr, Cond;
Daniel Sandersab94b532013-10-30 15:20:38 +0000594 bool IsConstantMask = false;
Daniel Sanders53fe6c42013-10-30 13:51:01 +0000595 APInt Mask, InvMask;
596
597 // If Op0Op0 is an appropriate mask, try to find it's inverse in either
598 // Op1Op0, or Op1Op1. Keep track of the Cond, IfSet, and IfClr nodes, while
599 // looking.
600 // IfClr will be set if we find a valid match.
601 if (isVSplat(Op0Op0, Mask, IsLittleEndian)) {
602 Cond = Op0Op0;
603 IfSet = Op0Op1;
604
Daniel Sandersc8c50fb2013-11-21 16:11:31 +0000605 if (isVSplat(Op1Op0, InvMask, IsLittleEndian) &&
606 Mask.getBitWidth() == InvMask.getBitWidth() && Mask == ~InvMask)
Daniel Sanders53fe6c42013-10-30 13:51:01 +0000607 IfClr = Op1Op1;
Daniel Sandersc8c50fb2013-11-21 16:11:31 +0000608 else if (isVSplat(Op1Op1, InvMask, IsLittleEndian) &&
609 Mask.getBitWidth() == InvMask.getBitWidth() && Mask == ~InvMask)
Daniel Sanders53fe6c42013-10-30 13:51:01 +0000610 IfClr = Op1Op0;
Daniel Sandersab94b532013-10-30 15:20:38 +0000611
612 IsConstantMask = true;
Daniel Sanders53fe6c42013-10-30 13:51:01 +0000613 }
614
615 // If IfClr is not yet set, and Op0Op1 is an appropriate mask, try the same
616 // thing again using this mask.
617 // IfClr will be set if we find a valid match.
618 if (!IfClr.getNode() && isVSplat(Op0Op1, Mask, IsLittleEndian)) {
619 Cond = Op0Op1;
620 IfSet = Op0Op0;
621
Daniel Sandersc8c50fb2013-11-21 16:11:31 +0000622 if (isVSplat(Op1Op0, InvMask, IsLittleEndian) &&
623 Mask.getBitWidth() == InvMask.getBitWidth() && Mask == ~InvMask)
Daniel Sanders53fe6c42013-10-30 13:51:01 +0000624 IfClr = Op1Op1;
Daniel Sandersc8c50fb2013-11-21 16:11:31 +0000625 else if (isVSplat(Op1Op1, InvMask, IsLittleEndian) &&
626 Mask.getBitWidth() == InvMask.getBitWidth() && Mask == ~InvMask)
Daniel Sanders53fe6c42013-10-30 13:51:01 +0000627 IfClr = Op1Op0;
Daniel Sandersab94b532013-10-30 15:20:38 +0000628
629 IsConstantMask = true;
630 }
631
632 // If IfClr is not yet set, try looking for a non-constant match.
633 // IfClr will be set if we find a valid match amongst the eight
634 // possibilities.
635 if (!IfClr.getNode()) {
636 if (isBitwiseInverse(Op0Op0, Op1Op0)) {
637 Cond = Op1Op0;
638 IfSet = Op1Op1;
639 IfClr = Op0Op1;
640 } else if (isBitwiseInverse(Op0Op1, Op1Op0)) {
641 Cond = Op1Op0;
642 IfSet = Op1Op1;
643 IfClr = Op0Op0;
644 } else if (isBitwiseInverse(Op0Op0, Op1Op1)) {
645 Cond = Op1Op1;
646 IfSet = Op1Op0;
647 IfClr = Op0Op1;
648 } else if (isBitwiseInverse(Op0Op1, Op1Op1)) {
649 Cond = Op1Op1;
650 IfSet = Op1Op0;
651 IfClr = Op0Op0;
652 } else if (isBitwiseInverse(Op1Op0, Op0Op0)) {
653 Cond = Op0Op0;
654 IfSet = Op0Op1;
655 IfClr = Op1Op1;
656 } else if (isBitwiseInverse(Op1Op1, Op0Op0)) {
657 Cond = Op0Op0;
658 IfSet = Op0Op1;
659 IfClr = Op1Op0;
660 } else if (isBitwiseInverse(Op1Op0, Op0Op1)) {
661 Cond = Op0Op1;
662 IfSet = Op0Op0;
663 IfClr = Op1Op1;
664 } else if (isBitwiseInverse(Op1Op1, Op0Op1)) {
665 Cond = Op0Op1;
666 IfSet = Op0Op0;
667 IfClr = Op1Op0;
668 }
Daniel Sanders53fe6c42013-10-30 13:51:01 +0000669 }
670
671 // At this point, IfClr will be set if we have a valid match.
672 if (!IfClr.getNode())
673 return SDValue();
674
675 assert(Cond.getNode() && IfSet.getNode());
676
677 // Fold degenerate cases.
Daniel Sandersab94b532013-10-30 15:20:38 +0000678 if (IsConstantMask) {
679 if (Mask.isAllOnesValue())
680 return IfSet;
681 else if (Mask == 0)
682 return IfClr;
683 }
Daniel Sanders53fe6c42013-10-30 13:51:01 +0000684
685 // Transform the DAG into an equivalent VSELECT.
Daniel Sandersdf2215452014-03-12 11:54:00 +0000686 return DAG.getNode(ISD::VSELECT, SDLoc(N), Ty, Cond, IfSet, IfClr);
Daniel Sanders53fe6c42013-10-30 13:51:01 +0000687 }
688
689 return SDValue();
690}
691
Akira Hatanaka9efcd762013-03-30 01:42:24 +0000692static SDValue performSUBECombine(SDNode *N, SelectionDAG &DAG,
693 TargetLowering::DAGCombinerInfo &DCI,
694 const MipsSubtarget *Subtarget) {
695 if (DCI.isBeforeLegalize())
696 return SDValue();
697
698 if (Subtarget->hasMips32() && N->getValueType(0) == MVT::i32 &&
699 selectMSUB(N, &DAG))
700 return SDValue(N, 0);
701
702 return SDValue();
703}
704
Akira Hatanaka5832fc62013-06-26 18:48:17 +0000705static SDValue genConstMult(SDValue X, uint64_t C, SDLoc DL, EVT VT,
706 EVT ShiftTy, SelectionDAG &DAG) {
707 // Clear the upper (64 - VT.sizeInBits) bits.
708 C &= ((uint64_t)-1) >> (64 - VT.getSizeInBits());
709
710 // Return 0.
711 if (C == 0)
712 return DAG.getConstant(0, VT);
713
714 // Return x.
715 if (C == 1)
716 return X;
717
718 // If c is power of 2, return (shl x, log2(c)).
719 if (isPowerOf2_64(C))
720 return DAG.getNode(ISD::SHL, DL, VT, X,
721 DAG.getConstant(Log2_64(C), ShiftTy));
722
723 unsigned Log2Ceil = Log2_64_Ceil(C);
724 uint64_t Floor = 1LL << Log2_64(C);
725 uint64_t Ceil = Log2Ceil == 64 ? 0LL : 1LL << Log2Ceil;
726
727 // If |c - floor_c| <= |c - ceil_c|,
728 // where floor_c = pow(2, floor(log2(c))) and ceil_c = pow(2, ceil(log2(c))),
729 // return (add constMult(x, floor_c), constMult(x, c - floor_c)).
730 if (C - Floor <= Ceil - C) {
731 SDValue Op0 = genConstMult(X, Floor, DL, VT, ShiftTy, DAG);
732 SDValue Op1 = genConstMult(X, C - Floor, DL, VT, ShiftTy, DAG);
733 return DAG.getNode(ISD::ADD, DL, VT, Op0, Op1);
734 }
735
736 // If |c - floor_c| > |c - ceil_c|,
737 // return (sub constMult(x, ceil_c), constMult(x, ceil_c - c)).
738 SDValue Op0 = genConstMult(X, Ceil, DL, VT, ShiftTy, DAG);
739 SDValue Op1 = genConstMult(X, Ceil - C, DL, VT, ShiftTy, DAG);
740 return DAG.getNode(ISD::SUB, DL, VT, Op0, Op1);
741}
742
743static SDValue performMULCombine(SDNode *N, SelectionDAG &DAG,
744 const TargetLowering::DAGCombinerInfo &DCI,
745 const MipsSETargetLowering *TL) {
746 EVT VT = N->getValueType(0);
747
748 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1)))
749 if (!VT.isVector())
750 return genConstMult(N->getOperand(0), C->getZExtValue(), SDLoc(N),
751 VT, TL->getScalarShiftAmountTy(VT), DAG);
752
753 return SDValue(N, 0);
754}
755
Akira Hatanaka1ebb2a12013-04-19 23:21:32 +0000756static SDValue performDSPShiftCombine(unsigned Opc, SDNode *N, EVT Ty,
757 SelectionDAG &DAG,
758 const MipsSubtarget *Subtarget) {
759 // See if this is a vector splat immediate node.
760 APInt SplatValue, SplatUndef;
761 unsigned SplatBitSize;
762 bool HasAnyUndefs;
763 unsigned EltSize = Ty.getVectorElementType().getSizeInBits();
764 BuildVectorSDNode *BV = dyn_cast<BuildVectorSDNode>(N->getOperand(1));
765
Daniel Sanders6e664bc2013-11-21 11:40:14 +0000766 if (!Subtarget->hasDSP())
767 return SDValue();
768
Akira Hatanaka0d6964c2013-04-22 19:58:23 +0000769 if (!BV ||
Akira Hatanakad8fb0322013-04-22 20:13:37 +0000770 !BV->isConstantSplat(SplatValue, SplatUndef, SplatBitSize, HasAnyUndefs,
Akira Hatanakae9d0b312013-04-23 18:09:42 +0000771 EltSize, !Subtarget->isLittle()) ||
Akira Hatanaka0d6964c2013-04-22 19:58:23 +0000772 (SplatBitSize != EltSize) ||
Akira Hatanakae9d0b312013-04-23 18:09:42 +0000773 (SplatValue.getZExtValue() >= EltSize))
Akira Hatanaka1ebb2a12013-04-19 23:21:32 +0000774 return SDValue();
775
Andrew Trickef9de2a2013-05-25 02:42:55 +0000776 return DAG.getNode(Opc, SDLoc(N), Ty, N->getOperand(0),
Akira Hatanaka1ebb2a12013-04-19 23:21:32 +0000777 DAG.getConstant(SplatValue.getZExtValue(), MVT::i32));
778}
779
780static SDValue performSHLCombine(SDNode *N, SelectionDAG &DAG,
781 TargetLowering::DAGCombinerInfo &DCI,
782 const MipsSubtarget *Subtarget) {
783 EVT Ty = N->getValueType(0);
784
785 if ((Ty != MVT::v2i16) && (Ty != MVT::v4i8))
786 return SDValue();
787
788 return performDSPShiftCombine(MipsISD::SHLL_DSP, N, Ty, DAG, Subtarget);
789}
790
Daniel Sandersa4c8f3a2013-09-23 14:03:12 +0000791// Fold sign-extensions into MipsISD::VEXTRACT_[SZ]EXT_ELT for MSA and fold
792// constant splats into MipsISD::SHRA_DSP for DSPr2.
793//
794// Performs the following transformations:
795// - Changes MipsISD::VEXTRACT_[SZ]EXT_ELT to sign extension if its
796// sign/zero-extension is completely overwritten by the new one performed by
797// the ISD::SRA and ISD::SHL nodes.
798// - Removes redundant sign extensions performed by an ISD::SRA and ISD::SHL
799// sequence.
800//
801// See performDSPShiftCombine for more information about the transformation
802// used for DSPr2.
Akira Hatanaka1ebb2a12013-04-19 23:21:32 +0000803static SDValue performSRACombine(SDNode *N, SelectionDAG &DAG,
804 TargetLowering::DAGCombinerInfo &DCI,
805 const MipsSubtarget *Subtarget) {
806 EVT Ty = N->getValueType(0);
807
Daniel Sandersa4c8f3a2013-09-23 14:03:12 +0000808 if (Subtarget->hasMSA()) {
809 SDValue Op0 = N->getOperand(0);
810 SDValue Op1 = N->getOperand(1);
811
812 // (sra (shl (MipsVExtract[SZ]Ext $a, $b, $c), imm:$d), imm:$d)
813 // where $d + sizeof($c) == 32
814 // or $d + sizeof($c) <= 32 and SExt
815 // -> (MipsVExtractSExt $a, $b, $c)
816 if (Op0->getOpcode() == ISD::SHL && Op1 == Op0->getOperand(1)) {
817 SDValue Op0Op0 = Op0->getOperand(0);
818 ConstantSDNode *ShAmount = dyn_cast<ConstantSDNode>(Op1);
819
820 if (!ShAmount)
821 return SDValue();
822
Daniel Sandersf4f1a872013-09-27 09:25:29 +0000823 if (Op0Op0->getOpcode() != MipsISD::VEXTRACT_SEXT_ELT &&
824 Op0Op0->getOpcode() != MipsISD::VEXTRACT_ZEXT_ELT)
825 return SDValue();
826
Daniel Sandersa4c8f3a2013-09-23 14:03:12 +0000827 EVT ExtendTy = cast<VTSDNode>(Op0Op0->getOperand(2))->getVT();
828 unsigned TotalBits = ShAmount->getZExtValue() + ExtendTy.getSizeInBits();
829
830 if (TotalBits == 32 ||
831 (Op0Op0->getOpcode() == MipsISD::VEXTRACT_SEXT_ELT &&
832 TotalBits <= 32)) {
833 SDValue Ops[] = { Op0Op0->getOperand(0), Op0Op0->getOperand(1),
834 Op0Op0->getOperand(2) };
835 DAG.MorphNodeTo(Op0Op0.getNode(), MipsISD::VEXTRACT_SEXT_ELT,
Craig Topper131de822014-04-27 19:21:16 +0000836 Op0Op0->getVTList(),
Craig Topper2d2aa0c2014-04-30 07:17:30 +0000837 makeArrayRef(Ops, Op0Op0->getNumOperands()));
Daniel Sandersa4c8f3a2013-09-23 14:03:12 +0000838 return Op0Op0;
839 }
840 }
841 }
842
Akira Hatanaka1ebb2a12013-04-19 23:21:32 +0000843 if ((Ty != MVT::v2i16) && ((Ty != MVT::v4i8) || !Subtarget->hasDSPR2()))
844 return SDValue();
845
846 return performDSPShiftCombine(MipsISD::SHRA_DSP, N, Ty, DAG, Subtarget);
847}
848
849
850static SDValue performSRLCombine(SDNode *N, SelectionDAG &DAG,
851 TargetLowering::DAGCombinerInfo &DCI,
852 const MipsSubtarget *Subtarget) {
853 EVT Ty = N->getValueType(0);
854
855 if (((Ty != MVT::v2i16) || !Subtarget->hasDSPR2()) && (Ty != MVT::v4i8))
856 return SDValue();
857
858 return performDSPShiftCombine(MipsISD::SHRL_DSP, N, Ty, DAG, Subtarget);
859}
860
Akira Hatanaka68741cc2013-04-30 22:37:26 +0000861static bool isLegalDSPCondCode(EVT Ty, ISD::CondCode CC) {
862 bool IsV216 = (Ty == MVT::v2i16);
863
864 switch (CC) {
865 case ISD::SETEQ:
866 case ISD::SETNE: return true;
867 case ISD::SETLT:
868 case ISD::SETLE:
869 case ISD::SETGT:
870 case ISD::SETGE: return IsV216;
871 case ISD::SETULT:
872 case ISD::SETULE:
873 case ISD::SETUGT:
874 case ISD::SETUGE: return !IsV216;
875 default: return false;
876 }
877}
878
879static SDValue performSETCCCombine(SDNode *N, SelectionDAG &DAG) {
880 EVT Ty = N->getValueType(0);
881
882 if ((Ty != MVT::v2i16) && (Ty != MVT::v4i8))
883 return SDValue();
884
885 if (!isLegalDSPCondCode(Ty, cast<CondCodeSDNode>(N->getOperand(2))->get()))
886 return SDValue();
887
Andrew Trickef9de2a2013-05-25 02:42:55 +0000888 return DAG.getNode(MipsISD::SETCC_DSP, SDLoc(N), Ty, N->getOperand(0),
Akira Hatanaka68741cc2013-04-30 22:37:26 +0000889 N->getOperand(1), N->getOperand(2));
890}
891
892static SDValue performVSELECTCombine(SDNode *N, SelectionDAG &DAG) {
893 EVT Ty = N->getValueType(0);
894
Daniel Sanders3ce56622013-09-24 12:18:31 +0000895 if (Ty.is128BitVector() && Ty.isInteger()) {
896 // Try the following combines:
897 // (vselect (setcc $a, $b, SETLT), $b, $a)) -> (vsmax $a, $b)
898 // (vselect (setcc $a, $b, SETLE), $b, $a)) -> (vsmax $a, $b)
899 // (vselect (setcc $a, $b, SETLT), $a, $b)) -> (vsmin $a, $b)
900 // (vselect (setcc $a, $b, SETLE), $a, $b)) -> (vsmin $a, $b)
901 // (vselect (setcc $a, $b, SETULT), $b, $a)) -> (vumax $a, $b)
902 // (vselect (setcc $a, $b, SETULE), $b, $a)) -> (vumax $a, $b)
903 // (vselect (setcc $a, $b, SETULT), $a, $b)) -> (vumin $a, $b)
904 // (vselect (setcc $a, $b, SETULE), $a, $b)) -> (vumin $a, $b)
905 // SETGT/SETGE/SETUGT/SETUGE variants of these will show up initially but
906 // will be expanded to equivalent SETLT/SETLE/SETULT/SETULE versions by the
907 // legalizer.
908 SDValue Op0 = N->getOperand(0);
Akira Hatanaka68741cc2013-04-30 22:37:26 +0000909
Daniel Sanders3ce56622013-09-24 12:18:31 +0000910 if (Op0->getOpcode() != ISD::SETCC)
911 return SDValue();
Akira Hatanaka68741cc2013-04-30 22:37:26 +0000912
Daniel Sanders3ce56622013-09-24 12:18:31 +0000913 ISD::CondCode CondCode = cast<CondCodeSDNode>(Op0->getOperand(2))->get();
914 bool Signed;
Akira Hatanaka68741cc2013-04-30 22:37:26 +0000915
Daniel Sanders3ce56622013-09-24 12:18:31 +0000916 if (CondCode == ISD::SETLT || CondCode == ISD::SETLE)
917 Signed = true;
918 else if (CondCode == ISD::SETULT || CondCode == ISD::SETULE)
919 Signed = false;
920 else
921 return SDValue();
922
923 SDValue Op1 = N->getOperand(1);
924 SDValue Op2 = N->getOperand(2);
925 SDValue Op0Op0 = Op0->getOperand(0);
926 SDValue Op0Op1 = Op0->getOperand(1);
927
928 if (Op1 == Op0Op0 && Op2 == Op0Op1)
929 return DAG.getNode(Signed ? MipsISD::VSMIN : MipsISD::VUMIN, SDLoc(N),
930 Ty, Op1, Op2);
931 else if (Op1 == Op0Op1 && Op2 == Op0Op0)
932 return DAG.getNode(Signed ? MipsISD::VSMAX : MipsISD::VUMAX, SDLoc(N),
933 Ty, Op1, Op2);
934 } else if ((Ty == MVT::v2i16) || (Ty == MVT::v4i8)) {
935 SDValue SetCC = N->getOperand(0);
936
937 if (SetCC.getOpcode() != MipsISD::SETCC_DSP)
938 return SDValue();
939
940 return DAG.getNode(MipsISD::SELECT_CC_DSP, SDLoc(N), Ty,
941 SetCC.getOperand(0), SetCC.getOperand(1),
942 N->getOperand(1), N->getOperand(2), SetCC.getOperand(2));
943 }
944
945 return SDValue();
Akira Hatanaka68741cc2013-04-30 22:37:26 +0000946}
947
Daniel Sandersf7456c72013-09-23 13:22:24 +0000948static SDValue performXORCombine(SDNode *N, SelectionDAG &DAG,
949 const MipsSubtarget *Subtarget) {
950 EVT Ty = N->getValueType(0);
951
952 if (Subtarget->hasMSA() && Ty.is128BitVector() && Ty.isInteger()) {
953 // Try the following combines:
954 // (xor (or $a, $b), (build_vector allones))
955 // (xor (or $a, $b), (bitcast (build_vector allones)))
956 SDValue Op0 = N->getOperand(0);
957 SDValue Op1 = N->getOperand(1);
958 SDValue NotOp;
Daniel Sandersf7456c72013-09-23 13:22:24 +0000959
960 if (ISD::isBuildVectorAllOnes(Op0.getNode()))
961 NotOp = Op1;
962 else if (ISD::isBuildVectorAllOnes(Op1.getNode()))
963 NotOp = Op0;
Daniel Sandersf7456c72013-09-23 13:22:24 +0000964 else
965 return SDValue();
966
967 if (NotOp->getOpcode() == ISD::OR)
968 return DAG.getNode(MipsISD::VNOR, SDLoc(N), Ty, NotOp->getOperand(0),
969 NotOp->getOperand(1));
970 }
971
972 return SDValue();
973}
974
Akira Hatanaka9efcd762013-03-30 01:42:24 +0000975SDValue
976MipsSETargetLowering::PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const {
977 SelectionDAG &DAG = DCI.DAG;
Akira Hatanaka68741cc2013-04-30 22:37:26 +0000978 SDValue Val;
Akira Hatanaka9efcd762013-03-30 01:42:24 +0000979
980 switch (N->getOpcode()) {
981 case ISD::ADDE:
982 return performADDECombine(N, DAG, DCI, Subtarget);
Daniel Sandersa4c8f3a2013-09-23 14:03:12 +0000983 case ISD::AND:
984 Val = performANDCombine(N, DAG, DCI, Subtarget);
985 break;
Daniel Sanders53fe6c42013-10-30 13:51:01 +0000986 case ISD::OR:
987 Val = performORCombine(N, DAG, DCI, Subtarget);
988 break;
Akira Hatanaka9efcd762013-03-30 01:42:24 +0000989 case ISD::SUBE:
990 return performSUBECombine(N, DAG, DCI, Subtarget);
Akira Hatanaka5832fc62013-06-26 18:48:17 +0000991 case ISD::MUL:
992 return performMULCombine(N, DAG, DCI, this);
Akira Hatanaka1ebb2a12013-04-19 23:21:32 +0000993 case ISD::SHL:
994 return performSHLCombine(N, DAG, DCI, Subtarget);
995 case ISD::SRA:
996 return performSRACombine(N, DAG, DCI, Subtarget);
997 case ISD::SRL:
998 return performSRLCombine(N, DAG, DCI, Subtarget);
Akira Hatanaka68741cc2013-04-30 22:37:26 +0000999 case ISD::VSELECT:
1000 return performVSELECTCombine(N, DAG);
Daniel Sandersf7456c72013-09-23 13:22:24 +00001001 case ISD::XOR:
1002 Val = performXORCombine(N, DAG, Subtarget);
1003 break;
1004 case ISD::SETCC:
Akira Hatanaka68741cc2013-04-30 22:37:26 +00001005 Val = performSETCCCombine(N, DAG);
1006 break;
Akira Hatanaka9efcd762013-03-30 01:42:24 +00001007 }
Akira Hatanaka68741cc2013-04-30 22:37:26 +00001008
Daniel Sanders62aeab82013-10-30 13:31:27 +00001009 if (Val.getNode()) {
1010 DEBUG(dbgs() << "\nMipsSE DAG Combine:\n";
1011 N->printrWithDepth(dbgs(), &DAG);
1012 dbgs() << "\n=> \n";
1013 Val.getNode()->printrWithDepth(dbgs(), &DAG);
1014 dbgs() << "\n");
Akira Hatanaka68741cc2013-04-30 22:37:26 +00001015 return Val;
Daniel Sanders62aeab82013-10-30 13:31:27 +00001016 }
Akira Hatanaka68741cc2013-04-30 22:37:26 +00001017
1018 return MipsTargetLowering::PerformDAGCombine(N, DCI);
Akira Hatanaka9efcd762013-03-30 01:42:24 +00001019}
1020
Akira Hatanaka96ca1822013-03-13 00:54:29 +00001021MachineBasicBlock *
1022MipsSETargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
1023 MachineBasicBlock *BB) const {
1024 switch (MI->getOpcode()) {
1025 default:
1026 return MipsTargetLowering::EmitInstrWithCustomInserter(MI, BB);
1027 case Mips::BPOSGE32_PSEUDO:
1028 return emitBPOSGE32(MI, BB);
Daniel Sandersce09d072013-08-28 12:14:50 +00001029 case Mips::SNZ_B_PSEUDO:
1030 return emitMSACBranchPseudo(MI, BB, Mips::BNZ_B);
1031 case Mips::SNZ_H_PSEUDO:
1032 return emitMSACBranchPseudo(MI, BB, Mips::BNZ_H);
1033 case Mips::SNZ_W_PSEUDO:
1034 return emitMSACBranchPseudo(MI, BB, Mips::BNZ_W);
1035 case Mips::SNZ_D_PSEUDO:
1036 return emitMSACBranchPseudo(MI, BB, Mips::BNZ_D);
1037 case Mips::SNZ_V_PSEUDO:
1038 return emitMSACBranchPseudo(MI, BB, Mips::BNZ_V);
1039 case Mips::SZ_B_PSEUDO:
1040 return emitMSACBranchPseudo(MI, BB, Mips::BZ_B);
1041 case Mips::SZ_H_PSEUDO:
1042 return emitMSACBranchPseudo(MI, BB, Mips::BZ_H);
1043 case Mips::SZ_W_PSEUDO:
1044 return emitMSACBranchPseudo(MI, BB, Mips::BZ_W);
1045 case Mips::SZ_D_PSEUDO:
1046 return emitMSACBranchPseudo(MI, BB, Mips::BZ_D);
1047 case Mips::SZ_V_PSEUDO:
1048 return emitMSACBranchPseudo(MI, BB, Mips::BZ_V);
Daniel Sanders39bb8ba2013-09-27 12:17:32 +00001049 case Mips::COPY_FW_PSEUDO:
1050 return emitCOPY_FW(MI, BB);
1051 case Mips::COPY_FD_PSEUDO:
1052 return emitCOPY_FD(MI, BB);
Daniel Sandersa5150702013-09-27 12:31:32 +00001053 case Mips::INSERT_FW_PSEUDO:
1054 return emitINSERT_FW(MI, BB);
1055 case Mips::INSERT_FD_PSEUDO:
1056 return emitINSERT_FD(MI, BB);
Daniel Sanderse296a0f2014-04-30 12:09:32 +00001057 case Mips::INSERT_B_VIDX_PSEUDO:
1058 return emitINSERT_DF_VIDX(MI, BB, 1, false);
1059 case Mips::INSERT_H_VIDX_PSEUDO:
1060 return emitINSERT_DF_VIDX(MI, BB, 2, false);
1061 case Mips::INSERT_W_VIDX_PSEUDO:
1062 return emitINSERT_DF_VIDX(MI, BB, 4, false);
1063 case Mips::INSERT_D_VIDX_PSEUDO:
1064 return emitINSERT_DF_VIDX(MI, BB, 8, false);
1065 case Mips::INSERT_FW_VIDX_PSEUDO:
1066 return emitINSERT_DF_VIDX(MI, BB, 4, true);
1067 case Mips::INSERT_FD_VIDX_PSEUDO:
1068 return emitINSERT_DF_VIDX(MI, BB, 8, true);
Daniel Sanders1dfddc72013-10-15 13:14:41 +00001069 case Mips::FILL_FW_PSEUDO:
1070 return emitFILL_FW(MI, BB);
1071 case Mips::FILL_FD_PSEUDO:
1072 return emitFILL_FD(MI, BB);
Daniel Sandersa9521602013-10-23 10:36:52 +00001073 case Mips::FEXP2_W_1_PSEUDO:
1074 return emitFEXP2_W_1(MI, BB);
1075 case Mips::FEXP2_D_1_PSEUDO:
1076 return emitFEXP2_D_1(MI, BB);
Akira Hatanaka96ca1822013-03-13 00:54:29 +00001077 }
1078}
1079
1080bool MipsSETargetLowering::
1081isEligibleForTailCallOptimization(const MipsCC &MipsCCInfo,
1082 unsigned NextStackOffset,
1083 const MipsFunctionInfo& FI) const {
1084 if (!EnableMipsTailCalls)
1085 return false;
1086
Akira Hatanaka96ca1822013-03-13 00:54:29 +00001087 // Return false if either the callee or caller has a byval argument.
1088 if (MipsCCInfo.hasByValArg() || FI.hasByvalArg())
1089 return false;
1090
1091 // Return true if the callee's argument area is no larger than the
1092 // caller's.
1093 return NextStackOffset <= FI.getIncomingArgSize();
1094}
1095
1096void MipsSETargetLowering::
1097getOpndList(SmallVectorImpl<SDValue> &Ops,
1098 std::deque< std::pair<unsigned, SDValue> > &RegsToPass,
1099 bool IsPICCall, bool GlobalOrExternal, bool InternalLinkage,
1100 CallLoweringInfo &CLI, SDValue Callee, SDValue Chain) const {
Akira Hatanaka168d4e52013-11-27 23:38:42 +00001101 Ops.push_back(Callee);
Akira Hatanaka96ca1822013-03-13 00:54:29 +00001102 MipsTargetLowering::getOpndList(Ops, RegsToPass, IsPICCall, GlobalOrExternal,
1103 InternalLinkage, CLI, Callee, Chain);
1104}
1105
Akira Hatanaka63791212013-09-07 00:52:30 +00001106SDValue MipsSETargetLowering::lowerLOAD(SDValue Op, SelectionDAG &DAG) const {
1107 LoadSDNode &Nd = *cast<LoadSDNode>(Op);
1108
1109 if (Nd.getMemoryVT() != MVT::f64 || !NoDPLoadStore)
1110 return MipsTargetLowering::lowerLOAD(Op, DAG);
1111
1112 // Replace a double precision load with two i32 loads and a buildpair64.
1113 SDLoc DL(Op);
1114 SDValue Ptr = Nd.getBasePtr(), Chain = Nd.getChain();
1115 EVT PtrVT = Ptr.getValueType();
1116
1117 // i32 load from lower address.
1118 SDValue Lo = DAG.getLoad(MVT::i32, DL, Chain, Ptr,
1119 MachinePointerInfo(), Nd.isVolatile(),
1120 Nd.isNonTemporal(), Nd.isInvariant(),
1121 Nd.getAlignment());
1122
1123 // i32 load from higher address.
1124 Ptr = DAG.getNode(ISD::ADD, DL, PtrVT, Ptr, DAG.getConstant(4, PtrVT));
1125 SDValue Hi = DAG.getLoad(MVT::i32, DL, Lo.getValue(1), Ptr,
1126 MachinePointerInfo(), Nd.isVolatile(),
1127 Nd.isNonTemporal(), Nd.isInvariant(),
Akira Hatanaka9cf069f2013-09-09 17:59:32 +00001128 std::min(Nd.getAlignment(), 4U));
Akira Hatanaka63791212013-09-07 00:52:30 +00001129
1130 if (!Subtarget->isLittle())
1131 std::swap(Lo, Hi);
1132
1133 SDValue BP = DAG.getNode(MipsISD::BuildPairF64, DL, MVT::f64, Lo, Hi);
1134 SDValue Ops[2] = {BP, Hi.getValue(1)};
Craig Topper64941d92014-04-27 19:20:57 +00001135 return DAG.getMergeValues(Ops, DL);
Akira Hatanaka63791212013-09-07 00:52:30 +00001136}
1137
1138SDValue MipsSETargetLowering::lowerSTORE(SDValue Op, SelectionDAG &DAG) const {
1139 StoreSDNode &Nd = *cast<StoreSDNode>(Op);
1140
1141 if (Nd.getMemoryVT() != MVT::f64 || !NoDPLoadStore)
1142 return MipsTargetLowering::lowerSTORE(Op, DAG);
1143
1144 // Replace a double precision store with two extractelement64s and i32 stores.
1145 SDLoc DL(Op);
1146 SDValue Val = Nd.getValue(), Ptr = Nd.getBasePtr(), Chain = Nd.getChain();
1147 EVT PtrVT = Ptr.getValueType();
1148 SDValue Lo = DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32,
1149 Val, DAG.getConstant(0, MVT::i32));
1150 SDValue Hi = DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32,
1151 Val, DAG.getConstant(1, MVT::i32));
1152
1153 if (!Subtarget->isLittle())
1154 std::swap(Lo, Hi);
1155
1156 // i32 store to lower address.
1157 Chain = DAG.getStore(Chain, DL, Lo, Ptr, MachinePointerInfo(),
1158 Nd.isVolatile(), Nd.isNonTemporal(), Nd.getAlignment(),
1159 Nd.getTBAAInfo());
1160
1161 // i32 store to higher address.
1162 Ptr = DAG.getNode(ISD::ADD, DL, PtrVT, Ptr, DAG.getConstant(4, PtrVT));
1163 return DAG.getStore(Chain, DL, Hi, Ptr, MachinePointerInfo(),
Akira Hatanaka9cf069f2013-09-09 17:59:32 +00001164 Nd.isVolatile(), Nd.isNonTemporal(),
1165 std::min(Nd.getAlignment(), 4U), Nd.getTBAAInfo());
Akira Hatanaka63791212013-09-07 00:52:30 +00001166}
1167
Akira Hatanakabe8612f2013-03-30 01:36:35 +00001168SDValue MipsSETargetLowering::lowerMulDiv(SDValue Op, unsigned NewOpc,
1169 bool HasLo, bool HasHi,
1170 SelectionDAG &DAG) const {
1171 EVT Ty = Op.getOperand(0).getValueType();
Andrew Trickef9de2a2013-05-25 02:42:55 +00001172 SDLoc DL(Op);
Akira Hatanakabe8612f2013-03-30 01:36:35 +00001173 SDValue Mult = DAG.getNode(NewOpc, DL, MVT::Untyped,
1174 Op.getOperand(0), Op.getOperand(1));
1175 SDValue Lo, Hi;
1176
1177 if (HasLo)
Akira Hatanakad98c99f2013-10-15 01:12:50 +00001178 Lo = DAG.getNode(MipsISD::MFLO, DL, Ty, Mult);
Akira Hatanakabe8612f2013-03-30 01:36:35 +00001179 if (HasHi)
Akira Hatanakad98c99f2013-10-15 01:12:50 +00001180 Hi = DAG.getNode(MipsISD::MFHI, DL, Ty, Mult);
Akira Hatanakabe8612f2013-03-30 01:36:35 +00001181
1182 if (!HasLo || !HasHi)
1183 return HasLo ? Lo : Hi;
1184
1185 SDValue Vals[] = { Lo, Hi };
Craig Topper64941d92014-04-27 19:20:57 +00001186 return DAG.getMergeValues(Vals, DL);
Akira Hatanakabe8612f2013-03-30 01:36:35 +00001187}
1188
Akira Hatanakaa6bbde52013-04-13 02:13:30 +00001189
Andrew Trickef9de2a2013-05-25 02:42:55 +00001190static SDValue initAccumulator(SDValue In, SDLoc DL, SelectionDAG &DAG) {
Akira Hatanakaa6bbde52013-04-13 02:13:30 +00001191 SDValue InLo = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i32, In,
1192 DAG.getConstant(0, MVT::i32));
1193 SDValue InHi = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i32, In,
1194 DAG.getConstant(1, MVT::i32));
Akira Hatanakad98c99f2013-10-15 01:12:50 +00001195 return DAG.getNode(MipsISD::MTLOHI, DL, MVT::Untyped, InLo, InHi);
Akira Hatanakaa6bbde52013-04-13 02:13:30 +00001196}
1197
Andrew Trickef9de2a2013-05-25 02:42:55 +00001198static SDValue extractLOHI(SDValue Op, SDLoc DL, SelectionDAG &DAG) {
Akira Hatanakad98c99f2013-10-15 01:12:50 +00001199 SDValue Lo = DAG.getNode(MipsISD::MFLO, DL, MVT::i32, Op);
1200 SDValue Hi = DAG.getNode(MipsISD::MFHI, DL, MVT::i32, Op);
Akira Hatanakaa6bbde52013-04-13 02:13:30 +00001201 return DAG.getNode(ISD::BUILD_PAIR, DL, MVT::i64, Lo, Hi);
1202}
1203
1204// This function expands mips intrinsic nodes which have 64-bit input operands
1205// or output values.
1206//
1207// out64 = intrinsic-node in64
1208// =>
1209// lo = copy (extract-element (in64, 0))
1210// hi = copy (extract-element (in64, 1))
1211// mips-specific-node
1212// v0 = copy lo
1213// v1 = copy hi
1214// out64 = merge-values (v0, v1)
1215//
1216static SDValue lowerDSPIntr(SDValue Op, SelectionDAG &DAG, unsigned Opc) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001217 SDLoc DL(Op);
Akira Hatanakaa6bbde52013-04-13 02:13:30 +00001218 bool HasChainIn = Op->getOperand(0).getValueType() == MVT::Other;
1219 SmallVector<SDValue, 3> Ops;
1220 unsigned OpNo = 0;
1221
1222 // See if Op has a chain input.
1223 if (HasChainIn)
1224 Ops.push_back(Op->getOperand(OpNo++));
1225
1226 // The next operand is the intrinsic opcode.
1227 assert(Op->getOperand(OpNo).getOpcode() == ISD::TargetConstant);
1228
1229 // See if the next operand has type i64.
1230 SDValue Opnd = Op->getOperand(++OpNo), In64;
1231
1232 if (Opnd.getValueType() == MVT::i64)
1233 In64 = initAccumulator(Opnd, DL, DAG);
1234 else
1235 Ops.push_back(Opnd);
1236
1237 // Push the remaining operands.
1238 for (++OpNo ; OpNo < Op->getNumOperands(); ++OpNo)
1239 Ops.push_back(Op->getOperand(OpNo));
1240
1241 // Add In64 to the end of the list.
1242 if (In64.getNode())
1243 Ops.push_back(In64);
1244
1245 // Scan output.
1246 SmallVector<EVT, 2> ResTys;
1247
1248 for (SDNode::value_iterator I = Op->value_begin(), E = Op->value_end();
1249 I != E; ++I)
1250 ResTys.push_back((*I == MVT::i64) ? MVT::Untyped : *I);
1251
1252 // Create node.
Craig Topper48d114b2014-04-26 18:35:24 +00001253 SDValue Val = DAG.getNode(Opc, DL, ResTys, Ops);
Akira Hatanakaa6bbde52013-04-13 02:13:30 +00001254 SDValue Out = (ResTys[0] == MVT::Untyped) ? extractLOHI(Val, DL, DAG) : Val;
1255
1256 if (!HasChainIn)
1257 return Out;
1258
1259 assert(Val->getValueType(1) == MVT::Other);
1260 SDValue Vals[] = { Out, SDValue(Val.getNode(), 1) };
Craig Topper64941d92014-04-27 19:20:57 +00001261 return DAG.getMergeValues(Vals, DL);
Akira Hatanakaa6bbde52013-04-13 02:13:30 +00001262}
1263
Daniel Sandersa4c8f3a2013-09-23 14:03:12 +00001264// Lower an MSA copy intrinsic into the specified SelectionDAG node
1265static SDValue lowerMSACopyIntr(SDValue Op, SelectionDAG &DAG, unsigned Opc) {
1266 SDLoc DL(Op);
1267 SDValue Vec = Op->getOperand(1);
1268 SDValue Idx = Op->getOperand(2);
1269 EVT ResTy = Op->getValueType(0);
1270 EVT EltTy = Vec->getValueType(0).getVectorElementType();
1271
1272 SDValue Result = DAG.getNode(Opc, DL, ResTy, Vec, Idx,
1273 DAG.getValueType(EltTy));
1274
1275 return Result;
1276}
1277
Daniel Sanders50b80412013-11-15 12:56:49 +00001278static SDValue lowerMSASplatZExt(SDValue Op, unsigned OpNr, SelectionDAG &DAG) {
1279 EVT ResVecTy = Op->getValueType(0);
1280 EVT ViaVecTy = ResVecTy;
1281 SDLoc DL(Op);
Daniel Sanders86d0c8d2013-09-23 14:29:55 +00001282
Daniel Sanders50b80412013-11-15 12:56:49 +00001283 // When ResVecTy == MVT::v2i64, LaneA is the upper 32 bits of the lane and
1284 // LaneB is the lower 32-bits. Otherwise LaneA and LaneB are alternating
1285 // lanes.
1286 SDValue LaneA;
1287 SDValue LaneB = Op->getOperand(2);
1288
1289 if (ResVecTy == MVT::v2i64) {
1290 LaneA = DAG.getConstant(0, MVT::i32);
Daniel Sandersf49dd822013-09-24 13:33:07 +00001291 ViaVecTy = MVT::v4i32;
Daniel Sanders50b80412013-11-15 12:56:49 +00001292 } else
1293 LaneA = LaneB;
Daniel Sanders86d0c8d2013-09-23 14:29:55 +00001294
Daniel Sanders50b80412013-11-15 12:56:49 +00001295 SDValue Ops[16] = { LaneA, LaneB, LaneA, LaneB, LaneA, LaneB, LaneA, LaneB,
1296 LaneA, LaneB, LaneA, LaneB, LaneA, LaneB, LaneA, LaneB };
Daniel Sandersf49dd822013-09-24 13:33:07 +00001297
Craig Topper48d114b2014-04-26 18:35:24 +00001298 SDValue Result = DAG.getNode(ISD::BUILD_VECTOR, DL, ViaVecTy,
Craig Topper2d2aa0c2014-04-30 07:17:30 +00001299 makeArrayRef(Ops, ViaVecTy.getVectorNumElements()));
Daniel Sanders50b80412013-11-15 12:56:49 +00001300
1301 if (ViaVecTy != ResVecTy)
1302 Result = DAG.getNode(ISD::BITCAST, DL, ResVecTy, Result);
Daniel Sandersf49dd822013-09-24 13:33:07 +00001303
1304 return Result;
1305}
1306
Daniel Sanders50b80412013-11-15 12:56:49 +00001307static SDValue lowerMSASplatImm(SDValue Op, unsigned ImmOp, SelectionDAG &DAG) {
1308 return DAG.getConstant(Op->getConstantOperandVal(ImmOp), Op->getValueType(0));
1309}
1310
1311static SDValue getBuildVectorSplat(EVT VecTy, SDValue SplatValue,
1312 bool BigEndian, SelectionDAG &DAG) {
1313 EVT ViaVecTy = VecTy;
1314 SDValue SplatValueA = SplatValue;
1315 SDValue SplatValueB = SplatValue;
1316 SDLoc DL(SplatValue);
1317
1318 if (VecTy == MVT::v2i64) {
1319 // v2i64 BUILD_VECTOR must be performed via v4i32 so split into i32's.
1320 ViaVecTy = MVT::v4i32;
1321
1322 SplatValueA = DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, SplatValue);
1323 SplatValueB = DAG.getNode(ISD::SRL, DL, MVT::i64, SplatValue,
1324 DAG.getConstant(32, MVT::i32));
1325 SplatValueB = DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, SplatValueB);
1326 }
1327
1328 // We currently hold the parts in little endian order. Swap them if
1329 // necessary.
1330 if (BigEndian)
1331 std::swap(SplatValueA, SplatValueB);
1332
1333 SDValue Ops[16] = { SplatValueA, SplatValueB, SplatValueA, SplatValueB,
1334 SplatValueA, SplatValueB, SplatValueA, SplatValueB,
1335 SplatValueA, SplatValueB, SplatValueA, SplatValueB,
1336 SplatValueA, SplatValueB, SplatValueA, SplatValueB };
1337
Craig Topper48d114b2014-04-26 18:35:24 +00001338 SDValue Result = DAG.getNode(ISD::BUILD_VECTOR, DL, ViaVecTy,
Craig Topper2d2aa0c2014-04-30 07:17:30 +00001339 makeArrayRef(Ops, ViaVecTy.getVectorNumElements()));
Daniel Sanders50b80412013-11-15 12:56:49 +00001340
1341 if (VecTy != ViaVecTy)
1342 Result = DAG.getNode(ISD::BITCAST, DL, VecTy, Result);
1343
1344 return Result;
Daniel Sandersf5bd9372013-09-11 10:51:30 +00001345}
1346
Daniel Sandersa5bc99f2013-11-12 10:31:49 +00001347static SDValue lowerMSABinaryBitImmIntr(SDValue Op, SelectionDAG &DAG,
1348 unsigned Opc, SDValue Imm,
1349 bool BigEndian) {
1350 EVT VecTy = Op->getValueType(0);
1351 SDValue Exp2Imm;
1352 SDLoc DL(Op);
1353
Daniel Sanders50b80412013-11-15 12:56:49 +00001354 // The DAG Combiner can't constant fold bitcasted vectors yet so we must do it
1355 // here for now.
Daniel Sandersa5bc99f2013-11-12 10:31:49 +00001356 if (VecTy == MVT::v2i64) {
1357 if (ConstantSDNode *CImm = dyn_cast<ConstantSDNode>(Imm)) {
1358 APInt BitImm = APInt(64, 1) << CImm->getAPIntValue();
1359
1360 SDValue BitImmHiOp = DAG.getConstant(BitImm.lshr(32).trunc(32), MVT::i32);
Daniel Sanders50b80412013-11-15 12:56:49 +00001361 SDValue BitImmLoOp = DAG.getConstant(BitImm.trunc(32), MVT::i32);
1362
1363 if (BigEndian)
1364 std::swap(BitImmLoOp, BitImmHiOp);
1365
1366 Exp2Imm =
1367 DAG.getNode(ISD::BITCAST, DL, MVT::v2i64,
1368 DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v4i32, BitImmLoOp,
1369 BitImmHiOp, BitImmLoOp, BitImmHiOp));
Daniel Sandersa5bc99f2013-11-12 10:31:49 +00001370 }
1371 }
1372
Craig Topper062a2ba2014-04-25 05:30:21 +00001373 if (!Exp2Imm.getNode()) {
Daniel Sandersa5bc99f2013-11-12 10:31:49 +00001374 // We couldnt constant fold, do a vector shift instead
Daniel Sanders50b80412013-11-15 12:56:49 +00001375
1376 // Extend i32 to i64 if necessary. Sign or zero extend doesn't matter since
1377 // only values 0-63 are valid.
1378 if (VecTy == MVT::v2i64)
1379 Imm = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i64, Imm);
1380
1381 Exp2Imm = getBuildVectorSplat(VecTy, Imm, BigEndian, DAG);
1382
1383 Exp2Imm =
1384 DAG.getNode(ISD::SHL, DL, VecTy, DAG.getConstant(1, VecTy), Exp2Imm);
Daniel Sandersa5bc99f2013-11-12 10:31:49 +00001385 }
1386
1387 return DAG.getNode(Opc, DL, VecTy, Op->getOperand(1), Exp2Imm);
1388}
1389
Daniel Sanders3f6eb542013-11-12 10:45:18 +00001390static SDValue lowerMSABitClear(SDValue Op, SelectionDAG &DAG) {
1391 EVT ResTy = Op->getValueType(0);
Daniel Sanders3f6eb542013-11-12 10:45:18 +00001392 SDLoc DL(Op);
Daniel Sanders50b80412013-11-15 12:56:49 +00001393 SDValue One = DAG.getConstant(1, ResTy);
Daniel Sanders3f6eb542013-11-12 10:45:18 +00001394 SDValue Bit = DAG.getNode(ISD::SHL, DL, ResTy, One, Op->getOperand(2));
1395
Daniel Sanders71ce0ca2013-11-15 16:02:04 +00001396 return DAG.getNode(ISD::AND, DL, ResTy, Op->getOperand(1),
1397 DAG.getNOT(DL, Bit, ResTy));
Daniel Sanders3f6eb542013-11-12 10:45:18 +00001398}
1399
1400static SDValue lowerMSABitClearImm(SDValue Op, SelectionDAG &DAG) {
1401 SDLoc DL(Op);
1402 EVT ResTy = Op->getValueType(0);
Daniel Sanders50b80412013-11-15 12:56:49 +00001403 APInt BitImm = APInt(ResTy.getVectorElementType().getSizeInBits(), 1)
1404 << cast<ConstantSDNode>(Op->getOperand(2))->getAPIntValue();
1405 SDValue BitMask = DAG.getConstant(~BitImm, ResTy);
Daniel Sanders3f6eb542013-11-12 10:45:18 +00001406
1407 return DAG.getNode(ISD::AND, DL, ResTy, Op->getOperand(1), BitMask);
1408}
1409
Akira Hatanakaa6bbde52013-04-13 02:13:30 +00001410SDValue MipsSETargetLowering::lowerINTRINSIC_WO_CHAIN(SDValue Op,
1411 SelectionDAG &DAG) const {
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001412 SDLoc DL(Op);
1413
Akira Hatanakaa6bbde52013-04-13 02:13:30 +00001414 switch (cast<ConstantSDNode>(Op->getOperand(0))->getZExtValue()) {
1415 default:
1416 return SDValue();
1417 case Intrinsic::mips_shilo:
1418 return lowerDSPIntr(Op, DAG, MipsISD::SHILO);
1419 case Intrinsic::mips_dpau_h_qbl:
1420 return lowerDSPIntr(Op, DAG, MipsISD::DPAU_H_QBL);
1421 case Intrinsic::mips_dpau_h_qbr:
1422 return lowerDSPIntr(Op, DAG, MipsISD::DPAU_H_QBR);
1423 case Intrinsic::mips_dpsu_h_qbl:
1424 return lowerDSPIntr(Op, DAG, MipsISD::DPSU_H_QBL);
1425 case Intrinsic::mips_dpsu_h_qbr:
1426 return lowerDSPIntr(Op, DAG, MipsISD::DPSU_H_QBR);
1427 case Intrinsic::mips_dpa_w_ph:
1428 return lowerDSPIntr(Op, DAG, MipsISD::DPA_W_PH);
1429 case Intrinsic::mips_dps_w_ph:
1430 return lowerDSPIntr(Op, DAG, MipsISD::DPS_W_PH);
1431 case Intrinsic::mips_dpax_w_ph:
1432 return lowerDSPIntr(Op, DAG, MipsISD::DPAX_W_PH);
1433 case Intrinsic::mips_dpsx_w_ph:
1434 return lowerDSPIntr(Op, DAG, MipsISD::DPSX_W_PH);
1435 case Intrinsic::mips_mulsa_w_ph:
1436 return lowerDSPIntr(Op, DAG, MipsISD::MULSA_W_PH);
1437 case Intrinsic::mips_mult:
1438 return lowerDSPIntr(Op, DAG, MipsISD::Mult);
1439 case Intrinsic::mips_multu:
1440 return lowerDSPIntr(Op, DAG, MipsISD::Multu);
1441 case Intrinsic::mips_madd:
1442 return lowerDSPIntr(Op, DAG, MipsISD::MAdd);
1443 case Intrinsic::mips_maddu:
1444 return lowerDSPIntr(Op, DAG, MipsISD::MAddu);
1445 case Intrinsic::mips_msub:
1446 return lowerDSPIntr(Op, DAG, MipsISD::MSub);
1447 case Intrinsic::mips_msubu:
1448 return lowerDSPIntr(Op, DAG, MipsISD::MSubu);
Daniel Sandersfa5ab1c2013-09-11 10:28:16 +00001449 case Intrinsic::mips_addv_b:
1450 case Intrinsic::mips_addv_h:
1451 case Intrinsic::mips_addv_w:
1452 case Intrinsic::mips_addv_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001453 return DAG.getNode(ISD::ADD, DL, Op->getValueType(0), Op->getOperand(1),
1454 Op->getOperand(2));
Daniel Sanders86d0c8d2013-09-23 14:29:55 +00001455 case Intrinsic::mips_addvi_b:
1456 case Intrinsic::mips_addvi_h:
1457 case Intrinsic::mips_addvi_w:
1458 case Intrinsic::mips_addvi_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001459 return DAG.getNode(ISD::ADD, DL, Op->getValueType(0), Op->getOperand(1),
1460 lowerMSASplatImm(Op, 2, DAG));
Daniel Sanders8ca81e42013-09-23 12:57:42 +00001461 case Intrinsic::mips_and_v:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001462 return DAG.getNode(ISD::AND, DL, Op->getValueType(0), Op->getOperand(1),
1463 Op->getOperand(2));
Daniel Sandersbfc39ce2013-09-24 12:32:47 +00001464 case Intrinsic::mips_andi_b:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001465 return DAG.getNode(ISD::AND, DL, Op->getValueType(0), Op->getOperand(1),
1466 lowerMSASplatImm(Op, 2, DAG));
Daniel Sanders3f6eb542013-11-12 10:45:18 +00001467 case Intrinsic::mips_bclr_b:
1468 case Intrinsic::mips_bclr_h:
1469 case Intrinsic::mips_bclr_w:
1470 case Intrinsic::mips_bclr_d:
1471 return lowerMSABitClear(Op, DAG);
1472 case Intrinsic::mips_bclri_b:
1473 case Intrinsic::mips_bclri_h:
1474 case Intrinsic::mips_bclri_w:
1475 case Intrinsic::mips_bclri_d:
1476 return lowerMSABitClearImm(Op, DAG);
Daniel Sandersd74b1302013-10-30 14:45:14 +00001477 case Intrinsic::mips_binsli_b:
1478 case Intrinsic::mips_binsli_h:
1479 case Intrinsic::mips_binsli_w:
1480 case Intrinsic::mips_binsli_d: {
Daniel Sandersdf2215452014-03-12 11:54:00 +00001481 // binsli_x(IfClear, IfSet, nbits) -> (vselect LBitsMask, IfSet, IfClear)
Daniel Sandersd74b1302013-10-30 14:45:14 +00001482 EVT VecTy = Op->getValueType(0);
1483 EVT EltTy = VecTy.getVectorElementType();
1484 APInt Mask = APInt::getHighBitsSet(EltTy.getSizeInBits(),
1485 Op->getConstantOperandVal(3));
1486 return DAG.getNode(ISD::VSELECT, DL, VecTy,
Daniel Sandersdf2215452014-03-12 11:54:00 +00001487 DAG.getConstant(Mask, VecTy, true), Op->getOperand(2),
1488 Op->getOperand(1));
Daniel Sandersd74b1302013-10-30 14:45:14 +00001489 }
1490 case Intrinsic::mips_binsri_b:
1491 case Intrinsic::mips_binsri_h:
1492 case Intrinsic::mips_binsri_w:
1493 case Intrinsic::mips_binsri_d: {
Daniel Sandersdf2215452014-03-12 11:54:00 +00001494 // binsri_x(IfClear, IfSet, nbits) -> (vselect RBitsMask, IfSet, IfClear)
Daniel Sandersd74b1302013-10-30 14:45:14 +00001495 EVT VecTy = Op->getValueType(0);
1496 EVT EltTy = VecTy.getVectorElementType();
1497 APInt Mask = APInt::getLowBitsSet(EltTy.getSizeInBits(),
1498 Op->getConstantOperandVal(3));
1499 return DAG.getNode(ISD::VSELECT, DL, VecTy,
Daniel Sandersdf2215452014-03-12 11:54:00 +00001500 DAG.getConstant(Mask, VecTy, true), Op->getOperand(2),
1501 Op->getOperand(1));
Daniel Sandersd74b1302013-10-30 14:45:14 +00001502 }
Daniel Sandersab94b532013-10-30 15:20:38 +00001503 case Intrinsic::mips_bmnz_v:
1504 return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0), Op->getOperand(3),
1505 Op->getOperand(2), Op->getOperand(1));
1506 case Intrinsic::mips_bmnzi_b:
1507 return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0),
1508 lowerMSASplatImm(Op, 3, DAG), Op->getOperand(2),
1509 Op->getOperand(1));
1510 case Intrinsic::mips_bmz_v:
1511 return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0), Op->getOperand(3),
1512 Op->getOperand(1), Op->getOperand(2));
1513 case Intrinsic::mips_bmzi_b:
1514 return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0),
1515 lowerMSASplatImm(Op, 3, DAG), Op->getOperand(1),
1516 Op->getOperand(2));
Daniel Sandersa5bc99f2013-11-12 10:31:49 +00001517 case Intrinsic::mips_bneg_b:
1518 case Intrinsic::mips_bneg_h:
1519 case Intrinsic::mips_bneg_w:
1520 case Intrinsic::mips_bneg_d: {
1521 EVT VecTy = Op->getValueType(0);
Daniel Sanders50b80412013-11-15 12:56:49 +00001522 SDValue One = DAG.getConstant(1, VecTy);
Daniel Sandersa5bc99f2013-11-12 10:31:49 +00001523
1524 return DAG.getNode(ISD::XOR, DL, VecTy, Op->getOperand(1),
1525 DAG.getNode(ISD::SHL, DL, VecTy, One,
1526 Op->getOperand(2)));
1527 }
1528 case Intrinsic::mips_bnegi_b:
1529 case Intrinsic::mips_bnegi_h:
1530 case Intrinsic::mips_bnegi_w:
1531 case Intrinsic::mips_bnegi_d:
1532 return lowerMSABinaryBitImmIntr(Op, DAG, ISD::XOR, Op->getOperand(2),
1533 !Subtarget->isLittle());
Daniel Sandersce09d072013-08-28 12:14:50 +00001534 case Intrinsic::mips_bnz_b:
1535 case Intrinsic::mips_bnz_h:
1536 case Intrinsic::mips_bnz_w:
1537 case Intrinsic::mips_bnz_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001538 return DAG.getNode(MipsISD::VALL_NONZERO, DL, Op->getValueType(0),
1539 Op->getOperand(1));
Daniel Sandersce09d072013-08-28 12:14:50 +00001540 case Intrinsic::mips_bnz_v:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001541 return DAG.getNode(MipsISD::VANY_NONZERO, DL, Op->getValueType(0),
1542 Op->getOperand(1));
Daniel Sanderse1d24352013-09-24 12:04:44 +00001543 case Intrinsic::mips_bsel_v:
Daniel Sandersdf2215452014-03-12 11:54:00 +00001544 // bsel_v(Mask, IfClear, IfSet) -> (vselect Mask, IfSet, IfClear)
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001545 return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0),
Daniel Sandersdf2215452014-03-12 11:54:00 +00001546 Op->getOperand(1), Op->getOperand(3),
1547 Op->getOperand(2));
Daniel Sanderse1d24352013-09-24 12:04:44 +00001548 case Intrinsic::mips_bseli_b:
Daniel Sandersdf2215452014-03-12 11:54:00 +00001549 // bseli_v(Mask, IfClear, IfSet) -> (vselect Mask, IfSet, IfClear)
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001550 return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0),
Daniel Sandersdf2215452014-03-12 11:54:00 +00001551 Op->getOperand(1), lowerMSASplatImm(Op, 3, DAG),
1552 Op->getOperand(2));
Daniel Sandersa5bc99f2013-11-12 10:31:49 +00001553 case Intrinsic::mips_bset_b:
1554 case Intrinsic::mips_bset_h:
1555 case Intrinsic::mips_bset_w:
1556 case Intrinsic::mips_bset_d: {
1557 EVT VecTy = Op->getValueType(0);
Daniel Sanders50b80412013-11-15 12:56:49 +00001558 SDValue One = DAG.getConstant(1, VecTy);
Daniel Sandersa5bc99f2013-11-12 10:31:49 +00001559
1560 return DAG.getNode(ISD::OR, DL, VecTy, Op->getOperand(1),
1561 DAG.getNode(ISD::SHL, DL, VecTy, One,
1562 Op->getOperand(2)));
1563 }
1564 case Intrinsic::mips_bseti_b:
1565 case Intrinsic::mips_bseti_h:
1566 case Intrinsic::mips_bseti_w:
1567 case Intrinsic::mips_bseti_d:
1568 return lowerMSABinaryBitImmIntr(Op, DAG, ISD::OR, Op->getOperand(2),
1569 !Subtarget->isLittle());
Daniel Sandersce09d072013-08-28 12:14:50 +00001570 case Intrinsic::mips_bz_b:
1571 case Intrinsic::mips_bz_h:
1572 case Intrinsic::mips_bz_w:
1573 case Intrinsic::mips_bz_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001574 return DAG.getNode(MipsISD::VALL_ZERO, DL, Op->getValueType(0),
1575 Op->getOperand(1));
Daniel Sandersce09d072013-08-28 12:14:50 +00001576 case Intrinsic::mips_bz_v:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001577 return DAG.getNode(MipsISD::VANY_ZERO, DL, Op->getValueType(0),
1578 Op->getOperand(1));
Daniel Sandersfd538dc2013-09-24 10:46:19 +00001579 case Intrinsic::mips_ceq_b:
1580 case Intrinsic::mips_ceq_h:
1581 case Intrinsic::mips_ceq_w:
1582 case Intrinsic::mips_ceq_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001583 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
Daniel Sandersfd538dc2013-09-24 10:46:19 +00001584 Op->getOperand(2), ISD::SETEQ);
1585 case Intrinsic::mips_ceqi_b:
1586 case Intrinsic::mips_ceqi_h:
1587 case Intrinsic::mips_ceqi_w:
1588 case Intrinsic::mips_ceqi_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001589 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
Daniel Sandersfd538dc2013-09-24 10:46:19 +00001590 lowerMSASplatImm(Op, 2, DAG), ISD::SETEQ);
1591 case Intrinsic::mips_cle_s_b:
1592 case Intrinsic::mips_cle_s_h:
1593 case Intrinsic::mips_cle_s_w:
1594 case Intrinsic::mips_cle_s_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001595 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
Daniel Sandersfd538dc2013-09-24 10:46:19 +00001596 Op->getOperand(2), ISD::SETLE);
1597 case Intrinsic::mips_clei_s_b:
1598 case Intrinsic::mips_clei_s_h:
1599 case Intrinsic::mips_clei_s_w:
1600 case Intrinsic::mips_clei_s_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001601 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
Daniel Sandersfd538dc2013-09-24 10:46:19 +00001602 lowerMSASplatImm(Op, 2, DAG), ISD::SETLE);
1603 case Intrinsic::mips_cle_u_b:
1604 case Intrinsic::mips_cle_u_h:
1605 case Intrinsic::mips_cle_u_w:
1606 case Intrinsic::mips_cle_u_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001607 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
Daniel Sandersfd538dc2013-09-24 10:46:19 +00001608 Op->getOperand(2), ISD::SETULE);
1609 case Intrinsic::mips_clei_u_b:
1610 case Intrinsic::mips_clei_u_h:
1611 case Intrinsic::mips_clei_u_w:
1612 case Intrinsic::mips_clei_u_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001613 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
Daniel Sandersfd538dc2013-09-24 10:46:19 +00001614 lowerMSASplatImm(Op, 2, DAG), ISD::SETULE);
1615 case Intrinsic::mips_clt_s_b:
1616 case Intrinsic::mips_clt_s_h:
1617 case Intrinsic::mips_clt_s_w:
1618 case Intrinsic::mips_clt_s_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001619 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
Daniel Sandersfd538dc2013-09-24 10:46:19 +00001620 Op->getOperand(2), ISD::SETLT);
1621 case Intrinsic::mips_clti_s_b:
1622 case Intrinsic::mips_clti_s_h:
1623 case Intrinsic::mips_clti_s_w:
1624 case Intrinsic::mips_clti_s_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001625 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
Daniel Sandersfd538dc2013-09-24 10:46:19 +00001626 lowerMSASplatImm(Op, 2, DAG), ISD::SETLT);
1627 case Intrinsic::mips_clt_u_b:
1628 case Intrinsic::mips_clt_u_h:
1629 case Intrinsic::mips_clt_u_w:
1630 case Intrinsic::mips_clt_u_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001631 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
Daniel Sandersfd538dc2013-09-24 10:46:19 +00001632 Op->getOperand(2), ISD::SETULT);
1633 case Intrinsic::mips_clti_u_b:
1634 case Intrinsic::mips_clti_u_h:
1635 case Intrinsic::mips_clti_u_w:
1636 case Intrinsic::mips_clti_u_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001637 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
Daniel Sandersfd538dc2013-09-24 10:46:19 +00001638 lowerMSASplatImm(Op, 2, DAG), ISD::SETULT);
Daniel Sandersa4c8f3a2013-09-23 14:03:12 +00001639 case Intrinsic::mips_copy_s_b:
1640 case Intrinsic::mips_copy_s_h:
1641 case Intrinsic::mips_copy_s_w:
1642 return lowerMSACopyIntr(Op, DAG, MipsISD::VEXTRACT_SEXT_ELT);
Daniel Sanders7f3d9462013-09-27 13:04:21 +00001643 case Intrinsic::mips_copy_s_d:
Daniel Sandersd897b562014-03-27 10:46:12 +00001644 if (hasMips64())
Matheus Almeida74070322014-01-29 14:05:28 +00001645 // Lower directly into VEXTRACT_SEXT_ELT since i64 is legal on Mips64.
1646 return lowerMSACopyIntr(Op, DAG, MipsISD::VEXTRACT_SEXT_ELT);
1647 else {
1648 // Lower into the generic EXTRACT_VECTOR_ELT node and let the type
1649 // legalizer and EXTRACT_VECTOR_ELT lowering sort it out.
1650 return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SDLoc(Op),
1651 Op->getValueType(0), Op->getOperand(1),
1652 Op->getOperand(2));
1653 }
Daniel Sandersa4c8f3a2013-09-23 14:03:12 +00001654 case Intrinsic::mips_copy_u_b:
1655 case Intrinsic::mips_copy_u_h:
1656 case Intrinsic::mips_copy_u_w:
1657 return lowerMSACopyIntr(Op, DAG, MipsISD::VEXTRACT_ZEXT_ELT);
Daniel Sanders7f3d9462013-09-27 13:04:21 +00001658 case Intrinsic::mips_copy_u_d:
Daniel Sandersd897b562014-03-27 10:46:12 +00001659 if (hasMips64())
Matheus Almeida74070322014-01-29 14:05:28 +00001660 // Lower directly into VEXTRACT_ZEXT_ELT since i64 is legal on Mips64.
1661 return lowerMSACopyIntr(Op, DAG, MipsISD::VEXTRACT_ZEXT_ELT);
1662 else {
1663 // Lower into the generic EXTRACT_VECTOR_ELT node and let the type
1664 // legalizer and EXTRACT_VECTOR_ELT lowering sort it out.
1665 // Note: When i64 is illegal, this results in copy_s.w instructions
1666 // instead of copy_u.w instructions. This makes no difference to the
1667 // behaviour since i64 is only illegal when the register file is 32-bit.
1668 return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SDLoc(Op),
1669 Op->getValueType(0), Op->getOperand(1),
1670 Op->getOperand(2));
1671 }
Daniel Sanders607952b2013-09-11 10:38:58 +00001672 case Intrinsic::mips_div_s_b:
1673 case Intrinsic::mips_div_s_h:
1674 case Intrinsic::mips_div_s_w:
1675 case Intrinsic::mips_div_s_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001676 return DAG.getNode(ISD::SDIV, DL, Op->getValueType(0), Op->getOperand(1),
1677 Op->getOperand(2));
Daniel Sanders607952b2013-09-11 10:38:58 +00001678 case Intrinsic::mips_div_u_b:
1679 case Intrinsic::mips_div_u_h:
1680 case Intrinsic::mips_div_u_w:
1681 case Intrinsic::mips_div_u_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001682 return DAG.getNode(ISD::UDIV, DL, Op->getValueType(0), Op->getOperand(1),
1683 Op->getOperand(2));
Daniel Sandersf5bd9372013-09-11 10:51:30 +00001684 case Intrinsic::mips_fadd_w:
1685 case Intrinsic::mips_fadd_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001686 return DAG.getNode(ISD::FADD, DL, Op->getValueType(0), Op->getOperand(1),
1687 Op->getOperand(2));
Daniel Sandersfd538dc2013-09-24 10:46:19 +00001688 // Don't lower mips_fcaf_[wd] since LLVM folds SETFALSE condcodes away
1689 case Intrinsic::mips_fceq_w:
1690 case Intrinsic::mips_fceq_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001691 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
Daniel Sandersfd538dc2013-09-24 10:46:19 +00001692 Op->getOperand(2), ISD::SETOEQ);
1693 case Intrinsic::mips_fcle_w:
1694 case Intrinsic::mips_fcle_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001695 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
Daniel Sandersfd538dc2013-09-24 10:46:19 +00001696 Op->getOperand(2), ISD::SETOLE);
1697 case Intrinsic::mips_fclt_w:
1698 case Intrinsic::mips_fclt_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001699 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
Daniel Sandersfd538dc2013-09-24 10:46:19 +00001700 Op->getOperand(2), ISD::SETOLT);
1701 case Intrinsic::mips_fcne_w:
1702 case Intrinsic::mips_fcne_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001703 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
Daniel Sandersfd538dc2013-09-24 10:46:19 +00001704 Op->getOperand(2), ISD::SETONE);
1705 case Intrinsic::mips_fcor_w:
1706 case Intrinsic::mips_fcor_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001707 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
Daniel Sandersfd538dc2013-09-24 10:46:19 +00001708 Op->getOperand(2), ISD::SETO);
1709 case Intrinsic::mips_fcueq_w:
1710 case Intrinsic::mips_fcueq_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001711 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
Daniel Sandersfd538dc2013-09-24 10:46:19 +00001712 Op->getOperand(2), ISD::SETUEQ);
1713 case Intrinsic::mips_fcule_w:
1714 case Intrinsic::mips_fcule_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001715 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
Daniel Sandersfd538dc2013-09-24 10:46:19 +00001716 Op->getOperand(2), ISD::SETULE);
1717 case Intrinsic::mips_fcult_w:
1718 case Intrinsic::mips_fcult_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001719 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
Daniel Sandersfd538dc2013-09-24 10:46:19 +00001720 Op->getOperand(2), ISD::SETULT);
1721 case Intrinsic::mips_fcun_w:
1722 case Intrinsic::mips_fcun_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001723 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
Daniel Sandersfd538dc2013-09-24 10:46:19 +00001724 Op->getOperand(2), ISD::SETUO);
1725 case Intrinsic::mips_fcune_w:
1726 case Intrinsic::mips_fcune_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001727 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
Daniel Sandersfd538dc2013-09-24 10:46:19 +00001728 Op->getOperand(2), ISD::SETUNE);
Daniel Sandersf5bd9372013-09-11 10:51:30 +00001729 case Intrinsic::mips_fdiv_w:
1730 case Intrinsic::mips_fdiv_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001731 return DAG.getNode(ISD::FDIV, DL, Op->getValueType(0), Op->getOperand(1),
1732 Op->getOperand(2));
Daniel Sanders015972b2013-10-11 10:00:06 +00001733 case Intrinsic::mips_ffint_u_w:
1734 case Intrinsic::mips_ffint_u_d:
1735 return DAG.getNode(ISD::UINT_TO_FP, DL, Op->getValueType(0),
1736 Op->getOperand(1));
1737 case Intrinsic::mips_ffint_s_w:
1738 case Intrinsic::mips_ffint_s_d:
1739 return DAG.getNode(ISD::SINT_TO_FP, DL, Op->getValueType(0),
1740 Op->getOperand(1));
Daniel Sanders7a289d02013-09-23 12:02:46 +00001741 case Intrinsic::mips_fill_b:
1742 case Intrinsic::mips_fill_h:
Daniel Sandersc72593e2013-09-27 13:20:41 +00001743 case Intrinsic::mips_fill_w:
1744 case Intrinsic::mips_fill_d: {
Daniel Sandersf49dd822013-09-24 13:33:07 +00001745 SmallVector<SDValue, 16> Ops;
1746 EVT ResTy = Op->getValueType(0);
1747
1748 for (unsigned i = 0; i < ResTy.getVectorNumElements(); ++i)
1749 Ops.push_back(Op->getOperand(1));
1750
Daniel Sandersc72593e2013-09-27 13:20:41 +00001751 // If ResTy is v2i64 then the type legalizer will break this node down into
1752 // an equivalent v4i32.
Craig Topper48d114b2014-04-26 18:35:24 +00001753 return DAG.getNode(ISD::BUILD_VECTOR, DL, ResTy, Ops);
Daniel Sandersf49dd822013-09-24 13:33:07 +00001754 }
Daniel Sandersa9521602013-10-23 10:36:52 +00001755 case Intrinsic::mips_fexp2_w:
1756 case Intrinsic::mips_fexp2_d: {
1757 EVT ResTy = Op->getValueType(0);
1758 return DAG.getNode(
1759 ISD::FMUL, SDLoc(Op), ResTy, Op->getOperand(1),
1760 DAG.getNode(ISD::FEXP2, SDLoc(Op), ResTy, Op->getOperand(2)));
1761 }
Daniel Sandersf5bd9372013-09-11 10:51:30 +00001762 case Intrinsic::mips_flog2_w:
1763 case Intrinsic::mips_flog2_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001764 return DAG.getNode(ISD::FLOG2, DL, Op->getValueType(0), Op->getOperand(1));
Daniel Sandersd7103f32013-10-11 10:14:25 +00001765 case Intrinsic::mips_fmadd_w:
1766 case Intrinsic::mips_fmadd_d:
1767 return DAG.getNode(ISD::FMA, SDLoc(Op), Op->getValueType(0),
1768 Op->getOperand(1), Op->getOperand(2), Op->getOperand(3));
Daniel Sandersf5bd9372013-09-11 10:51:30 +00001769 case Intrinsic::mips_fmul_w:
1770 case Intrinsic::mips_fmul_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001771 return DAG.getNode(ISD::FMUL, DL, Op->getValueType(0), Op->getOperand(1),
1772 Op->getOperand(2));
Daniel Sanderse67bd872013-10-11 10:27:32 +00001773 case Intrinsic::mips_fmsub_w:
1774 case Intrinsic::mips_fmsub_d: {
1775 EVT ResTy = Op->getValueType(0);
1776 return DAG.getNode(ISD::FSUB, SDLoc(Op), ResTy, Op->getOperand(1),
1777 DAG.getNode(ISD::FMUL, SDLoc(Op), ResTy,
1778 Op->getOperand(2), Op->getOperand(3)));
1779 }
Daniel Sandersf5bd9372013-09-11 10:51:30 +00001780 case Intrinsic::mips_frint_w:
1781 case Intrinsic::mips_frint_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001782 return DAG.getNode(ISD::FRINT, DL, Op->getValueType(0), Op->getOperand(1));
Daniel Sandersf5bd9372013-09-11 10:51:30 +00001783 case Intrinsic::mips_fsqrt_w:
1784 case Intrinsic::mips_fsqrt_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001785 return DAG.getNode(ISD::FSQRT, DL, Op->getValueType(0), Op->getOperand(1));
Daniel Sandersf5bd9372013-09-11 10:51:30 +00001786 case Intrinsic::mips_fsub_w:
1787 case Intrinsic::mips_fsub_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001788 return DAG.getNode(ISD::FSUB, DL, Op->getValueType(0), Op->getOperand(1),
1789 Op->getOperand(2));
Daniel Sanders015972b2013-10-11 10:00:06 +00001790 case Intrinsic::mips_ftrunc_u_w:
1791 case Intrinsic::mips_ftrunc_u_d:
1792 return DAG.getNode(ISD::FP_TO_UINT, DL, Op->getValueType(0),
1793 Op->getOperand(1));
1794 case Intrinsic::mips_ftrunc_s_w:
1795 case Intrinsic::mips_ftrunc_s_d:
1796 return DAG.getNode(ISD::FP_TO_SINT, DL, Op->getValueType(0),
1797 Op->getOperand(1));
Daniel Sanders2ed228b2013-09-24 14:36:12 +00001798 case Intrinsic::mips_ilvev_b:
1799 case Intrinsic::mips_ilvev_h:
1800 case Intrinsic::mips_ilvev_w:
1801 case Intrinsic::mips_ilvev_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001802 return DAG.getNode(MipsISD::ILVEV, DL, Op->getValueType(0),
Daniel Sanders2ed228b2013-09-24 14:36:12 +00001803 Op->getOperand(1), Op->getOperand(2));
1804 case Intrinsic::mips_ilvl_b:
1805 case Intrinsic::mips_ilvl_h:
1806 case Intrinsic::mips_ilvl_w:
1807 case Intrinsic::mips_ilvl_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001808 return DAG.getNode(MipsISD::ILVL, DL, Op->getValueType(0),
Daniel Sanders2ed228b2013-09-24 14:36:12 +00001809 Op->getOperand(1), Op->getOperand(2));
1810 case Intrinsic::mips_ilvod_b:
1811 case Intrinsic::mips_ilvod_h:
1812 case Intrinsic::mips_ilvod_w:
1813 case Intrinsic::mips_ilvod_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001814 return DAG.getNode(MipsISD::ILVOD, DL, Op->getValueType(0),
Daniel Sanders2ed228b2013-09-24 14:36:12 +00001815 Op->getOperand(1), Op->getOperand(2));
1816 case Intrinsic::mips_ilvr_b:
1817 case Intrinsic::mips_ilvr_h:
1818 case Intrinsic::mips_ilvr_w:
1819 case Intrinsic::mips_ilvr_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001820 return DAG.getNode(MipsISD::ILVR, DL, Op->getValueType(0),
Daniel Sanders2ed228b2013-09-24 14:36:12 +00001821 Op->getOperand(1), Op->getOperand(2));
Daniel Sandersa4c8f3a2013-09-23 14:03:12 +00001822 case Intrinsic::mips_insert_b:
1823 case Intrinsic::mips_insert_h:
1824 case Intrinsic::mips_insert_w:
Daniel Sanders6098b332013-09-27 13:36:54 +00001825 case Intrinsic::mips_insert_d:
1826 return DAG.getNode(ISD::INSERT_VECTOR_ELT, SDLoc(Op), Op->getValueType(0),
1827 Op->getOperand(1), Op->getOperand(3), Op->getOperand(2));
Daniel Sandersb50ccf82014-04-01 10:35:28 +00001828 case Intrinsic::mips_insve_b:
1829 case Intrinsic::mips_insve_h:
1830 case Intrinsic::mips_insve_w:
1831 case Intrinsic::mips_insve_d:
1832 return DAG.getNode(MipsISD::INSVE, DL, Op->getValueType(0),
1833 Op->getOperand(1), Op->getOperand(2), Op->getOperand(3),
1834 DAG.getConstant(0, MVT::i32));
Daniel Sanders7a289d02013-09-23 12:02:46 +00001835 case Intrinsic::mips_ldi_b:
1836 case Intrinsic::mips_ldi_h:
1837 case Intrinsic::mips_ldi_w:
1838 case Intrinsic::mips_ldi_d:
Daniel Sandersf49dd822013-09-24 13:33:07 +00001839 return lowerMSASplatImm(Op, 1, DAG);
Matheus Almeida4b27eb52014-02-10 12:05:17 +00001840 case Intrinsic::mips_lsa:
1841 case Intrinsic::mips_dlsa: {
Daniel Sandersa4eaf592013-10-17 13:38:20 +00001842 EVT ResTy = Op->getValueType(0);
1843 return DAG.getNode(ISD::ADD, SDLoc(Op), ResTy, Op->getOperand(1),
1844 DAG.getNode(ISD::SHL, SDLoc(Op), ResTy,
1845 Op->getOperand(2), Op->getOperand(3)));
1846 }
Daniel Sanders50e5ed32013-10-11 10:50:42 +00001847 case Intrinsic::mips_maddv_b:
1848 case Intrinsic::mips_maddv_h:
1849 case Intrinsic::mips_maddv_w:
1850 case Intrinsic::mips_maddv_d: {
1851 EVT ResTy = Op->getValueType(0);
1852 return DAG.getNode(ISD::ADD, SDLoc(Op), ResTy, Op->getOperand(1),
1853 DAG.getNode(ISD::MUL, SDLoc(Op), ResTy,
1854 Op->getOperand(2), Op->getOperand(3)));
1855 }
Daniel Sanders3ce56622013-09-24 12:18:31 +00001856 case Intrinsic::mips_max_s_b:
1857 case Intrinsic::mips_max_s_h:
1858 case Intrinsic::mips_max_s_w:
1859 case Intrinsic::mips_max_s_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001860 return DAG.getNode(MipsISD::VSMAX, DL, Op->getValueType(0),
1861 Op->getOperand(1), Op->getOperand(2));
Daniel Sanders3ce56622013-09-24 12:18:31 +00001862 case Intrinsic::mips_max_u_b:
1863 case Intrinsic::mips_max_u_h:
1864 case Intrinsic::mips_max_u_w:
1865 case Intrinsic::mips_max_u_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001866 return DAG.getNode(MipsISD::VUMAX, DL, Op->getValueType(0),
1867 Op->getOperand(1), Op->getOperand(2));
Daniel Sanders3ce56622013-09-24 12:18:31 +00001868 case Intrinsic::mips_maxi_s_b:
1869 case Intrinsic::mips_maxi_s_h:
1870 case Intrinsic::mips_maxi_s_w:
1871 case Intrinsic::mips_maxi_s_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001872 return DAG.getNode(MipsISD::VSMAX, DL, Op->getValueType(0),
1873 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
Daniel Sanders3ce56622013-09-24 12:18:31 +00001874 case Intrinsic::mips_maxi_u_b:
1875 case Intrinsic::mips_maxi_u_h:
1876 case Intrinsic::mips_maxi_u_w:
1877 case Intrinsic::mips_maxi_u_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001878 return DAG.getNode(MipsISD::VUMAX, DL, Op->getValueType(0),
1879 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
Daniel Sanders3ce56622013-09-24 12:18:31 +00001880 case Intrinsic::mips_min_s_b:
1881 case Intrinsic::mips_min_s_h:
1882 case Intrinsic::mips_min_s_w:
1883 case Intrinsic::mips_min_s_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001884 return DAG.getNode(MipsISD::VSMIN, DL, Op->getValueType(0),
1885 Op->getOperand(1), Op->getOperand(2));
Daniel Sanders3ce56622013-09-24 12:18:31 +00001886 case Intrinsic::mips_min_u_b:
1887 case Intrinsic::mips_min_u_h:
1888 case Intrinsic::mips_min_u_w:
1889 case Intrinsic::mips_min_u_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001890 return DAG.getNode(MipsISD::VUMIN, DL, Op->getValueType(0),
1891 Op->getOperand(1), Op->getOperand(2));
Daniel Sanders3ce56622013-09-24 12:18:31 +00001892 case Intrinsic::mips_mini_s_b:
1893 case Intrinsic::mips_mini_s_h:
1894 case Intrinsic::mips_mini_s_w:
1895 case Intrinsic::mips_mini_s_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001896 return DAG.getNode(MipsISD::VSMIN, DL, Op->getValueType(0),
1897 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
Daniel Sanders3ce56622013-09-24 12:18:31 +00001898 case Intrinsic::mips_mini_u_b:
1899 case Intrinsic::mips_mini_u_h:
1900 case Intrinsic::mips_mini_u_w:
1901 case Intrinsic::mips_mini_u_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001902 return DAG.getNode(MipsISD::VUMIN, DL, Op->getValueType(0),
1903 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
Daniel Sanders0210dd42013-10-01 10:22:35 +00001904 case Intrinsic::mips_mod_s_b:
1905 case Intrinsic::mips_mod_s_h:
1906 case Intrinsic::mips_mod_s_w:
1907 case Intrinsic::mips_mod_s_d:
1908 return DAG.getNode(ISD::SREM, DL, Op->getValueType(0), Op->getOperand(1),
1909 Op->getOperand(2));
1910 case Intrinsic::mips_mod_u_b:
1911 case Intrinsic::mips_mod_u_h:
1912 case Intrinsic::mips_mod_u_w:
1913 case Intrinsic::mips_mod_u_d:
1914 return DAG.getNode(ISD::UREM, DL, Op->getValueType(0), Op->getOperand(1),
1915 Op->getOperand(2));
Daniel Sandersfbcb5822013-09-11 11:58:30 +00001916 case Intrinsic::mips_mulv_b:
1917 case Intrinsic::mips_mulv_h:
1918 case Intrinsic::mips_mulv_w:
1919 case Intrinsic::mips_mulv_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001920 return DAG.getNode(ISD::MUL, DL, Op->getValueType(0), Op->getOperand(1),
1921 Op->getOperand(2));
Daniel Sanders50e5ed32013-10-11 10:50:42 +00001922 case Intrinsic::mips_msubv_b:
1923 case Intrinsic::mips_msubv_h:
1924 case Intrinsic::mips_msubv_w:
1925 case Intrinsic::mips_msubv_d: {
1926 EVT ResTy = Op->getValueType(0);
1927 return DAG.getNode(ISD::SUB, SDLoc(Op), ResTy, Op->getOperand(1),
1928 DAG.getNode(ISD::MUL, SDLoc(Op), ResTy,
1929 Op->getOperand(2), Op->getOperand(3)));
1930 }
Daniel Sandersfbcb5822013-09-11 11:58:30 +00001931 case Intrinsic::mips_nlzc_b:
1932 case Intrinsic::mips_nlzc_h:
1933 case Intrinsic::mips_nlzc_w:
1934 case Intrinsic::mips_nlzc_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001935 return DAG.getNode(ISD::CTLZ, DL, Op->getValueType(0), Op->getOperand(1));
Daniel Sandersf7456c72013-09-23 13:22:24 +00001936 case Intrinsic::mips_nor_v: {
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001937 SDValue Res = DAG.getNode(ISD::OR, DL, Op->getValueType(0),
1938 Op->getOperand(1), Op->getOperand(2));
1939 return DAG.getNOT(DL, Res, Res->getValueType(0));
Daniel Sandersf7456c72013-09-23 13:22:24 +00001940 }
Daniel Sandersbfc39ce2013-09-24 12:32:47 +00001941 case Intrinsic::mips_nori_b: {
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001942 SDValue Res = DAG.getNode(ISD::OR, DL, Op->getValueType(0),
1943 Op->getOperand(1),
1944 lowerMSASplatImm(Op, 2, DAG));
1945 return DAG.getNOT(DL, Res, Res->getValueType(0));
Daniel Sandersbfc39ce2013-09-24 12:32:47 +00001946 }
Daniel Sanders8ca81e42013-09-23 12:57:42 +00001947 case Intrinsic::mips_or_v:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001948 return DAG.getNode(ISD::OR, DL, Op->getValueType(0), Op->getOperand(1),
1949 Op->getOperand(2));
Daniel Sandersbfc39ce2013-09-24 12:32:47 +00001950 case Intrinsic::mips_ori_b:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001951 return DAG.getNode(ISD::OR, DL, Op->getValueType(0),
1952 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
Daniel Sandersfae5f2a2013-09-24 14:53:25 +00001953 case Intrinsic::mips_pckev_b:
1954 case Intrinsic::mips_pckev_h:
1955 case Intrinsic::mips_pckev_w:
1956 case Intrinsic::mips_pckev_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001957 return DAG.getNode(MipsISD::PCKEV, DL, Op->getValueType(0),
Daniel Sandersfae5f2a2013-09-24 14:53:25 +00001958 Op->getOperand(1), Op->getOperand(2));
1959 case Intrinsic::mips_pckod_b:
1960 case Intrinsic::mips_pckod_h:
1961 case Intrinsic::mips_pckod_w:
1962 case Intrinsic::mips_pckod_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001963 return DAG.getNode(MipsISD::PCKOD, DL, Op->getValueType(0),
Daniel Sandersfae5f2a2013-09-24 14:53:25 +00001964 Op->getOperand(1), Op->getOperand(2));
Daniel Sanders766cb692013-09-23 13:40:21 +00001965 case Intrinsic::mips_pcnt_b:
1966 case Intrinsic::mips_pcnt_h:
1967 case Intrinsic::mips_pcnt_w:
1968 case Intrinsic::mips_pcnt_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001969 return DAG.getNode(ISD::CTPOP, DL, Op->getValueType(0), Op->getOperand(1));
Daniel Sanders26307182013-09-24 14:20:00 +00001970 case Intrinsic::mips_shf_b:
1971 case Intrinsic::mips_shf_h:
1972 case Intrinsic::mips_shf_w:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001973 return DAG.getNode(MipsISD::SHF, DL, Op->getValueType(0),
Daniel Sanders26307182013-09-24 14:20:00 +00001974 Op->getOperand(2), Op->getOperand(1));
Daniel Sandersfbcb5822013-09-11 11:58:30 +00001975 case Intrinsic::mips_sll_b:
1976 case Intrinsic::mips_sll_h:
1977 case Intrinsic::mips_sll_w:
1978 case Intrinsic::mips_sll_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001979 return DAG.getNode(ISD::SHL, DL, Op->getValueType(0), Op->getOperand(1),
1980 Op->getOperand(2));
Daniel Sanderscba19222013-09-24 10:28:18 +00001981 case Intrinsic::mips_slli_b:
1982 case Intrinsic::mips_slli_h:
1983 case Intrinsic::mips_slli_w:
1984 case Intrinsic::mips_slli_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00001985 return DAG.getNode(ISD::SHL, DL, Op->getValueType(0),
1986 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
Daniel Sanderse7ef0c82013-10-30 13:07:44 +00001987 case Intrinsic::mips_splat_b:
1988 case Intrinsic::mips_splat_h:
1989 case Intrinsic::mips_splat_w:
1990 case Intrinsic::mips_splat_d:
1991 // We can't lower via VECTOR_SHUFFLE because it requires constant shuffle
1992 // masks, nor can we lower via BUILD_VECTOR & EXTRACT_VECTOR_ELT because
1993 // EXTRACT_VECTOR_ELT can't extract i64's on MIPS32.
1994 // Instead we lower to MipsISD::VSHF and match from there.
1995 return DAG.getNode(MipsISD::VSHF, DL, Op->getValueType(0),
Daniel Sanders50b80412013-11-15 12:56:49 +00001996 lowerMSASplatZExt(Op, 2, DAG), Op->getOperand(1),
Daniel Sanderse7ef0c82013-10-30 13:07:44 +00001997 Op->getOperand(1));
Daniel Sanders7e51fe12013-09-27 11:48:57 +00001998 case Intrinsic::mips_splati_b:
1999 case Intrinsic::mips_splati_h:
2000 case Intrinsic::mips_splati_w:
2001 case Intrinsic::mips_splati_d:
2002 return DAG.getNode(MipsISD::VSHF, DL, Op->getValueType(0),
2003 lowerMSASplatImm(Op, 2, DAG), Op->getOperand(1),
2004 Op->getOperand(1));
Daniel Sandersfbcb5822013-09-11 11:58:30 +00002005 case Intrinsic::mips_sra_b:
2006 case Intrinsic::mips_sra_h:
2007 case Intrinsic::mips_sra_w:
2008 case Intrinsic::mips_sra_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00002009 return DAG.getNode(ISD::SRA, DL, Op->getValueType(0), Op->getOperand(1),
2010 Op->getOperand(2));
Daniel Sanderscba19222013-09-24 10:28:18 +00002011 case Intrinsic::mips_srai_b:
2012 case Intrinsic::mips_srai_h:
2013 case Intrinsic::mips_srai_w:
2014 case Intrinsic::mips_srai_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00002015 return DAG.getNode(ISD::SRA, DL, Op->getValueType(0),
2016 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
Daniel Sandersfbcb5822013-09-11 11:58:30 +00002017 case Intrinsic::mips_srl_b:
2018 case Intrinsic::mips_srl_h:
2019 case Intrinsic::mips_srl_w:
2020 case Intrinsic::mips_srl_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00002021 return DAG.getNode(ISD::SRL, DL, Op->getValueType(0), Op->getOperand(1),
2022 Op->getOperand(2));
Daniel Sanderscba19222013-09-24 10:28:18 +00002023 case Intrinsic::mips_srli_b:
2024 case Intrinsic::mips_srli_h:
2025 case Intrinsic::mips_srli_w:
2026 case Intrinsic::mips_srli_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00002027 return DAG.getNode(ISD::SRL, DL, Op->getValueType(0),
2028 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
Daniel Sandersfbcb5822013-09-11 11:58:30 +00002029 case Intrinsic::mips_subv_b:
2030 case Intrinsic::mips_subv_h:
2031 case Intrinsic::mips_subv_w:
2032 case Intrinsic::mips_subv_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00002033 return DAG.getNode(ISD::SUB, DL, Op->getValueType(0), Op->getOperand(1),
2034 Op->getOperand(2));
Daniel Sanders86d0c8d2013-09-23 14:29:55 +00002035 case Intrinsic::mips_subvi_b:
2036 case Intrinsic::mips_subvi_h:
2037 case Intrinsic::mips_subvi_w:
2038 case Intrinsic::mips_subvi_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00002039 return DAG.getNode(ISD::SUB, DL, Op->getValueType(0),
2040 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
Daniel Sanderse5087042013-09-24 14:02:15 +00002041 case Intrinsic::mips_vshf_b:
2042 case Intrinsic::mips_vshf_h:
2043 case Intrinsic::mips_vshf_w:
2044 case Intrinsic::mips_vshf_d:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00002045 return DAG.getNode(MipsISD::VSHF, DL, Op->getValueType(0),
Daniel Sanderse5087042013-09-24 14:02:15 +00002046 Op->getOperand(1), Op->getOperand(2), Op->getOperand(3));
Daniel Sanders8ca81e42013-09-23 12:57:42 +00002047 case Intrinsic::mips_xor_v:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00002048 return DAG.getNode(ISD::XOR, DL, Op->getValueType(0), Op->getOperand(1),
2049 Op->getOperand(2));
Daniel Sandersbfc39ce2013-09-24 12:32:47 +00002050 case Intrinsic::mips_xori_b:
Daniel Sanders84e7caf2013-09-27 10:25:41 +00002051 return DAG.getNode(ISD::XOR, DL, Op->getValueType(0),
2052 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
Akira Hatanakaa6bbde52013-04-13 02:13:30 +00002053 }
2054}
2055
Daniel Sanderse6ed5b72013-08-28 12:04:29 +00002056static SDValue lowerMSALoadIntr(SDValue Op, SelectionDAG &DAG, unsigned Intr) {
2057 SDLoc DL(Op);
2058 SDValue ChainIn = Op->getOperand(0);
2059 SDValue Address = Op->getOperand(2);
2060 SDValue Offset = Op->getOperand(3);
2061 EVT ResTy = Op->getValueType(0);
2062 EVT PtrTy = Address->getValueType(0);
2063
2064 Address = DAG.getNode(ISD::ADD, DL, PtrTy, Address, Offset);
2065
2066 return DAG.getLoad(ResTy, DL, ChainIn, Address, MachinePointerInfo(), false,
2067 false, false, 16);
2068}
2069
Akira Hatanakaa6bbde52013-04-13 02:13:30 +00002070SDValue MipsSETargetLowering::lowerINTRINSIC_W_CHAIN(SDValue Op,
2071 SelectionDAG &DAG) const {
Daniel Sanderse6ed5b72013-08-28 12:04:29 +00002072 unsigned Intr = cast<ConstantSDNode>(Op->getOperand(1))->getZExtValue();
2073 switch (Intr) {
Akira Hatanakaa6bbde52013-04-13 02:13:30 +00002074 default:
2075 return SDValue();
2076 case Intrinsic::mips_extp:
2077 return lowerDSPIntr(Op, DAG, MipsISD::EXTP);
2078 case Intrinsic::mips_extpdp:
2079 return lowerDSPIntr(Op, DAG, MipsISD::EXTPDP);
2080 case Intrinsic::mips_extr_w:
2081 return lowerDSPIntr(Op, DAG, MipsISD::EXTR_W);
2082 case Intrinsic::mips_extr_r_w:
2083 return lowerDSPIntr(Op, DAG, MipsISD::EXTR_R_W);
2084 case Intrinsic::mips_extr_rs_w:
2085 return lowerDSPIntr(Op, DAG, MipsISD::EXTR_RS_W);
2086 case Intrinsic::mips_extr_s_h:
2087 return lowerDSPIntr(Op, DAG, MipsISD::EXTR_S_H);
2088 case Intrinsic::mips_mthlip:
2089 return lowerDSPIntr(Op, DAG, MipsISD::MTHLIP);
2090 case Intrinsic::mips_mulsaq_s_w_ph:
2091 return lowerDSPIntr(Op, DAG, MipsISD::MULSAQ_S_W_PH);
2092 case Intrinsic::mips_maq_s_w_phl:
2093 return lowerDSPIntr(Op, DAG, MipsISD::MAQ_S_W_PHL);
2094 case Intrinsic::mips_maq_s_w_phr:
2095 return lowerDSPIntr(Op, DAG, MipsISD::MAQ_S_W_PHR);
2096 case Intrinsic::mips_maq_sa_w_phl:
2097 return lowerDSPIntr(Op, DAG, MipsISD::MAQ_SA_W_PHL);
2098 case Intrinsic::mips_maq_sa_w_phr:
2099 return lowerDSPIntr(Op, DAG, MipsISD::MAQ_SA_W_PHR);
2100 case Intrinsic::mips_dpaq_s_w_ph:
2101 return lowerDSPIntr(Op, DAG, MipsISD::DPAQ_S_W_PH);
2102 case Intrinsic::mips_dpsq_s_w_ph:
2103 return lowerDSPIntr(Op, DAG, MipsISD::DPSQ_S_W_PH);
2104 case Intrinsic::mips_dpaq_sa_l_w:
2105 return lowerDSPIntr(Op, DAG, MipsISD::DPAQ_SA_L_W);
2106 case Intrinsic::mips_dpsq_sa_l_w:
2107 return lowerDSPIntr(Op, DAG, MipsISD::DPSQ_SA_L_W);
2108 case Intrinsic::mips_dpaqx_s_w_ph:
2109 return lowerDSPIntr(Op, DAG, MipsISD::DPAQX_S_W_PH);
2110 case Intrinsic::mips_dpaqx_sa_w_ph:
2111 return lowerDSPIntr(Op, DAG, MipsISD::DPAQX_SA_W_PH);
2112 case Intrinsic::mips_dpsqx_s_w_ph:
2113 return lowerDSPIntr(Op, DAG, MipsISD::DPSQX_S_W_PH);
2114 case Intrinsic::mips_dpsqx_sa_w_ph:
2115 return lowerDSPIntr(Op, DAG, MipsISD::DPSQX_SA_W_PH);
Daniel Sanderse6ed5b72013-08-28 12:04:29 +00002116 case Intrinsic::mips_ld_b:
2117 case Intrinsic::mips_ld_h:
2118 case Intrinsic::mips_ld_w:
2119 case Intrinsic::mips_ld_d:
Daniel Sanderse6ed5b72013-08-28 12:04:29 +00002120 return lowerMSALoadIntr(Op, DAG, Intr);
2121 }
2122}
2123
2124static SDValue lowerMSAStoreIntr(SDValue Op, SelectionDAG &DAG, unsigned Intr) {
2125 SDLoc DL(Op);
2126 SDValue ChainIn = Op->getOperand(0);
2127 SDValue Value = Op->getOperand(2);
2128 SDValue Address = Op->getOperand(3);
2129 SDValue Offset = Op->getOperand(4);
2130 EVT PtrTy = Address->getValueType(0);
2131
2132 Address = DAG.getNode(ISD::ADD, DL, PtrTy, Address, Offset);
2133
2134 return DAG.getStore(ChainIn, DL, Value, Address, MachinePointerInfo(), false,
2135 false, 16);
2136}
2137
2138SDValue MipsSETargetLowering::lowerINTRINSIC_VOID(SDValue Op,
2139 SelectionDAG &DAG) const {
2140 unsigned Intr = cast<ConstantSDNode>(Op->getOperand(1))->getZExtValue();
2141 switch (Intr) {
2142 default:
2143 return SDValue();
2144 case Intrinsic::mips_st_b:
2145 case Intrinsic::mips_st_h:
2146 case Intrinsic::mips_st_w:
2147 case Intrinsic::mips_st_d:
Daniel Sandersce09d072013-08-28 12:14:50 +00002148 return lowerMSAStoreIntr(Op, DAG, Intr);
Akira Hatanakaa6bbde52013-04-13 02:13:30 +00002149 }
2150}
2151
Daniel Sanders7a289d02013-09-23 12:02:46 +00002152/// \brief Check if the given BuildVectorSDNode is a splat.
2153/// This method currently relies on DAG nodes being reused when equivalent,
2154/// so it's possible for this to return false even when isConstantSplat returns
2155/// true.
2156static bool isSplatVector(const BuildVectorSDNode *N) {
Daniel Sanders7a289d02013-09-23 12:02:46 +00002157 unsigned int nOps = N->getNumOperands();
Daniel Sandersab94b532013-10-30 15:20:38 +00002158 assert(nOps > 1 && "isSplatVector has 0 or 1 sized build vector");
Daniel Sanders7a289d02013-09-23 12:02:46 +00002159
2160 SDValue Operand0 = N->getOperand(0);
2161
2162 for (unsigned int i = 1; i < nOps; ++i) {
2163 if (N->getOperand(i) != Operand0)
2164 return false;
2165 }
2166
2167 return true;
2168}
2169
Daniel Sandersa4c8f3a2013-09-23 14:03:12 +00002170// Lower ISD::EXTRACT_VECTOR_ELT into MipsISD::VEXTRACT_SEXT_ELT.
2171//
2172// The non-value bits resulting from ISD::EXTRACT_VECTOR_ELT are undefined. We
2173// choose to sign-extend but we could have equally chosen zero-extend. The
2174// DAGCombiner will fold any sign/zero extension of the ISD::EXTRACT_VECTOR_ELT
2175// result into this node later (possibly changing it to a zero-extend in the
2176// process).
2177SDValue MipsSETargetLowering::
2178lowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const {
2179 SDLoc DL(Op);
2180 EVT ResTy = Op->getValueType(0);
2181 SDValue Op0 = Op->getOperand(0);
Daniel Sanders39bb8ba2013-09-27 12:17:32 +00002182 EVT VecTy = Op0->getValueType(0);
2183
2184 if (!VecTy.is128BitVector())
2185 return SDValue();
2186
2187 if (ResTy.isInteger()) {
2188 SDValue Op1 = Op->getOperand(1);
2189 EVT EltTy = VecTy.getVectorElementType();
2190 return DAG.getNode(MipsISD::VEXTRACT_SEXT_ELT, DL, ResTy, Op0, Op1,
2191 DAG.getValueType(EltTy));
2192 }
2193
2194 return Op;
Daniel Sandersa4c8f3a2013-09-23 14:03:12 +00002195}
2196
Daniel Sandersf49dd822013-09-24 13:33:07 +00002197static bool isConstantOrUndef(const SDValue Op) {
2198 if (Op->getOpcode() == ISD::UNDEF)
2199 return true;
2200 if (dyn_cast<ConstantSDNode>(Op))
2201 return true;
2202 if (dyn_cast<ConstantFPSDNode>(Op))
2203 return true;
2204 return false;
2205}
2206
2207static bool isConstantOrUndefBUILD_VECTOR(const BuildVectorSDNode *Op) {
2208 for (unsigned i = 0; i < Op->getNumOperands(); ++i)
2209 if (isConstantOrUndef(Op->getOperand(i)))
2210 return true;
2211 return false;
2212}
2213
Daniel Sanders7a289d02013-09-23 12:02:46 +00002214// Lowers ISD::BUILD_VECTOR into appropriate SelectionDAG nodes for the
2215// backend.
2216//
2217// Lowers according to the following rules:
Daniel Sandersf49dd822013-09-24 13:33:07 +00002218// - Constant splats are legal as-is as long as the SplatBitSize is a power of
2219// 2 less than or equal to 64 and the value fits into a signed 10-bit
2220// immediate
2221// - Constant splats are lowered to bitconverted BUILD_VECTORs if SplatBitSize
2222// is a power of 2 less than or equal to 64 and the value does not fit into a
2223// signed 10-bit immediate
2224// - Non-constant splats are legal as-is.
2225// - Non-constant non-splats are lowered to sequences of INSERT_VECTOR_ELT.
2226// - All others are illegal and must be expanded.
Daniel Sanders7a289d02013-09-23 12:02:46 +00002227SDValue MipsSETargetLowering::lowerBUILD_VECTOR(SDValue Op,
2228 SelectionDAG &DAG) const {
2229 BuildVectorSDNode *Node = cast<BuildVectorSDNode>(Op);
2230 EVT ResTy = Op->getValueType(0);
2231 SDLoc DL(Op);
2232 APInt SplatValue, SplatUndef;
2233 unsigned SplatBitSize;
2234 bool HasAnyUndefs;
2235
2236 if (!Subtarget->hasMSA() || !ResTy.is128BitVector())
2237 return SDValue();
2238
2239 if (Node->isConstantSplat(SplatValue, SplatUndef, SplatBitSize,
2240 HasAnyUndefs, 8,
Daniel Sandersf49dd822013-09-24 13:33:07 +00002241 !Subtarget->isLittle()) && SplatBitSize <= 64) {
2242 // We can only cope with 8, 16, 32, or 64-bit elements
2243 if (SplatBitSize != 8 && SplatBitSize != 16 && SplatBitSize != 32 &&
2244 SplatBitSize != 64)
2245 return SDValue();
2246
2247 // If the value fits into a simm10 then we can use ldi.[bhwd]
Daniel Sandersfd8e4162013-11-22 11:24:50 +00002248 // However, if it isn't an integer type we will have to bitcast from an
Daniel Sandersd40aea82013-11-22 13:22:52 +00002249 // integer type first. Also, if there are any undefs, we must lower them
Daniel Sanders630dbe02013-11-22 13:14:06 +00002250 // to defined values first.
2251 if (ResTy.isInteger() && !HasAnyUndefs && SplatValue.isSignedIntN(10))
Daniel Sandersf49dd822013-09-24 13:33:07 +00002252 return Op;
2253
2254 EVT ViaVecTy;
Daniel Sanders7a289d02013-09-23 12:02:46 +00002255
2256 switch (SplatBitSize) {
2257 default:
2258 return SDValue();
Daniel Sandersf49dd822013-09-24 13:33:07 +00002259 case 8:
2260 ViaVecTy = MVT::v16i8;
Daniel Sanders7a289d02013-09-23 12:02:46 +00002261 break;
2262 case 16:
Daniel Sandersf49dd822013-09-24 13:33:07 +00002263 ViaVecTy = MVT::v8i16;
Daniel Sanders7a289d02013-09-23 12:02:46 +00002264 break;
Daniel Sandersf49dd822013-09-24 13:33:07 +00002265 case 32:
2266 ViaVecTy = MVT::v4i32;
Daniel Sanders7a289d02013-09-23 12:02:46 +00002267 break;
Daniel Sandersf49dd822013-09-24 13:33:07 +00002268 case 64:
2269 // There's no fill.d to fall back on for 64-bit values
2270 return SDValue();
Daniel Sanders7a289d02013-09-23 12:02:46 +00002271 }
2272
Daniel Sanders50b80412013-11-15 12:56:49 +00002273 // SelectionDAG::getConstant will promote SplatValue appropriately.
2274 SDValue Result = DAG.getConstant(SplatValue, ViaVecTy);
Daniel Sandersf49dd822013-09-24 13:33:07 +00002275
Daniel Sanders50b80412013-11-15 12:56:49 +00002276 // Bitcast to the type we originally wanted
Daniel Sandersf49dd822013-09-24 13:33:07 +00002277 if (ViaVecTy != ResTy)
2278 Result = DAG.getNode(ISD::BITCAST, SDLoc(Node), ResTy, Result);
Daniel Sanders7a289d02013-09-23 12:02:46 +00002279
2280 return Result;
Daniel Sandersf49dd822013-09-24 13:33:07 +00002281 } else if (isSplatVector(Node))
2282 return Op;
2283 else if (!isConstantOrUndefBUILD_VECTOR(Node)) {
Daniel Sandersf86622b2013-09-24 13:16:15 +00002284 // Use INSERT_VECTOR_ELT operations rather than expand to stores.
2285 // The resulting code is the same length as the expansion, but it doesn't
2286 // use memory operations
2287 EVT ResTy = Node->getValueType(0);
2288
2289 assert(ResTy.isVector());
2290
2291 unsigned NumElts = ResTy.getVectorNumElements();
2292 SDValue Vector = DAG.getUNDEF(ResTy);
2293 for (unsigned i = 0; i < NumElts; ++i) {
2294 Vector = DAG.getNode(ISD::INSERT_VECTOR_ELT, DL, ResTy, Vector,
2295 Node->getOperand(i),
2296 DAG.getConstant(i, MVT::i32));
2297 }
2298 return Vector;
2299 }
Daniel Sanders7a289d02013-09-23 12:02:46 +00002300
2301 return SDValue();
2302}
2303
Daniel Sanders26307182013-09-24 14:20:00 +00002304// Lower VECTOR_SHUFFLE into SHF (if possible).
2305//
2306// SHF splits the vector into blocks of four elements, then shuffles these
2307// elements according to a <4 x i2> constant (encoded as an integer immediate).
2308//
2309// It is therefore possible to lower into SHF when the mask takes the form:
2310// <a, b, c, d, a+4, b+4, c+4, d+4, a+8, b+8, c+8, d+8, ...>
2311// When undef's appear they are treated as if they were whatever value is
2312// necessary in order to fit the above form.
2313//
2314// For example:
2315// %2 = shufflevector <8 x i16> %0, <8 x i16> undef,
2316// <8 x i32> <i32 3, i32 2, i32 1, i32 0,
2317// i32 7, i32 6, i32 5, i32 4>
2318// is lowered to:
2319// (SHF_H $w0, $w1, 27)
2320// where the 27 comes from:
2321// 3 + (2 << 2) + (1 << 4) + (0 << 6)
2322static SDValue lowerVECTOR_SHUFFLE_SHF(SDValue Op, EVT ResTy,
2323 SmallVector<int, 16> Indices,
2324 SelectionDAG &DAG) {
2325 int SHFIndices[4] = { -1, -1, -1, -1 };
2326
2327 if (Indices.size() < 4)
2328 return SDValue();
2329
2330 for (unsigned i = 0; i < 4; ++i) {
2331 for (unsigned j = i; j < Indices.size(); j += 4) {
2332 int Idx = Indices[j];
2333
2334 // Convert from vector index to 4-element subvector index
2335 // If an index refers to an element outside of the subvector then give up
2336 if (Idx != -1) {
2337 Idx -= 4 * (j / 4);
2338 if (Idx < 0 || Idx >= 4)
2339 return SDValue();
2340 }
2341
2342 // If the mask has an undef, replace it with the current index.
2343 // Note that it might still be undef if the current index is also undef
2344 if (SHFIndices[i] == -1)
2345 SHFIndices[i] = Idx;
2346
2347 // Check that non-undef values are the same as in the mask. If they
2348 // aren't then give up
2349 if (!(Idx == -1 || Idx == SHFIndices[i]))
2350 return SDValue();
2351 }
2352 }
2353
2354 // Calculate the immediate. Replace any remaining undefs with zero
2355 APInt Imm(32, 0);
2356 for (int i = 3; i >= 0; --i) {
2357 int Idx = SHFIndices[i];
2358
2359 if (Idx == -1)
2360 Idx = 0;
2361
2362 Imm <<= 2;
2363 Imm |= Idx & 0x3;
2364 }
2365
2366 return DAG.getNode(MipsISD::SHF, SDLoc(Op), ResTy,
2367 DAG.getConstant(Imm, MVT::i32), Op->getOperand(0));
2368}
2369
Daniel Sanders2ed228b2013-09-24 14:36:12 +00002370// Lower VECTOR_SHUFFLE into ILVEV (if possible).
2371//
2372// ILVEV interleaves the even elements from each vector.
2373//
2374// It is possible to lower into ILVEV when the mask takes the form:
2375// <0, n, 2, n+2, 4, n+4, ...>
2376// where n is the number of elements in the vector.
2377//
2378// When undef's appear in the mask they are treated as if they were whatever
2379// value is necessary in order to fit the above form.
2380static SDValue lowerVECTOR_SHUFFLE_ILVEV(SDValue Op, EVT ResTy,
2381 SmallVector<int, 16> Indices,
2382 SelectionDAG &DAG) {
2383 assert ((Indices.size() % 2) == 0);
2384 int WsIdx = 0;
2385 int WtIdx = ResTy.getVectorNumElements();
2386
2387 for (unsigned i = 0; i < Indices.size(); i += 2) {
2388 if (Indices[i] != -1 && Indices[i] != WsIdx)
2389 return SDValue();
2390 if (Indices[i+1] != -1 && Indices[i+1] != WtIdx)
2391 return SDValue();
2392 WsIdx += 2;
2393 WtIdx += 2;
2394 }
2395
2396 return DAG.getNode(MipsISD::ILVEV, SDLoc(Op), ResTy, Op->getOperand(0),
2397 Op->getOperand(1));
2398}
2399
2400// Lower VECTOR_SHUFFLE into ILVOD (if possible).
2401//
2402// ILVOD interleaves the odd elements from each vector.
2403//
2404// It is possible to lower into ILVOD when the mask takes the form:
2405// <1, n+1, 3, n+3, 5, n+5, ...>
2406// where n is the number of elements in the vector.
2407//
2408// When undef's appear in the mask they are treated as if they were whatever
2409// value is necessary in order to fit the above form.
2410static SDValue lowerVECTOR_SHUFFLE_ILVOD(SDValue Op, EVT ResTy,
2411 SmallVector<int, 16> Indices,
2412 SelectionDAG &DAG) {
2413 assert ((Indices.size() % 2) == 0);
2414 int WsIdx = 1;
2415 int WtIdx = ResTy.getVectorNumElements() + 1;
2416
2417 for (unsigned i = 0; i < Indices.size(); i += 2) {
2418 if (Indices[i] != -1 && Indices[i] != WsIdx)
2419 return SDValue();
2420 if (Indices[i+1] != -1 && Indices[i+1] != WtIdx)
2421 return SDValue();
2422 WsIdx += 2;
2423 WtIdx += 2;
2424 }
2425
2426 return DAG.getNode(MipsISD::ILVOD, SDLoc(Op), ResTy, Op->getOperand(0),
2427 Op->getOperand(1));
2428}
2429
2430// Lower VECTOR_SHUFFLE into ILVL (if possible).
2431//
2432// ILVL interleaves consecutive elements from the left half of each vector.
2433//
2434// It is possible to lower into ILVL when the mask takes the form:
2435// <0, n, 1, n+1, 2, n+2, ...>
2436// where n is the number of elements in the vector.
2437//
2438// When undef's appear in the mask they are treated as if they were whatever
2439// value is necessary in order to fit the above form.
2440static SDValue lowerVECTOR_SHUFFLE_ILVL(SDValue Op, EVT ResTy,
2441 SmallVector<int, 16> Indices,
2442 SelectionDAG &DAG) {
2443 assert ((Indices.size() % 2) == 0);
2444 int WsIdx = 0;
2445 int WtIdx = ResTy.getVectorNumElements();
2446
2447 for (unsigned i = 0; i < Indices.size(); i += 2) {
2448 if (Indices[i] != -1 && Indices[i] != WsIdx)
2449 return SDValue();
2450 if (Indices[i+1] != -1 && Indices[i+1] != WtIdx)
2451 return SDValue();
2452 WsIdx ++;
2453 WtIdx ++;
2454 }
2455
2456 return DAG.getNode(MipsISD::ILVL, SDLoc(Op), ResTy, Op->getOperand(0),
2457 Op->getOperand(1));
2458}
2459
2460// Lower VECTOR_SHUFFLE into ILVR (if possible).
2461//
2462// ILVR interleaves consecutive elements from the right half of each vector.
2463//
2464// It is possible to lower into ILVR when the mask takes the form:
2465// <x, n+x, x+1, n+x+1, x+2, n+x+2, ...>
2466// where n is the number of elements in the vector and x is half n.
2467//
2468// When undef's appear in the mask they are treated as if they were whatever
2469// value is necessary in order to fit the above form.
2470static SDValue lowerVECTOR_SHUFFLE_ILVR(SDValue Op, EVT ResTy,
2471 SmallVector<int, 16> Indices,
2472 SelectionDAG &DAG) {
2473 assert ((Indices.size() % 2) == 0);
2474 unsigned NumElts = ResTy.getVectorNumElements();
2475 int WsIdx = NumElts / 2;
2476 int WtIdx = NumElts + NumElts / 2;
2477
2478 for (unsigned i = 0; i < Indices.size(); i += 2) {
2479 if (Indices[i] != -1 && Indices[i] != WsIdx)
2480 return SDValue();
2481 if (Indices[i+1] != -1 && Indices[i+1] != WtIdx)
2482 return SDValue();
2483 WsIdx ++;
2484 WtIdx ++;
2485 }
2486
2487 return DAG.getNode(MipsISD::ILVR, SDLoc(Op), ResTy, Op->getOperand(0),
2488 Op->getOperand(1));
2489}
2490
Daniel Sandersfae5f2a2013-09-24 14:53:25 +00002491// Lower VECTOR_SHUFFLE into PCKEV (if possible).
2492//
2493// PCKEV copies the even elements of each vector into the result vector.
2494//
2495// It is possible to lower into PCKEV when the mask takes the form:
2496// <0, 2, 4, ..., n, n+2, n+4, ...>
2497// where n is the number of elements in the vector.
2498//
2499// When undef's appear in the mask they are treated as if they were whatever
2500// value is necessary in order to fit the above form.
2501static SDValue lowerVECTOR_SHUFFLE_PCKEV(SDValue Op, EVT ResTy,
2502 SmallVector<int, 16> Indices,
2503 SelectionDAG &DAG) {
2504 assert ((Indices.size() % 2) == 0);
2505 int Idx = 0;
2506
2507 for (unsigned i = 0; i < Indices.size(); ++i) {
2508 if (Indices[i] != -1 && Indices[i] != Idx)
2509 return SDValue();
2510 Idx += 2;
2511 }
2512
2513 return DAG.getNode(MipsISD::PCKEV, SDLoc(Op), ResTy, Op->getOperand(0),
2514 Op->getOperand(1));
2515}
2516
2517// Lower VECTOR_SHUFFLE into PCKOD (if possible).
2518//
2519// PCKOD copies the odd elements of each vector into the result vector.
2520//
2521// It is possible to lower into PCKOD when the mask takes the form:
2522// <1, 3, 5, ..., n+1, n+3, n+5, ...>
2523// where n is the number of elements in the vector.
2524//
2525// When undef's appear in the mask they are treated as if they were whatever
2526// value is necessary in order to fit the above form.
2527static SDValue lowerVECTOR_SHUFFLE_PCKOD(SDValue Op, EVT ResTy,
2528 SmallVector<int, 16> Indices,
2529 SelectionDAG &DAG) {
2530 assert ((Indices.size() % 2) == 0);
2531 int Idx = 1;
2532
2533 for (unsigned i = 0; i < Indices.size(); ++i) {
2534 if (Indices[i] != -1 && Indices[i] != Idx)
2535 return SDValue();
2536 Idx += 2;
2537 }
2538
2539 return DAG.getNode(MipsISD::PCKOD, SDLoc(Op), ResTy, Op->getOperand(0),
2540 Op->getOperand(1));
2541}
2542
Daniel Sanderse5087042013-09-24 14:02:15 +00002543// Lower VECTOR_SHUFFLE into VSHF.
2544//
2545// This mostly consists of converting the shuffle indices in Indices into a
2546// BUILD_VECTOR and adding it as an operand to the resulting VSHF. There is
2547// also code to eliminate unused operands of the VECTOR_SHUFFLE. For example,
2548// if the type is v8i16 and all the indices are less than 8 then the second
2549// operand is unused and can be replaced with anything. We choose to replace it
2550// with the used operand since this reduces the number of instructions overall.
2551static SDValue lowerVECTOR_SHUFFLE_VSHF(SDValue Op, EVT ResTy,
2552 SmallVector<int, 16> Indices,
2553 SelectionDAG &DAG) {
2554 SmallVector<SDValue, 16> Ops;
2555 SDValue Op0;
2556 SDValue Op1;
2557 EVT MaskVecTy = ResTy.changeVectorElementTypeToInteger();
2558 EVT MaskEltTy = MaskVecTy.getVectorElementType();
2559 bool Using1stVec = false;
2560 bool Using2ndVec = false;
2561 SDLoc DL(Op);
2562 int ResTyNumElts = ResTy.getVectorNumElements();
2563
2564 for (int i = 0; i < ResTyNumElts; ++i) {
2565 // Idx == -1 means UNDEF
2566 int Idx = Indices[i];
2567
2568 if (0 <= Idx && Idx < ResTyNumElts)
2569 Using1stVec = true;
2570 if (ResTyNumElts <= Idx && Idx < ResTyNumElts * 2)
2571 Using2ndVec = true;
2572 }
2573
2574 for (SmallVector<int, 16>::iterator I = Indices.begin(); I != Indices.end();
2575 ++I)
2576 Ops.push_back(DAG.getTargetConstant(*I, MaskEltTy));
2577
Craig Topper48d114b2014-04-26 18:35:24 +00002578 SDValue MaskVec = DAG.getNode(ISD::BUILD_VECTOR, DL, MaskVecTy, Ops);
Daniel Sanderse5087042013-09-24 14:02:15 +00002579
2580 if (Using1stVec && Using2ndVec) {
2581 Op0 = Op->getOperand(0);
2582 Op1 = Op->getOperand(1);
2583 } else if (Using1stVec)
2584 Op0 = Op1 = Op->getOperand(0);
2585 else if (Using2ndVec)
2586 Op0 = Op1 = Op->getOperand(1);
2587 else
2588 llvm_unreachable("shuffle vector mask references neither vector operand?");
2589
Daniel Sandersf88a29e2014-03-21 16:56:51 +00002590 // VECTOR_SHUFFLE concatenates the vectors in an vectorwise fashion.
2591 // <0b00, 0b01> + <0b10, 0b11> -> <0b00, 0b01, 0b10, 0b11>
2592 // VSHF concatenates the vectors in a bitwise fashion:
2593 // <0b00, 0b01> + <0b10, 0b11> ->
2594 // 0b0100 + 0b1110 -> 0b01001110
2595 // <0b10, 0b11, 0b00, 0b01>
2596 // We must therefore swap the operands to get the correct result.
2597 return DAG.getNode(MipsISD::VSHF, DL, ResTy, MaskVec, Op1, Op0);
Daniel Sanderse5087042013-09-24 14:02:15 +00002598}
2599
2600// Lower VECTOR_SHUFFLE into one of a number of instructions depending on the
2601// indices in the shuffle.
2602SDValue MipsSETargetLowering::lowerVECTOR_SHUFFLE(SDValue Op,
2603 SelectionDAG &DAG) const {
2604 ShuffleVectorSDNode *Node = cast<ShuffleVectorSDNode>(Op);
2605 EVT ResTy = Op->getValueType(0);
2606
2607 if (!ResTy.is128BitVector())
2608 return SDValue();
2609
2610 int ResTyNumElts = ResTy.getVectorNumElements();
2611 SmallVector<int, 16> Indices;
2612
2613 for (int i = 0; i < ResTyNumElts; ++i)
2614 Indices.push_back(Node->getMaskElt(i));
2615
Daniel Sanders26307182013-09-24 14:20:00 +00002616 SDValue Result = lowerVECTOR_SHUFFLE_SHF(Op, ResTy, Indices, DAG);
2617 if (Result.getNode())
2618 return Result;
Daniel Sanders2ed228b2013-09-24 14:36:12 +00002619 Result = lowerVECTOR_SHUFFLE_ILVEV(Op, ResTy, Indices, DAG);
2620 if (Result.getNode())
2621 return Result;
2622 Result = lowerVECTOR_SHUFFLE_ILVOD(Op, ResTy, Indices, DAG);
2623 if (Result.getNode())
2624 return Result;
2625 Result = lowerVECTOR_SHUFFLE_ILVL(Op, ResTy, Indices, DAG);
2626 if (Result.getNode())
2627 return Result;
2628 Result = lowerVECTOR_SHUFFLE_ILVR(Op, ResTy, Indices, DAG);
2629 if (Result.getNode())
2630 return Result;
Daniel Sandersfae5f2a2013-09-24 14:53:25 +00002631 Result = lowerVECTOR_SHUFFLE_PCKEV(Op, ResTy, Indices, DAG);
2632 if (Result.getNode())
2633 return Result;
2634 Result = lowerVECTOR_SHUFFLE_PCKOD(Op, ResTy, Indices, DAG);
2635 if (Result.getNode())
2636 return Result;
Daniel Sanderse5087042013-09-24 14:02:15 +00002637 return lowerVECTOR_SHUFFLE_VSHF(Op, ResTy, Indices, DAG);
2638}
2639
Akira Hatanaka96ca1822013-03-13 00:54:29 +00002640MachineBasicBlock * MipsSETargetLowering::
2641emitBPOSGE32(MachineInstr *MI, MachineBasicBlock *BB) const{
2642 // $bb:
2643 // bposge32_pseudo $vr0
2644 // =>
2645 // $bb:
2646 // bposge32 $tbb
2647 // $fbb:
2648 // li $vr2, 0
2649 // b $sink
2650 // $tbb:
2651 // li $vr1, 1
2652 // $sink:
2653 // $vr0 = phi($vr2, $fbb, $vr1, $tbb)
2654
2655 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
2656 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +00002657 const TargetRegisterClass *RC = &Mips::GPR32RegClass;
Akira Hatanaka96ca1822013-03-13 00:54:29 +00002658 DebugLoc DL = MI->getDebugLoc();
2659 const BasicBlock *LLVM_BB = BB->getBasicBlock();
Benjamin Kramerb6d0bd42014-03-02 12:27:27 +00002660 MachineFunction::iterator It = std::next(MachineFunction::iterator(BB));
Akira Hatanaka96ca1822013-03-13 00:54:29 +00002661 MachineFunction *F = BB->getParent();
2662 MachineBasicBlock *FBB = F->CreateMachineBasicBlock(LLVM_BB);
2663 MachineBasicBlock *TBB = F->CreateMachineBasicBlock(LLVM_BB);
2664 MachineBasicBlock *Sink = F->CreateMachineBasicBlock(LLVM_BB);
2665 F->insert(It, FBB);
2666 F->insert(It, TBB);
2667 F->insert(It, Sink);
2668
2669 // Transfer the remainder of BB and its successor edges to Sink.
Benjamin Kramerb6d0bd42014-03-02 12:27:27 +00002670 Sink->splice(Sink->begin(), BB, std::next(MachineBasicBlock::iterator(MI)),
Akira Hatanaka96ca1822013-03-13 00:54:29 +00002671 BB->end());
2672 Sink->transferSuccessorsAndUpdatePHIs(BB);
2673
2674 // Add successors.
2675 BB->addSuccessor(FBB);
2676 BB->addSuccessor(TBB);
2677 FBB->addSuccessor(Sink);
2678 TBB->addSuccessor(Sink);
2679
2680 // Insert the real bposge32 instruction to $BB.
2681 BuildMI(BB, DL, TII->get(Mips::BPOSGE32)).addMBB(TBB);
2682
2683 // Fill $FBB.
2684 unsigned VR2 = RegInfo.createVirtualRegister(RC);
2685 BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::ADDiu), VR2)
2686 .addReg(Mips::ZERO).addImm(0);
2687 BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::B)).addMBB(Sink);
2688
2689 // Fill $TBB.
2690 unsigned VR1 = RegInfo.createVirtualRegister(RC);
2691 BuildMI(*TBB, TBB->end(), DL, TII->get(Mips::ADDiu), VR1)
2692 .addReg(Mips::ZERO).addImm(1);
2693
2694 // Insert phi function to $Sink.
2695 BuildMI(*Sink, Sink->begin(), DL, TII->get(Mips::PHI),
2696 MI->getOperand(0).getReg())
2697 .addReg(VR2).addMBB(FBB).addReg(VR1).addMBB(TBB);
2698
2699 MI->eraseFromParent(); // The pseudo instruction is gone now.
2700 return Sink;
2701}
Daniel Sandersce09d072013-08-28 12:14:50 +00002702
2703MachineBasicBlock * MipsSETargetLowering::
2704emitMSACBranchPseudo(MachineInstr *MI, MachineBasicBlock *BB,
2705 unsigned BranchOp) const{
2706 // $bb:
2707 // vany_nonzero $rd, $ws
2708 // =>
2709 // $bb:
2710 // bnz.b $ws, $tbb
2711 // b $fbb
2712 // $fbb:
2713 // li $rd1, 0
2714 // b $sink
2715 // $tbb:
2716 // li $rd2, 1
2717 // $sink:
2718 // $rd = phi($rd1, $fbb, $rd2, $tbb)
2719
2720 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
2721 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
2722 const TargetRegisterClass *RC = &Mips::GPR32RegClass;
2723 DebugLoc DL = MI->getDebugLoc();
2724 const BasicBlock *LLVM_BB = BB->getBasicBlock();
Benjamin Kramerb6d0bd42014-03-02 12:27:27 +00002725 MachineFunction::iterator It = std::next(MachineFunction::iterator(BB));
Daniel Sandersce09d072013-08-28 12:14:50 +00002726 MachineFunction *F = BB->getParent();
2727 MachineBasicBlock *FBB = F->CreateMachineBasicBlock(LLVM_BB);
2728 MachineBasicBlock *TBB = F->CreateMachineBasicBlock(LLVM_BB);
2729 MachineBasicBlock *Sink = F->CreateMachineBasicBlock(LLVM_BB);
2730 F->insert(It, FBB);
2731 F->insert(It, TBB);
2732 F->insert(It, Sink);
2733
2734 // Transfer the remainder of BB and its successor edges to Sink.
Benjamin Kramerb6d0bd42014-03-02 12:27:27 +00002735 Sink->splice(Sink->begin(), BB, std::next(MachineBasicBlock::iterator(MI)),
Daniel Sandersce09d072013-08-28 12:14:50 +00002736 BB->end());
2737 Sink->transferSuccessorsAndUpdatePHIs(BB);
2738
2739 // Add successors.
2740 BB->addSuccessor(FBB);
2741 BB->addSuccessor(TBB);
2742 FBB->addSuccessor(Sink);
2743 TBB->addSuccessor(Sink);
2744
2745 // Insert the real bnz.b instruction to $BB.
2746 BuildMI(BB, DL, TII->get(BranchOp))
2747 .addReg(MI->getOperand(1).getReg())
2748 .addMBB(TBB);
2749
2750 // Fill $FBB.
2751 unsigned RD1 = RegInfo.createVirtualRegister(RC);
2752 BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::ADDiu), RD1)
2753 .addReg(Mips::ZERO).addImm(0);
2754 BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::B)).addMBB(Sink);
2755
2756 // Fill $TBB.
2757 unsigned RD2 = RegInfo.createVirtualRegister(RC);
2758 BuildMI(*TBB, TBB->end(), DL, TII->get(Mips::ADDiu), RD2)
2759 .addReg(Mips::ZERO).addImm(1);
2760
2761 // Insert phi function to $Sink.
2762 BuildMI(*Sink, Sink->begin(), DL, TII->get(Mips::PHI),
2763 MI->getOperand(0).getReg())
2764 .addReg(RD1).addMBB(FBB).addReg(RD2).addMBB(TBB);
2765
2766 MI->eraseFromParent(); // The pseudo instruction is gone now.
2767 return Sink;
2768}
Daniel Sanders39bb8ba2013-09-27 12:17:32 +00002769
2770// Emit the COPY_FW pseudo instruction.
2771//
2772// copy_fw_pseudo $fd, $ws, n
2773// =>
2774// copy_u_w $rt, $ws, $n
2775// mtc1 $rt, $fd
2776//
2777// When n is zero, the equivalent operation can be performed with (potentially)
2778// zero instructions due to register overlaps. This optimization is never valid
2779// for lane 1 because it would require FR=0 mode which isn't supported by MSA.
2780MachineBasicBlock * MipsSETargetLowering::
2781emitCOPY_FW(MachineInstr *MI, MachineBasicBlock *BB) const{
2782 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
2783 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
2784 DebugLoc DL = MI->getDebugLoc();
2785 unsigned Fd = MI->getOperand(0).getReg();
2786 unsigned Ws = MI->getOperand(1).getReg();
2787 unsigned Lane = MI->getOperand(2).getImm();
2788
2789 if (Lane == 0)
2790 BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Fd).addReg(Ws, 0, Mips::sub_lo);
2791 else {
2792 unsigned Wt = RegInfo.createVirtualRegister(&Mips::MSA128WRegClass);
2793
Daniel Sandersd9207702014-03-04 13:54:30 +00002794 BuildMI(*BB, MI, DL, TII->get(Mips::SPLATI_W), Wt).addReg(Ws).addImm(Lane);
Daniel Sanders39bb8ba2013-09-27 12:17:32 +00002795 BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Fd).addReg(Wt, 0, Mips::sub_lo);
2796 }
2797
2798 MI->eraseFromParent(); // The pseudo instruction is gone now.
2799 return BB;
2800}
2801
2802// Emit the COPY_FD pseudo instruction.
2803//
2804// copy_fd_pseudo $fd, $ws, n
2805// =>
2806// splati.d $wt, $ws, $n
2807// copy $fd, $wt:sub_64
2808//
2809// When n is zero, the equivalent operation can be performed with (potentially)
2810// zero instructions due to register overlaps. This optimization is always
2811// valid because FR=1 mode which is the only supported mode in MSA.
2812MachineBasicBlock * MipsSETargetLowering::
2813emitCOPY_FD(MachineInstr *MI, MachineBasicBlock *BB) const{
2814 assert(Subtarget->isFP64bit());
2815
2816 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
2817 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
2818 unsigned Fd = MI->getOperand(0).getReg();
2819 unsigned Ws = MI->getOperand(1).getReg();
2820 unsigned Lane = MI->getOperand(2).getImm() * 2;
2821 DebugLoc DL = MI->getDebugLoc();
2822
2823 if (Lane == 0)
2824 BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Fd).addReg(Ws, 0, Mips::sub_64);
2825 else {
2826 unsigned Wt = RegInfo.createVirtualRegister(&Mips::MSA128DRegClass);
2827
2828 BuildMI(*BB, MI, DL, TII->get(Mips::SPLATI_D), Wt).addReg(Ws).addImm(1);
2829 BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Fd).addReg(Wt, 0, Mips::sub_64);
2830 }
2831
2832 MI->eraseFromParent(); // The pseudo instruction is gone now.
2833 return BB;
2834}
Daniel Sandersa5150702013-09-27 12:31:32 +00002835
2836// Emit the INSERT_FW pseudo instruction.
2837//
2838// insert_fw_pseudo $wd, $wd_in, $n, $fs
2839// =>
2840// subreg_to_reg $wt:sub_lo, $fs
2841// insve_w $wd[$n], $wd_in, $wt[0]
Daniel Sanders1dfddc72013-10-15 13:14:41 +00002842MachineBasicBlock *
2843MipsSETargetLowering::emitINSERT_FW(MachineInstr *MI,
2844 MachineBasicBlock *BB) const {
Daniel Sandersa5150702013-09-27 12:31:32 +00002845 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
2846 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
2847 DebugLoc DL = MI->getDebugLoc();
2848 unsigned Wd = MI->getOperand(0).getReg();
2849 unsigned Wd_in = MI->getOperand(1).getReg();
2850 unsigned Lane = MI->getOperand(2).getImm();
2851 unsigned Fs = MI->getOperand(3).getReg();
2852 unsigned Wt = RegInfo.createVirtualRegister(&Mips::MSA128WRegClass);
2853
2854 BuildMI(*BB, MI, DL, TII->get(Mips::SUBREG_TO_REG), Wt)
Daniel Sanders1dfddc72013-10-15 13:14:41 +00002855 .addImm(0)
2856 .addReg(Fs)
2857 .addImm(Mips::sub_lo);
Daniel Sandersa5150702013-09-27 12:31:32 +00002858 BuildMI(*BB, MI, DL, TII->get(Mips::INSVE_W), Wd)
Daniel Sanders1dfddc72013-10-15 13:14:41 +00002859 .addReg(Wd_in)
2860 .addImm(Lane)
Daniel Sandersb50ccf82014-04-01 10:35:28 +00002861 .addReg(Wt)
2862 .addImm(0);
Daniel Sandersa5150702013-09-27 12:31:32 +00002863
Daniel Sanders1dfddc72013-10-15 13:14:41 +00002864 MI->eraseFromParent(); // The pseudo instruction is gone now.
Daniel Sandersa5150702013-09-27 12:31:32 +00002865 return BB;
2866}
2867
2868// Emit the INSERT_FD pseudo instruction.
2869//
2870// insert_fd_pseudo $wd, $fs, n
2871// =>
2872// subreg_to_reg $wt:sub_64, $fs
2873// insve_d $wd[$n], $wd_in, $wt[0]
Daniel Sanders1dfddc72013-10-15 13:14:41 +00002874MachineBasicBlock *
2875MipsSETargetLowering::emitINSERT_FD(MachineInstr *MI,
2876 MachineBasicBlock *BB) const {
Daniel Sandersa5150702013-09-27 12:31:32 +00002877 assert(Subtarget->isFP64bit());
2878
2879 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
2880 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
2881 DebugLoc DL = MI->getDebugLoc();
2882 unsigned Wd = MI->getOperand(0).getReg();
2883 unsigned Wd_in = MI->getOperand(1).getReg();
2884 unsigned Lane = MI->getOperand(2).getImm();
2885 unsigned Fs = MI->getOperand(3).getReg();
2886 unsigned Wt = RegInfo.createVirtualRegister(&Mips::MSA128DRegClass);
2887
2888 BuildMI(*BB, MI, DL, TII->get(Mips::SUBREG_TO_REG), Wt)
Daniel Sanders1dfddc72013-10-15 13:14:41 +00002889 .addImm(0)
2890 .addReg(Fs)
2891 .addImm(Mips::sub_64);
Daniel Sandersa5150702013-09-27 12:31:32 +00002892 BuildMI(*BB, MI, DL, TII->get(Mips::INSVE_D), Wd)
Daniel Sanders1dfddc72013-10-15 13:14:41 +00002893 .addReg(Wd_in)
2894 .addImm(Lane)
Daniel Sandersb50ccf82014-04-01 10:35:28 +00002895 .addReg(Wt)
2896 .addImm(0);
Daniel Sanders1dfddc72013-10-15 13:14:41 +00002897
2898 MI->eraseFromParent(); // The pseudo instruction is gone now.
2899 return BB;
2900}
2901
Daniel Sanderse296a0f2014-04-30 12:09:32 +00002902// Emit the INSERT_([BHWD]|F[WD])_VIDX pseudo instruction.
2903//
2904// For integer:
2905// (INSERT_([BHWD]|F[WD])_PSEUDO $wd, $wd_in, $n, $rs)
2906// =>
2907// (SLL $lanetmp1, $lane, <log2size)
2908// (SLD_B $wdtmp1, $wd_in, $wd_in, $lanetmp1)
2909// (INSERT_[BHWD], $wdtmp2, $wdtmp1, 0, $rs)
2910// (NEG $lanetmp2, $lanetmp1)
2911// (SLD_B $wd, $wdtmp2, $wdtmp2, $lanetmp2)
2912//
2913// For floating point:
2914// (INSERT_([BHWD]|F[WD])_PSEUDO $wd, $wd_in, $n, $fs)
2915// =>
2916// (SUBREG_TO_REG $wt, $fs, <subreg>)
2917// (SLL $lanetmp1, $lane, <log2size)
2918// (SLD_B $wdtmp1, $wd_in, $wd_in, $lanetmp1)
2919// (INSVE_[WD], $wdtmp2, 0, $wdtmp1, 0)
2920// (NEG $lanetmp2, $lanetmp1)
2921// (SLD_B $wd, $wdtmp2, $wdtmp2, $lanetmp2)
2922MachineBasicBlock *
2923MipsSETargetLowering::emitINSERT_DF_VIDX(MachineInstr *MI,
2924 MachineBasicBlock *BB,
2925 unsigned EltSizeInBytes,
2926 bool IsFP) const {
2927 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
2928 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
2929 DebugLoc DL = MI->getDebugLoc();
2930 unsigned Wd = MI->getOperand(0).getReg();
2931 unsigned SrcVecReg = MI->getOperand(1).getReg();
2932 unsigned LaneReg = MI->getOperand(2).getReg();
2933 unsigned SrcValReg = MI->getOperand(3).getReg();
2934
2935 const TargetRegisterClass *VecRC = nullptr;
2936 const TargetRegisterClass *GPRRC = isGP64bit() ? &Mips::GPR64RegClass
2937 : &Mips::GPR32RegClass;
2938 unsigned EltLog2Size;
2939 unsigned InsertOp = 0;
2940 unsigned InsveOp = 0;
2941 switch (EltSizeInBytes) {
2942 default:
2943 llvm_unreachable("Unexpected size");
2944 case 1:
2945 EltLog2Size = 0;
2946 InsertOp = Mips::INSERT_B;
2947 InsveOp = Mips::INSVE_B;
2948 VecRC = &Mips::MSA128BRegClass;
2949 break;
2950 case 2:
2951 EltLog2Size = 1;
2952 InsertOp = Mips::INSERT_H;
2953 InsveOp = Mips::INSVE_H;
2954 VecRC = &Mips::MSA128HRegClass;
2955 break;
2956 case 4:
2957 EltLog2Size = 2;
2958 InsertOp = Mips::INSERT_W;
2959 InsveOp = Mips::INSVE_W;
2960 VecRC = &Mips::MSA128WRegClass;
2961 break;
2962 case 8:
2963 EltLog2Size = 3;
2964 InsertOp = Mips::INSERT_D;
2965 InsveOp = Mips::INSVE_D;
2966 VecRC = &Mips::MSA128DRegClass;
2967 break;
2968 }
2969
2970 if (IsFP) {
2971 unsigned Wt = RegInfo.createVirtualRegister(VecRC);
2972 BuildMI(*BB, MI, DL, TII->get(Mips::SUBREG_TO_REG), Wt)
2973 .addImm(0)
2974 .addReg(SrcValReg)
2975 .addImm(EltSizeInBytes == 8 ? Mips::sub_64 : Mips::sub_lo);
2976 SrcValReg = Wt;
2977 }
2978
2979 // Convert the lane index into a byte index
2980 if (EltSizeInBytes != 1) {
2981 unsigned LaneTmp1 = RegInfo.createVirtualRegister(GPRRC);
2982 BuildMI(*BB, MI, DL, TII->get(Mips::SLL), LaneTmp1)
2983 .addReg(LaneReg)
2984 .addImm(EltLog2Size);
2985 LaneReg = LaneTmp1;
2986 }
2987
2988 // Rotate bytes around so that the desired lane is element zero
2989 unsigned WdTmp1 = RegInfo.createVirtualRegister(VecRC);
2990 BuildMI(*BB, MI, DL, TII->get(Mips::SLD_B), WdTmp1)
2991 .addReg(SrcVecReg)
2992 .addReg(SrcVecReg)
2993 .addReg(LaneReg);
2994
2995 unsigned WdTmp2 = RegInfo.createVirtualRegister(VecRC);
2996 if (IsFP) {
2997 // Use insve.df to insert to element zero
2998 BuildMI(*BB, MI, DL, TII->get(InsveOp), WdTmp2)
2999 .addReg(WdTmp1)
3000 .addImm(0)
3001 .addReg(SrcValReg)
3002 .addImm(0);
3003 } else {
3004 // Use insert.df to insert to element zero
3005 BuildMI(*BB, MI, DL, TII->get(InsertOp), WdTmp2)
3006 .addReg(WdTmp1)
3007 .addReg(SrcValReg)
3008 .addImm(0);
3009 }
3010
3011 // Rotate elements the rest of the way for a full rotation.
3012 // sld.df inteprets $rt modulo the number of columns so we only need to negate
3013 // the lane index to do this.
3014 unsigned LaneTmp2 = RegInfo.createVirtualRegister(GPRRC);
3015 BuildMI(*BB, MI, DL, TII->get(Mips::SUB), LaneTmp2)
3016 .addReg(Mips::ZERO)
3017 .addReg(LaneReg);
3018 BuildMI(*BB, MI, DL, TII->get(Mips::SLD_B), Wd)
3019 .addReg(WdTmp2)
3020 .addReg(WdTmp2)
3021 .addReg(LaneTmp2);
3022
3023 MI->eraseFromParent(); // The pseudo instruction is gone now.
3024 return BB;
3025}
3026
Daniel Sanders1dfddc72013-10-15 13:14:41 +00003027// Emit the FILL_FW pseudo instruction.
3028//
3029// fill_fw_pseudo $wd, $fs
3030// =>
3031// implicit_def $wt1
3032// insert_subreg $wt2:subreg_lo, $wt1, $fs
3033// splati.w $wd, $wt2[0]
3034MachineBasicBlock *
3035MipsSETargetLowering::emitFILL_FW(MachineInstr *MI,
3036 MachineBasicBlock *BB) const {
3037 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
3038 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3039 DebugLoc DL = MI->getDebugLoc();
3040 unsigned Wd = MI->getOperand(0).getReg();
3041 unsigned Fs = MI->getOperand(1).getReg();
3042 unsigned Wt1 = RegInfo.createVirtualRegister(&Mips::MSA128WRegClass);
3043 unsigned Wt2 = RegInfo.createVirtualRegister(&Mips::MSA128WRegClass);
3044
3045 BuildMI(*BB, MI, DL, TII->get(Mips::IMPLICIT_DEF), Wt1);
3046 BuildMI(*BB, MI, DL, TII->get(Mips::INSERT_SUBREG), Wt2)
3047 .addReg(Wt1)
3048 .addReg(Fs)
3049 .addImm(Mips::sub_lo);
3050 BuildMI(*BB, MI, DL, TII->get(Mips::SPLATI_W), Wd).addReg(Wt2).addImm(0);
3051
3052 MI->eraseFromParent(); // The pseudo instruction is gone now.
3053 return BB;
3054}
3055
3056// Emit the FILL_FD pseudo instruction.
3057//
3058// fill_fd_pseudo $wd, $fs
3059// =>
3060// implicit_def $wt1
3061// insert_subreg $wt2:subreg_64, $wt1, $fs
3062// splati.d $wd, $wt2[0]
3063MachineBasicBlock *
3064MipsSETargetLowering::emitFILL_FD(MachineInstr *MI,
3065 MachineBasicBlock *BB) const {
3066 assert(Subtarget->isFP64bit());
3067
3068 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
3069 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3070 DebugLoc DL = MI->getDebugLoc();
3071 unsigned Wd = MI->getOperand(0).getReg();
3072 unsigned Fs = MI->getOperand(1).getReg();
3073 unsigned Wt1 = RegInfo.createVirtualRegister(&Mips::MSA128DRegClass);
3074 unsigned Wt2 = RegInfo.createVirtualRegister(&Mips::MSA128DRegClass);
3075
3076 BuildMI(*BB, MI, DL, TII->get(Mips::IMPLICIT_DEF), Wt1);
3077 BuildMI(*BB, MI, DL, TII->get(Mips::INSERT_SUBREG), Wt2)
3078 .addReg(Wt1)
3079 .addReg(Fs)
3080 .addImm(Mips::sub_64);
3081 BuildMI(*BB, MI, DL, TII->get(Mips::SPLATI_D), Wd).addReg(Wt2).addImm(0);
Daniel Sandersa5150702013-09-27 12:31:32 +00003082
3083 MI->eraseFromParent(); // The pseudo instruction is gone now.
3084 return BB;
3085}
Daniel Sandersa9521602013-10-23 10:36:52 +00003086
3087// Emit the FEXP2_W_1 pseudo instructions.
3088//
3089// fexp2_w_1_pseudo $wd, $wt
3090// =>
3091// ldi.w $ws, 1
3092// fexp2.w $wd, $ws, $wt
3093MachineBasicBlock *
3094MipsSETargetLowering::emitFEXP2_W_1(MachineInstr *MI,
3095 MachineBasicBlock *BB) const {
3096 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
3097 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3098 const TargetRegisterClass *RC = &Mips::MSA128WRegClass;
3099 unsigned Ws1 = RegInfo.createVirtualRegister(RC);
3100 unsigned Ws2 = RegInfo.createVirtualRegister(RC);
3101 DebugLoc DL = MI->getDebugLoc();
3102
3103 // Splat 1.0 into a vector
3104 BuildMI(*BB, MI, DL, TII->get(Mips::LDI_W), Ws1).addImm(1);
3105 BuildMI(*BB, MI, DL, TII->get(Mips::FFINT_U_W), Ws2).addReg(Ws1);
3106
3107 // Emit 1.0 * fexp2(Wt)
3108 BuildMI(*BB, MI, DL, TII->get(Mips::FEXP2_W), MI->getOperand(0).getReg())
3109 .addReg(Ws2)
3110 .addReg(MI->getOperand(1).getReg());
3111
3112 MI->eraseFromParent(); // The pseudo instruction is gone now.
3113 return BB;
3114}
3115
3116// Emit the FEXP2_D_1 pseudo instructions.
3117//
3118// fexp2_d_1_pseudo $wd, $wt
3119// =>
3120// ldi.d $ws, 1
3121// fexp2.d $wd, $ws, $wt
3122MachineBasicBlock *
3123MipsSETargetLowering::emitFEXP2_D_1(MachineInstr *MI,
3124 MachineBasicBlock *BB) const {
3125 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
3126 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3127 const TargetRegisterClass *RC = &Mips::MSA128DRegClass;
3128 unsigned Ws1 = RegInfo.createVirtualRegister(RC);
3129 unsigned Ws2 = RegInfo.createVirtualRegister(RC);
3130 DebugLoc DL = MI->getDebugLoc();
3131
3132 // Splat 1.0 into a vector
3133 BuildMI(*BB, MI, DL, TII->get(Mips::LDI_D), Ws1).addImm(1);
3134 BuildMI(*BB, MI, DL, TII->get(Mips::FFINT_U_D), Ws2).addReg(Ws1);
3135
3136 // Emit 1.0 * fexp2(Wt)
3137 BuildMI(*BB, MI, DL, TII->get(Mips::FEXP2_D), MI->getOperand(0).getReg())
3138 .addReg(Ws2)
3139 .addReg(MI->getOperand(1).getReg());
3140
3141 MI->eraseFromParent(); // The pseudo instruction is gone now.
3142 return BB;
3143}