~ubuntu-branches/ubuntu/trusty/llvm-toolchain-snapshot/trusty-201310232150

« back to all changes in this revision

Viewing changes to lib/Target/Mips/MipsSEISelLowering.cpp

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-27 15:01:57 UTC
  • mfrom: (0.10.1) (0.9.1) (0.8.1) (0.7.1) (0.6.1) (0.5.2)
  • Revision ID: package-import@ubuntu.com-20130527150157-tdkrsjpuvht7v0qx
Tags: 1:3.4~svn182733-1~exp1
* New snapshot release (3.4 release)
* Add a symlink of libLLVM-3.4.so.1 to usr/lib/llvm-3.4/lib/libLLVM-3.4.so
    to fix make the llvm-config-3.4 --libdir work (Closes: #708677)
  * Various packages rename to allow co installations:
    * libclang1 => libclang1-3.4
    * libclang1-dbg => libclang1-3.4-dbg
    * libclang-dev => libclang-3.4-dev
    * libclang-common-dev => libclang-common-3.4-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
      setOperationAction(ISD::STORE, VecTys[i], Legal);
53
53
      setOperationAction(ISD::BITCAST, VecTys[i], Legal);
54
54
    }
 
55
 
 
56
    setTargetDAGCombine(ISD::SHL);
 
57
    setTargetDAGCombine(ISD::SRA);
 
58
    setTargetDAGCombine(ISD::SRL);
 
59
    setTargetDAGCombine(ISD::SETCC);
 
60
    setTargetDAGCombine(ISD::VSELECT);
55
61
  }
56
62
 
57
63
  if (Subtarget->hasDSPR2())
87
93
  setOperationAction(ISD::UDIVREM, MVT::i32, Custom);
88
94
  setOperationAction(ISD::SDIVREM, MVT::i64, Custom);
89
95
  setOperationAction(ISD::UDIVREM, MVT::i64, Custom);
90
 
  setOperationAction(ISD::MEMBARRIER,         MVT::Other, Custom);
91
96
  setOperationAction(ISD::ATOMIC_FENCE,       MVT::Other, Custom);
92
97
  setOperationAction(ISD::LOAD,               MVT::i32, Custom);
93
98
  setOperationAction(ISD::STORE,              MVT::i32, Custom);
128
133
  case ISD::MULHU:     return lowerMulDiv(Op, MipsISD::Multu, false, true, DAG);
129
134
  case ISD::MUL:       return lowerMulDiv(Op, MipsISD::Mult, true, false, DAG);
130
135
  case ISD::SDIVREM:   return lowerMulDiv(Op, MipsISD::DivRem, true, true, DAG);
131
 
  case ISD::UDIVREM:   return lowerMulDiv(Op, MipsISD::DivRemU, true, true, DAG);
 
136
  case ISD::UDIVREM:   return lowerMulDiv(Op, MipsISD::DivRemU, true, true,
 
137
                                          DAG);
132
138
  case ISD::INTRINSIC_WO_CHAIN: return lowerINTRINSIC_WO_CHAIN(Op, DAG);
133
139
  case ISD::INTRINSIC_W_CHAIN:  return lowerINTRINSIC_W_CHAIN(Op, DAG);
134
140
  }
180
186
  if (!MultHi.hasOneUse() || !MultLo.hasOneUse())
181
187
    return false;
182
188
 
183
 
  DebugLoc DL = ADDENode->getDebugLoc();
 
189
  SDLoc DL(ADDENode);
184
190
 
185
191
  // Initialize accumulator.
186
192
  SDValue ACCIn = CurDAG->getNode(MipsISD::InsertLOHI, DL, MVT::Untyped,
256
262
  if (!MultHi.hasOneUse() || !MultLo.hasOneUse())
257
263
    return false;
258
264
 
259
 
  DebugLoc DL = SUBENode->getDebugLoc();
 
265
  SDLoc DL(SUBENode);
260
266
 
261
267
  // Initialize accumulator.
262
268
  SDValue ACCIn = CurDAG->getNode(MipsISD::InsertLOHI, DL, MVT::Untyped,
314
320
  return SDValue();
315
321
}
316
322
 
 
323
static SDValue performDSPShiftCombine(unsigned Opc, SDNode *N, EVT Ty,
 
324
                                      SelectionDAG &DAG,
 
325
                                      const MipsSubtarget *Subtarget) {
 
326
  // See if this is a vector splat immediate node.
 
327
  APInt SplatValue, SplatUndef;
 
328
  unsigned SplatBitSize;
 
329
  bool HasAnyUndefs;
 
330
  unsigned EltSize = Ty.getVectorElementType().getSizeInBits();
 
331
  BuildVectorSDNode *BV = dyn_cast<BuildVectorSDNode>(N->getOperand(1));
 
332
 
 
333
  if (!BV ||
 
334
      !BV->isConstantSplat(SplatValue, SplatUndef, SplatBitSize, HasAnyUndefs,
 
335
                           EltSize, !Subtarget->isLittle()) ||
 
336
      (SplatBitSize != EltSize) ||
 
337
      (SplatValue.getZExtValue() >= EltSize))
 
338
    return SDValue();
 
339
 
 
340
  return DAG.getNode(Opc, SDLoc(N), Ty, N->getOperand(0),
 
341
                     DAG.getConstant(SplatValue.getZExtValue(), MVT::i32));
 
342
}
 
343
 
 
344
static SDValue performSHLCombine(SDNode *N, SelectionDAG &DAG,
 
345
                                 TargetLowering::DAGCombinerInfo &DCI,
 
346
                                 const MipsSubtarget *Subtarget) {
 
347
  EVT Ty = N->getValueType(0);
 
348
 
 
349
  if ((Ty != MVT::v2i16) && (Ty != MVT::v4i8))
 
350
    return SDValue();
 
351
 
 
352
  return performDSPShiftCombine(MipsISD::SHLL_DSP, N, Ty, DAG, Subtarget);
 
353
}
 
354
 
 
355
static SDValue performSRACombine(SDNode *N, SelectionDAG &DAG,
 
356
                                 TargetLowering::DAGCombinerInfo &DCI,
 
357
                                 const MipsSubtarget *Subtarget) {
 
358
  EVT Ty = N->getValueType(0);
 
359
 
 
360
  if ((Ty != MVT::v2i16) && ((Ty != MVT::v4i8) || !Subtarget->hasDSPR2()))
 
361
    return SDValue();
 
362
 
 
363
  return performDSPShiftCombine(MipsISD::SHRA_DSP, N, Ty, DAG, Subtarget);
 
364
}
 
365
 
 
366
 
 
367
static SDValue performSRLCombine(SDNode *N, SelectionDAG &DAG,
 
368
                                 TargetLowering::DAGCombinerInfo &DCI,
 
369
                                 const MipsSubtarget *Subtarget) {
 
370
  EVT Ty = N->getValueType(0);
 
371
 
 
372
  if (((Ty != MVT::v2i16) || !Subtarget->hasDSPR2()) && (Ty != MVT::v4i8))
 
373
    return SDValue();
 
374
 
 
375
  return performDSPShiftCombine(MipsISD::SHRL_DSP, N, Ty, DAG, Subtarget);
 
376
}
 
377
 
 
378
static bool isLegalDSPCondCode(EVT Ty, ISD::CondCode CC) {
 
379
  bool IsV216 = (Ty == MVT::v2i16);
 
380
 
 
381
  switch (CC) {
 
382
  case ISD::SETEQ:
 
383
  case ISD::SETNE:  return true;
 
384
  case ISD::SETLT:
 
385
  case ISD::SETLE:
 
386
  case ISD::SETGT:
 
387
  case ISD::SETGE:  return IsV216;
 
388
  case ISD::SETULT:
 
389
  case ISD::SETULE:
 
390
  case ISD::SETUGT:
 
391
  case ISD::SETUGE: return !IsV216;
 
392
  default:          return false;
 
393
  }
 
394
}
 
395
 
 
396
static SDValue performSETCCCombine(SDNode *N, SelectionDAG &DAG) {
 
397
  EVT Ty = N->getValueType(0);
 
398
 
 
399
  if ((Ty != MVT::v2i16) && (Ty != MVT::v4i8))
 
400
    return SDValue();
 
401
 
 
402
  if (!isLegalDSPCondCode(Ty, cast<CondCodeSDNode>(N->getOperand(2))->get()))
 
403
    return SDValue();
 
404
 
 
405
  return DAG.getNode(MipsISD::SETCC_DSP, SDLoc(N), Ty, N->getOperand(0),
 
406
                     N->getOperand(1), N->getOperand(2));
 
407
}
 
408
 
 
409
static SDValue performVSELECTCombine(SDNode *N, SelectionDAG &DAG) {
 
410
  EVT Ty = N->getValueType(0);
 
411
 
 
412
  if ((Ty != MVT::v2i16) && (Ty != MVT::v4i8))
 
413
    return SDValue();
 
414
 
 
415
  SDValue SetCC = N->getOperand(0);
 
416
 
 
417
  if (SetCC.getOpcode() != MipsISD::SETCC_DSP)
 
418
    return SDValue();
 
419
 
 
420
  return DAG.getNode(MipsISD::SELECT_CC_DSP, SDLoc(N), Ty,
 
421
                     SetCC.getOperand(0), SetCC.getOperand(1), N->getOperand(1),
 
422
                     N->getOperand(2), SetCC.getOperand(2));
 
423
}
 
424
 
317
425
SDValue
318
426
MipsSETargetLowering::PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const {
319
427
  SelectionDAG &DAG = DCI.DAG;
 
428
  SDValue Val;
320
429
 
321
430
  switch (N->getOpcode()) {
322
431
  case ISD::ADDE:
323
432
    return performADDECombine(N, DAG, DCI, Subtarget);
324
433
  case ISD::SUBE:
325
434
    return performSUBECombine(N, DAG, DCI, Subtarget);
326
 
  default:
327
 
    return MipsTargetLowering::PerformDAGCombine(N, DCI);
328
 
  }
 
435
  case ISD::SHL:
 
436
    return performSHLCombine(N, DAG, DCI, Subtarget);
 
437
  case ISD::SRA:
 
438
    return performSRACombine(N, DAG, DCI, Subtarget);
 
439
  case ISD::SRL:
 
440
    return performSRLCombine(N, DAG, DCI, Subtarget);
 
441
  case ISD::VSELECT:
 
442
    return performVSELECTCombine(N, DAG);
 
443
  case ISD::SETCC: {
 
444
    Val = performSETCCCombine(N, DAG);
 
445
    break;
 
446
  }
 
447
  }
 
448
 
 
449
  if (Val.getNode())
 
450
    return Val;
 
451
 
 
452
  return MipsTargetLowering::PerformDAGCombine(N, DCI);
329
453
}
330
454
 
331
455
MachineBasicBlock *
376
500
                                          bool HasLo, bool HasHi,
377
501
                                          SelectionDAG &DAG) const {
378
502
  EVT Ty = Op.getOperand(0).getValueType();
379
 
  DebugLoc DL = Op.getDebugLoc();
 
503
  SDLoc DL(Op);
380
504
  SDValue Mult = DAG.getNode(NewOpc, DL, MVT::Untyped,
381
505
                             Op.getOperand(0), Op.getOperand(1));
382
506
  SDValue Lo, Hi;
396
520
}
397
521
 
398
522
 
399
 
static SDValue initAccumulator(SDValue In, DebugLoc DL, SelectionDAG &DAG) {
 
523
static SDValue initAccumulator(SDValue In, SDLoc DL, SelectionDAG &DAG) {
400
524
  SDValue InLo = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i32, In,
401
525
                             DAG.getConstant(0, MVT::i32));
402
526
  SDValue InHi = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i32, In,
404
528
  return DAG.getNode(MipsISD::InsertLOHI, DL, MVT::Untyped, InLo, InHi);
405
529
}
406
530
 
407
 
static SDValue extractLOHI(SDValue Op, DebugLoc DL, SelectionDAG &DAG) {
 
531
static SDValue extractLOHI(SDValue Op, SDLoc DL, SelectionDAG &DAG) {
408
532
  SDValue Lo = DAG.getNode(MipsISD::ExtractLOHI, DL, MVT::i32, Op,
409
533
                           DAG.getConstant(Mips::sub_lo, MVT::i32));
410
534
  SDValue Hi = DAG.getNode(MipsISD::ExtractLOHI, DL, MVT::i32, Op,
425
549
// out64 = merge-values (v0, v1)
426
550
//
427
551
static SDValue lowerDSPIntr(SDValue Op, SelectionDAG &DAG, unsigned Opc) {
428
 
  DebugLoc DL = Op.getDebugLoc();
 
552
  SDLoc DL(Op);
429
553
  bool HasChainIn = Op->getOperand(0).getValueType() == MVT::Other;
430
554
  SmallVector<SDValue, 3> Ops;
431
555
  unsigned OpNo = 0;