LLVM 24.0.0git
MipsSEISelLowering.cpp
Go to the documentation of this file.
1//===- MipsSEISelLowering.cpp - MipsSE DAG Lowering Interface -------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Subclass of MipsTargetLowering specialized for mips32/64.
10//
11//===----------------------------------------------------------------------===//
12
13#include "MipsSEISelLowering.h"
14#include "MipsMachineFunction.h"
15#include "MipsRegisterInfo.h"
16#include "MipsSubtarget.h"
17#include "llvm/ADT/APInt.h"
34#include "llvm/IR/DebugLoc.h"
35#include "llvm/IR/Intrinsics.h"
36#include "llvm/IR/IntrinsicsMips.h"
39#include "llvm/Support/Debug.h"
43#include <algorithm>
44#include <cassert>
45#include <cstddef>
46#include <cstdint>
47#include <iterator>
48#include <utility>
49
50using namespace llvm;
51
52#define DEBUG_TYPE "mips-isel"
53
54static cl::opt<bool> NoDPLoadStore("mno-ldc1-sdc1", cl::init(false),
55 cl::desc("Expand double precision loads and "
56 "stores to their single precision "
57 "counterparts"));
58
59// Widen the v2 vectors to the register width, i.e. v2i16 -> v8i16,
60// v2i32 -> v4i32, etc, to ensure the correct rail size is used, i.e.
61// INST.h for v16, INST.w for v32, INST.d for v64.
64 if (this->Subtarget.hasMSA()) {
65 switch (VT.SimpleTy) {
66 // Leave v2i1 vectors to be promoted to larger ones.
67 // Other i1 types will be promoted by default.
68 case MVT::v2i1:
69 return TypePromoteInteger;
70 break;
71 // 16-bit vector types (v2 and longer)
72 case MVT::v2i8:
73 // 32-bit vector types (v2 and longer)
74 case MVT::v2i16:
75 case MVT::v4i8:
76 // 64-bit vector types (v2 and longer)
77 case MVT::v2i32:
78 case MVT::v4i16:
79 case MVT::v8i8:
80 return TypeWidenVector;
81 break;
82 // Only word (.w) and doubleword (.d) are available for floating point
83 // vectors. That means floating point vectors should be either v2f64
84 // or v4f32.
85 // Here we only explicitly widen the f32 types - f16 will be promoted
86 // by default.
87 case MVT::v2f32:
88 case MVT::v3f32:
89 return TypeWidenVector;
90 // v2i64 is already 128-bit wide.
91 default:
92 break;
93 }
94 }
96}
97
99 const MipsSubtarget &STI)
100 : MipsTargetLowering(TM, STI) {
101 // Set up the register classes
102 addRegisterClass(MVT::i32, &Mips::GPR32RegClass);
103
104 if (Subtarget.isGP64bit())
105 addRegisterClass(MVT::i64, &Mips::GPR64RegClass);
106
107 if (Subtarget.hasDSP() || Subtarget.hasMSA()) {
108 // Expand all truncating stores and extending loads.
111 setTruncStoreAction(VT0, VT1, Expand);
115 }
116 }
117 }
118
119 if (Subtarget.hasDSP()) {
120 MVT::SimpleValueType VecTys[2] = {MVT::v2i16, MVT::v4i8};
121
122 for (const auto &VecTy : VecTys) {
123 addRegisterClass(VecTy, &Mips::DSPRRegClass);
124
125 // Expand all builtin opcodes.
126 for (unsigned Opc = 0; Opc < ISD::BUILTIN_OP_END; ++Opc)
128
134 }
135
138
139 if (Subtarget.hasMips32r2()) {
142 }
143 }
144
145 if (Subtarget.hasDSPR2())
146 setOperationAction(ISD::MUL, MVT::v2i16, Legal);
147
148 if (Subtarget.hasMSA()) {
149 addMSAIntType(MVT::v16i8, &Mips::MSA128BRegClass);
150 addMSAIntType(MVT::v8i16, &Mips::MSA128HRegClass);
151 addMSAIntType(MVT::v4i32, &Mips::MSA128WRegClass);
152 addMSAIntType(MVT::v2i64, &Mips::MSA128DRegClass);
153 addMSAFloatType(MVT::v8f16, &Mips::MSA128HRegClass);
154 addMSAFloatType(MVT::v4f32, &Mips::MSA128WRegClass);
155 addMSAFloatType(MVT::v2f64, &Mips::MSA128DRegClass);
156
157 // Shuffle half vectors as integers to avoid expanding them through
158 // EXTRACT_VECTOR_ELT and BUILD_VECTOR with an illegal scalar f16 type.
159 setOperationPromotedToType(ISD::VECTOR_SHUFFLE, MVT::v8f16, MVT::v8i16);
160
161 // We're using soft promotion for f16, but msa has some instructions for
162 // conversion to/from f16. Mark those conversions as custom so we can take
163 // advantage of these instructions.
164 for (MVT VT : {MVT::f32, MVT::f64}) {
167 }
168
171 }
172
173 if (!Subtarget.useSoftFloat()) {
174 addRegisterClass(MVT::f32, &Mips::FGR32RegClass);
175
176 // When dealing with single precision only, use libcalls
177 if (!Subtarget.isSingleFloat()) {
178 if (Subtarget.isFP64bit())
179 addRegisterClass(MVT::f64, &Mips::FGR64RegClass);
180 else
181 addRegisterClass(MVT::f64, &Mips::AFGR64RegClass);
182 }
183
186 setOperationAction(Op, MVT::f32, Legal);
187 setOperationAction(Op, MVT::f64, Legal);
188 }
189 }
190
191 // Targets with 64bits integer registers, but no 64bit floating point register
192 // do not support conversion between them
193 if (Subtarget.isGP64bit() && Subtarget.isSingleFloat() &&
194 !Subtarget.useSoftFloat()) {
199 }
200
205
206 if (Subtarget.hasCnMips())
208 else if (Subtarget.isR5900()) {
209 // R5900 doesn't have DMULT/DMULTU/DDIV/DDIVU - expand to 32-bit ops
217 } else if (Subtarget.isGP64bit())
219
220 if (Subtarget.isGP64bit() && !Subtarget.isR5900()) {
227 }
228
231
235 if (Subtarget.hasMips32r6()) {
238 } else {
241 }
242
244
248
249 if (Subtarget.hasMips32r2() && !Subtarget.useSoftFloat() &&
250 !Subtarget.hasMips64()) {
252 }
253
254 if (NoDPLoadStore || (Subtarget.hasMips1() && !Subtarget.hasMips2())) {
257 }
258
259 if (Subtarget.hasMips32r6()) {
260 // MIPS32r6 replaces the accumulator-based multiplies with a three register
261 // instruction
267
268 // MIPS32r6 replaces the accumulator-based division/remainder with separate
269 // three register division and remainder instructions.
276
277 // MIPS32r6 replaces conditional moves with an equivalent that removes the
278 // need for three GPR read ports.
282
286
287 assert(Subtarget.isFP64bit() && "FR=1 is required for MIPS32r6");
291
293
294 // Floating point > and >= are supported via < and <=
303
312 }
313
314 if (Subtarget.hasMips64r6()) {
315 // MIPS64r6 replaces the accumulator-based multiplies with a three register
316 // instruction
322
323 // MIPS32r6 replaces the accumulator-based division/remainder with separate
324 // three register division and remainder instructions.
331
332 // MIPS64r6 replaces conditional moves with an equivalent that removes the
333 // need for three GPR read ports.
337 }
338
339 if (Subtarget.isR5900()) {
340 // R5900 FPU only supports 4 compare conditions: C.F, C.EQ, C.OLT, C.OLE
341 // (and their inversions via bc1t/bc1f). Expand all conditions that would
342 // require C.UN, C.UEQ, C.ULT, or C.ULE instructions (not available on
343 // R5900). The legalizer resolves these via operand swapping, condition
344 // inversion, and decomposition into supported conditions.
356
357 // R5900 FPU does not support IEEE 754 special values (NaN, infinity). Use
358 // custom lowering to decide per-instruction: hardware when nnan+ninf flags
359 // guarantee no NaN or infinity, software libcall otherwise.
365 }
366
367 computeRegisterProperties(Subtarget.getRegisterInfo());
368}
369
370const MipsTargetLowering *
372 const MipsSubtarget &STI) {
373 return new MipsSETargetLowering(TM, STI);
374}
375
378 if (VT == MVT::Untyped)
379 return Subtarget.hasDSP() ? &Mips::ACC64DSPRegClass : &Mips::ACC64RegClass;
380
382}
383
384// Enable MSA support for the given integer type and Register class.
387 addRegisterClass(Ty, RC);
388
389 // Expand all builtin opcodes.
390 for (unsigned Opc = 0; Opc < ISD::BUILTIN_OP_END; ++Opc)
392
400
422
423 if (Ty == MVT::v4i32 || Ty == MVT::v2i64) {
428 }
429
436}
437
438// Enable MSA support for the given floating-point type and Register class.
441 addRegisterClass(Ty, RC);
442
443 // Expand all builtin opcodes.
444 for (unsigned Opc = 0; Opc < ISD::BUILTIN_OP_END; ++Opc)
446
454
455 if (Ty != MVT::v8f16) {
467
475 }
476}
477
478SDValue MipsSETargetLowering::lowerSELECT(SDValue Op, SelectionDAG &DAG) const {
481
482 EVT ResTy = Op->getValueType(0);
483 SDLoc DL(Op);
484
485 // Although MTC1_D64 takes an i32 and writes an f64, the upper 32 bits of the
486 // floating point register are undefined. Not really an issue as sel.d, which
487 // is produced from an FSELECT node, only looks at bit 0.
488 SDValue Tmp = DAG.getNode(MipsISD::MTC1_D64, DL, MVT::f64, Op->getOperand(0));
489 return DAG.getNode(MipsISD::FSELECT, DL, ResTy, Tmp, Op->getOperand(1),
490 Op->getOperand(2));
491}
492
493// Lower FP16_TO_FP (the soft-promote-half representation of an f16 -> f32/f64
494// conversion).
495SDValue MipsSETargetLowering::lowerFP16_TO_FP(SDValue Op,
496 SelectionDAG &DAG) const {
497 SDLoc DL(Op);
498 EVT ResTy = Op.getValueType();
499 assert((ResTy == MVT::f32 || ResTy == MVT::f64) && "Unexpected FP16_TO_FP");
500
501 // The operand type is i32 because i16 isn't actually legal on MIPS.
502 SDValue In = Op.getOperand(0);
503 assert(In.getValueType() == MVT::i32 && "Unexpected FP16_TO_FP operand type");
504
505 // Splat into a v8i16 (the 32-bit In value is truncated to the lower 16 bits).
506 SDValue Splatted = DAG.getSplatBuildVector(MVT::v8i16, DL, In);
507
508 // Bitcast from v8i16 to v8f16.
509 SDValue HVec = DAG.getNode(ISD::BITCAST, DL, MVT::v8f16, Splatted);
510
511 // Convert from v8f16 to v4f32.
512 SDValue F32Vec = DAG.getNode(
513 ISD::INTRINSIC_WO_CHAIN, DL, MVT::v4f32,
514 DAG.getConstant(Intrinsic::mips_fexupr_w, DL, MVT::i32), HVec);
515 SDValue Res;
516 if (ResTy == MVT::f32) {
517 // Every lane has the converted value, just read it from lane 0.
518 Res = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, F32Vec,
519 DAG.getVectorIdxConstant(0, DL));
520 } else {
521 // Convert from v4f32 to v2f64.
522 SDValue F64Vec = DAG.getNode(
523 ISD::INTRINSIC_WO_CHAIN, DL, MVT::v2f64,
524 DAG.getConstant(Intrinsic::mips_fexupr_d, DL, MVT::i32), F32Vec);
525 // Every lane has the converted value, just read it from lane 0.
526 Res = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f64, F64Vec,
527 DAG.getVectorIdxConstant(0, DL));
528 }
529
530 return Res;
531}
532
533// Lower FP_TO_FP16 (the soft-promote-half representation of an f32/f64 -> f16
534// conversion)
535SDValue MipsSETargetLowering::lowerFP_TO_FP16(SDValue Op,
536 SelectionDAG &DAG) const {
537 SDLoc DL(Op);
538 EVT ResTy = Op.getValueType();
539 SDValue In = Op.getOperand(0);
540 assert((In.getValueType() == MVT::f32 || In.getValueType() == MVT::f64) &&
541 "Unexpected FP_TO_FP16");
542
543 SDValue F32Vec;
544 if (In.getValueType() == MVT::f64) {
545 // Splat f64 to v2f64, then convert to v4f32.
546 SDValue F64Vec = DAG.getSplatBuildVector(MVT::v2f64, DL, In);
547 F32Vec = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, DL, MVT::v4f32,
548 DAG.getConstant(Intrinsic::mips_fexdo_w, DL, MVT::i32),
549 F64Vec, F64Vec);
550 } else {
551 // Splat f32 to v4f32.
552 F32Vec = DAG.getSplatBuildVector(MVT::v4f32, DL, In);
553 }
554
555 // Then convert from v4f32 to v8f16.
556 SDValue HVec = DAG.getNode(
557 ISD::INTRINSIC_WO_CHAIN, DL, MVT::v8f16,
558 DAG.getConstant(Intrinsic::mips_fexdo_h, DL, MVT::i32), F32Vec, F32Vec);
559
560 // Finally cast to v8i16 (f16 is soft-promoted).
561 SDValue IVec = DAG.getNode(ISD::BITCAST, DL, MVT::v8i16, HVec);
562 SDValue Res = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, ResTy, IVec,
563 DAG.getVectorIdxConstant(0, DL));
564
565 return Res;
566}
567
569 EVT VT, unsigned, Align, MachineMemOperand::Flags, unsigned *Fast) const {
571
572 if (Subtarget.systemSupportsUnalignedAccess()) {
573 // MIPS32r6/MIPS64r6 is required to support unaligned access. It's
574 // implementation defined whether this is handled by hardware, software, or
575 // a hybrid of the two but it's expected that most implementations will
576 // handle the majority of cases in hardware.
577 if (Fast)
578 *Fast = 1;
579 return true;
580 } else if (Subtarget.hasMips32r6()) {
581 return false;
582 }
583
584 switch (SVT) {
585 case MVT::i64:
586 case MVT::i32:
587 if (Fast)
588 *Fast = 1;
589 return true;
590 default:
591 return false;
592 }
593}
594
596 SelectionDAG &DAG) const {
597 switch(Op.getOpcode()) {
598 case ISD::LOAD: return lowerLOAD(Op, DAG);
599 case ISD::STORE: return lowerSTORE(Op, DAG);
600 case ISD::SMUL_LOHI: return lowerMulDiv(Op, MipsISD::Mult, true, true, DAG);
601 case ISD::UMUL_LOHI: return lowerMulDiv(Op, MipsISD::Multu, true, true, DAG);
602 case ISD::MULHS: return lowerMulDiv(Op, MipsISD::Mult, false, true, DAG);
603 case ISD::MULHU: return lowerMulDiv(Op, MipsISD::Multu, false, true, DAG);
604 case ISD::MUL: return lowerMulDiv(Op, MipsISD::Mult, true, false, DAG);
605 case ISD::SDIVREM: return lowerMulDiv(Op, MipsISD::DivRem, true, true, DAG);
606 case ISD::UDIVREM: return lowerMulDiv(Op, MipsISD::DivRemU, true, true,
607 DAG);
608 case ISD::INTRINSIC_WO_CHAIN: return lowerINTRINSIC_WO_CHAIN(Op, DAG);
609 case ISD::INTRINSIC_W_CHAIN: return lowerINTRINSIC_W_CHAIN(Op, DAG);
610 case ISD::INTRINSIC_VOID: return lowerINTRINSIC_VOID(Op, DAG);
611 case ISD::EXTRACT_VECTOR_ELT: return lowerEXTRACT_VECTOR_ELT(Op, DAG);
612 case ISD::BUILD_VECTOR: return lowerBUILD_VECTOR(Op, DAG);
613 case ISD::VECTOR_SHUFFLE: return lowerVECTOR_SHUFFLE(Op, DAG);
614 case ISD::SELECT:
615 return lowerSELECT(Op, DAG);
616 case ISD::FP16_TO_FP:
618 return lowerFP16_TO_FP(Op, DAG);
619 case ISD::FP_TO_FP16:
621 return lowerFP_TO_FP16(Op, DAG);
622 case ISD::BITCAST: return lowerBITCAST(Op, DAG);
623 case ISD::FADD:
624 return lowerR5900FPOp(Op, DAG, RTLIB::ADD_F32);
625 case ISD::FSUB:
626 return lowerR5900FPOp(Op, DAG, RTLIB::SUB_F32);
627 case ISD::FMUL:
628 return lowerR5900FPOp(Op, DAG, RTLIB::MUL_F32);
629 case ISD::FDIV:
630 return lowerR5900FPOp(Op, DAG, RTLIB::DIV_F32);
631 case ISD::FSQRT:
632 return lowerR5900FPOp(Op, DAG, RTLIB::SQRT_F32);
633 }
634
636}
637
638SDValue MipsSETargetLowering::lowerR5900FPOp(SDValue Op, SelectionDAG &DAG,
639 RTLIB::Libcall LC) const {
641 SDNodeFlags Flags = Op->getFlags();
642
643 if (Flags.hasNoNaNs() && Flags.hasNoInfs()) {
644 // Use the hardware FPU instruction if the operation is guaranteed to have
645 // no NaN or infinity inputs/outputs (nnan+ninf flags).
646 return Op;
647 }
648
649 // Fall back to a software libcall for IEEE correctness.
650 SDLoc DL(Op);
651 MVT VT = Op.getSimpleValueType();
652 SmallVector<SDValue, 2> Ops(Op->op_begin(), Op->op_end());
654 auto [Result, Chain] = makeLibCall(DAG, LC, VT, Ops, CallOptions, DL);
655 return Result;
656}
657
658// Fold zero extensions into MipsISD::VEXTRACT_[SZ]EXT_ELT
659//
660// Performs the following transformations:
661// - Changes MipsISD::VEXTRACT_[SZ]EXT_ELT to zero extension if its
662// sign/zero-extension is completely overwritten by the new one performed by
663// the ISD::AND.
664// - Removes redundant zero extensions performed by an ISD::AND.
667 const MipsSubtarget &Subtarget) {
668 if (!Subtarget.hasMSA())
669 return SDValue();
670
671 SDValue Op0 = N->getOperand(0);
672 SDValue Op1 = N->getOperand(1);
673 unsigned Op0Opcode = Op0->getOpcode();
674
675 // (and (MipsVExtract[SZ]Ext $a, $b, $c), imm:$d)
676 // where $d + 1 == 2^n and n == 32
677 // or $d + 1 == 2^n and n <= 32 and ZExt
678 // -> (MipsVExtractZExt $a, $b, $c)
679 if (Op0Opcode == MipsISD::VEXTRACT_SEXT_ELT ||
680 Op0Opcode == MipsISD::VEXTRACT_ZEXT_ELT) {
682
683 if (!Mask)
684 return SDValue();
685
686 int32_t Log2IfPositive = (Mask->getAPIntValue() + 1).exactLogBase2();
687
688 if (Log2IfPositive <= 0)
689 return SDValue(); // Mask+1 is not a power of 2
690
691 SDValue Op0Op2 = Op0->getOperand(2);
692 EVT ExtendTy = cast<VTSDNode>(Op0Op2)->getVT();
693 unsigned ExtendTySize = ExtendTy.getSizeInBits();
694 unsigned Log2 = Log2IfPositive;
695
696 if ((Op0Opcode == MipsISD::VEXTRACT_ZEXT_ELT && Log2 >= ExtendTySize) ||
697 Log2 == ExtendTySize) {
698 SDValue Ops[] = { Op0->getOperand(0), Op0->getOperand(1), Op0Op2 };
699 return DAG.getNode(MipsISD::VEXTRACT_ZEXT_ELT, SDLoc(Op0),
700 Op0->getVTList(),
701 ArrayRef(Ops, Op0->getNumOperands()));
702 }
703 }
704
705 return SDValue();
706}
707
708// Determine if the specified node is a constant vector splat.
709//
710// Returns true and sets Imm if:
711// * N is a ISD::BUILD_VECTOR representing a constant splat
712//
713// This function is quite similar to MipsSEDAGToDAGISel::selectVSplat. The
714// differences are that it assumes the MSA has already been checked and the
715// arbitrary requirement for a maximum of 32-bit integers isn't applied (and
716// must not be in order for binsri.d to be selectable).
717static bool isVSplat(SDValue N, APInt &Imm, bool IsLittleEndian) {
719
720 if (!Node)
721 return false;
722
723 APInt SplatValue, SplatUndef;
724 unsigned SplatBitSize;
725 bool HasAnyUndefs;
726
727 if (!Node->isConstantSplat(SplatValue, SplatUndef, SplatBitSize, HasAnyUndefs,
728 8, !IsLittleEndian))
729 return false;
730
731 Imm = SplatValue;
732
733 return true;
734}
735
736// Test whether the given node is an all-ones build_vector.
738 // Look through bitcasts. Endianness doesn't matter because we are looking
739 // for an all-ones value.
740 if (N->getOpcode() == ISD::BITCAST)
741 N = N->getOperand(0);
742
744
745 if (!BVN)
746 return false;
747
748 APInt SplatValue, SplatUndef;
749 unsigned SplatBitSize;
750 bool HasAnyUndefs;
751
752 // Endianness doesn't matter in this context because we are looking for
753 // an all-ones value.
754 if (BVN->isConstantSplat(SplatValue, SplatUndef, SplatBitSize, HasAnyUndefs))
755 return SplatValue.isAllOnes();
756
757 return false;
758}
759
760// Test whether N is the bitwise inverse of OfNode.
761static bool isBitwiseInverse(SDValue N, SDValue OfNode) {
762 if (N->getOpcode() != ISD::XOR)
763 return false;
764
765 if (isVectorAllOnes(N->getOperand(0)))
766 return N->getOperand(1) == OfNode;
767
768 if (isVectorAllOnes(N->getOperand(1)))
769 return N->getOperand(0) == OfNode;
770
771 return false;
772}
773
774// Perform combines where ISD::OR is the root node.
775//
776// Performs the following transformations:
777// - (or (and $a, $mask), (and $b, $inv_mask)) => (vselect $mask, $a, $b)
778// where $inv_mask is the bitwise inverse of $mask and the 'or' has a 128-bit
779// vector type.
782 const MipsSubtarget &Subtarget) {
783 if (!Subtarget.hasMSA())
784 return SDValue();
785
786 EVT Ty = N->getValueType(0);
787
788 if (!Ty.is128BitVector())
789 return SDValue();
790
791 SDValue Op0 = N->getOperand(0);
792 SDValue Op1 = N->getOperand(1);
793
794 if (Op0->getOpcode() == ISD::AND && Op1->getOpcode() == ISD::AND) {
795 SDValue Op0Op0 = Op0->getOperand(0);
796 SDValue Op0Op1 = Op0->getOperand(1);
797 SDValue Op1Op0 = Op1->getOperand(0);
798 SDValue Op1Op1 = Op1->getOperand(1);
799 bool IsLittleEndian = !Subtarget.isLittle();
800
801 SDValue IfSet, IfClr, Cond;
802 bool IsConstantMask = false;
803 APInt Mask, InvMask;
804
805 // If Op0Op0 is an appropriate mask, try to find it's inverse in either
806 // Op1Op0, or Op1Op1. Keep track of the Cond, IfSet, and IfClr nodes, while
807 // looking.
808 // IfClr will be set if we find a valid match.
809 if (isVSplat(Op0Op0, Mask, IsLittleEndian)) {
810 Cond = Op0Op0;
811 IfSet = Op0Op1;
812
813 if (isVSplat(Op1Op0, InvMask, IsLittleEndian) &&
814 Mask.getBitWidth() == InvMask.getBitWidth() && Mask == ~InvMask)
815 IfClr = Op1Op1;
816 else if (isVSplat(Op1Op1, InvMask, IsLittleEndian) &&
817 Mask.getBitWidth() == InvMask.getBitWidth() && Mask == ~InvMask)
818 IfClr = Op1Op0;
819
820 IsConstantMask = true;
821 }
822
823 // If IfClr is not yet set, and Op0Op1 is an appropriate mask, try the same
824 // thing again using this mask.
825 // IfClr will be set if we find a valid match.
826 if (!IfClr.getNode() && isVSplat(Op0Op1, Mask, IsLittleEndian)) {
827 Cond = Op0Op1;
828 IfSet = Op0Op0;
829
830 if (isVSplat(Op1Op0, InvMask, IsLittleEndian) &&
831 Mask.getBitWidth() == InvMask.getBitWidth() && Mask == ~InvMask)
832 IfClr = Op1Op1;
833 else if (isVSplat(Op1Op1, InvMask, IsLittleEndian) &&
834 Mask.getBitWidth() == InvMask.getBitWidth() && Mask == ~InvMask)
835 IfClr = Op1Op0;
836
837 IsConstantMask = true;
838 }
839
840 // If IfClr is not yet set, try looking for a non-constant match.
841 // IfClr will be set if we find a valid match amongst the eight
842 // possibilities.
843 if (!IfClr.getNode()) {
844 if (isBitwiseInverse(Op0Op0, Op1Op0)) {
845 Cond = Op1Op0;
846 IfSet = Op1Op1;
847 IfClr = Op0Op1;
848 } else if (isBitwiseInverse(Op0Op1, Op1Op0)) {
849 Cond = Op1Op0;
850 IfSet = Op1Op1;
851 IfClr = Op0Op0;
852 } else if (isBitwiseInverse(Op0Op0, Op1Op1)) {
853 Cond = Op1Op1;
854 IfSet = Op1Op0;
855 IfClr = Op0Op1;
856 } else if (isBitwiseInverse(Op0Op1, Op1Op1)) {
857 Cond = Op1Op1;
858 IfSet = Op1Op0;
859 IfClr = Op0Op0;
860 } else if (isBitwiseInverse(Op1Op0, Op0Op0)) {
861 Cond = Op0Op0;
862 IfSet = Op0Op1;
863 IfClr = Op1Op1;
864 } else if (isBitwiseInverse(Op1Op1, Op0Op0)) {
865 Cond = Op0Op0;
866 IfSet = Op0Op1;
867 IfClr = Op1Op0;
868 } else if (isBitwiseInverse(Op1Op0, Op0Op1)) {
869 Cond = Op0Op1;
870 IfSet = Op0Op0;
871 IfClr = Op1Op1;
872 } else if (isBitwiseInverse(Op1Op1, Op0Op1)) {
873 Cond = Op0Op1;
874 IfSet = Op0Op0;
875 IfClr = Op1Op0;
876 }
877 }
878
879 // At this point, IfClr will be set if we have a valid match.
880 if (!IfClr.getNode())
881 return SDValue();
882
883 assert(Cond.getNode() && IfSet.getNode());
884
885 // Fold degenerate cases.
886 if (IsConstantMask) {
887 if (Mask.isAllOnes())
888 return IfSet;
889 else if (Mask == 0)
890 return IfClr;
891 }
892
893 // Transform the DAG into an equivalent VSELECT.
894 return DAG.getNode(ISD::VSELECT, SDLoc(N), Ty, Cond, IfSet, IfClr);
895 }
896
897 return SDValue();
898}
899
901 SelectionDAG &DAG,
902 const MipsSubtarget &Subtarget) {
903 // Estimate the number of operations the below transform will turn a
904 // constant multiply into. The number is approximately equal to the minimal
905 // number of powers of two that constant can be broken down to by adding
906 // or subtracting them.
907 //
908 // If we have taken more than 12[1] / 8[2] steps to attempt the
909 // optimization for a native sized value, it is more than likely that this
910 // optimization will make things worse.
911 //
912 // [1] MIPS64 requires 6 instructions at most to materialize any constant,
913 // multiplication requires at least 4 cycles, but another cycle (or two)
914 // to retrieve the result from the HI/LO registers.
915 //
916 // [2] For MIPS32, more than 8 steps is expensive as the constant could be
917 // materialized in 2 instructions, multiplication requires at least 4
918 // cycles, but another cycle (or two) to retrieve the result from the
919 // HI/LO registers.
920 //
921 // TODO:
922 // - MaxSteps needs to consider the `VT` of the constant for the current
923 // target.
924 // - Consider to perform this optimization after type legalization.
925 // That allows to remove a workaround for types not supported natively.
926 // - Take in account `-Os, -Oz` flags because this optimization
927 // increases code size.
928 unsigned MaxSteps = Subtarget.isABI_O32() ? 8 : 12;
929
930 SmallVector<APInt, 16> WorkStack(1, C);
931 unsigned Steps = 0;
932 unsigned BitWidth = C.getBitWidth();
933
934 while (!WorkStack.empty()) {
935 APInt Val = WorkStack.pop_back_val();
936
937 if (Val == 0 || Val == 1)
938 continue;
939
940 if (Steps >= MaxSteps)
941 return false;
942
943 if (Val.isPowerOf2()) {
944 ++Steps;
945 continue;
946 }
947
948 APInt Floor = APInt(BitWidth, 1) << Val.logBase2();
949 APInt Ceil = Val.isNegative() ? APInt(BitWidth, 0)
950 : APInt(BitWidth, 1) << C.ceilLogBase2();
951 if ((Val - Floor).ule(Ceil - Val)) {
952 WorkStack.push_back(Floor);
953 WorkStack.push_back(Val - Floor);
954 } else {
955 WorkStack.push_back(Ceil);
956 WorkStack.push_back(Ceil - Val);
957 }
958
959 ++Steps;
960 }
961
962 // If the value being multiplied is not supported natively, we have to pay
963 // an additional legalization cost, conservatively assume an increase in the
964 // cost of 3 instructions per step. This values for this heuristic were
965 // determined experimentally.
966 unsigned RegisterSize = DAG.getTargetLoweringInfo()
967 .getRegisterType(*DAG.getContext(), VT)
968 .getSizeInBits();
969 Steps *= (VT.getSizeInBits() != RegisterSize) * 3;
970 if (Steps > 27)
971 return false;
972
973 return true;
974}
975
977 EVT ShiftTy, SelectionDAG &DAG) {
978 // Return 0.
979 if (C == 0)
980 return DAG.getConstant(0, DL, VT);
981
982 // Return x.
983 if (C == 1)
984 return X;
985
986 // If c is power of 2, return (shl x, log2(c)).
987 if (C.isPowerOf2())
988 return DAG.getNode(ISD::SHL, DL, VT, X,
989 DAG.getConstant(C.logBase2(), DL, ShiftTy));
990
991 unsigned BitWidth = C.getBitWidth();
992 APInt Floor = APInt(BitWidth, 1) << C.logBase2();
993 APInt Ceil = C.isNegative() ? APInt(BitWidth, 0) :
994 APInt(BitWidth, 1) << C.ceilLogBase2();
995
996 // If |c - floor_c| <= |c - ceil_c|,
997 // where floor_c = pow(2, floor(log2(c))) and ceil_c = pow(2, ceil(log2(c))),
998 // return (add constMult(x, floor_c), constMult(x, c - floor_c)).
999 if ((C - Floor).ule(Ceil - C)) {
1000 SDValue Op0 = genConstMult(X, Floor, DL, VT, ShiftTy, DAG);
1001 SDValue Op1 = genConstMult(X, C - Floor, DL, VT, ShiftTy, DAG);
1002 return DAG.getNode(ISD::ADD, DL, VT, Op0, Op1);
1003 }
1004
1005 // If |c - floor_c| > |c - ceil_c|,
1006 // return (sub constMult(x, ceil_c), constMult(x, ceil_c - c)).
1007 SDValue Op0 = genConstMult(X, Ceil, DL, VT, ShiftTy, DAG);
1008 SDValue Op1 = genConstMult(X, Ceil - C, DL, VT, ShiftTy, DAG);
1009 return DAG.getNode(ISD::SUB, DL, VT, Op0, Op1);
1010}
1011
1014 const MipsSETargetLowering *TL,
1015 const MipsSubtarget &Subtarget) {
1016 EVT VT = N->getValueType(0);
1017
1018 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1)))
1020 C->getAPIntValue(), VT, DAG, Subtarget))
1021 return genConstMult(N->getOperand(0), C->getAPIntValue(), SDLoc(N), VT,
1023 DAG);
1024
1025 return SDValue(N, 0);
1026}
1027
1029 SelectionDAG &DAG,
1030 const MipsSubtarget &Subtarget) {
1031 // See if this is a vector splat immediate node.
1032 APInt SplatValue, SplatUndef;
1033 unsigned SplatBitSize;
1034 bool HasAnyUndefs;
1035 unsigned EltSize = Ty.getScalarSizeInBits();
1036 BuildVectorSDNode *BV = dyn_cast<BuildVectorSDNode>(N->getOperand(1));
1037
1038 if (!Subtarget.hasDSP())
1039 return SDValue();
1040
1041 if (!BV ||
1042 !BV->isConstantSplat(SplatValue, SplatUndef, SplatBitSize, HasAnyUndefs,
1043 EltSize, !Subtarget.isLittle()) ||
1044 (SplatBitSize != EltSize) ||
1045 (SplatValue.getZExtValue() >= EltSize))
1046 return SDValue();
1047
1048 SDLoc DL(N);
1049 return DAG.getNode(Opc, DL, Ty, N->getOperand(0),
1050 DAG.getConstant(SplatValue.getZExtValue(), DL, MVT::i32));
1051}
1052
1055 const MipsSubtarget &Subtarget) {
1056 EVT Ty = N->getValueType(0);
1057
1058 if ((Ty != MVT::v2i16) && (Ty != MVT::v4i8))
1059 return SDValue();
1060
1061 return performDSPShiftCombine(MipsISD::SHLL_DSP, N, Ty, DAG, Subtarget);
1062}
1063
1064// Fold sign-extensions into MipsISD::VEXTRACT_[SZ]EXT_ELT for MSA and fold
1065// constant splats into MipsISD::SHRA_DSP for DSPr2.
1066//
1067// Performs the following transformations:
1068// - Changes MipsISD::VEXTRACT_[SZ]EXT_ELT to sign extension if its
1069// sign/zero-extension is completely overwritten by the new one performed by
1070// the ISD::SRA and ISD::SHL nodes.
1071// - Removes redundant sign extensions performed by an ISD::SRA and ISD::SHL
1072// sequence.
1073//
1074// See performDSPShiftCombine for more information about the transformation
1075// used for DSPr2.
1078 const MipsSubtarget &Subtarget) {
1079 EVT Ty = N->getValueType(0);
1080
1081 if (Subtarget.hasMSA()) {
1082 SDValue Op0 = N->getOperand(0);
1083 SDValue Op1 = N->getOperand(1);
1084
1085 // (sra (shl (MipsVExtract[SZ]Ext $a, $b, $c), imm:$d), imm:$d)
1086 // where $d + sizeof($c) == 32
1087 // or $d + sizeof($c) <= 32 and SExt
1088 // -> (MipsVExtractSExt $a, $b, $c)
1089 if (Op0->getOpcode() == ISD::SHL && Op1 == Op0->getOperand(1)) {
1090 SDValue Op0Op0 = Op0->getOperand(0);
1092
1093 if (!ShAmount)
1094 return SDValue();
1095
1096 if (Op0Op0->getOpcode() != MipsISD::VEXTRACT_SEXT_ELT &&
1097 Op0Op0->getOpcode() != MipsISD::VEXTRACT_ZEXT_ELT)
1098 return SDValue();
1099
1100 EVT ExtendTy = cast<VTSDNode>(Op0Op0->getOperand(2))->getVT();
1101 unsigned TotalBits = ShAmount->getZExtValue() + ExtendTy.getSizeInBits();
1102
1103 if (TotalBits == 32 ||
1104 (Op0Op0->getOpcode() == MipsISD::VEXTRACT_SEXT_ELT &&
1105 TotalBits <= 32)) {
1106 SDValue Ops[] = { Op0Op0->getOperand(0), Op0Op0->getOperand(1),
1107 Op0Op0->getOperand(2) };
1108 return DAG.getNode(MipsISD::VEXTRACT_SEXT_ELT, SDLoc(Op0Op0),
1109 Op0Op0->getVTList(),
1110 ArrayRef(Ops, Op0Op0->getNumOperands()));
1111 }
1112 }
1113 }
1114
1115 if ((Ty != MVT::v2i16) && ((Ty != MVT::v4i8) || !Subtarget.hasDSPR2()))
1116 return SDValue();
1117
1118 return performDSPShiftCombine(MipsISD::SHRA_DSP, N, Ty, DAG, Subtarget);
1119}
1120
1121
1124 const MipsSubtarget &Subtarget) {
1125 EVT Ty = N->getValueType(0);
1126
1127 if (((Ty != MVT::v2i16) || !Subtarget.hasDSPR2()) && (Ty != MVT::v4i8))
1128 return SDValue();
1129
1130 return performDSPShiftCombine(MipsISD::SHRL_DSP, N, Ty, DAG, Subtarget);
1131}
1132
1134 bool IsV216 = (Ty == MVT::v2i16);
1135
1136 switch (CC) {
1137 case ISD::SETEQ:
1138 case ISD::SETNE: return true;
1139 case ISD::SETLT:
1140 case ISD::SETLE:
1141 case ISD::SETGT:
1142 case ISD::SETGE: return IsV216;
1143 case ISD::SETULT:
1144 case ISD::SETULE:
1145 case ISD::SETUGT:
1146 case ISD::SETUGE: return !IsV216;
1147 default: return false;
1148 }
1149}
1150
1152 EVT Ty = N->getValueType(0);
1153
1154 if ((Ty != MVT::v2i16) && (Ty != MVT::v4i8))
1155 return SDValue();
1156
1157 if (!isLegalDSPCondCode(Ty, cast<CondCodeSDNode>(N->getOperand(2))->get()))
1158 return SDValue();
1159
1160 return DAG.getNode(MipsISD::SETCC_DSP, SDLoc(N), Ty, N->getOperand(0),
1161 N->getOperand(1), N->getOperand(2));
1162}
1163
1165 EVT Ty = N->getValueType(0);
1166
1167 if (Ty == MVT::v2i16 || Ty == MVT::v4i8) {
1168 SDValue SetCC = N->getOperand(0);
1169
1170 if (SetCC.getOpcode() != MipsISD::SETCC_DSP)
1171 return SDValue();
1172
1173 return DAG.getNode(MipsISD::SELECT_CC_DSP, SDLoc(N), Ty,
1174 SetCC.getOperand(0), SetCC.getOperand(1),
1175 N->getOperand(1), N->getOperand(2), SetCC.getOperand(2));
1176 }
1177
1178 return SDValue();
1179}
1180
1182 const MipsSubtarget &Subtarget) {
1183 EVT Ty = N->getValueType(0);
1184
1185 if (Subtarget.hasMSA() && Ty.is128BitVector() && Ty.isInteger()) {
1186 // Try the following combines:
1187 // (xor (or $a, $b), (build_vector allones))
1188 // (xor (or $a, $b), (bitcast (build_vector allones)))
1189 SDValue Op0 = N->getOperand(0);
1190 SDValue Op1 = N->getOperand(1);
1191 SDValue NotOp;
1192
1194 NotOp = Op1;
1195 else if (ISD::isBuildVectorAllOnes(Op1.getNode()))
1196 NotOp = Op0;
1197 else
1198 return SDValue();
1199
1200 if (NotOp->getOpcode() == ISD::OR)
1201 return DAG.getNode(MipsISD::VNOR, SDLoc(N), Ty, NotOp->getOperand(0),
1202 NotOp->getOperand(1));
1203 }
1204
1205 return SDValue();
1206}
1207
1208// Convert (fp_to_uint (fp16_to_fp x)) into (fp_to_sint (fp16_to_fp x)).
1210 SDValue Src = N->getOperand(0);
1211 EVT VT = N->getValueType(0);
1212
1213 // Use a trick from TargetLowering::expandFP_TO_UINT: we know that every
1214 // integer value that can be represented by f16 is <= 65504, i.e. a signed
1215 // integer of 17 bits or more can represent all values and fptoui and fptosi
1216 // are equivalent.
1217 //
1218 // NOTE: the result of fptoui is poison when the value does not fit in the
1219 // destination type (e.g. because it is negative).
1220 if (Src.getOpcode() != ISD::FP16_TO_FP || VT.getScalarSizeInBits() < 17)
1221 return SDValue();
1222 return DAG.getNode(ISD::FP_TO_SINT, SDLoc(N), VT, Src);
1223}
1224
1225SDValue
1227 SelectionDAG &DAG = DCI.DAG;
1228 SDValue Val;
1229
1230 switch (N->getOpcode()) {
1231 case ISD::AND:
1232 Val = performANDCombine(N, DAG, DCI, Subtarget);
1233 break;
1234 case ISD::OR:
1235 Val = performORCombine(N, DAG, DCI, Subtarget);
1236 break;
1237 case ISD::MUL:
1238 return performMULCombine(N, DAG, DCI, this, Subtarget);
1239 case ISD::SHL:
1240 Val = performSHLCombine(N, DAG, DCI, Subtarget);
1241 break;
1242 case ISD::SRA:
1243 return performSRACombine(N, DAG, DCI, Subtarget);
1244 case ISD::SRL:
1245 return performSRLCombine(N, DAG, DCI, Subtarget);
1246 case ISD::VSELECT:
1247 return performVSELECTCombine(N, DAG);
1248 case ISD::XOR:
1249 Val = performXORCombine(N, DAG, Subtarget);
1250 break;
1251 case ISD::SETCC:
1252 Val = performSETCCCombine(N, DAG);
1253 break;
1254 case ISD::FP_TO_UINT:
1255 Val = performFP_TO_UINTCombine(N, DAG);
1256 break;
1257 }
1258
1259 if (Val.getNode()) {
1260 LLVM_DEBUG(dbgs() << "\nMipsSE DAG Combine:\n";
1261 N->printrWithDepth(dbgs(), &DAG); dbgs() << "\n=> \n";
1262 Val.getNode()->printrWithDepth(dbgs(), &DAG); dbgs() << "\n");
1263 return Val;
1264 }
1265
1267}
1268
1271 MachineBasicBlock *BB) const {
1272 switch (MI.getOpcode()) {
1273 default:
1275 case Mips::BPOSGE32_PSEUDO:
1276 return emitBPOSGE32(MI, BB);
1277 case Mips::SNZ_B_PSEUDO:
1278 return emitMSACBranchPseudo(MI, BB, Mips::BNZ_B);
1279 case Mips::SNZ_H_PSEUDO:
1280 return emitMSACBranchPseudo(MI, BB, Mips::BNZ_H);
1281 case Mips::SNZ_W_PSEUDO:
1282 return emitMSACBranchPseudo(MI, BB, Mips::BNZ_W);
1283 case Mips::SNZ_D_PSEUDO:
1284 return emitMSACBranchPseudo(MI, BB, Mips::BNZ_D);
1285 case Mips::SNZ_V_PSEUDO:
1286 return emitMSACBranchPseudo(MI, BB, Mips::BNZ_V);
1287 case Mips::SZ_B_PSEUDO:
1288 return emitMSACBranchPseudo(MI, BB, Mips::BZ_B);
1289 case Mips::SZ_H_PSEUDO:
1290 return emitMSACBranchPseudo(MI, BB, Mips::BZ_H);
1291 case Mips::SZ_W_PSEUDO:
1292 return emitMSACBranchPseudo(MI, BB, Mips::BZ_W);
1293 case Mips::SZ_D_PSEUDO:
1294 return emitMSACBranchPseudo(MI, BB, Mips::BZ_D);
1295 case Mips::SZ_V_PSEUDO:
1296 return emitMSACBranchPseudo(MI, BB, Mips::BZ_V);
1297 case Mips::COPY_FW_PSEUDO:
1298 return emitCOPY_FW(MI, BB);
1299 case Mips::COPY_FD_PSEUDO:
1300 return emitCOPY_FD(MI, BB);
1301 case Mips::INSERT_FW_PSEUDO:
1302 return emitINSERT_FW(MI, BB);
1303 case Mips::INSERT_FD_PSEUDO:
1304 return emitINSERT_FD(MI, BB);
1305 case Mips::INSERT_B_VIDX_PSEUDO:
1306 case Mips::INSERT_B_VIDX64_PSEUDO:
1307 return emitINSERT_DF_VIDX(MI, BB, 1, false);
1308 case Mips::INSERT_H_VIDX_PSEUDO:
1309 case Mips::INSERT_H_VIDX64_PSEUDO:
1310 return emitINSERT_DF_VIDX(MI, BB, 2, false);
1311 case Mips::INSERT_W_VIDX_PSEUDO:
1312 case Mips::INSERT_W_VIDX64_PSEUDO:
1313 return emitINSERT_DF_VIDX(MI, BB, 4, false);
1314 case Mips::INSERT_D_VIDX_PSEUDO:
1315 case Mips::INSERT_D_VIDX64_PSEUDO:
1316 return emitINSERT_DF_VIDX(MI, BB, 8, false);
1317 case Mips::INSERT_FW_VIDX_PSEUDO:
1318 case Mips::INSERT_FW_VIDX64_PSEUDO:
1319 return emitINSERT_DF_VIDX(MI, BB, 4, true);
1320 case Mips::INSERT_FD_VIDX_PSEUDO:
1321 case Mips::INSERT_FD_VIDX64_PSEUDO:
1322 return emitINSERT_DF_VIDX(MI, BB, 8, true);
1323 case Mips::FILL_FW_PSEUDO:
1324 return emitFILL_FW(MI, BB);
1325 case Mips::FILL_FD_PSEUDO:
1326 return emitFILL_FD(MI, BB);
1327 case Mips::FEXP2_W_1_PSEUDO:
1328 return emitFEXP2_W_1(MI, BB);
1329 case Mips::FEXP2_D_1_PSEUDO:
1330 return emitFEXP2_D_1(MI, BB);
1331 }
1332}
1333
1334bool MipsSETargetLowering::isEligibleForTailCallOptimization(
1335 const CCState &CCInfo, unsigned NextStackOffset,
1336 const MipsFunctionInfo &FI) const {
1337 // Exception has to be cleared with eret.
1338 if (FI.isISR())
1339 return false;
1340
1341 // Return false if either the callee or caller has a byval argument.
1342 if (CCInfo.getInRegsParamsCount() > 0 || FI.hasByvalArg())
1343 return false;
1344
1345 // Return true if the callee's argument area is no larger than the caller's.
1346 return NextStackOffset <= FI.getIncomingArgSize();
1347}
1348
1349void MipsSETargetLowering::
1350getOpndList(SmallVectorImpl<SDValue> &Ops,
1351 std::deque<std::pair<unsigned, SDValue>> &RegsToPass,
1352 bool IsPICCall, bool GlobalOrExternal, bool InternalLinkage,
1353 bool IsCallReloc, CallLoweringInfo &CLI, SDValue Callee,
1354 SDValue Chain) const {
1355 Ops.push_back(Callee);
1356 MipsTargetLowering::getOpndList(Ops, RegsToPass, IsPICCall, GlobalOrExternal,
1357 InternalLinkage, IsCallReloc, CLI, Callee,
1358 Chain);
1359}
1360
1361SDValue MipsSETargetLowering::lowerLOAD(SDValue Op, SelectionDAG &DAG) const {
1362 LoadSDNode &Nd = *cast<LoadSDNode>(Op);
1363
1364 if (Nd.getMemoryVT() != MVT::f64 || (!NoDPLoadStore && Subtarget.hasMips2()))
1365 return MipsTargetLowering::lowerLOAD(Op, DAG);
1366
1367 // Replace a double precision load with two i32 loads and a buildpair64.
1368 SDLoc DL(Op);
1369 SDValue Ptr = Nd.getBasePtr(), Chain = Nd.getChain();
1370 EVT PtrVT = Ptr.getValueType();
1371 EVT VT = Subtarget.hasMips2() ? MVT::i32 : MVT::f32;
1372
1373 // i32 load from lower address.
1374 SDValue Lo = DAG.getLoad(VT, DL, Chain, Ptr, MachinePointerInfo(),
1375 Nd.getAlign(), Nd.getMemOperand()->getFlags());
1376
1377 // i32 load from higher address.
1378 Ptr = DAG.getNode(ISD::ADD, DL, PtrVT, Ptr, DAG.getConstant(4, DL, PtrVT));
1379 SDValue Hi = DAG.getLoad(VT, DL, Lo.getValue(1), Ptr, MachinePointerInfo(),
1380 commonAlignment(Nd.getAlign(), 4),
1381 Nd.getMemOperand()->getFlags());
1382
1383 if (!Subtarget.isLittle())
1384 std::swap(Lo, Hi);
1385
1386 SDValue BP;
1387 if (Subtarget.hasMips2())
1388 BP = DAG.getNode(MipsISD::BuildPairF64, DL, MVT::f64, Lo, Hi);
1389 else
1390 BP = DAG.getNode(MipsISD::BuildPairF64_FPR, DL, MVT::f64, Hi, Lo);
1391
1392 SDValue Ops[2] = {BP, Hi.getValue(1)};
1393 return DAG.getMergeValues(Ops, DL);
1394}
1395
1396SDValue MipsSETargetLowering::lowerSTORE(SDValue Op, SelectionDAG &DAG) const {
1397 StoreSDNode &Nd = *cast<StoreSDNode>(Op);
1398
1399 if (Nd.getMemoryVT() != MVT::f64 || (!NoDPLoadStore && Subtarget.hasMips2()))
1401
1402 // Replace a double precision store with two extractelement64s and i32 stores.
1403 SDLoc DL(Op);
1404 SDValue Val = Nd.getValue(), Ptr = Nd.getBasePtr(), Chain = Nd.getChain();
1405 EVT PtrVT = Ptr.getValueType();
1406 EVT VT = Subtarget.hasMips2() ? MVT::i32 : MVT::f32;
1407
1408 unsigned ExtractOp = Subtarget.hasMips2() ? MipsISD::ExtractElementF64
1409 : MipsISD::ExtractElementF64_FPR;
1410 SDValue Lo =
1411 DAG.getNode(ExtractOp, DL, VT, Val, DAG.getConstant(0, DL, MVT::i32));
1412 SDValue Hi =
1413 DAG.getNode(ExtractOp, DL, VT, Val, DAG.getConstant(1, DL, MVT::i32));
1414
1415 if (!Subtarget.isLittle())
1416 std::swap(Lo, Hi);
1417
1418 // i32 store to lower address.
1419 Chain = DAG.getStore(Chain, DL, Lo, Ptr, MachinePointerInfo(), Nd.getAlign(),
1420 Nd.getMemOperand()->getFlags(), Nd.getAAInfo());
1421
1422 // i32 store to higher address.
1423 Ptr = DAG.getNode(ISD::ADD, DL, PtrVT, Ptr, DAG.getConstant(4, DL, PtrVT));
1424 return DAG.getStore(Chain, DL, Hi, Ptr, MachinePointerInfo(),
1425 commonAlignment(Nd.getAlign(), 4),
1426 Nd.getMemOperand()->getFlags(), Nd.getAAInfo());
1427}
1428
1429SDValue MipsSETargetLowering::lowerBITCAST(SDValue Op,
1430 SelectionDAG &DAG) const {
1431 SDLoc DL(Op);
1432 MVT Src = Op.getOperand(0).getValueType().getSimpleVT();
1433 MVT Dest = Op.getValueType().getSimpleVT();
1434
1435 // Bitcast i64 to double.
1436 if (Src == MVT::i64 && Dest == MVT::f64) {
1437 SDValue Lo, Hi;
1438 std::tie(Lo, Hi) =
1439 DAG.SplitScalar(Op.getOperand(0), DL, MVT::i32, MVT::i32);
1440 return DAG.getNode(MipsISD::BuildPairF64, DL, MVT::f64, Lo, Hi);
1441 }
1442
1443 // Bitcast double to i64.
1444 if (Src == MVT::f64 && Dest == MVT::i64) {
1445 // Skip lower bitcast when operand0 has converted float results to integer
1446 // which was done by function SoftenFloatResult.
1447 if (getTypeAction(*DAG.getContext(), Op.getOperand(0).getValueType()) ==
1449 return SDValue();
1450 SDValue Lo =
1451 DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, Op.getOperand(0),
1452 DAG.getConstant(0, DL, MVT::i32));
1453 SDValue Hi =
1454 DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, Op.getOperand(0),
1455 DAG.getConstant(1, DL, MVT::i32));
1456 return DAG.getNode(ISD::BUILD_PAIR, DL, MVT::i64, Lo, Hi);
1457 }
1458
1459 // Skip other cases of bitcast and use default lowering.
1460 return SDValue();
1461}
1462
1463SDValue MipsSETargetLowering::lowerMulDiv(SDValue Op, unsigned NewOpc,
1464 bool HasLo, bool HasHi,
1465 SelectionDAG &DAG) const {
1466 // MIPS32r6/MIPS64r6 removed accumulator based multiplies.
1467 assert(!Subtarget.hasMips32r6());
1468
1469 EVT Ty = Op.getOperand(0).getValueType();
1470 SDLoc DL(Op);
1471 SDValue Mult = DAG.getNode(NewOpc, DL, MVT::Untyped,
1472 Op.getOperand(0), Op.getOperand(1));
1473 SDValue Lo, Hi;
1474
1475 if (HasLo)
1476 Lo = DAG.getNode(MipsISD::MFLO, DL, Ty, Mult);
1477 if (HasHi)
1478 Hi = DAG.getNode(MipsISD::MFHI, DL, Ty, Mult);
1479
1480 if (!HasLo || !HasHi)
1481 return HasLo ? Lo : Hi;
1482
1483 SDValue Vals[] = { Lo, Hi };
1484 return DAG.getMergeValues(Vals, DL);
1485}
1486
1488 SDValue InLo, InHi;
1489 std::tie(InLo, InHi) = DAG.SplitScalar(In, DL, MVT::i32, MVT::i32);
1490 return DAG.getNode(MipsISD::MTLOHI, DL, MVT::Untyped, InLo, InHi);
1491}
1492
1494 SDValue Lo = DAG.getNode(MipsISD::MFLO, DL, MVT::i32, Op);
1495 SDValue Hi = DAG.getNode(MipsISD::MFHI, DL, MVT::i32, Op);
1496 return DAG.getNode(ISD::BUILD_PAIR, DL, MVT::i64, Lo, Hi);
1497}
1498
1499// This function expands mips intrinsic nodes which have 64-bit input operands
1500// or output values.
1501//
1502// out64 = intrinsic-node in64
1503// =>
1504// lo = copy (extract-element (in64, 0))
1505// hi = copy (extract-element (in64, 1))
1506// mips-specific-node
1507// v0 = copy lo
1508// v1 = copy hi
1509// out64 = merge-values (v0, v1)
1510//
1512 SDLoc DL(Op);
1513 bool HasChainIn = Op->getOperand(0).getValueType() == MVT::Other;
1515 unsigned OpNo = 0;
1516
1517 // See if Op has a chain input.
1518 if (HasChainIn)
1519 Ops.push_back(Op->getOperand(OpNo++));
1520
1521 // The next operand is the intrinsic opcode.
1522 assert(Op->getOperand(OpNo).getOpcode() == ISD::TargetConstant);
1523
1524 // See if the next operand has type i64.
1525 SDValue Opnd = Op->getOperand(++OpNo), In64;
1526
1527 if (Opnd.getValueType() == MVT::i64)
1528 In64 = initAccumulator(Opnd, DL, DAG);
1529 else
1530 Ops.push_back(Opnd);
1531
1532 // Push the remaining operands.
1533 for (++OpNo ; OpNo < Op->getNumOperands(); ++OpNo)
1534 Ops.push_back(Op->getOperand(OpNo));
1535
1536 // Add In64 to the end of the list.
1537 if (In64.getNode())
1538 Ops.push_back(In64);
1539
1540 // Scan output.
1541 SmallVector<EVT, 2> ResTys;
1542
1543 for (EVT Ty : Op->values())
1544 ResTys.push_back((Ty == MVT::i64) ? MVT::Untyped : Ty);
1545
1546 // Create node.
1547 SDValue Val = DAG.getNode(Opc, DL, ResTys, Ops);
1548 SDValue Out = (ResTys[0] == MVT::Untyped) ? extractLOHI(Val, DL, DAG) : Val;
1549
1550 if (!HasChainIn)
1551 return Out;
1552
1553 assert(Val->getValueType(1) == MVT::Other);
1554 SDValue Vals[] = { Out, SDValue(Val.getNode(), 1) };
1555 return DAG.getMergeValues(Vals, DL);
1556}
1557
1558// Lower an MSA copy intrinsic into the specified SelectionDAG node
1560 SDLoc DL(Op);
1561 SDValue Vec = Op->getOperand(1);
1562 const TargetLowering &TLI = DAG.getTargetLoweringInfo();
1563 SDValue Idx = DAG.getZExtOrTrunc(Op->getOperand(2), DL,
1564 TLI.getVectorIdxTy(DAG.getDataLayout()));
1565 EVT ResTy = Op->getValueType(0);
1566 EVT EltTy = Vec->getValueType(0).getVectorElementType();
1567
1568 SDValue Result = DAG.getNode(Opc, DL, ResTy, Vec, Idx,
1569 DAG.getValueType(EltTy));
1570
1571 return Result;
1572}
1573
1574static SDValue lowerMSASplatZExt(SDValue Op, unsigned OpNr, SelectionDAG &DAG) {
1575 EVT ResVecTy = Op->getValueType(0);
1576 EVT ViaVecTy = ResVecTy;
1577 bool BigEndian = !DAG.getSubtarget().getTargetTriple().isLittleEndian();
1578 SDLoc DL(Op);
1579
1580 // When ResVecTy == MVT::v2i64, LaneA is the upper 32 bits of the lane and
1581 // LaneB is the lower 32-bits. Otherwise LaneA and LaneB are alternating
1582 // lanes.
1583 SDValue LaneA = Op->getOperand(OpNr);
1584 SDValue LaneB;
1585
1586 if (ResVecTy == MVT::v2i64) {
1587 // In case of the index being passed as an immediate value, set the upper
1588 // lane to 0 so that the splati.d instruction can be matched.
1589 if (isa<ConstantSDNode>(LaneA))
1590 LaneB = DAG.getConstant(0, DL, MVT::i32);
1591 // Having the index passed in a register, set the upper lane to the same
1592 // value as the lower - this results in the BUILD_VECTOR node not being
1593 // expanded through stack. This way we are able to pattern match the set of
1594 // nodes created here to splat.d.
1595 else
1596 LaneB = LaneA;
1597 ViaVecTy = MVT::v4i32;
1598 if(BigEndian)
1599 std::swap(LaneA, LaneB);
1600 } else
1601 LaneB = LaneA;
1602
1603 SDValue Ops[16] = { LaneA, LaneB, LaneA, LaneB, LaneA, LaneB, LaneA, LaneB,
1604 LaneA, LaneB, LaneA, LaneB, LaneA, LaneB, LaneA, LaneB };
1605
1606 SDValue Result = DAG.getBuildVector(
1607 ViaVecTy, DL, ArrayRef(Ops, ViaVecTy.getVectorNumElements()));
1608
1609 if (ViaVecTy != ResVecTy) {
1610 SDValue One = DAG.getConstant(1, DL, ViaVecTy);
1611 Result = DAG.getNode(ISD::BITCAST, DL, ResVecTy,
1612 DAG.getNode(ISD::AND, DL, ViaVecTy, Result, One));
1613 }
1614
1615 return Result;
1616}
1617
1618static SDValue lowerMSASplatImm(SDValue Op, unsigned ImmOp, SelectionDAG &DAG,
1619 bool IsSigned = false) {
1620 auto *CImm = cast<ConstantSDNode>(Op->getOperand(ImmOp));
1621 return DAG.getConstant(
1622 APInt(Op->getValueType(0).getScalarType().getSizeInBits(),
1623 IsSigned ? CImm->getSExtValue() : CImm->getZExtValue(), IsSigned),
1624 SDLoc(Op), Op->getValueType(0));
1625}
1626
1627static SDValue getBuildVectorSplat(EVT VecTy, SDValue SplatValue,
1628 bool BigEndian, SelectionDAG &DAG) {
1629 EVT ViaVecTy = VecTy;
1630 SDValue SplatValueA = SplatValue;
1631 SDValue SplatValueB = SplatValue;
1632 SDLoc DL(SplatValue);
1633
1634 if (VecTy == MVT::v2i64) {
1635 // v2i64 BUILD_VECTOR must be performed via v4i32 so split into i32's.
1636 ViaVecTy = MVT::v4i32;
1637
1638 SplatValueA = DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, SplatValue);
1639 SplatValueB = DAG.getNode(ISD::SRL, DL, MVT::i64, SplatValue,
1640 DAG.getConstant(32, DL, MVT::i32));
1641 SplatValueB = DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, SplatValueB);
1642 }
1643
1644 // We currently hold the parts in little endian order. Swap them if
1645 // necessary.
1646 if (BigEndian)
1647 std::swap(SplatValueA, SplatValueB);
1648
1649 SDValue Ops[16] = { SplatValueA, SplatValueB, SplatValueA, SplatValueB,
1650 SplatValueA, SplatValueB, SplatValueA, SplatValueB,
1651 SplatValueA, SplatValueB, SplatValueA, SplatValueB,
1652 SplatValueA, SplatValueB, SplatValueA, SplatValueB };
1653
1654 SDValue Result = DAG.getBuildVector(
1655 ViaVecTy, DL, ArrayRef(Ops, ViaVecTy.getVectorNumElements()));
1656
1657 if (VecTy != ViaVecTy)
1658 Result = DAG.getNode(ISD::BITCAST, DL, VecTy, Result);
1659
1660 return Result;
1661}
1662
1664 unsigned Opc, SDValue Imm,
1665 bool BigEndian) {
1666 EVT VecTy = Op->getValueType(0);
1667 SDValue Exp2Imm;
1668 SDLoc DL(Op);
1669
1670 // The DAG Combiner can't constant fold bitcasted vectors yet so we must do it
1671 // here for now.
1672 if (VecTy == MVT::v2i64) {
1674 APInt BitImm = APInt(64, 1) << CImm->getAPIntValue();
1675
1676 SDValue BitImmHiOp = DAG.getConstant(BitImm.lshr(32).trunc(32), DL,
1677 MVT::i32);
1678 SDValue BitImmLoOp = DAG.getConstant(BitImm.trunc(32), DL, MVT::i32);
1679
1680 if (BigEndian)
1681 std::swap(BitImmLoOp, BitImmHiOp);
1682
1683 Exp2Imm = DAG.getNode(
1684 ISD::BITCAST, DL, MVT::v2i64,
1685 DAG.getBuildVector(MVT::v4i32, DL,
1686 {BitImmLoOp, BitImmHiOp, BitImmLoOp, BitImmHiOp}));
1687 }
1688 }
1689
1690 if (!Exp2Imm.getNode()) {
1691 // We couldnt constant fold, do a vector shift instead
1692
1693 // Extend i32 to i64 if necessary. Sign or zero extend doesn't matter since
1694 // only values 0-63 are valid.
1695 if (VecTy == MVT::v2i64)
1696 Imm = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i64, Imm);
1697
1698 Exp2Imm = getBuildVectorSplat(VecTy, Imm, BigEndian, DAG);
1699
1700 Exp2Imm = DAG.getNode(ISD::SHL, DL, VecTy, DAG.getConstant(1, DL, VecTy),
1701 Exp2Imm);
1702 }
1703
1704 return DAG.getNode(Opc, DL, VecTy, Op->getOperand(1), Exp2Imm);
1705}
1706
1708 SDLoc DL(Op);
1709 EVT ResTy = Op->getValueType(0);
1710 SDValue Vec = Op->getOperand(2);
1711 bool BigEndian = !DAG.getSubtarget().getTargetTriple().isLittleEndian();
1712 MVT ResEltTy = ResTy == MVT::v2i64 ? MVT::i64 : MVT::i32;
1713 SDValue ConstValue = DAG.getConstant(Vec.getScalarValueSizeInBits() - 1,
1714 DL, ResEltTy);
1715 SDValue SplatVec = getBuildVectorSplat(ResTy, ConstValue, BigEndian, DAG);
1716
1717 return DAG.getNode(ISD::AND, DL, ResTy, Vec, SplatVec);
1718}
1719
1721 EVT ResTy = Op->getValueType(0);
1722 SDLoc DL(Op);
1723 SDValue One = DAG.getConstant(1, DL, ResTy);
1724 SDValue Bit = DAG.getNode(ISD::SHL, DL, ResTy, One, truncateVecElts(Op, DAG));
1725
1726 return DAG.getNode(ISD::AND, DL, ResTy, Op->getOperand(1),
1727 DAG.getNOT(DL, Bit, ResTy));
1728}
1729
1731 SDLoc DL(Op);
1732 EVT ResTy = Op->getValueType(0);
1733 APInt BitImm = APInt(ResTy.getScalarSizeInBits(), 1)
1734 << Op->getConstantOperandAPInt(2);
1735 SDValue BitMask = DAG.getConstant(~BitImm, DL, ResTy);
1736
1737 return DAG.getNode(ISD::AND, DL, ResTy, Op->getOperand(1), BitMask);
1738}
1739
1740SDValue MipsSETargetLowering::lowerINTRINSIC_WO_CHAIN(SDValue Op,
1741 SelectionDAG &DAG) const {
1742 SDLoc DL(Op);
1743 unsigned Intrinsic = Op->getConstantOperandVal(0);
1744 switch (Intrinsic) {
1745 default:
1746 return SDValue();
1747 case Intrinsic::mips_shilo:
1748 return lowerDSPIntr(Op, DAG, MipsISD::SHILO);
1749 case Intrinsic::mips_dpau_h_qbl:
1750 return lowerDSPIntr(Op, DAG, MipsISD::DPAU_H_QBL);
1751 case Intrinsic::mips_dpau_h_qbr:
1752 return lowerDSPIntr(Op, DAG, MipsISD::DPAU_H_QBR);
1753 case Intrinsic::mips_dpsu_h_qbl:
1754 return lowerDSPIntr(Op, DAG, MipsISD::DPSU_H_QBL);
1755 case Intrinsic::mips_dpsu_h_qbr:
1756 return lowerDSPIntr(Op, DAG, MipsISD::DPSU_H_QBR);
1757 case Intrinsic::mips_dpa_w_ph:
1758 return lowerDSPIntr(Op, DAG, MipsISD::DPA_W_PH);
1759 case Intrinsic::mips_dps_w_ph:
1760 return lowerDSPIntr(Op, DAG, MipsISD::DPS_W_PH);
1761 case Intrinsic::mips_dpax_w_ph:
1762 return lowerDSPIntr(Op, DAG, MipsISD::DPAX_W_PH);
1763 case Intrinsic::mips_dpsx_w_ph:
1764 return lowerDSPIntr(Op, DAG, MipsISD::DPSX_W_PH);
1765 case Intrinsic::mips_mulsa_w_ph:
1766 return lowerDSPIntr(Op, DAG, MipsISD::MULSA_W_PH);
1767 case Intrinsic::mips_mult:
1768 return lowerDSPIntr(Op, DAG, MipsISD::Mult);
1769 case Intrinsic::mips_multu:
1770 return lowerDSPIntr(Op, DAG, MipsISD::Multu);
1771 case Intrinsic::mips_madd:
1772 return lowerDSPIntr(Op, DAG, MipsISD::MAdd);
1773 case Intrinsic::mips_maddu:
1774 return lowerDSPIntr(Op, DAG, MipsISD::MAddu);
1775 case Intrinsic::mips_msub:
1776 return lowerDSPIntr(Op, DAG, MipsISD::MSub);
1777 case Intrinsic::mips_msubu:
1778 return lowerDSPIntr(Op, DAG, MipsISD::MSubu);
1779 case Intrinsic::mips_addv_b:
1780 case Intrinsic::mips_addv_h:
1781 case Intrinsic::mips_addv_w:
1782 case Intrinsic::mips_addv_d:
1783 return DAG.getNode(ISD::ADD, DL, Op->getValueType(0), Op->getOperand(1),
1784 Op->getOperand(2));
1785 case Intrinsic::mips_addvi_b:
1786 case Intrinsic::mips_addvi_h:
1787 case Intrinsic::mips_addvi_w:
1788 case Intrinsic::mips_addvi_d:
1789 return DAG.getNode(ISD::ADD, DL, Op->getValueType(0), Op->getOperand(1),
1790 lowerMSASplatImm(Op, 2, DAG));
1791 case Intrinsic::mips_and_v:
1792 return DAG.getNode(ISD::AND, DL, Op->getValueType(0), Op->getOperand(1),
1793 Op->getOperand(2));
1794 case Intrinsic::mips_andi_b:
1795 return DAG.getNode(ISD::AND, DL, Op->getValueType(0), Op->getOperand(1),
1796 lowerMSASplatImm(Op, 2, DAG));
1797 case Intrinsic::mips_bclr_b:
1798 case Intrinsic::mips_bclr_h:
1799 case Intrinsic::mips_bclr_w:
1800 case Intrinsic::mips_bclr_d:
1801 return lowerMSABitClear(Op, DAG);
1802 case Intrinsic::mips_bclri_b:
1803 case Intrinsic::mips_bclri_h:
1804 case Intrinsic::mips_bclri_w:
1805 case Intrinsic::mips_bclri_d:
1806 return lowerMSABitClearImm(Op, DAG);
1807 case Intrinsic::mips_binsli_b:
1808 case Intrinsic::mips_binsli_h:
1809 case Intrinsic::mips_binsli_w:
1810 case Intrinsic::mips_binsli_d: {
1811 // binsli_x(IfClear, IfSet, nbits) -> (vselect LBitsMask, IfSet, IfClear)
1812 EVT VecTy = Op->getValueType(0);
1813 EVT EltTy = VecTy.getVectorElementType();
1814 if (Op->getConstantOperandVal(3) >= EltTy.getSizeInBits())
1815 report_fatal_error("Immediate out of range");
1817 Op->getConstantOperandVal(3) + 1);
1818 return DAG.getNode(ISD::VSELECT, DL, VecTy,
1819 DAG.getConstant(Mask, DL, VecTy, true),
1820 Op->getOperand(2), Op->getOperand(1));
1821 }
1822 case Intrinsic::mips_binsri_b:
1823 case Intrinsic::mips_binsri_h:
1824 case Intrinsic::mips_binsri_w:
1825 case Intrinsic::mips_binsri_d: {
1826 // binsri_x(IfClear, IfSet, nbits) -> (vselect RBitsMask, IfSet, IfClear)
1827 EVT VecTy = Op->getValueType(0);
1828 EVT EltTy = VecTy.getVectorElementType();
1829 if (Op->getConstantOperandVal(3) >= EltTy.getSizeInBits())
1830 report_fatal_error("Immediate out of range");
1831 APInt Mask = APInt::getLowBitsSet(EltTy.getSizeInBits(),
1832 Op->getConstantOperandVal(3) + 1);
1833 return DAG.getNode(ISD::VSELECT, DL, VecTy,
1834 DAG.getConstant(Mask, DL, VecTy, true),
1835 Op->getOperand(2), Op->getOperand(1));
1836 }
1837 case Intrinsic::mips_bmnz_v:
1838 return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0), Op->getOperand(3),
1839 Op->getOperand(2), Op->getOperand(1));
1840 case Intrinsic::mips_bmnzi_b:
1841 return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0),
1842 lowerMSASplatImm(Op, 3, DAG), Op->getOperand(2),
1843 Op->getOperand(1));
1844 case Intrinsic::mips_bmz_v:
1845 return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0), Op->getOperand(3),
1846 Op->getOperand(1), Op->getOperand(2));
1847 case Intrinsic::mips_bmzi_b:
1848 return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0),
1849 lowerMSASplatImm(Op, 3, DAG), Op->getOperand(1),
1850 Op->getOperand(2));
1851 case Intrinsic::mips_bneg_b:
1852 case Intrinsic::mips_bneg_h:
1853 case Intrinsic::mips_bneg_w:
1854 case Intrinsic::mips_bneg_d: {
1855 EVT VecTy = Op->getValueType(0);
1856 SDValue One = DAG.getConstant(1, DL, VecTy);
1857
1858 return DAG.getNode(ISD::XOR, DL, VecTy, Op->getOperand(1),
1859 DAG.getNode(ISD::SHL, DL, VecTy, One,
1860 truncateVecElts(Op, DAG)));
1861 }
1862 case Intrinsic::mips_bnegi_b:
1863 case Intrinsic::mips_bnegi_h:
1864 case Intrinsic::mips_bnegi_w:
1865 case Intrinsic::mips_bnegi_d:
1866 return lowerMSABinaryBitImmIntr(Op, DAG, ISD::XOR, Op->getOperand(2),
1867 !Subtarget.isLittle());
1868 case Intrinsic::mips_bnz_b:
1869 case Intrinsic::mips_bnz_h:
1870 case Intrinsic::mips_bnz_w:
1871 case Intrinsic::mips_bnz_d:
1872 return DAG.getNode(MipsISD::VALL_NONZERO, DL, Op->getValueType(0),
1873 Op->getOperand(1));
1874 case Intrinsic::mips_bnz_v:
1875 return DAG.getNode(MipsISD::VANY_NONZERO, DL, Op->getValueType(0),
1876 Op->getOperand(1));
1877 case Intrinsic::mips_bsel_v:
1878 // bsel_v(Mask, IfClear, IfSet) -> (vselect Mask, IfSet, IfClear)
1879 return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0),
1880 Op->getOperand(1), Op->getOperand(3),
1881 Op->getOperand(2));
1882 case Intrinsic::mips_bseli_b:
1883 // bseli_v(Mask, IfClear, IfSet) -> (vselect Mask, IfSet, IfClear)
1884 return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0),
1885 Op->getOperand(1), lowerMSASplatImm(Op, 3, DAG),
1886 Op->getOperand(2));
1887 case Intrinsic::mips_bset_b:
1888 case Intrinsic::mips_bset_h:
1889 case Intrinsic::mips_bset_w:
1890 case Intrinsic::mips_bset_d: {
1891 EVT VecTy = Op->getValueType(0);
1892 SDValue One = DAG.getConstant(1, DL, VecTy);
1893
1894 return DAG.getNode(ISD::OR, DL, VecTy, Op->getOperand(1),
1895 DAG.getNode(ISD::SHL, DL, VecTy, One,
1896 truncateVecElts(Op, DAG)));
1897 }
1898 case Intrinsic::mips_bseti_b:
1899 case Intrinsic::mips_bseti_h:
1900 case Intrinsic::mips_bseti_w:
1901 case Intrinsic::mips_bseti_d:
1902 return lowerMSABinaryBitImmIntr(Op, DAG, ISD::OR, Op->getOperand(2),
1903 !Subtarget.isLittle());
1904 case Intrinsic::mips_bz_b:
1905 case Intrinsic::mips_bz_h:
1906 case Intrinsic::mips_bz_w:
1907 case Intrinsic::mips_bz_d:
1908 return DAG.getNode(MipsISD::VALL_ZERO, DL, Op->getValueType(0),
1909 Op->getOperand(1));
1910 case Intrinsic::mips_bz_v:
1911 return DAG.getNode(MipsISD::VANY_ZERO, DL, Op->getValueType(0),
1912 Op->getOperand(1));
1913 case Intrinsic::mips_ceq_b:
1914 case Intrinsic::mips_ceq_h:
1915 case Intrinsic::mips_ceq_w:
1916 case Intrinsic::mips_ceq_d:
1917 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1918 Op->getOperand(2), ISD::SETEQ);
1919 case Intrinsic::mips_ceqi_b:
1920 case Intrinsic::mips_ceqi_h:
1921 case Intrinsic::mips_ceqi_w:
1922 case Intrinsic::mips_ceqi_d:
1923 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1924 lowerMSASplatImm(Op, 2, DAG, true), ISD::SETEQ);
1925 case Intrinsic::mips_cle_s_b:
1926 case Intrinsic::mips_cle_s_h:
1927 case Intrinsic::mips_cle_s_w:
1928 case Intrinsic::mips_cle_s_d:
1929 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1930 Op->getOperand(2), ISD::SETLE);
1931 case Intrinsic::mips_clei_s_b:
1932 case Intrinsic::mips_clei_s_h:
1933 case Intrinsic::mips_clei_s_w:
1934 case Intrinsic::mips_clei_s_d:
1935 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1936 lowerMSASplatImm(Op, 2, DAG, true), ISD::SETLE);
1937 case Intrinsic::mips_cle_u_b:
1938 case Intrinsic::mips_cle_u_h:
1939 case Intrinsic::mips_cle_u_w:
1940 case Intrinsic::mips_cle_u_d:
1941 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1942 Op->getOperand(2), ISD::SETULE);
1943 case Intrinsic::mips_clei_u_b:
1944 case Intrinsic::mips_clei_u_h:
1945 case Intrinsic::mips_clei_u_w:
1946 case Intrinsic::mips_clei_u_d:
1947 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1948 lowerMSASplatImm(Op, 2, DAG), ISD::SETULE);
1949 case Intrinsic::mips_clt_s_b:
1950 case Intrinsic::mips_clt_s_h:
1951 case Intrinsic::mips_clt_s_w:
1952 case Intrinsic::mips_clt_s_d:
1953 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1954 Op->getOperand(2), ISD::SETLT);
1955 case Intrinsic::mips_clti_s_b:
1956 case Intrinsic::mips_clti_s_h:
1957 case Intrinsic::mips_clti_s_w:
1958 case Intrinsic::mips_clti_s_d:
1959 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1960 lowerMSASplatImm(Op, 2, DAG, true), ISD::SETLT);
1961 case Intrinsic::mips_clt_u_b:
1962 case Intrinsic::mips_clt_u_h:
1963 case Intrinsic::mips_clt_u_w:
1964 case Intrinsic::mips_clt_u_d:
1965 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1966 Op->getOperand(2), ISD::SETULT);
1967 case Intrinsic::mips_clti_u_b:
1968 case Intrinsic::mips_clti_u_h:
1969 case Intrinsic::mips_clti_u_w:
1970 case Intrinsic::mips_clti_u_d:
1971 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1972 lowerMSASplatImm(Op, 2, DAG), ISD::SETULT);
1973 case Intrinsic::mips_copy_s_b:
1974 case Intrinsic::mips_copy_s_h:
1975 case Intrinsic::mips_copy_s_w:
1976 return lowerMSACopyIntr(Op, DAG, MipsISD::VEXTRACT_SEXT_ELT);
1977 case Intrinsic::mips_copy_s_d:
1978 if (Subtarget.hasMips64())
1979 // Lower directly into VEXTRACT_SEXT_ELT since i64 is legal on Mips64.
1980 return lowerMSACopyIntr(Op, DAG, MipsISD::VEXTRACT_SEXT_ELT);
1981 else {
1982 // Lower into the generic EXTRACT_VECTOR_ELT node and let the type
1983 // legalizer and EXTRACT_VECTOR_ELT lowering sort it out.
1984 return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SDLoc(Op),
1985 Op->getValueType(0), Op->getOperand(1),
1986 Op->getOperand(2));
1987 }
1988 case Intrinsic::mips_copy_u_b:
1989 case Intrinsic::mips_copy_u_h:
1990 case Intrinsic::mips_copy_u_w:
1991 return lowerMSACopyIntr(Op, DAG, MipsISD::VEXTRACT_ZEXT_ELT);
1992 case Intrinsic::mips_copy_u_d:
1993 if (Subtarget.hasMips64())
1994 // Lower directly into VEXTRACT_ZEXT_ELT since i64 is legal on Mips64.
1995 return lowerMSACopyIntr(Op, DAG, MipsISD::VEXTRACT_ZEXT_ELT);
1996 else {
1997 // Lower into the generic EXTRACT_VECTOR_ELT node and let the type
1998 // legalizer and EXTRACT_VECTOR_ELT lowering sort it out.
1999 // Note: When i64 is illegal, this results in copy_s.w instructions
2000 // instead of copy_u.w instructions. This makes no difference to the
2001 // behaviour since i64 is only illegal when the register file is 32-bit.
2002 return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SDLoc(Op),
2003 Op->getValueType(0), Op->getOperand(1),
2004 Op->getOperand(2));
2005 }
2006 case Intrinsic::mips_div_s_b:
2007 case Intrinsic::mips_div_s_h:
2008 case Intrinsic::mips_div_s_w:
2009 case Intrinsic::mips_div_s_d:
2010 return DAG.getNode(ISD::SDIV, DL, Op->getValueType(0), Op->getOperand(1),
2011 Op->getOperand(2));
2012 case Intrinsic::mips_div_u_b:
2013 case Intrinsic::mips_div_u_h:
2014 case Intrinsic::mips_div_u_w:
2015 case Intrinsic::mips_div_u_d:
2016 return DAG.getNode(ISD::UDIV, DL, Op->getValueType(0), Op->getOperand(1),
2017 Op->getOperand(2));
2018 case Intrinsic::mips_fadd_w:
2019 case Intrinsic::mips_fadd_d:
2020 return DAG.getNode(ISD::FADD, DL, Op->getValueType(0), Op->getOperand(1),
2021 Op->getOperand(2), Op->getFlags());
2022 // Don't lower mips_fcaf_[wd] since LLVM folds SETFALSE condcodes away
2023 case Intrinsic::mips_fceq_w:
2024 case Intrinsic::mips_fceq_d:
2025 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2026 Op->getOperand(2), ISD::SETOEQ);
2027 case Intrinsic::mips_fcle_w:
2028 case Intrinsic::mips_fcle_d:
2029 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2030 Op->getOperand(2), ISD::SETOLE);
2031 case Intrinsic::mips_fclt_w:
2032 case Intrinsic::mips_fclt_d:
2033 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2034 Op->getOperand(2), ISD::SETOLT);
2035 case Intrinsic::mips_fcne_w:
2036 case Intrinsic::mips_fcne_d:
2037 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2038 Op->getOperand(2), ISD::SETONE);
2039 case Intrinsic::mips_fcor_w:
2040 case Intrinsic::mips_fcor_d:
2041 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2042 Op->getOperand(2), ISD::SETO);
2043 case Intrinsic::mips_fcueq_w:
2044 case Intrinsic::mips_fcueq_d:
2045 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2046 Op->getOperand(2), ISD::SETUEQ);
2047 case Intrinsic::mips_fcule_w:
2048 case Intrinsic::mips_fcule_d:
2049 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2050 Op->getOperand(2), ISD::SETULE);
2051 case Intrinsic::mips_fcult_w:
2052 case Intrinsic::mips_fcult_d:
2053 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2054 Op->getOperand(2), ISD::SETULT);
2055 case Intrinsic::mips_fcun_w:
2056 case Intrinsic::mips_fcun_d:
2057 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2058 Op->getOperand(2), ISD::SETUO);
2059 case Intrinsic::mips_fcune_w:
2060 case Intrinsic::mips_fcune_d:
2061 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2062 Op->getOperand(2), ISD::SETUNE);
2063 case Intrinsic::mips_fdiv_w:
2064 case Intrinsic::mips_fdiv_d:
2065 // TODO: If intrinsics have fast-math-flags, propagate them.
2066 return DAG.getNode(ISD::FDIV, DL, Op->getValueType(0), Op->getOperand(1),
2067 Op->getOperand(2));
2068 case Intrinsic::mips_ffint_u_w:
2069 case Intrinsic::mips_ffint_u_d:
2070 return DAG.getNode(ISD::UINT_TO_FP, DL, Op->getValueType(0),
2071 Op->getOperand(1));
2072 case Intrinsic::mips_ffint_s_w:
2073 case Intrinsic::mips_ffint_s_d:
2074 return DAG.getNode(ISD::SINT_TO_FP, DL, Op->getValueType(0),
2075 Op->getOperand(1));
2076 case Intrinsic::mips_fill_b:
2077 case Intrinsic::mips_fill_h:
2078 case Intrinsic::mips_fill_w:
2079 case Intrinsic::mips_fill_d: {
2080 EVT ResTy = Op->getValueType(0);
2082 Op->getOperand(1));
2083
2084 // If ResTy is v2i64 then the type legalizer will break this node down into
2085 // an equivalent v4i32.
2086 return DAG.getBuildVector(ResTy, DL, Ops);
2087 }
2088 case Intrinsic::mips_fexp2_w:
2089 case Intrinsic::mips_fexp2_d: {
2090 // TODO: If intrinsics have fast-math-flags, propagate them.
2091 EVT ResTy = Op->getValueType(0);
2092 return DAG.getNode(
2093 ISD::FMUL, SDLoc(Op), ResTy, Op->getOperand(1),
2094 DAG.getNode(ISD::FEXP2, SDLoc(Op), ResTy, Op->getOperand(2)));
2095 }
2096 case Intrinsic::mips_flog2_w:
2097 case Intrinsic::mips_flog2_d:
2098 return DAG.getNode(ISD::FLOG2, DL, Op->getValueType(0), Op->getOperand(1));
2099 case Intrinsic::mips_fmadd_w:
2100 case Intrinsic::mips_fmadd_d:
2101 return DAG.getNode(ISD::FMA, SDLoc(Op), Op->getValueType(0),
2102 Op->getOperand(1), Op->getOperand(2), Op->getOperand(3));
2103 case Intrinsic::mips_fmul_w:
2104 case Intrinsic::mips_fmul_d:
2105 return DAG.getNode(ISD::FMUL, DL, Op->getValueType(0), Op->getOperand(1),
2106 Op->getOperand(2), Op->getFlags());
2107 case Intrinsic::mips_fmsub_w:
2108 case Intrinsic::mips_fmsub_d: {
2109 // TODO: If intrinsics have fast-math-flags, propagate them.
2110 return DAG.getNode(MipsISD::FMS, SDLoc(Op), Op->getValueType(0),
2111 Op->getOperand(1), Op->getOperand(2), Op->getOperand(3));
2112 }
2113 case Intrinsic::mips_frint_w:
2114 case Intrinsic::mips_frint_d:
2115 return DAG.getNode(ISD::FRINT, DL, Op->getValueType(0), Op->getOperand(1));
2116 case Intrinsic::mips_fsqrt_w:
2117 case Intrinsic::mips_fsqrt_d:
2118 return DAG.getNode(ISD::FSQRT, DL, Op->getValueType(0), Op->getOperand(1));
2119 case Intrinsic::mips_fsub_w:
2120 case Intrinsic::mips_fsub_d:
2121 return DAG.getNode(ISD::FSUB, DL, Op->getValueType(0), Op->getOperand(1),
2122 Op->getOperand(2), Op->getFlags());
2123 case Intrinsic::mips_ftrunc_u_w:
2124 case Intrinsic::mips_ftrunc_u_d:
2125 return DAG.getNode(ISD::FP_TO_UINT, DL, Op->getValueType(0),
2126 Op->getOperand(1));
2127 case Intrinsic::mips_ftrunc_s_w:
2128 case Intrinsic::mips_ftrunc_s_d:
2129 return DAG.getNode(ISD::FP_TO_SINT, DL, Op->getValueType(0),
2130 Op->getOperand(1));
2131 case Intrinsic::mips_ilvev_b:
2132 case Intrinsic::mips_ilvev_h:
2133 case Intrinsic::mips_ilvev_w:
2134 case Intrinsic::mips_ilvev_d:
2135 return DAG.getNode(MipsISD::ILVEV, DL, Op->getValueType(0),
2136 Op->getOperand(1), Op->getOperand(2));
2137 case Intrinsic::mips_ilvl_b:
2138 case Intrinsic::mips_ilvl_h:
2139 case Intrinsic::mips_ilvl_w:
2140 case Intrinsic::mips_ilvl_d:
2141 return DAG.getNode(MipsISD::ILVL, DL, Op->getValueType(0),
2142 Op->getOperand(1), Op->getOperand(2));
2143 case Intrinsic::mips_ilvod_b:
2144 case Intrinsic::mips_ilvod_h:
2145 case Intrinsic::mips_ilvod_w:
2146 case Intrinsic::mips_ilvod_d:
2147 return DAG.getNode(MipsISD::ILVOD, DL, Op->getValueType(0),
2148 Op->getOperand(1), Op->getOperand(2));
2149 case Intrinsic::mips_ilvr_b:
2150 case Intrinsic::mips_ilvr_h:
2151 case Intrinsic::mips_ilvr_w:
2152 case Intrinsic::mips_ilvr_d:
2153 return DAG.getNode(MipsISD::ILVR, DL, Op->getValueType(0),
2154 Op->getOperand(1), Op->getOperand(2));
2155 case Intrinsic::mips_insert_b:
2156 case Intrinsic::mips_insert_h:
2157 case Intrinsic::mips_insert_w:
2158 case Intrinsic::mips_insert_d:
2159 return DAG.getNode(ISD::INSERT_VECTOR_ELT, SDLoc(Op), Op->getValueType(0),
2160 Op->getOperand(1), Op->getOperand(3), Op->getOperand(2));
2161 case Intrinsic::mips_insve_b:
2162 case Intrinsic::mips_insve_h:
2163 case Intrinsic::mips_insve_w:
2164 case Intrinsic::mips_insve_d: {
2165 // Report an error for out of range values.
2166 int64_t Max;
2167 switch (Intrinsic) {
2168 case Intrinsic::mips_insve_b: Max = 15; break;
2169 case Intrinsic::mips_insve_h: Max = 7; break;
2170 case Intrinsic::mips_insve_w: Max = 3; break;
2171 case Intrinsic::mips_insve_d: Max = 1; break;
2172 default: llvm_unreachable("Unmatched intrinsic");
2173 }
2174 int64_t Value = cast<ConstantSDNode>(Op->getOperand(2))->getSExtValue();
2175 if (Value < 0 || Value > Max)
2176 report_fatal_error("Immediate out of range");
2177 return DAG.getNode(MipsISD::INSVE, DL, Op->getValueType(0),
2178 Op->getOperand(1), Op->getOperand(2), Op->getOperand(3),
2179 DAG.getConstant(0, DL, MVT::i32));
2180 }
2181 case Intrinsic::mips_ldi_b:
2182 case Intrinsic::mips_ldi_h:
2183 case Intrinsic::mips_ldi_w:
2184 case Intrinsic::mips_ldi_d:
2185 return lowerMSASplatImm(Op, 1, DAG, true);
2186 case Intrinsic::mips_lsa:
2187 case Intrinsic::mips_dlsa: {
2188 EVT ResTy = Op->getValueType(0);
2189 return DAG.getNode(ISD::ADD, SDLoc(Op), ResTy, Op->getOperand(1),
2190 DAG.getNode(ISD::SHL, SDLoc(Op), ResTy,
2191 Op->getOperand(2), Op->getOperand(3)));
2192 }
2193 case Intrinsic::mips_maddv_b:
2194 case Intrinsic::mips_maddv_h:
2195 case Intrinsic::mips_maddv_w:
2196 case Intrinsic::mips_maddv_d: {
2197 EVT ResTy = Op->getValueType(0);
2198 return DAG.getNode(ISD::ADD, SDLoc(Op), ResTy, Op->getOperand(1),
2199 DAG.getNode(ISD::MUL, SDLoc(Op), ResTy,
2200 Op->getOperand(2), Op->getOperand(3)));
2201 }
2202 case Intrinsic::mips_max_s_b:
2203 case Intrinsic::mips_max_s_h:
2204 case Intrinsic::mips_max_s_w:
2205 case Intrinsic::mips_max_s_d:
2206 return DAG.getNode(ISD::SMAX, DL, Op->getValueType(0),
2207 Op->getOperand(1), Op->getOperand(2));
2208 case Intrinsic::mips_max_u_b:
2209 case Intrinsic::mips_max_u_h:
2210 case Intrinsic::mips_max_u_w:
2211 case Intrinsic::mips_max_u_d:
2212 return DAG.getNode(ISD::UMAX, DL, Op->getValueType(0),
2213 Op->getOperand(1), Op->getOperand(2));
2214 case Intrinsic::mips_maxi_s_b:
2215 case Intrinsic::mips_maxi_s_h:
2216 case Intrinsic::mips_maxi_s_w:
2217 case Intrinsic::mips_maxi_s_d:
2218 return DAG.getNode(ISD::SMAX, DL, Op->getValueType(0),
2219 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG, true));
2220 case Intrinsic::mips_maxi_u_b:
2221 case Intrinsic::mips_maxi_u_h:
2222 case Intrinsic::mips_maxi_u_w:
2223 case Intrinsic::mips_maxi_u_d:
2224 return DAG.getNode(ISD::UMAX, DL, Op->getValueType(0),
2225 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
2226 case Intrinsic::mips_min_s_b:
2227 case Intrinsic::mips_min_s_h:
2228 case Intrinsic::mips_min_s_w:
2229 case Intrinsic::mips_min_s_d:
2230 return DAG.getNode(ISD::SMIN, DL, Op->getValueType(0),
2231 Op->getOperand(1), Op->getOperand(2));
2232 case Intrinsic::mips_min_u_b:
2233 case Intrinsic::mips_min_u_h:
2234 case Intrinsic::mips_min_u_w:
2235 case Intrinsic::mips_min_u_d:
2236 return DAG.getNode(ISD::UMIN, DL, Op->getValueType(0),
2237 Op->getOperand(1), Op->getOperand(2));
2238 case Intrinsic::mips_mini_s_b:
2239 case Intrinsic::mips_mini_s_h:
2240 case Intrinsic::mips_mini_s_w:
2241 case Intrinsic::mips_mini_s_d:
2242 return DAG.getNode(ISD::SMIN, DL, Op->getValueType(0),
2243 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG, true));
2244 case Intrinsic::mips_mini_u_b:
2245 case Intrinsic::mips_mini_u_h:
2246 case Intrinsic::mips_mini_u_w:
2247 case Intrinsic::mips_mini_u_d:
2248 return DAG.getNode(ISD::UMIN, DL, Op->getValueType(0),
2249 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
2250 case Intrinsic::mips_mod_s_b:
2251 case Intrinsic::mips_mod_s_h:
2252 case Intrinsic::mips_mod_s_w:
2253 case Intrinsic::mips_mod_s_d:
2254 return DAG.getNode(ISD::SREM, DL, Op->getValueType(0), Op->getOperand(1),
2255 Op->getOperand(2));
2256 case Intrinsic::mips_mod_u_b:
2257 case Intrinsic::mips_mod_u_h:
2258 case Intrinsic::mips_mod_u_w:
2259 case Intrinsic::mips_mod_u_d:
2260 return DAG.getNode(ISD::UREM, DL, Op->getValueType(0), Op->getOperand(1),
2261 Op->getOperand(2));
2262 case Intrinsic::mips_mulv_b:
2263 case Intrinsic::mips_mulv_h:
2264 case Intrinsic::mips_mulv_w:
2265 case Intrinsic::mips_mulv_d:
2266 return DAG.getNode(ISD::MUL, DL, Op->getValueType(0), Op->getOperand(1),
2267 Op->getOperand(2));
2268 case Intrinsic::mips_msubv_b:
2269 case Intrinsic::mips_msubv_h:
2270 case Intrinsic::mips_msubv_w:
2271 case Intrinsic::mips_msubv_d: {
2272 EVT ResTy = Op->getValueType(0);
2273 return DAG.getNode(ISD::SUB, SDLoc(Op), ResTy, Op->getOperand(1),
2274 DAG.getNode(ISD::MUL, SDLoc(Op), ResTy,
2275 Op->getOperand(2), Op->getOperand(3)));
2276 }
2277 case Intrinsic::mips_nlzc_b:
2278 case Intrinsic::mips_nlzc_h:
2279 case Intrinsic::mips_nlzc_w:
2280 case Intrinsic::mips_nlzc_d:
2281 return DAG.getNode(ISD::CTLZ, DL, Op->getValueType(0), Op->getOperand(1));
2282 case Intrinsic::mips_nor_v: {
2283 SDValue Res = DAG.getNode(ISD::OR, DL, Op->getValueType(0),
2284 Op->getOperand(1), Op->getOperand(2));
2285 return DAG.getNOT(DL, Res, Res->getValueType(0));
2286 }
2287 case Intrinsic::mips_nori_b: {
2288 SDValue Res = DAG.getNode(ISD::OR, DL, Op->getValueType(0),
2289 Op->getOperand(1),
2290 lowerMSASplatImm(Op, 2, DAG));
2291 return DAG.getNOT(DL, Res, Res->getValueType(0));
2292 }
2293 case Intrinsic::mips_or_v:
2294 return DAG.getNode(ISD::OR, DL, Op->getValueType(0), Op->getOperand(1),
2295 Op->getOperand(2));
2296 case Intrinsic::mips_ori_b:
2297 return DAG.getNode(ISD::OR, DL, Op->getValueType(0),
2298 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
2299 case Intrinsic::mips_pckev_b:
2300 case Intrinsic::mips_pckev_h:
2301 case Intrinsic::mips_pckev_w:
2302 case Intrinsic::mips_pckev_d:
2303 return DAG.getNode(MipsISD::PCKEV, DL, Op->getValueType(0),
2304 Op->getOperand(1), Op->getOperand(2));
2305 case Intrinsic::mips_pckod_b:
2306 case Intrinsic::mips_pckod_h:
2307 case Intrinsic::mips_pckod_w:
2308 case Intrinsic::mips_pckod_d:
2309 return DAG.getNode(MipsISD::PCKOD, DL, Op->getValueType(0),
2310 Op->getOperand(1), Op->getOperand(2));
2311 case Intrinsic::mips_pcnt_b:
2312 case Intrinsic::mips_pcnt_h:
2313 case Intrinsic::mips_pcnt_w:
2314 case Intrinsic::mips_pcnt_d:
2315 return DAG.getNode(ISD::CTPOP, DL, Op->getValueType(0), Op->getOperand(1));
2316 case Intrinsic::mips_sat_s_b:
2317 case Intrinsic::mips_sat_s_h:
2318 case Intrinsic::mips_sat_s_w:
2319 case Intrinsic::mips_sat_s_d:
2320 case Intrinsic::mips_sat_u_b:
2321 case Intrinsic::mips_sat_u_h:
2322 case Intrinsic::mips_sat_u_w:
2323 case Intrinsic::mips_sat_u_d: {
2324 // Report an error for out of range values.
2325 int64_t Max;
2326 switch (Intrinsic) {
2327 case Intrinsic::mips_sat_s_b:
2328 case Intrinsic::mips_sat_u_b: Max = 7; break;
2329 case Intrinsic::mips_sat_s_h:
2330 case Intrinsic::mips_sat_u_h: Max = 15; break;
2331 case Intrinsic::mips_sat_s_w:
2332 case Intrinsic::mips_sat_u_w: Max = 31; break;
2333 case Intrinsic::mips_sat_s_d:
2334 case Intrinsic::mips_sat_u_d: Max = 63; break;
2335 default: llvm_unreachable("Unmatched intrinsic");
2336 }
2337 int64_t Value = cast<ConstantSDNode>(Op->getOperand(2))->getSExtValue();
2338 if (Value < 0 || Value > Max)
2339 report_fatal_error("Immediate out of range");
2340 return SDValue();
2341 }
2342 case Intrinsic::mips_shf_b:
2343 case Intrinsic::mips_shf_h:
2344 case Intrinsic::mips_shf_w: {
2345 int64_t Value = cast<ConstantSDNode>(Op->getOperand(2))->getSExtValue();
2346 if (Value < 0 || Value > 255)
2347 report_fatal_error("Immediate out of range");
2348 return DAG.getNode(MipsISD::SHF, DL, Op->getValueType(0),
2349 Op->getOperand(2), Op->getOperand(1));
2350 }
2351 case Intrinsic::mips_sldi_b:
2352 case Intrinsic::mips_sldi_h:
2353 case Intrinsic::mips_sldi_w:
2354 case Intrinsic::mips_sldi_d: {
2355 // Report an error for out of range values.
2356 int64_t Max;
2357 switch (Intrinsic) {
2358 case Intrinsic::mips_sldi_b: Max = 15; break;
2359 case Intrinsic::mips_sldi_h: Max = 7; break;
2360 case Intrinsic::mips_sldi_w: Max = 3; break;
2361 case Intrinsic::mips_sldi_d: Max = 1; break;
2362 default: llvm_unreachable("Unmatched intrinsic");
2363 }
2364 int64_t Value = cast<ConstantSDNode>(Op->getOperand(3))->getSExtValue();
2365 if (Value < 0 || Value > Max)
2366 report_fatal_error("Immediate out of range");
2367 return SDValue();
2368 }
2369 case Intrinsic::mips_sll_b:
2370 case Intrinsic::mips_sll_h:
2371 case Intrinsic::mips_sll_w:
2372 case Intrinsic::mips_sll_d:
2373 return DAG.getNode(ISD::SHL, DL, Op->getValueType(0), Op->getOperand(1),
2374 truncateVecElts(Op, DAG));
2375 case Intrinsic::mips_slli_b:
2376 case Intrinsic::mips_slli_h:
2377 case Intrinsic::mips_slli_w:
2378 case Intrinsic::mips_slli_d:
2379 return DAG.getNode(ISD::SHL, DL, Op->getValueType(0),
2380 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
2381 case Intrinsic::mips_splat_b:
2382 case Intrinsic::mips_splat_h:
2383 case Intrinsic::mips_splat_w:
2384 case Intrinsic::mips_splat_d:
2385 // We can't lower via VECTOR_SHUFFLE because it requires constant shuffle
2386 // masks, nor can we lower via BUILD_VECTOR & EXTRACT_VECTOR_ELT because
2387 // EXTRACT_VECTOR_ELT can't extract i64's on MIPS32.
2388 // Instead we lower to MipsISD::VSHF and match from there.
2389 return DAG.getNode(MipsISD::VSHF, DL, Op->getValueType(0),
2390 lowerMSASplatZExt(Op, 2, DAG), Op->getOperand(1),
2391 Op->getOperand(1));
2392 case Intrinsic::mips_splati_b:
2393 case Intrinsic::mips_splati_h:
2394 case Intrinsic::mips_splati_w:
2395 case Intrinsic::mips_splati_d:
2396 return DAG.getNode(MipsISD::VSHF, DL, Op->getValueType(0),
2397 lowerMSASplatImm(Op, 2, DAG), Op->getOperand(1),
2398 Op->getOperand(1));
2399 case Intrinsic::mips_sra_b:
2400 case Intrinsic::mips_sra_h:
2401 case Intrinsic::mips_sra_w:
2402 case Intrinsic::mips_sra_d:
2403 return DAG.getNode(ISD::SRA, DL, Op->getValueType(0), Op->getOperand(1),
2404 truncateVecElts(Op, DAG));
2405 case Intrinsic::mips_srai_b:
2406 case Intrinsic::mips_srai_h:
2407 case Intrinsic::mips_srai_w:
2408 case Intrinsic::mips_srai_d:
2409 return DAG.getNode(ISD::SRA, DL, Op->getValueType(0),
2410 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
2411 case Intrinsic::mips_srari_b:
2412 case Intrinsic::mips_srari_h:
2413 case Intrinsic::mips_srari_w:
2414 case Intrinsic::mips_srari_d: {
2415 // Report an error for out of range values.
2416 int64_t Max;
2417 switch (Intrinsic) {
2418 case Intrinsic::mips_srari_b: Max = 7; break;
2419 case Intrinsic::mips_srari_h: Max = 15; break;
2420 case Intrinsic::mips_srari_w: Max = 31; break;
2421 case Intrinsic::mips_srari_d: Max = 63; break;
2422 default: llvm_unreachable("Unmatched intrinsic");
2423 }
2424 int64_t Value = cast<ConstantSDNode>(Op->getOperand(2))->getSExtValue();
2425 if (Value < 0 || Value > Max)
2426 report_fatal_error("Immediate out of range");
2427 return SDValue();
2428 }
2429 case Intrinsic::mips_srl_b:
2430 case Intrinsic::mips_srl_h:
2431 case Intrinsic::mips_srl_w:
2432 case Intrinsic::mips_srl_d:
2433 return DAG.getNode(ISD::SRL, DL, Op->getValueType(0), Op->getOperand(1),
2434 truncateVecElts(Op, DAG));
2435 case Intrinsic::mips_srli_b:
2436 case Intrinsic::mips_srli_h:
2437 case Intrinsic::mips_srli_w:
2438 case Intrinsic::mips_srli_d:
2439 return DAG.getNode(ISD::SRL, DL, Op->getValueType(0),
2440 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
2441 case Intrinsic::mips_srlri_b:
2442 case Intrinsic::mips_srlri_h:
2443 case Intrinsic::mips_srlri_w:
2444 case Intrinsic::mips_srlri_d: {
2445 // Report an error for out of range values.
2446 int64_t Max;
2447 switch (Intrinsic) {
2448 case Intrinsic::mips_srlri_b: Max = 7; break;
2449 case Intrinsic::mips_srlri_h: Max = 15; break;
2450 case Intrinsic::mips_srlri_w: Max = 31; break;
2451 case Intrinsic::mips_srlri_d: Max = 63; break;
2452 default: llvm_unreachable("Unmatched intrinsic");
2453 }
2454 int64_t Value = cast<ConstantSDNode>(Op->getOperand(2))->getSExtValue();
2455 if (Value < 0 || Value > Max)
2456 report_fatal_error("Immediate out of range");
2457 return SDValue();
2458 }
2459 case Intrinsic::mips_subv_b:
2460 case Intrinsic::mips_subv_h:
2461 case Intrinsic::mips_subv_w:
2462 case Intrinsic::mips_subv_d:
2463 return DAG.getNode(ISD::SUB, DL, Op->getValueType(0), Op->getOperand(1),
2464 Op->getOperand(2));
2465 case Intrinsic::mips_subvi_b:
2466 case Intrinsic::mips_subvi_h:
2467 case Intrinsic::mips_subvi_w:
2468 case Intrinsic::mips_subvi_d:
2469 return DAG.getNode(ISD::SUB, DL, Op->getValueType(0),
2470 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
2471 case Intrinsic::mips_vshf_b:
2472 case Intrinsic::mips_vshf_h:
2473 case Intrinsic::mips_vshf_w:
2474 case Intrinsic::mips_vshf_d:
2475 return DAG.getNode(MipsISD::VSHF, DL, Op->getValueType(0),
2476 Op->getOperand(1), Op->getOperand(2), Op->getOperand(3));
2477 case Intrinsic::mips_xor_v:
2478 return DAG.getNode(ISD::XOR, DL, Op->getValueType(0), Op->getOperand(1),
2479 Op->getOperand(2));
2480 case Intrinsic::mips_xori_b:
2481 return DAG.getNode(ISD::XOR, DL, Op->getValueType(0),
2482 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
2483 case Intrinsic::thread_pointer: {
2484 EVT PtrVT = getPointerTy(DAG.getDataLayout());
2485 return DAG.getNode(MipsISD::ThreadPointer, DL, PtrVT);
2486 }
2487 }
2488}
2489
2490static SDValue lowerMSALoadIntr(SDValue Op, SelectionDAG &DAG, unsigned Intr,
2491 const MipsSubtarget &Subtarget) {
2492 SDLoc DL(Op);
2493 SDValue ChainIn = Op->getOperand(0);
2494 SDValue Address = Op->getOperand(2);
2495 SDValue Offset = Op->getOperand(3);
2496 EVT ResTy = Op->getValueType(0);
2497 EVT PtrTy = Address->getValueType(0);
2498
2499 // For N64 addresses have the underlying type MVT::i64. This intrinsic
2500 // however takes an i32 signed constant offset. The actual type of the
2501 // intrinsic is a scaled signed i10.
2502 if (Subtarget.isABI_N64())
2503 Offset = DAG.getNode(ISD::SIGN_EXTEND, DL, PtrTy, Offset);
2504
2505 Address = DAG.getNode(ISD::ADD, DL, PtrTy, Address, Offset);
2506 return DAG.getLoad(ResTy, DL, ChainIn, Address, MachinePointerInfo(),
2507 Align(16));
2508}
2509
2510SDValue MipsSETargetLowering::lowerINTRINSIC_W_CHAIN(SDValue Op,
2511 SelectionDAG &DAG) const {
2512 unsigned Intr = Op->getConstantOperandVal(1);
2513 switch (Intr) {
2514 default:
2515 return SDValue();
2516 case Intrinsic::mips_extp:
2517 return lowerDSPIntr(Op, DAG, MipsISD::EXTP);
2518 case Intrinsic::mips_extpdp:
2519 return lowerDSPIntr(Op, DAG, MipsISD::EXTPDP);
2520 case Intrinsic::mips_extr_w:
2521 return lowerDSPIntr(Op, DAG, MipsISD::EXTR_W);
2522 case Intrinsic::mips_extr_r_w:
2523 return lowerDSPIntr(Op, DAG, MipsISD::EXTR_R_W);
2524 case Intrinsic::mips_extr_rs_w:
2525 return lowerDSPIntr(Op, DAG, MipsISD::EXTR_RS_W);
2526 case Intrinsic::mips_extr_s_h:
2527 return lowerDSPIntr(Op, DAG, MipsISD::EXTR_S_H);
2528 case Intrinsic::mips_mthlip:
2529 return lowerDSPIntr(Op, DAG, MipsISD::MTHLIP);
2530 case Intrinsic::mips_mulsaq_s_w_ph:
2531 return lowerDSPIntr(Op, DAG, MipsISD::MULSAQ_S_W_PH);
2532 case Intrinsic::mips_maq_s_w_phl:
2533 return lowerDSPIntr(Op, DAG, MipsISD::MAQ_S_W_PHL);
2534 case Intrinsic::mips_maq_s_w_phr:
2535 return lowerDSPIntr(Op, DAG, MipsISD::MAQ_S_W_PHR);
2536 case Intrinsic::mips_maq_sa_w_phl:
2537 return lowerDSPIntr(Op, DAG, MipsISD::MAQ_SA_W_PHL);
2538 case Intrinsic::mips_maq_sa_w_phr:
2539 return lowerDSPIntr(Op, DAG, MipsISD::MAQ_SA_W_PHR);
2540 case Intrinsic::mips_dpaq_s_w_ph:
2541 return lowerDSPIntr(Op, DAG, MipsISD::DPAQ_S_W_PH);
2542 case Intrinsic::mips_dpsq_s_w_ph:
2543 return lowerDSPIntr(Op, DAG, MipsISD::DPSQ_S_W_PH);
2544 case Intrinsic::mips_dpaq_sa_l_w:
2545 return lowerDSPIntr(Op, DAG, MipsISD::DPAQ_SA_L_W);
2546 case Intrinsic::mips_dpsq_sa_l_w:
2547 return lowerDSPIntr(Op, DAG, MipsISD::DPSQ_SA_L_W);
2548 case Intrinsic::mips_dpaqx_s_w_ph:
2549 return lowerDSPIntr(Op, DAG, MipsISD::DPAQX_S_W_PH);
2550 case Intrinsic::mips_dpaqx_sa_w_ph:
2551 return lowerDSPIntr(Op, DAG, MipsISD::DPAQX_SA_W_PH);
2552 case Intrinsic::mips_dpsqx_s_w_ph:
2553 return lowerDSPIntr(Op, DAG, MipsISD::DPSQX_S_W_PH);
2554 case Intrinsic::mips_dpsqx_sa_w_ph:
2555 return lowerDSPIntr(Op, DAG, MipsISD::DPSQX_SA_W_PH);
2556 case Intrinsic::mips_ld_b:
2557 case Intrinsic::mips_ld_h:
2558 case Intrinsic::mips_ld_w:
2559 case Intrinsic::mips_ld_d:
2560 return lowerMSALoadIntr(Op, DAG, Intr, Subtarget);
2561 }
2562}
2563
2565 const MipsSubtarget &Subtarget) {
2566 SDLoc DL(Op);
2567 SDValue ChainIn = Op->getOperand(0);
2568 SDValue Value = Op->getOperand(2);
2569 SDValue Address = Op->getOperand(3);
2570 SDValue Offset = Op->getOperand(4);
2571 EVT PtrTy = Address->getValueType(0);
2572
2573 // For N64 addresses have the underlying type MVT::i64. This intrinsic
2574 // however takes an i32 signed constant offset. The actual type of the
2575 // intrinsic is a scaled signed i10.
2576 if (Subtarget.isABI_N64())
2577 Offset = DAG.getNode(ISD::SIGN_EXTEND, DL, PtrTy, Offset);
2578
2579 Address = DAG.getNode(ISD::ADD, DL, PtrTy, Address, Offset);
2580
2581 return DAG.getStore(ChainIn, DL, Value, Address, MachinePointerInfo(),
2582 Align(16));
2583}
2584
2585SDValue MipsSETargetLowering::lowerINTRINSIC_VOID(SDValue Op,
2586 SelectionDAG &DAG) const {
2587 unsigned Intr = Op->getConstantOperandVal(1);
2588 switch (Intr) {
2589 default:
2590 return SDValue();
2591 case Intrinsic::mips_st_b:
2592 case Intrinsic::mips_st_h:
2593 case Intrinsic::mips_st_w:
2594 case Intrinsic::mips_st_d:
2595 return lowerMSAStoreIntr(Op, DAG, Intr, Subtarget);
2596 }
2597}
2598
2599// Lower ISD::EXTRACT_VECTOR_ELT into MipsISD::VEXTRACT_SEXT_ELT.
2600//
2601// The non-value bits resulting from ISD::EXTRACT_VECTOR_ELT are undefined. We
2602// choose to sign-extend but we could have equally chosen zero-extend. The
2603// DAGCombiner will fold any sign/zero extension of the ISD::EXTRACT_VECTOR_ELT
2604// result into this node later (possibly changing it to a zero-extend in the
2605// process).
2606SDValue MipsSETargetLowering::
2607lowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const {
2608 SDLoc DL(Op);
2609 EVT ResTy = Op->getValueType(0);
2610 SDValue Op0 = Op->getOperand(0);
2611 EVT VecTy = Op0->getValueType(0);
2612
2613 if (!VecTy.is128BitVector())
2614 return SDValue();
2615
2616 if (ResTy.isInteger()) {
2617 SDValue Op1 = Op->getOperand(1);
2618 EVT EltTy = VecTy.getVectorElementType();
2619 return DAG.getNode(MipsISD::VEXTRACT_SEXT_ELT, DL, ResTy, Op0, Op1,
2620 DAG.getValueType(EltTy));
2621 }
2622
2623 return Op;
2624}
2625
2626static bool isConstantOrUndef(const SDValue Op) {
2627 if (Op->isUndef())
2628 return true;
2630 return true;
2632 return true;
2633 return false;
2634}
2635
2637 for (unsigned i = 0; i < Op->getNumOperands(); ++i)
2638 if (isConstantOrUndef(Op->getOperand(i)))
2639 return true;
2640 return false;
2641}
2642
2643// Lowers ISD::BUILD_VECTOR into appropriate SelectionDAG nodes for the
2644// backend.
2645//
2646// Lowers according to the following rules:
2647// - Constant splats are legal as-is as long as the SplatBitSize is a power of
2648// 2 less than or equal to 64 and the value fits into a signed 10-bit
2649// immediate
2650// - Constant splats are lowered to bitconverted BUILD_VECTORs if SplatBitSize
2651// is a power of 2 less than or equal to 64 and the value does not fit into a
2652// signed 10-bit immediate
2653// - Non-constant splats are legal as-is.
2654// - Non-constant non-splats are lowered to sequences of INSERT_VECTOR_ELT.
2655// - All others are illegal and must be expanded.
2656SDValue MipsSETargetLowering::lowerBUILD_VECTOR(SDValue Op,
2657 SelectionDAG &DAG) const {
2658 BuildVectorSDNode *Node = cast<BuildVectorSDNode>(Op);
2659 EVT ResTy = Op->getValueType(0);
2660 SDLoc DL(Op);
2661 APInt SplatValue, SplatUndef;
2662 unsigned SplatBitSize;
2663 bool HasAnyUndefs;
2664
2665 if (!Subtarget.hasMSA() || !ResTy.is128BitVector())
2666 return SDValue();
2667
2668 if (Node->isConstantSplat(SplatValue, SplatUndef, SplatBitSize,
2669 HasAnyUndefs, 8,
2670 !Subtarget.isLittle()) && SplatBitSize <= 64) {
2671 // We can only cope with 8, 16, 32, or 64-bit elements
2672 if (SplatBitSize != 8 && SplatBitSize != 16 && SplatBitSize != 32 &&
2673 SplatBitSize != 64)
2674 return SDValue();
2675
2676 // If the value isn't an integer type we will have to bitcast
2677 // from an integer type first. Also, if there are any undefs, we must
2678 // lower them to defined values first.
2679 if (ResTy.isInteger() && !HasAnyUndefs)
2680 return Op;
2681
2682 EVT ViaVecTy;
2683
2684 switch (SplatBitSize) {
2685 default:
2686 return SDValue();
2687 case 8:
2688 ViaVecTy = MVT::v16i8;
2689 break;
2690 case 16:
2691 ViaVecTy = MVT::v8i16;
2692 break;
2693 case 32:
2694 ViaVecTy = MVT::v4i32;
2695 break;
2696 case 64:
2697 // There's no fill.d to fall back on for 64-bit values
2698 return SDValue();
2699 }
2700
2701 // SelectionDAG::getConstant will promote SplatValue appropriately.
2702 SDValue Result = DAG.getConstant(SplatValue, DL, ViaVecTy);
2703
2704 // Bitcast to the type we originally wanted
2705 if (ViaVecTy != ResTy)
2706 Result = DAG.getNode(ISD::BITCAST, SDLoc(Node), ResTy, Result);
2707
2708 return Result;
2709 } else if (DAG.isSplatValue(Op, /* AllowUndefs */ false))
2710 return Op;
2711 else if (!isConstantOrUndefBUILD_VECTOR(Node)) {
2712 // Use INSERT_VECTOR_ELT operations rather than expand to stores.
2713 // The resulting code is the same length as the expansion, but it doesn't
2714 // use memory operations
2715 EVT ResTy = Node->getValueType(0);
2716
2717 assert(ResTy.isVector());
2718
2719 unsigned NumElts = ResTy.getVectorNumElements();
2720 SDValue Vector = DAG.getUNDEF(ResTy);
2721 for (unsigned i = 0; i < NumElts; ++i) {
2723 Node->getOperand(i),
2724 DAG.getConstant(i, DL, MVT::i32));
2725 }
2726 return Vector;
2727 }
2728
2729 return SDValue();
2730}
2731
2732// Lower VECTOR_SHUFFLE into SHF (if possible).
2733//
2734// SHF splits the vector into blocks of four elements, then shuffles these
2735// elements according to a <4 x i2> constant (encoded as an integer immediate).
2736//
2737// It is therefore possible to lower into SHF when the mask takes the form:
2738// <a, b, c, d, a+4, b+4, c+4, d+4, a+8, b+8, c+8, d+8, ...>
2739// When undef's appear they are treated as if they were whatever value is
2740// necessary in order to fit the above forms.
2741//
2742// For example:
2743// %2 = shufflevector <8 x i16> %0, <8 x i16> undef,
2744// <8 x i32> <i32 3, i32 2, i32 1, i32 0,
2745// i32 7, i32 6, i32 5, i32 4>
2746// is lowered to:
2747// (SHF_H $w0, $w1, 27)
2748// where the 27 comes from:
2749// 3 + (2 << 2) + (1 << 4) + (0 << 6)
2751 SmallVector<int, 16> Indices,
2752 SelectionDAG &DAG) {
2753 int SHFIndices[4] = { -1, -1, -1, -1 };
2754
2755 if (Indices.size() < 4)
2756 return SDValue();
2757
2758 for (unsigned i = 0; i < 4; ++i) {
2759 for (unsigned j = i; j < Indices.size(); j += 4) {
2760 int Idx = Indices[j];
2761
2762 // Convert from vector index to 4-element subvector index
2763 // If an index refers to an element outside of the subvector then give up
2764 if (Idx != -1) {
2765 Idx -= 4 * (j / 4);
2766 if (Idx < 0 || Idx >= 4)
2767 return SDValue();
2768 }
2769
2770 // If the mask has an undef, replace it with the current index.
2771 // Note that it might still be undef if the current index is also undef
2772 if (SHFIndices[i] == -1)
2773 SHFIndices[i] = Idx;
2774
2775 // Check that non-undef values are the same as in the mask. If they
2776 // aren't then give up
2777 if (!(Idx == -1 || Idx == SHFIndices[i]))
2778 return SDValue();
2779 }
2780 }
2781
2782 // Calculate the immediate. Replace any remaining undefs with zero
2783 APInt Imm(32, 0);
2784 for (int i = 3; i >= 0; --i) {
2785 int Idx = SHFIndices[i];
2786
2787 if (Idx == -1)
2788 Idx = 0;
2789
2790 Imm <<= 2;
2791 Imm |= Idx & 0x3;
2792 }
2793
2794 SDLoc DL(Op);
2795 return DAG.getNode(MipsISD::SHF, DL, ResTy,
2796 DAG.getTargetConstant(Imm, DL, MVT::i32),
2797 Op->getOperand(0));
2798}
2799
2800/// Determine whether a range fits a regular pattern of values.
2801/// This function accounts for the possibility of jumping over the End iterator.
2802template <typename ValType>
2803static bool
2805 unsigned CheckStride,
2807 ValType ExpectedIndex, unsigned ExpectedIndexStride) {
2808 auto &I = Begin;
2809
2810 while (I != End) {
2811 if (*I != -1 && *I != ExpectedIndex)
2812 return false;
2813 ExpectedIndex += ExpectedIndexStride;
2814
2815 // Incrementing past End is undefined behaviour so we must increment one
2816 // step at a time and check for End at each step.
2817 for (unsigned n = 0; n < CheckStride && I != End; ++n, ++I)
2818 ; // Empty loop body.
2819 }
2820 return true;
2821}
2822
2823// Determine whether VECTOR_SHUFFLE is a SPLATI.
2824//
2825// It is a SPLATI when the mask is:
2826// <x, x, x, ...>
2827// where x is any valid index.
2828//
2829// When undef's appear in the mask they are treated as if they were whatever
2830// value is necessary in order to fit the above form.
2832 SmallVector<int, 16> Indices,
2833 SelectionDAG &DAG) {
2834 assert((Indices.size() % 2) == 0);
2835
2836 int SplatIndex = -1;
2837 for (const auto &V : Indices) {
2838 if (V != -1) {
2839 SplatIndex = V;
2840 break;
2841 }
2842 }
2843
2844 return fitsRegularPattern<int>(Indices.begin(), 1, Indices.end(), SplatIndex,
2845 0);
2846}
2847
2848// Lower VECTOR_SHUFFLE into ILVEV (if possible).
2849//
2850// ILVEV interleaves the even elements from each vector.
2851//
2852// It is possible to lower into ILVEV when the mask consists of two of the
2853// following forms interleaved:
2854// <0, 2, 4, ...>
2855// <n, n+2, n+4, ...>
2856// where n is the number of elements in the vector.
2857// For example:
2858// <0, 0, 2, 2, 4, 4, ...>
2859// <0, n, 2, n+2, 4, n+4, ...>
2860//
2861// When undef's appear in the mask they are treated as if they were whatever
2862// value is necessary in order to fit the above forms.
2864 SmallVector<int, 16> Indices,
2865 SelectionDAG &DAG) {
2866 assert((Indices.size() % 2) == 0);
2867
2868 SDValue Wt;
2869 SDValue Ws;
2870 const auto &Begin = Indices.begin();
2871 const auto &End = Indices.end();
2872
2873 // Check even elements are taken from the even elements of one half or the
2874 // other and pick an operand accordingly.
2875 if (fitsRegularPattern<int>(Begin, 2, End, 0, 2))
2876 Wt = Op->getOperand(0);
2877 else if (fitsRegularPattern<int>(Begin, 2, End, Indices.size(), 2))
2878 Wt = Op->getOperand(1);
2879 else
2880 return SDValue();
2881
2882 // Check odd elements are taken from the even elements of one half or the
2883 // other and pick an operand accordingly.
2884 if (fitsRegularPattern<int>(Begin + 1, 2, End, 0, 2))
2885 Ws = Op->getOperand(0);
2886 else if (fitsRegularPattern<int>(Begin + 1, 2, End, Indices.size(), 2))
2887 Ws = Op->getOperand(1);
2888 else
2889 return SDValue();
2890
2891 return DAG.getNode(MipsISD::ILVEV, SDLoc(Op), ResTy, Ws, Wt);
2892}
2893
2894// Lower VECTOR_SHUFFLE into ILVOD (if possible).
2895//
2896// ILVOD interleaves the odd elements from each vector.
2897//
2898// It is possible to lower into ILVOD when the mask consists of two of the
2899// following forms interleaved:
2900// <1, 3, 5, ...>
2901// <n+1, n+3, n+5, ...>
2902// where n is the number of elements in the vector.
2903// For example:
2904// <1, 1, 3, 3, 5, 5, ...>
2905// <1, n+1, 3, n+3, 5, n+5, ...>
2906//
2907// When undef's appear in the mask they are treated as if they were whatever
2908// value is necessary in order to fit the above forms.
2910 SmallVector<int, 16> Indices,
2911 SelectionDAG &DAG) {
2912 assert((Indices.size() % 2) == 0);
2913
2914 SDValue Wt;
2915 SDValue Ws;
2916 const auto &Begin = Indices.begin();
2917 const auto &End = Indices.end();
2918
2919 // Check even elements are taken from the odd elements of one half or the
2920 // other and pick an operand accordingly.
2921 if (fitsRegularPattern<int>(Begin, 2, End, 1, 2))
2922 Wt = Op->getOperand(0);
2923 else if (fitsRegularPattern<int>(Begin, 2, End, Indices.size() + 1, 2))
2924 Wt = Op->getOperand(1);
2925 else
2926 return SDValue();
2927
2928 // Check odd elements are taken from the odd elements of one half or the
2929 // other and pick an operand accordingly.
2930 if (fitsRegularPattern<int>(Begin + 1, 2, End, 1, 2))
2931 Ws = Op->getOperand(0);
2932 else if (fitsRegularPattern<int>(Begin + 1, 2, End, Indices.size() + 1, 2))
2933 Ws = Op->getOperand(1);
2934 else
2935 return SDValue();
2936
2937 return DAG.getNode(MipsISD::ILVOD, SDLoc(Op), ResTy, Ws, Wt);
2938}
2939
2940// Lower VECTOR_SHUFFLE into ILVR (if possible).
2941//
2942// ILVR interleaves consecutive elements from the right (lowest-indexed) half of
2943// each vector.
2944//
2945// It is possible to lower into ILVR when the mask consists of two of the
2946// following forms interleaved:
2947// <0, 1, 2, ...>
2948// <n, n+1, n+2, ...>
2949// where n is the number of elements in the vector.
2950// For example:
2951// <0, 0, 1, 1, 2, 2, ...>
2952// <0, n, 1, n+1, 2, n+2, ...>
2953//
2954// When undef's appear in the mask they are treated as if they were whatever
2955// value is necessary in order to fit the above forms.
2957 SmallVector<int, 16> Indices,
2958 SelectionDAG &DAG) {
2959 assert((Indices.size() % 2) == 0);
2960
2961 SDValue Wt;
2962 SDValue Ws;
2963 const auto &Begin = Indices.begin();
2964 const auto &End = Indices.end();
2965
2966 // Check even elements are taken from the right (lowest-indexed) elements of
2967 // one half or the other and pick an operand accordingly.
2968 if (fitsRegularPattern<int>(Begin, 2, End, 0, 1))
2969 Wt = Op->getOperand(0);
2970 else if (fitsRegularPattern<int>(Begin, 2, End, Indices.size(), 1))
2971 Wt = Op->getOperand(1);
2972 else
2973 return SDValue();
2974
2975 // Check odd elements are taken from the right (lowest-indexed) elements of
2976 // one half or the other and pick an operand accordingly.
2977 if (fitsRegularPattern<int>(Begin + 1, 2, End, 0, 1))
2978 Ws = Op->getOperand(0);
2979 else if (fitsRegularPattern<int>(Begin + 1, 2, End, Indices.size(), 1))
2980 Ws = Op->getOperand(1);
2981 else
2982 return SDValue();
2983
2984 return DAG.getNode(MipsISD::ILVR, SDLoc(Op), ResTy, Ws, Wt);
2985}
2986
2987// Lower VECTOR_SHUFFLE into ILVL (if possible).
2988//
2989// ILVL interleaves consecutive elements from the left (highest-indexed) half
2990// of each vector.
2991//
2992// It is possible to lower into ILVL when the mask consists of two of the
2993// following forms interleaved:
2994// <x, x+1, x+2, ...>
2995// <n+x, n+x+1, n+x+2, ...>
2996// where n is the number of elements in the vector and x is half n.
2997// For example:
2998// <x, x, x+1, x+1, x+2, x+2, ...>
2999// <x, n+x, x+1, n+x+1, x+2, n+x+2, ...>
3000//
3001// When undef's appear in the mask they are treated as if they were whatever
3002// value is necessary in order to fit the above forms.
3004 SmallVector<int, 16> Indices,
3005 SelectionDAG &DAG) {
3006 assert((Indices.size() % 2) == 0);
3007
3008 unsigned HalfSize = Indices.size() / 2;
3009 SDValue Wt;
3010 SDValue Ws;
3011 const auto &Begin = Indices.begin();
3012 const auto &End = Indices.end();
3013
3014 // Check even elements are taken from the left (highest-indexed) elements of
3015 // one half or the other and pick an operand accordingly.
3016 if (fitsRegularPattern<int>(Begin, 2, End, HalfSize, 1))
3017 Wt = Op->getOperand(0);
3018 else if (fitsRegularPattern<int>(Begin, 2, End, Indices.size() + HalfSize, 1))
3019 Wt = Op->getOperand(1);
3020 else
3021 return SDValue();
3022
3023 // Check odd elements are taken from the left (highest-indexed) elements of
3024 // one half or the other and pick an operand accordingly.
3025 if (fitsRegularPattern<int>(Begin + 1, 2, End, HalfSize, 1))
3026 Ws = Op->getOperand(0);
3027 else if (fitsRegularPattern<int>(Begin + 1, 2, End, Indices.size() + HalfSize,
3028 1))
3029 Ws = Op->getOperand(1);
3030 else
3031 return SDValue();
3032
3033 return DAG.getNode(MipsISD::ILVL, SDLoc(Op), ResTy, Ws, Wt);
3034}
3035
3036// Lower VECTOR_SHUFFLE into PCKEV (if possible).
3037//
3038// PCKEV copies the even elements of each vector into the result vector.
3039//
3040// It is possible to lower into PCKEV when the mask consists of two of the
3041// following forms concatenated:
3042// <0, 2, 4, ...>
3043// <n, n+2, n+4, ...>
3044// where n is the number of elements in the vector.
3045// For example:
3046// <0, 2, 4, ..., 0, 2, 4, ...>
3047// <0, 2, 4, ..., n, n+2, n+4, ...>
3048//
3049// When undef's appear in the mask they are treated as if they were whatever
3050// value is necessary in order to fit the above forms.
3052 SmallVector<int, 16> Indices,
3053 SelectionDAG &DAG) {
3054 assert((Indices.size() % 2) == 0);
3055
3056 SDValue Wt;
3057 SDValue Ws;
3058 const auto &Begin = Indices.begin();
3059 const auto &Mid = Indices.begin() + Indices.size() / 2;
3060 const auto &End = Indices.end();
3061
3062 if (fitsRegularPattern<int>(Begin, 1, Mid, 0, 2))
3063 Wt = Op->getOperand(0);
3064 else if (fitsRegularPattern<int>(Begin, 1, Mid, Indices.size(), 2))
3065 Wt = Op->getOperand(1);
3066 else
3067 return SDValue();
3068
3069 if (fitsRegularPattern<int>(Mid, 1, End, 0, 2))
3070 Ws = Op->getOperand(0);
3071 else if (fitsRegularPattern<int>(Mid, 1, End, Indices.size(), 2))
3072 Ws = Op->getOperand(1);
3073 else
3074 return SDValue();
3075
3076 return DAG.getNode(MipsISD::PCKEV, SDLoc(Op), ResTy, Ws, Wt);
3077}
3078
3079// Lower VECTOR_SHUFFLE into PCKOD (if possible).
3080//
3081// PCKOD copies the odd elements of each vector into the result vector.
3082//
3083// It is possible to lower into PCKOD when the mask consists of two of the
3084// following forms concatenated:
3085// <1, 3, 5, ...>
3086// <n+1, n+3, n+5, ...>
3087// where n is the number of elements in the vector.
3088// For example:
3089// <1, 3, 5, ..., 1, 3, 5, ...>
3090// <1, 3, 5, ..., n+1, n+3, n+5, ...>
3091//
3092// When undef's appear in the mask they are treated as if they were whatever
3093// value is necessary in order to fit the above forms.
3095 SmallVector<int, 16> Indices,
3096 SelectionDAG &DAG) {
3097 assert((Indices.size() % 2) == 0);
3098
3099 SDValue Wt;
3100 SDValue Ws;
3101 const auto &Begin = Indices.begin();
3102 const auto &Mid = Indices.begin() + Indices.size() / 2;
3103 const auto &End = Indices.end();
3104
3105 if (fitsRegularPattern<int>(Begin, 1, Mid, 1, 2))
3106 Wt = Op->getOperand(0);
3107 else if (fitsRegularPattern<int>(Begin, 1, Mid, Indices.size() + 1, 2))
3108 Wt = Op->getOperand(1);
3109 else
3110 return SDValue();
3111
3112 if (fitsRegularPattern<int>(Mid, 1, End, 1, 2))
3113 Ws = Op->getOperand(0);
3114 else if (fitsRegularPattern<int>(Mid, 1, End, Indices.size() + 1, 2))
3115 Ws = Op->getOperand(1);
3116 else
3117 return SDValue();
3118
3119 return DAG.getNode(MipsISD::PCKOD, SDLoc(Op), ResTy, Ws, Wt);
3120}
3121
3122// Lower VECTOR_SHUFFLE into VSHF.
3123//
3124// This mostly consists of converting the shuffle indices in Indices into a
3125// BUILD_VECTOR and adding it as an operand to the resulting VSHF. There is
3126// also code to eliminate unused operands of the VECTOR_SHUFFLE. For example,
3127// if the type is v8i16 and all the indices are less than 8 then the second
3128// operand is unused and can be replaced with anything. We choose to replace it
3129// with the used operand since this reduces the number of instructions overall.
3130//
3131// NOTE: SPLATI shuffle masks may contain UNDEFs, since isSPLATI() treats
3132// UNDEFs as same as SPLATI index.
3133// For other instances we use the last valid index if UNDEF is
3134// encountered.
3136 const SmallVector<int, 16> &Indices,
3137 const bool isSPLATI,
3138 SelectionDAG &DAG) {
3140 SDValue Op0;
3141 SDValue Op1;
3142 EVT MaskVecTy = ResTy.changeVectorElementTypeToInteger();
3143 EVT MaskEltTy = MaskVecTy.getVectorElementType();
3144 bool Using1stVec = false;
3145 bool Using2ndVec = false;
3146 SDLoc DL(Op);
3147 int ResTyNumElts = ResTy.getVectorNumElements();
3148
3149 for (int i = 0; i < ResTyNumElts; ++i) {
3150 // Idx == -1 means UNDEF/poison
3151 int Idx = Indices[i];
3152
3153 if (0 <= Idx && Idx < ResTyNumElts)
3154 Using1stVec = true;
3155 if (ResTyNumElts <= Idx && Idx < ResTyNumElts * 2)
3156 Using2ndVec = true;
3157 }
3158
3159 // Find the first non-undef index. This index is used as a default when there
3160 // is a leading UNDEF/poison.
3161 int SplatIndex = 0;
3162 for (int Idx : Indices)
3163 if (Idx >= 0) {
3164 SplatIndex = Idx;
3165 break;
3166 }
3167
3168 int LastValidIndex = SplatIndex;
3169 for (size_t i = 0; i < Indices.size(); i++) {
3170 int Idx = Indices[i];
3171 if (Idx < 0) {
3172 // Continue using splati index or use the last valid index.
3173 Idx = isSPLATI ? SplatIndex : LastValidIndex;
3174 } else {
3175 LastValidIndex = Idx;
3176 }
3177 Ops.push_back(DAG.getTargetConstant(Idx, DL, MaskEltTy));
3178 }
3179
3180 SDValue MaskVec = DAG.getBuildVector(MaskVecTy, DL, Ops);
3181
3182 if (Using1stVec && Using2ndVec) {
3183 Op0 = Op->getOperand(0);
3184 Op1 = Op->getOperand(1);
3185 } else if (Using1stVec)
3186 Op0 = Op1 = Op->getOperand(0);
3187 else if (Using2ndVec)
3188 Op0 = Op1 = Op->getOperand(1);
3189 else
3190 llvm_unreachable("shuffle vector mask references neither vector operand?");
3191
3192 // VECTOR_SHUFFLE concatenates the vectors in an vectorwise fashion.
3193 // <0b00, 0b01> + <0b10, 0b11> -> <0b00, 0b01, 0b10, 0b11>
3194 // VSHF concatenates the vectors in a bitwise fashion:
3195 // <0b00, 0b01> + <0b10, 0b11> ->
3196 // 0b0100 + 0b1110 -> 0b01001110
3197 // <0b10, 0b11, 0b00, 0b01>
3198 // We must therefore swap the operands to get the correct result.
3199 return DAG.getNode(MipsISD::VSHF, DL, ResTy, MaskVec, Op1, Op0);
3200}
3201
3202// Lower VECTOR_SHUFFLE into one of a number of instructions depending on the
3203// indices in the shuffle.
3204SDValue MipsSETargetLowering::lowerVECTOR_SHUFFLE(SDValue Op,
3205 SelectionDAG &DAG) const {
3206 ShuffleVectorSDNode *Node = cast<ShuffleVectorSDNode>(Op);
3207 EVT ResTy = Op->getValueType(0);
3208
3209 if (!ResTy.is128BitVector())
3210 return SDValue();
3211
3212 int ResTyNumElts = ResTy.getVectorNumElements();
3213 SmallVector<int, 16> Indices;
3214
3215 for (int i = 0; i < ResTyNumElts; ++i)
3216 Indices.push_back(Node->getMaskElt(i));
3217
3218 // splati.[bhwd] is preferable to the others but is matched from
3219 // MipsISD::VSHF.
3220 if (isVECTOR_SHUFFLE_SPLATI(Op, ResTy, Indices, DAG))
3221 return lowerVECTOR_SHUFFLE_VSHF(Op, ResTy, Indices, true, DAG);
3222 SDValue Result;
3223 if ((Result = lowerVECTOR_SHUFFLE_ILVEV(Op, ResTy, Indices, DAG)))
3224 return Result;
3225 if ((Result = lowerVECTOR_SHUFFLE_ILVOD(Op, ResTy, Indices, DAG)))
3226 return Result;
3227 if ((Result = lowerVECTOR_SHUFFLE_ILVL(Op, ResTy, Indices, DAG)))
3228 return Result;
3229 if ((Result = lowerVECTOR_SHUFFLE_ILVR(Op, ResTy, Indices, DAG)))
3230 return Result;
3231 if ((Result = lowerVECTOR_SHUFFLE_PCKEV(Op, ResTy, Indices, DAG)))
3232 return Result;
3233 if ((Result = lowerVECTOR_SHUFFLE_PCKOD(Op, ResTy, Indices, DAG)))
3234 return Result;
3235 if ((Result = lowerVECTOR_SHUFFLE_SHF(Op, ResTy, Indices, DAG)))
3236 return Result;
3237 return lowerVECTOR_SHUFFLE_VSHF(Op, ResTy, Indices, false, DAG);
3238}
3239
3241MipsSETargetLowering::emitBPOSGE32(MachineInstr &MI,
3242 MachineBasicBlock *BB) const {
3243 // $bb:
3244 // bposge32_pseudo $vr0
3245 // =>
3246 // $bb:
3247 // bposge32 $tbb
3248 // $fbb:
3249 // li $vr2, 0
3250 // b $sink
3251 // $tbb:
3252 // li $vr1, 1
3253 // $sink:
3254 // $vr0 = phi($vr2, $fbb, $vr1, $tbb)
3255
3256 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3257 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3258 const TargetRegisterClass *RC = &Mips::GPR32RegClass;
3259 DebugLoc DL = MI.getDebugLoc();
3260 const BasicBlock *LLVM_BB = BB->getBasicBlock();
3262 MachineFunction *F = BB->getParent();
3263 MachineBasicBlock *FBB = F->CreateMachineBasicBlock(LLVM_BB);
3264 MachineBasicBlock *TBB = F->CreateMachineBasicBlock(LLVM_BB);
3265 MachineBasicBlock *Sink = F->CreateMachineBasicBlock(LLVM_BB);
3266 F->insert(It, FBB);
3267 F->insert(It, TBB);
3268 F->insert(It, Sink);
3269
3270 // Transfer the remainder of BB and its successor edges to Sink.
3271 Sink->splice(Sink->begin(), BB, std::next(MachineBasicBlock::iterator(MI)),
3272 BB->end());
3274
3275 // Add successors.
3276 BB->addSuccessor(FBB);
3277 BB->addSuccessor(TBB);
3278 FBB->addSuccessor(Sink);
3279 TBB->addSuccessor(Sink);
3280
3281 // Insert the real bposge32 instruction to $BB.
3282 BuildMI(BB, DL, TII->get(Mips::BPOSGE32)).addMBB(TBB);
3283 // Insert the real bposge32c instruction to $BB.
3284 BuildMI(BB, DL, TII->get(Mips::BPOSGE32C_MMR3)).addMBB(TBB);
3285
3286 // Fill $FBB.
3287 Register VR2 = RegInfo.createVirtualRegister(RC);
3288 BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::ADDiu), VR2)
3289 .addReg(Mips::ZERO).addImm(0);
3290 BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::B)).addMBB(Sink);
3291
3292 // Fill $TBB.
3293 Register VR1 = RegInfo.createVirtualRegister(RC);
3294 BuildMI(*TBB, TBB->end(), DL, TII->get(Mips::ADDiu), VR1)
3295 .addReg(Mips::ZERO).addImm(1);
3296
3297 // Insert phi function to $Sink.
3298 BuildMI(*Sink, Sink->begin(), DL, TII->get(Mips::PHI),
3299 MI.getOperand(0).getReg())
3300 .addReg(VR2)
3301 .addMBB(FBB)
3302 .addReg(VR1)
3303 .addMBB(TBB);
3304
3305 MI.eraseFromParent(); // The pseudo instruction is gone now.
3306 return Sink;
3307}
3308
3309MachineBasicBlock *MipsSETargetLowering::emitMSACBranchPseudo(
3310 MachineInstr &MI, MachineBasicBlock *BB, unsigned BranchOp) const {
3311 // $bb:
3312 // vany_nonzero $rd, $ws
3313 // =>
3314 // $bb:
3315 // bnz.b $ws, $tbb
3316 // b $fbb
3317 // $fbb:
3318 // li $rd1, 0
3319 // b $sink
3320 // $tbb:
3321 // li $rd2, 1
3322 // $sink:
3323 // $rd = phi($rd1, $fbb, $rd2, $tbb)
3324
3325 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3326 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3327 const TargetRegisterClass *RC = &Mips::GPR32RegClass;
3328 DebugLoc DL = MI.getDebugLoc();
3329 const BasicBlock *LLVM_BB = BB->getBasicBlock();
3331 MachineFunction *F = BB->getParent();
3332 MachineBasicBlock *FBB = F->CreateMachineBasicBlock(LLVM_BB);
3333 MachineBasicBlock *TBB = F->CreateMachineBasicBlock(LLVM_BB);
3334 MachineBasicBlock *Sink = F->CreateMachineBasicBlock(LLVM_BB);
3335 F->insert(It, FBB);
3336 F->insert(It, TBB);
3337 F->insert(It, Sink);
3338
3339 // Transfer the remainder of BB and its successor edges to Sink.
3340 Sink->splice(Sink->begin(), BB, std::next(MachineBasicBlock::iterator(MI)),
3341 BB->end());
3343
3344 // Add successors.
3345 BB->addSuccessor(FBB);
3346 BB->addSuccessor(TBB);
3347 FBB->addSuccessor(Sink);
3348 TBB->addSuccessor(Sink);
3349
3350 // Insert the real bnz.b instruction to $BB.
3351 BuildMI(BB, DL, TII->get(BranchOp))
3352 .addReg(MI.getOperand(1).getReg())
3353 .addMBB(TBB);
3354
3355 // Fill $FBB.
3356 Register RD1 = RegInfo.createVirtualRegister(RC);
3357 BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::ADDiu), RD1)
3358 .addReg(Mips::ZERO).addImm(0);
3359 BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::B)).addMBB(Sink);
3360
3361 // Fill $TBB.
3362 Register RD2 = RegInfo.createVirtualRegister(RC);
3363 BuildMI(*TBB, TBB->end(), DL, TII->get(Mips::ADDiu), RD2)
3364 .addReg(Mips::ZERO).addImm(1);
3365
3366 // Insert phi function to $Sink.
3367 BuildMI(*Sink, Sink->begin(), DL, TII->get(Mips::PHI),
3368 MI.getOperand(0).getReg())
3369 .addReg(RD1)
3370 .addMBB(FBB)
3371 .addReg(RD2)
3372 .addMBB(TBB);
3373
3374 MI.eraseFromParent(); // The pseudo instruction is gone now.
3375 return Sink;
3376}
3377
3378// Emit the COPY_FW pseudo instruction.
3379//
3380// copy_fw_pseudo $fd, $ws, n
3381// =>
3382// copy_u_w $rt, $ws, $n
3383// mtc1 $rt, $fd
3384//
3385// When n is zero, the equivalent operation can be performed with (potentially)
3386// zero instructions due to register overlaps. This optimization is never valid
3387// for lane 1 because it would require FR=0 mode which isn't supported by MSA.
3389MipsSETargetLowering::emitCOPY_FW(MachineInstr &MI,
3390 MachineBasicBlock *BB) const {
3391 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3392 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3393 DebugLoc DL = MI.getDebugLoc();
3394 Register Fd = MI.getOperand(0).getReg();
3395 Register Ws = MI.getOperand(1).getReg();
3396 unsigned Lane = MI.getOperand(2).getImm();
3397
3398 if (Lane == 0) {
3399 unsigned Wt = Ws;
3400 if (!Subtarget.useOddSPReg()) {
3401 // We must copy to an even-numbered MSA register so that the
3402 // single-precision sub-register is also guaranteed to be even-numbered.
3403 Wt = RegInfo.createVirtualRegister(&Mips::MSA128WEvensRegClass);
3404
3405 BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Wt).addReg(Ws);
3406 }
3407
3408 BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Fd).addReg(Wt, {}, Mips::sub_lo);
3409 } else {
3410 Register Wt = RegInfo.createVirtualRegister(
3411 Subtarget.useOddSPReg() ? &Mips::MSA128WRegClass
3412 : &Mips::MSA128WEvensRegClass);
3413
3414 BuildMI(*BB, MI, DL, TII->get(Mips::SPLATI_W), Wt).addReg(Ws).addImm(Lane);
3415 BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Fd).addReg(Wt, {}, Mips::sub_lo);
3416 }
3417
3418 MI.eraseFromParent(); // The pseudo instruction is gone now.
3419 return BB;
3420}
3421
3422// Emit the COPY_FD pseudo instruction.
3423//
3424// copy_fd_pseudo $fd, $ws, n
3425// =>
3426// splati.d $wt, $ws, $n
3427// copy $fd, $wt:sub_64
3428//
3429// When n is zero, the equivalent operation can be performed with (potentially)
3430// zero instructions due to register overlaps. This optimization is always
3431// valid because FR=1 mode which is the only supported mode in MSA.
3433MipsSETargetLowering::emitCOPY_FD(MachineInstr &MI,
3434 MachineBasicBlock *BB) const {
3435 assert(Subtarget.isFP64bit());
3436
3437 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3438 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3439 Register Fd = MI.getOperand(0).getReg();
3440 Register Ws = MI.getOperand(1).getReg();
3441 unsigned Lane = MI.getOperand(2).getImm() * 2;
3442 DebugLoc DL = MI.getDebugLoc();
3443
3444 if (Lane == 0)
3445 BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Fd).addReg(Ws, {}, Mips::sub_64);
3446 else {
3447 Register Wt = RegInfo.createVirtualRegister(&Mips::MSA128DRegClass);
3448
3449 BuildMI(*BB, MI, DL, TII->get(Mips::SPLATI_D), Wt).addReg(Ws).addImm(1);
3450 BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Fd).addReg(Wt, {}, Mips::sub_64);
3451 }
3452
3453 MI.eraseFromParent(); // The pseudo instruction is gone now.
3454 return BB;
3455}
3456
3457// Emit the INSERT_FW pseudo instruction.
3458//
3459// insert_fw_pseudo $wd, $wd_in, $n, $fs
3460// =>
3461// subreg_to_reg $wt:sub_lo, $fs
3462// insve_w $wd[$n], $wd_in, $wt[0]
3464MipsSETargetLowering::emitINSERT_FW(MachineInstr &MI,
3465 MachineBasicBlock *BB) const {
3466 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3467 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3468 DebugLoc DL = MI.getDebugLoc();
3469 Register Wd = MI.getOperand(0).getReg();
3470 Register Wd_in = MI.getOperand(1).getReg();
3471 unsigned Lane = MI.getOperand(2).getImm();
3472 Register Fs = MI.getOperand(3).getReg();
3473 Register Wt = RegInfo.createVirtualRegister(
3474 Subtarget.useOddSPReg() ? &Mips::MSA128WRegClass
3475 : &Mips::MSA128WEvensRegClass);
3476
3477 BuildMI(*BB, MI, DL, TII->get(Mips::SUBREG_TO_REG), Wt)
3478 .addReg(Fs)
3479 .addImm(Mips::sub_lo);
3480 BuildMI(*BB, MI, DL, TII->get(Mips::INSVE_W), Wd)
3481 .addReg(Wd_in)
3482 .addImm(Lane)
3483 .addReg(Wt)
3484 .addImm(0);
3485
3486 MI.eraseFromParent(); // The pseudo instruction is gone now.
3487 return BB;
3488}
3489
3490// Emit the INSERT_FD pseudo instruction.
3491//
3492// insert_fd_pseudo $wd, $fs, n
3493// =>
3494// subreg_to_reg $wt:sub_64, $fs
3495// insve_d $wd[$n], $wd_in, $wt[0]
3497MipsSETargetLowering::emitINSERT_FD(MachineInstr &MI,
3498 MachineBasicBlock *BB) const {
3499 assert(Subtarget.isFP64bit());
3500
3501 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3502 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3503 DebugLoc DL = MI.getDebugLoc();
3504 Register Wd = MI.getOperand(0).getReg();
3505 Register Wd_in = MI.getOperand(1).getReg();
3506 unsigned Lane = MI.getOperand(2).getImm();
3507 Register Fs = MI.getOperand(3).getReg();
3508 Register Wt = RegInfo.createVirtualRegister(&Mips::MSA128DRegClass);
3509
3510 BuildMI(*BB, MI, DL, TII->get(Mips::SUBREG_TO_REG), Wt)
3511 .addReg(Fs)
3512 .addImm(Mips::sub_64);
3513 BuildMI(*BB, MI, DL, TII->get(Mips::INSVE_D), Wd)
3514 .addReg(Wd_in)
3515 .addImm(Lane)
3516 .addReg(Wt)
3517 .addImm(0);
3518
3519 MI.eraseFromParent(); // The pseudo instruction is gone now.
3520 return BB;
3521}
3522
3523// Emit the INSERT_([BHWD]|F[WD])_VIDX pseudo instruction.
3524//
3525// For integer:
3526// (INSERT_([BHWD]|F[WD])_PSEUDO $wd, $wd_in, $n, $rs)
3527// =>
3528// (SLL $lanetmp1, $lane, <log2size)
3529// (SLD_B $wdtmp1, $wd_in, $wd_in, $lanetmp1)
3530// (INSERT_[BHWD], $wdtmp2, $wdtmp1, 0, $rs)
3531// (NEG $lanetmp2, $lanetmp1)
3532// (SLD_B $wd, $wdtmp2, $wdtmp2, $lanetmp2)
3533//
3534// For floating point:
3535// (INSERT_([BHWD]|F[WD])_PSEUDO $wd, $wd_in, $n, $fs)
3536// =>
3537// (SUBREG_TO_REG $wt, $fs, <subreg>)
3538// (SLL $lanetmp1, $lane, <log2size)
3539// (SLD_B $wdtmp1, $wd_in, $wd_in, $lanetmp1)
3540// (INSVE_[WD], $wdtmp2, 0, $wdtmp1, 0)
3541// (NEG $lanetmp2, $lanetmp1)
3542// (SLD_B $wd, $wdtmp2, $wdtmp2, $lanetmp2)
3543MachineBasicBlock *MipsSETargetLowering::emitINSERT_DF_VIDX(
3544 MachineInstr &MI, MachineBasicBlock *BB, unsigned EltSizeInBytes,
3545 bool IsFP) const {
3546 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3547 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3548 DebugLoc DL = MI.getDebugLoc();
3549 Register Wd = MI.getOperand(0).getReg();
3550 Register SrcVecReg = MI.getOperand(1).getReg();
3551 Register LaneReg = MI.getOperand(2).getReg();
3552 Register SrcValReg = MI.getOperand(3).getReg();
3553
3554 const TargetRegisterClass *VecRC = nullptr;
3555 // FIXME: This should be true for N32 too.
3556 const TargetRegisterClass *GPRRC =
3557 Subtarget.isABI_N64() ? &Mips::GPR64RegClass : &Mips::GPR32RegClass;
3558 unsigned SubRegIdx = Subtarget.isABI_N64() ? Mips::sub_32 : 0;
3559 unsigned ShiftOp = Subtarget.isABI_N64() ? Mips::DSLL : Mips::SLL;
3560 unsigned EltLog2Size;
3561 unsigned InsertOp = 0;
3562 unsigned InsveOp = 0;
3563 switch (EltSizeInBytes) {
3564 default:
3565 llvm_unreachable("Unexpected size");
3566 case 1:
3567 EltLog2Size = 0;
3568 InsertOp = Mips::INSERT_B;
3569 InsveOp = Mips::INSVE_B;
3570 VecRC = &Mips::MSA128BRegClass;
3571 break;
3572 case 2:
3573 EltLog2Size = 1;
3574 InsertOp = Mips::INSERT_H;
3575 InsveOp = Mips::INSVE_H;
3576 VecRC = &Mips::MSA128HRegClass;
3577 break;
3578 case 4:
3579 EltLog2Size = 2;
3580 InsertOp = Mips::INSERT_W;
3581 InsveOp = Mips::INSVE_W;
3582 VecRC = &Mips::MSA128WRegClass;
3583 break;
3584 case 8:
3585 EltLog2Size = 3;
3586 InsertOp = Mips::INSERT_D;
3587 InsveOp = Mips::INSVE_D;
3588 VecRC = &Mips::MSA128DRegClass;
3589 break;
3590 }
3591
3592 if (IsFP) {
3593 Register Wt = RegInfo.createVirtualRegister(VecRC);
3594 BuildMI(*BB, MI, DL, TII->get(Mips::SUBREG_TO_REG), Wt)
3595 .addReg(SrcValReg)
3596 .addImm(EltSizeInBytes == 8 ? Mips::sub_64 : Mips::sub_lo);
3597 SrcValReg = Wt;
3598 }
3599
3600 // Convert the lane index into a byte index
3601 if (EltSizeInBytes != 1) {
3602 Register LaneTmp1 = RegInfo.createVirtualRegister(GPRRC);
3603 BuildMI(*BB, MI, DL, TII->get(ShiftOp), LaneTmp1)
3604 .addReg(LaneReg)
3605 .addImm(EltLog2Size);
3606 LaneReg = LaneTmp1;
3607 }
3608
3609 // Rotate bytes around so that the desired lane is element zero
3610 Register WdTmp1 = RegInfo.createVirtualRegister(VecRC);
3611 BuildMI(*BB, MI, DL, TII->get(Mips::SLD_B), WdTmp1)
3612 .addReg(SrcVecReg)
3613 .addReg(SrcVecReg)
3614 .addReg(LaneReg, {}, SubRegIdx);
3615
3616 Register WdTmp2 = RegInfo.createVirtualRegister(VecRC);
3617 if (IsFP) {
3618 // Use insve.df to insert to element zero
3619 BuildMI(*BB, MI, DL, TII->get(InsveOp), WdTmp2)
3620 .addReg(WdTmp1)
3621 .addImm(0)
3622 .addReg(SrcValReg)
3623 .addImm(0);
3624 } else {
3625 // Use insert.df to insert to element zero
3626 BuildMI(*BB, MI, DL, TII->get(InsertOp), WdTmp2)
3627 .addReg(WdTmp1)
3628 .addReg(SrcValReg)
3629 .addImm(0);
3630 }
3631
3632 // Rotate elements the rest of the way for a full rotation.
3633 // sld.df inteprets $rt modulo the number of columns so we only need to negate
3634 // the lane index to do this.
3635 Register LaneTmp2 = RegInfo.createVirtualRegister(GPRRC);
3636 BuildMI(*BB, MI, DL, TII->get(Subtarget.isABI_N64() ? Mips::DSUB : Mips::SUB),
3637 LaneTmp2)
3638 .addReg(Subtarget.isABI_N64() ? Mips::ZERO_64 : Mips::ZERO)
3639 .addReg(LaneReg);
3640 BuildMI(*BB, MI, DL, TII->get(Mips::SLD_B), Wd)
3641 .addReg(WdTmp2)
3642 .addReg(WdTmp2)
3643 .addReg(LaneTmp2, {}, SubRegIdx);
3644
3645 MI.eraseFromParent(); // The pseudo instruction is gone now.
3646 return BB;
3647}
3648
3649// Emit the FILL_FW pseudo instruction.
3650//
3651// fill_fw_pseudo $wd, $fs
3652// =>
3653// implicit_def $wt1
3654// insert_subreg $wt2:subreg_lo, $wt1, $fs
3655// splati.w $wd, $wt2[0]
3657MipsSETargetLowering::emitFILL_FW(MachineInstr &MI,
3658 MachineBasicBlock *BB) const {
3659 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3660 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3661 DebugLoc DL = MI.getDebugLoc();
3662 Register Wd = MI.getOperand(0).getReg();
3663 Register Fs = MI.getOperand(1).getReg();
3664 Register Wt1 = RegInfo.createVirtualRegister(
3665 Subtarget.useOddSPReg() ? &Mips::MSA128WRegClass
3666 : &Mips::MSA128WEvensRegClass);
3667 Register Wt2 = RegInfo.createVirtualRegister(
3668 Subtarget.useOddSPReg() ? &Mips::MSA128WRegClass
3669 : &Mips::MSA128WEvensRegClass);
3670
3671 BuildMI(*BB, MI, DL, TII->get(Mips::IMPLICIT_DEF), Wt1);
3672 BuildMI(*BB, MI, DL, TII->get(Mips::INSERT_SUBREG), Wt2)
3673 .addReg(Wt1)
3674 .addReg(Fs)
3675 .addImm(Mips::sub_lo);
3676 BuildMI(*BB, MI, DL, TII->get(Mips::SPLATI_W), Wd).addReg(Wt2).addImm(0);
3677
3678 MI.eraseFromParent(); // The pseudo instruction is gone now.
3679 return BB;
3680}
3681
3682// Emit the FILL_FD pseudo instruction.
3683//
3684// fill_fd_pseudo $wd, $fs
3685// =>
3686// implicit_def $wt1
3687// insert_subreg $wt2:subreg_64, $wt1, $fs
3688// splati.d $wd, $wt2[0]
3690MipsSETargetLowering::emitFILL_FD(MachineInstr &MI,
3691 MachineBasicBlock *BB) const {
3692 assert(Subtarget.isFP64bit());
3693
3694 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3695 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3696 DebugLoc DL = MI.getDebugLoc();
3697 Register Wd = MI.getOperand(0).getReg();
3698 Register Fs = MI.getOperand(1).getReg();
3699 Register Wt1 = RegInfo.createVirtualRegister(&Mips::MSA128DRegClass);
3700 Register Wt2 = RegInfo.createVirtualRegister(&Mips::MSA128DRegClass);
3701
3702 BuildMI(*BB, MI, DL, TII->get(Mips::IMPLICIT_DEF), Wt1);
3703 BuildMI(*BB, MI, DL, TII->get(Mips::INSERT_SUBREG), Wt2)
3704 .addReg(Wt1)
3705 .addReg(Fs)
3706 .addImm(Mips::sub_64);
3707 BuildMI(*BB, MI, DL, TII->get(Mips::SPLATI_D), Wd).addReg(Wt2).addImm(0);
3708
3709 MI.eraseFromParent(); // The pseudo instruction is gone now.
3710 return BB;
3711}
3712
3713// Emit the FEXP2_W_1 pseudo instructions.
3714//
3715// fexp2_w_1_pseudo $wd, $wt
3716// =>
3717// ldi.w $ws, 1
3718// fexp2.w $wd, $ws, $wt
3720MipsSETargetLowering::emitFEXP2_W_1(MachineInstr &MI,
3721 MachineBasicBlock *BB) const {
3722 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3723 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3724 const TargetRegisterClass *RC = &Mips::MSA128WRegClass;
3725 Register Ws1 = RegInfo.createVirtualRegister(RC);
3726 Register Ws2 = RegInfo.createVirtualRegister(RC);
3727 DebugLoc DL = MI.getDebugLoc();
3728
3729 // Splat 1.0 into a vector
3730 BuildMI(*BB, MI, DL, TII->get(Mips::LDI_W), Ws1).addImm(1);
3731 BuildMI(*BB, MI, DL, TII->get(Mips::FFINT_U_W), Ws2).addReg(Ws1);
3732
3733 // Emit 1.0 * fexp2(Wt)
3734 BuildMI(*BB, MI, DL, TII->get(Mips::FEXP2_W), MI.getOperand(0).getReg())
3735 .addReg(Ws2)
3736 .addReg(MI.getOperand(1).getReg());
3737
3738 MI.eraseFromParent(); // The pseudo instruction is gone now.
3739 return BB;
3740}
3741
3742// Emit the FEXP2_D_1 pseudo instructions.
3743//
3744// fexp2_d_1_pseudo $wd, $wt
3745// =>
3746// ldi.d $ws, 1
3747// fexp2.d $wd, $ws, $wt
3749MipsSETargetLowering::emitFEXP2_D_1(MachineInstr &MI,
3750 MachineBasicBlock *BB) const {
3751 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3752 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3753 const TargetRegisterClass *RC = &Mips::MSA128DRegClass;
3754 Register Ws1 = RegInfo.createVirtualRegister(RC);
3755 Register Ws2 = RegInfo.createVirtualRegister(RC);
3756 DebugLoc DL = MI.getDebugLoc();
3757
3758 // Splat 1.0 into a vector
3759 BuildMI(*BB, MI, DL, TII->get(Mips::LDI_D), Ws1).addImm(1);
3760 BuildMI(*BB, MI, DL, TII->get(Mips::FFINT_U_D), Ws2).addReg(Ws1);
3761
3762 // Emit 1.0 * fexp2(Wt)
3763 BuildMI(*BB, MI, DL, TII->get(Mips::FEXP2_D), MI.getOperand(0).getReg())
3764 .addReg(Ws2)
3765 .addReg(MI.getOperand(1).getReg());
3766
3767 MI.eraseFromParent(); // The pseudo instruction is gone now.
3768 return BB;
3769}
static SDValue performSHLCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI, SelectionDAG &DAG)
If the operand is a bitwise AND with a constant RHS, and the shift has a constant RHS and is the only...
static SDValue performORCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI)
static SDValue performANDCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI)
static SDValue performSETCCCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI, SelectionDAG &DAG)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned Imm
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define X(NUM, ENUM, NAME)
Definition ELF.h:857
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
static bool fitsRegularPattern(typename SmallVectorImpl< ValType >::const_iterator Begin, unsigned CheckStride, typename SmallVectorImpl< ValType >::const_iterator End, ValType ExpectedIndex, unsigned ExpectedIndexStride)
Determine whether a range fits a regular pattern of values.
static SDValue performVSELECTCombine(SDNode *N, SelectionDAG &DAG, TargetLowering::DAGCombinerInfo &DCI, const LoongArchSubtarget &Subtarget)
static SDValue performSRLCombine(SDNode *N, SelectionDAG &DAG, TargetLowering::DAGCombinerInfo &DCI, const LoongArchSubtarget &Subtarget)
static SDValue truncateVecElts(SDNode *Node, SelectionDAG &DAG)
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Promote Memory to Register
Definition Mem2Reg.cpp:110
static SDValue lowerMSABinaryBitImmIntr(SDValue Op, SelectionDAG &DAG, unsigned Opc, SDValue Imm, bool BigEndian)
static SDValue lowerMSABitClearImm(SDValue Op, SelectionDAG &DAG)
static SDValue performMULCombine(SDNode *N, SelectionDAG &DAG, const TargetLowering::DAGCombinerInfo &DCI, const MipsSETargetLowering *TL, const MipsSubtarget &Subtarget)
static SDValue performXORCombine(SDNode *N, SelectionDAG &DAG, const MipsSubtarget &Subtarget)
static SDValue lowerDSPIntr(SDValue Op, SelectionDAG &DAG, unsigned Opc)
static SDValue performDSPShiftCombine(unsigned Opc, SDNode *N, EVT Ty, SelectionDAG &DAG, const MipsSubtarget &Subtarget)
static SDValue lowerMSACopyIntr(SDValue Op, SelectionDAG &DAG, unsigned Opc)
static cl::opt< bool > NoDPLoadStore("mno-ldc1-sdc1", cl::init(false), cl::desc("Expand double precision loads and " "stores to their single precision " "counterparts"))
static SDValue lowerVECTOR_SHUFFLE_ILVR(SDValue Op, EVT ResTy, SmallVector< int, 16 > Indices, SelectionDAG &DAG)
static SDValue getBuildVectorSplat(EVT VecTy, SDValue SplatValue, bool BigEndian, SelectionDAG &DAG)
static bool isVSplat(SDValue N, APInt &Imm, bool IsLittleEndian)
static SDValue initAccumulator(SDValue In, const SDLoc &DL, SelectionDAG &DAG)
static bool isBitwiseInverse(SDValue N, SDValue OfNode)
static SDValue lowerMSAStoreIntr(SDValue Op, SelectionDAG &DAG, unsigned Intr, const MipsSubtarget &Subtarget)
static SDValue performSRACombine(SDNode *N, SelectionDAG &DAG, TargetLowering::DAGCombinerInfo &DCI, const MipsSubtarget &Subtarget)
static bool isVectorAllOnes(SDValue N)
static SDValue lowerVECTOR_SHUFFLE_PCKOD(SDValue Op, EVT ResTy, SmallVector< int, 16 > Indices, SelectionDAG &DAG)
static SDValue performFP_TO_UINTCombine(SDNode *N, SelectionDAG &DAG)
static bool isLegalDSPCondCode(EVT Ty, ISD::CondCode CC)
static SDValue lowerMSASplatZExt(SDValue Op, unsigned OpNr, SelectionDAG &DAG)
static SDValue lowerMSABitClear(SDValue Op, SelectionDAG &DAG)
static SDValue lowerVECTOR_SHUFFLE_PCKEV(SDValue Op, EVT ResTy, SmallVector< int, 16 > Indices, SelectionDAG &DAG)
static SDValue genConstMult(SDValue X, APInt C, const SDLoc &DL, EVT VT, EVT ShiftTy, SelectionDAG &DAG)
static SDValue lowerMSASplatImm(SDValue Op, unsigned ImmOp, SelectionDAG &DAG, bool IsSigned=false)
static SDValue lowerVECTOR_SHUFFLE_ILVOD(SDValue Op, EVT ResTy, SmallVector< int, 16 > Indices, SelectionDAG &DAG)
static bool isConstantOrUndef(const SDValue Op)
static SDValue lowerVECTOR_SHUFFLE_VSHF(SDValue Op, EVT ResTy, const SmallVector< int, 16 > &Indices, const bool isSPLATI, SelectionDAG &DAG)
static SDValue lowerVECTOR_SHUFFLE_SHF(SDValue Op, EVT ResTy, SmallVector< int, 16 > Indices, SelectionDAG &DAG)
static SDValue extractLOHI(SDValue Op, const SDLoc &DL, SelectionDAG &DAG)
static bool shouldTransformMulToShiftsAddsSubs(APInt C, EVT VT, SelectionDAG &DAG, const MipsSubtarget &Subtarget)
static SDValue lowerVECTOR_SHUFFLE_ILVEV(SDValue Op, EVT ResTy, SmallVector< int, 16 > Indices, SelectionDAG &DAG)
static bool isVECTOR_SHUFFLE_SPLATI(SDValue Op, EVT ResTy, SmallVector< int, 16 > Indices, SelectionDAG &DAG)
static bool isConstantOrUndefBUILD_VECTOR(const BuildVectorSDNode *Op)
static SDValue lowerMSALoadIntr(SDValue Op, SelectionDAG &DAG, unsigned Intr, const MipsSubtarget &Subtarget)
static SDValue lowerVECTOR_SHUFFLE_ILVL(SDValue Op, EVT ResTy, SmallVector< int, 16 > Indices, SelectionDAG &DAG)
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
const SmallVectorImpl< MachineOperand > & Cond
static cl::opt< unsigned > MaxSteps("has-predecessor-max-steps", cl::Hidden, cl::init(8192), cl::desc("DAG combiner limit number of steps when searching DAG " "for predecessor nodes"))
This file defines the SmallVector class.
#define LLVM_DEBUG(...)
Definition Debug.h:119
This file describes how to lower LLVM code to machine code.
Class for arbitrary precision integers.
Definition APInt.h:78
uint64_t getZExtValue() const
Get zero extended value.
Definition APInt.h:1560
LLVM_ABI APInt trunc(unsigned width) const
Truncate to new width.
Definition APInt.cpp:970
bool isAllOnes() const
Determine if all bits are set. This is true for zero-width values.
Definition APInt.h:367
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition APInt.h:1508
bool isNegative() const
Determine sign of this APInt.
Definition APInt.h:325
unsigned logBase2() const
Definition APInt.h:1781
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
Definition APInt.h:436
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Constructs an APInt value that has the bottom loBitsSet bits set.
Definition APInt.h:302
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Constructs an APInt value that has the top hiBitsSet bits set.
Definition APInt.h:292
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
Definition APInt.h:853
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
A "pseudo-class" with methods for operating on BUILD_VECTORs.
LLVM_ABI bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef, unsigned &SplatBitSize, bool &HasAnyUndefs, unsigned MinSplatBits=0, bool isBigEndian=false) const
Check if this is a constant splat, and if so, find the smallest element size that splats the vector.
CCState - This class holds information needed while lowering arguments and return values.
unsigned getInRegsParamsCount() const
uint64_t getZExtValue() const
const SDValue & getBasePtr() const
const Triple & getTargetTriple() const
Machine Value Type.
SimpleValueType SimpleTy
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
static auto fixedlen_vector_valuetypes()
LLVM_ABI void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *FromMBB)
Transfers all the successors, as in transferSuccessors, and update PHI operands in the successor bloc...
LLVM_ABI instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
LLVM_ABI void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
MachineInstrBundleIterator< MachineInstr > iterator
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
BasicBlockListType::iterator iterator
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineInstr - Allocate a new MachineInstr.
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
Representation of each machine instruction.
Flags
Flags values. These may be or'd together.
Flags getFlags() const
Return the raw flags of the source value,.
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
Align getAlign() const
AAMDNodes getAAInfo() const
Returns the AA info that describes the dereference.
MachineMemOperand * getMemOperand() const
Return the unique MachineMemOperand object describing the memory reference performed by operation.
const SDValue & getChain() const
EVT getMemoryVT() const
Return the type of the in-memory value.
MipsFunctionInfo - This class is derived from MachineFunction private Mips target-specific informatio...
unsigned getIncomingArgSize() const
SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override
This method will be invoked for all target nodes and for any target-independent nodes that the target...
TargetLoweringBase::LegalizeTypeAction getPreferredVectorAction(MVT VT) const override
Return the preferred vector type legalization action.
void addMSAFloatType(MVT::SimpleValueType Ty, const TargetRegisterClass *RC)
Enable MSA support for the given floating-point type and Register class.
void addMSAIntType(MVT::SimpleValueType Ty, const TargetRegisterClass *RC)
Enable MSA support for the given integer type and Register class.
MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *MBB) const override
This method should be implemented by targets that mark instructions with the 'usesCustomInserter' fla...
const TargetRegisterClass * getRepRegClassFor(MVT VT) const override
Return the 'representative' register class for the specified value type.
bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AS=0, Align Alignment=Align(1), MachineMemOperand::Flags Flags=MachineMemOperand::MONone, unsigned *Fast=nullptr) const override
Determine if the target supports unaligned memory accesses.
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override
This callback is invoked for operations that are unsupported by the target, which are registered to u...
MipsSETargetLowering(const MipsTargetMachine &TM, const MipsSubtarget &STI)
bool hasMips32r6() const
bool isLittle() const
bool hasDSPR2() const
MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override
Return the type to use for a scalar shift opcode, given the shifted amount type.
MipsTargetLowering(const MipsTargetMachine &TM, const MipsSubtarget &STI)
SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override
This method will be invoked for all target nodes and for any target-independent nodes that the target...
MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *MBB) const override
This method should be implemented by targets that mark instructions with the 'usesCustomInserter' fla...
SDValue lowerSTORE(SDValue Op, SelectionDAG &DAG) const
virtual void getOpndList(SmallVectorImpl< SDValue > &Ops, std::deque< std::pair< unsigned, SDValue > > &RegsToPass, bool IsPICCall, bool GlobalOrExternal, bool InternalLinkage, bool IsCallReloc, CallLoweringInfo &CLI, SDValue Callee, SDValue Chain) const
This function fills Ops, which is the list of operands that will later be used when a function call n...
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override
LowerOperation - Provide custom lowering hooks for some operations.
const MipsSubtarget & Subtarget
SDValue lowerLOAD(SDValue Op, SelectionDAG &DAG) const
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
unsigned getNumOperands() const
Return the number of values used by this operation.
SDVTList getVTList() const
const SDValue & getOperand(unsigned Num) const
LLVM_ABI void printrWithDepth(raw_ostream &O, const SelectionDAG *G=nullptr, unsigned depth=100) const
Print a SelectionDAG node and children up to depth "depth." The given SelectionDAG allows target-spec...
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
SDNode * getNode() const
get the SDNode which holds the desired result
SDValue getValue(unsigned R) const
EVT getValueType() const
Return the ValueType of the referenced return value.
const SDValue & getOperand(unsigned i) const
uint64_t getScalarValueSizeInBits() const
unsigned getOpcode() const
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
const TargetSubtargetInfo & getSubtarget() const
LLVM_ABI SDValue getMergeValues(ArrayRef< SDValue > Ops, const SDLoc &dl)
Create a MERGE_VALUES node from the given operands.
SDValue getSetCC(const SDLoc &DL, EVT VT, SDValue LHS, SDValue RHS, ISD::CondCode Cond, SDValue Chain=SDValue(), bool IsSignaling=false, SDNodeFlags Flags={})
Helper function to make it easier to build SetCC's if you just have an ISD::CondCode instead of an SD...
LLVM_ABI SDValue getNOT(const SDLoc &DL, SDValue Val, EVT VT)
Create a bitwise NOT operation as (XOR Val, -1).
const TargetLowering & getTargetLoweringInfo() const
SDValue getUNDEF(EVT VT)
Return an UNDEF node. UNDEF does not have a useful SDLoc.
SDValue getBuildVector(EVT VT, const SDLoc &DL, ArrayRef< SDValue > Ops)
Return an ISD::BUILD_VECTOR node.
LLVM_ABI bool isSplatValue(SDValue V, const APInt &DemandedElts, APInt &UndefElts, unsigned Depth=0) const
Test whether V has a splatted value for all the demanded elements.
const DataLayout & getDataLayout() const
LLVM_ABI SDValue getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, Align Alignment, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const MMOMetadata &Metadata=MMOMetadata())
Helper function to build ISD::STORE nodes.
LLVM_ABI SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
LLVM_ABI SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const MMOMetadata &Metadata=MMOMetadata())
Loads are not normal binary operators: their result type is not determined by their operands,...
LLVM_ABI SDValue getValueType(EVT)
LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
SDValue getTargetConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
LLVM_ABI SDValue getVectorIdxConstant(uint64_t Val, const SDLoc &DL, bool isTarget=false)
SDValue getSplatBuildVector(EVT VT, const SDLoc &DL, SDValue Op)
Return a splat ISD::BUILD_VECTOR node, consisting of Op splatted to all elements.
LLVM_ABI SDValue getZExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either zero-extending or trunca...
LLVMContext * getContext() const
LLVM_ABI std::pair< SDValue, SDValue > SplitScalar(const SDValue &N, const SDLoc &DL, const EVT &LoVT, const EVT &HiVT)
Split the scalar node with EXTRACT_ELEMENT using the provided VTs and return the low/high part.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
typename SuperClass::const_iterator const_iterator
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
const SDValue & getBasePtr() const
const SDValue & getValue() const
void setOperationAction(unsigned Op, MVT VT, LegalizeAction Action)
Indicate that the specified operation does not work with the specified type and indicate what to do a...
MVT getVectorIdxTy(const DataLayout &DL) const
Returns the type to be used for the index operand of: ISD::INSERT_VECTOR_ELT, ISD::EXTRACT_VECTOR_ELT...
void setOperationPromotedToType(unsigned Opc, MVT OrigVT, MVT DestVT)
Convenience method to set an operation to Promote and specify the type in a single call.
LegalizeTypeAction
This enum indicates whether a types are legal for a target, and if not, what action should be used to...
MVT getRegisterType(LLVMContext &Context, EVT VT) const
Return the type of registers that this ValueType will eventually require.
virtual TargetLoweringBase::LegalizeTypeAction getPreferredVectorAction(MVT VT) const
Return the preferred vector type legalization action.
void computeRegisterProperties(const TargetRegisterInfo *TRI)
Once all of the register classes are added, this allows us to compute derived properties we expose.
void addRegisterClass(MVT VT, const TargetRegisterClass *RC)
Add the specified register class as an available regclass for the specified value type.
virtual MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
void setTruncStoreAction(MVT ValVT, MVT MemVT, LegalizeAction Action)
Indicate that the specified truncating store does not work with the specified type and indicate what ...
virtual const TargetRegisterClass * getRepRegClassFor(MVT VT) const
Return the 'representative' register class for the specified value type.
void setCondCodeAction(ArrayRef< ISD::CondCode > CCs, MVT VT, LegalizeAction Action)
Indicate that the specified condition code is or isn't supported on the target and indicate what to d...
void setTargetDAGCombine(ArrayRef< ISD::NodeType > NTs)
Targets should invoke this method for each target independent node that they want to provide a custom...
void setLoadExtAction(unsigned ExtType, MVT ValVT, MVT MemVT, LegalizeAction Action)
Indicate that the specified load with extension does not work with the specified type and indicate wh...
LegalizeTypeAction getTypeAction(LLVMContext &Context, EVT VT) const
Return how we should legalize values of this type, either it is already legal (return 'Legal') or we ...
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
std::pair< SDValue, SDValue > makeLibCall(SelectionDAG &DAG, RTLIB::LibcallImpl LibcallImpl, EVT RetVT, ArrayRef< SDValue > Ops, MakeLibCallOptions CallOptions, const SDLoc &dl, SDValue Chain=SDValue()) const
Returns a pair of (return value, chain).
LLVM_ABI bool isLittleEndian() const
Tests whether the target triple is little endian.
Definition Triple.cpp:2211
LLVM Value Representation.
Definition Value.h:75
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
@ SETCC
SetCC operator - This evaluates to a true value iff the condition is true.
Definition ISDOpcodes.h:837
@ POISON
POISON - A poison node.
Definition ISDOpcodes.h:238
@ SMUL_LOHI
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
Definition ISDOpcodes.h:277
@ ADDC
Carry-setting nodes for multiple precision addition and subtraction.
Definition ISDOpcodes.h:296
@ ADD
Simple integer binary arithmetic operators.
Definition ISDOpcodes.h:266
@ LOAD
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
@ FMA
FMA - Perform a * b + c with no intermediate rounding step.
Definition ISDOpcodes.h:523
@ INTRINSIC_VOID
OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...) This node represents a target intrin...
Definition ISDOpcodes.h:222
@ SINT_TO_FP
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
Definition ISDOpcodes.h:898
@ FADD
Simple binary floating point operators.
Definition ISDOpcodes.h:420
@ ATOMIC_FENCE
OUTCHAIN = ATOMIC_FENCE(INCHAIN, ordering, scope) This corresponds to the fence instruction.
@ SDIVREM
SDIVREM/UDIVREM - Divide two integers and produce both a quotient and remainder result.
Definition ISDOpcodes.h:282
@ FP16_TO_FP
FP16_TO_FP, FP_TO_FP16 - These operators are used to perform promotions and truncation for half-preci...
@ BITCAST
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
@ BUILD_PAIR
BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.
Definition ISDOpcodes.h:256
@ STRICT_FSQRT
Constrained versions of libm-equivalent floating point intrinsics.
Definition ISDOpcodes.h:441
@ BUILTIN_OP_END
BUILTIN_OP_END - This must be the last enum value in this list.
@ SIGN_EXTEND
Conversion operators.
Definition ISDOpcodes.h:862
@ SELECT
Select(COND, TRUEVAL, FALSEVAL).
Definition ISDOpcodes.h:814
@ UNDEF
UNDEF - An undefined node.
Definition ISDOpcodes.h:235
@ BasicBlock
Various leaf nodes.
Definition ISDOpcodes.h:83
@ STRICT_FP_TO_FP16
@ MULHU
MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing an unsigned/signed value of...
Definition ISDOpcodes.h:714
@ STRICT_FP16_TO_FP
@ SHL
Shift and rotation operations.
Definition ISDOpcodes.h:779
@ VECTOR_SHUFFLE
VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as VEC1/VEC2.
Definition ISDOpcodes.h:659
@ EXTRACT_VECTOR_ELT
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
Definition ISDOpcodes.h:581
@ ZERO_EXTEND
ZERO_EXTEND - Used for integer types, zeroing the new bits.
Definition ISDOpcodes.h:868
@ SELECT_CC
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
Definition ISDOpcodes.h:829
@ SMIN
[US]{MIN/MAX} - Binary minimum or maximum of signed or unsigned integers.
Definition ISDOpcodes.h:737
@ VSELECT
Select with a vector condition (op #0) and two vector operands (ops #1 and #2), returning a vector re...
Definition ISDOpcodes.h:823
@ FP_TO_SINT
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition ISDOpcodes.h:944
@ TargetConstant
TargetConstant* - Like Constant*, but the DAG does not do any folding, simplification,...
Definition ISDOpcodes.h:181
@ AND
Bitwise operators - logical and, logical or, logical xor.
Definition ISDOpcodes.h:749
@ INTRINSIC_WO_CHAIN
RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...) This node represents a target intrinsic fun...
Definition ISDOpcodes.h:207
@ ADDE
Carry-using nodes for multiple precision addition and subtraction.
Definition ISDOpcodes.h:306
@ STRICT_FADD
Constrained versions of the binary floating point operators.
Definition ISDOpcodes.h:430
@ INSERT_VECTOR_ELT
INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element at IDX replaced with VAL.
Definition ISDOpcodes.h:570
@ TRUNCATE
TRUNCATE - Completely drop the high bits.
Definition ISDOpcodes.h:874
@ BRCOND
BRCOND - Conditional branch.
@ INTRINSIC_W_CHAIN
RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...) This node represents a target in...
Definition ISDOpcodes.h:215
@ BUILD_VECTOR
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a fixed-width vector with the specified,...
Definition ISDOpcodes.h:561
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
LLVM_ABI bool isBuildVectorAllOnes(const SDNode *N)
Return true if the specified node is a BUILD_VECTOR where all of the elements are ~0 or undef.
initializer< Ty > init(const Ty &Val)
NodeAddr< NodeBase * > Node
Definition RDFGraph.h:381
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
@ Fast
Assign the register banks as fast as possible (default).
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
const MipsTargetLowering * createMipsSETargetLowering(const MipsTargetMachine &TM, const MipsSubtarget &STI)
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
Definition Alignment.h:201
unsigned Log2(Align A)
Returns the log2 of the alignment.
Definition Alignment.h:197
@ Custom
The result value requires a custom uniformity check.
Definition Uniformity.h:31
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition BitVector.h:880
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Extended Value Type.
Definition ValueTypes.h:35
EVT changeVectorElementTypeToInteger() const
Return a vector with the same number of elements as this vector, but with the element type converted ...
Definition ValueTypes.h:90
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition ValueTypes.h:396
uint64_t getScalarSizeInBits() const
Definition ValueTypes.h:408
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition ValueTypes.h:339
bool is128BitVector() const
Return true if this is a 128-bit vector type.
Definition ValueTypes.h:230
bool isVector() const
Return true if this is a vector value type.
Definition ValueTypes.h:176
EVT getVectorElementType() const
Given a vector type, return the type of each element.
Definition ValueTypes.h:351
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
Definition ValueTypes.h:359
bool isInteger() const
Return true if this is an integer or a vector integer type.
Definition ValueTypes.h:160
This class contains a discriminated union of information about pointers in memory operands,...
These are IR-level optimization flags that may be propagated to SDNodes.
This structure is used to pass arguments to makeLibCall function.