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"
38#include "llvm/Support/Debug.h"
42#include <algorithm>
43#include <cassert>
44#include <cstddef>
45#include <cstdint>
46#include <iterator>
47#include <utility>
48
49using namespace llvm;
50
51#define DEBUG_TYPE "mips-isel"
52
53// Widen the v2 vectors to the register width, i.e. v2i16 -> v8i16,
54// v2i32 -> v4i32, etc, to ensure the correct rail size is used, i.e.
55// INST.h for v16, INST.w for v32, INST.d for v64.
58 if (this->Subtarget.hasMSA()) {
59 switch (VT.SimpleTy) {
60 // Leave v2i1 vectors to be promoted to larger ones.
61 // Other i1 types will be promoted by default.
62 case MVT::v2i1:
63 return TypePromoteInteger;
64 break;
65 // 16-bit vector types (v2 and longer)
66 case MVT::v2i8:
67 // 32-bit vector types (v2 and longer)
68 case MVT::v2i16:
69 case MVT::v4i8:
70 // 64-bit vector types (v2 and longer)
71 case MVT::v2i32:
72 case MVT::v4i16:
73 case MVT::v8i8:
74 return TypeWidenVector;
75 break;
76 // Only word (.w) and doubleword (.d) are available for floating point
77 // vectors. That means floating point vectors should be either v2f64
78 // or v4f32.
79 // Here we only explicitly widen the f32 types - f16 will be promoted
80 // by default.
81 case MVT::v2f32:
82 case MVT::v3f32:
83 return TypeWidenVector;
84 // v2i64 is already 128-bit wide.
85 default:
86 break;
87 }
88 }
90}
91
93 const MipsSubtarget &STI)
94 : MipsTargetLowering(TM, STI) {
95 // Set up the register classes
96 addRegisterClass(MVT::i32, &Mips::GPR32RegClass);
97
98 if (Subtarget.isGP64bit())
99 addRegisterClass(MVT::i64, &Mips::GPR64RegClass);
100
101 if (Subtarget.hasDSP() || Subtarget.hasMSA()) {
102 // Expand all truncating stores and extending loads.
105 setTruncStoreAction(VT0, VT1, Expand);
109 }
110 }
111 }
112
113 if (Subtarget.hasDSP()) {
114 MVT::SimpleValueType VecTys[2] = {MVT::v2i16, MVT::v4i8};
115
116 for (const auto &VecTy : VecTys) {
117 addRegisterClass(VecTy, &Mips::DSPRRegClass);
118
119 // Expand all builtin opcodes.
120 for (unsigned Opc = 0; Opc < ISD::BUILTIN_OP_END; ++Opc)
122
128 }
129
132
133 if (Subtarget.hasMips32r2()) {
136 }
137 }
138
139 if (Subtarget.hasDSPR2())
140 setOperationAction(ISD::MUL, MVT::v2i16, Legal);
141
142 if (Subtarget.hasMSA()) {
143 addMSAIntType(MVT::v16i8, &Mips::MSA128BRegClass);
144 addMSAIntType(MVT::v8i16, &Mips::MSA128HRegClass);
145 addMSAIntType(MVT::v4i32, &Mips::MSA128WRegClass);
146 addMSAIntType(MVT::v2i64, &Mips::MSA128DRegClass);
147 addMSAFloatType(MVT::v8f16, &Mips::MSA128HRegClass);
148 addMSAFloatType(MVT::v4f32, &Mips::MSA128WRegClass);
149 addMSAFloatType(MVT::v2f64, &Mips::MSA128DRegClass);
150
151 // Shuffle half vectors as integers to avoid expanding them through
152 // EXTRACT_VECTOR_ELT and BUILD_VECTOR with an illegal scalar f16 type.
153 setOperationPromotedToType(ISD::VECTOR_SHUFFLE, MVT::v8f16, MVT::v8i16);
154
155 // We're using soft promotion for f16, but msa has some instructions for
156 // conversion to/from f16. Mark those conversions as custom so we can take
157 // advantage of these instructions.
158 for (MVT VT : {MVT::f32, MVT::f64}) {
161 }
162
165 }
166
167 if (!Subtarget.useSoftFloat()) {
168 addRegisterClass(MVT::f32, &Mips::FGR32RegClass);
169
170 // RINT uses the current rounding mode and may raise inexact.
171 if (Subtarget.hasMips32r6() && !Subtarget.inMicroMipsMode()) {
174 if (!Subtarget.isSingleFloat()) {
177 }
178 }
179
180 // Standard r6 has a fused multiply-add with a tied accumulator. Scalar
181 // FMA selection for the microMIPS encodings is not implemented here.
182 if (Subtarget.hasMips32r6() && !Subtarget.inMicroMipsMode()) {
183 // Keep strict nodes intact so their exception chains survive selection.
184 for (auto Op : {ISD::FMA, ISD::STRICT_FMA}) {
185 setOperationAction(Op, MVT::f32, Legal);
186 if (!Subtarget.isSingleFloat() && Subtarget.isFP64bit())
187 setOperationAction(Op, MVT::f64, Legal);
188 }
189 }
190
191 // When dealing with single precision only, use libcalls
192 if (!Subtarget.isSingleFloat()) {
193 if (Subtarget.isFP64bit())
194 addRegisterClass(MVT::f64, &Mips::FGR64RegClass);
195 else
196 addRegisterClass(MVT::f64, &Mips::AFGR64RegClass);
197 }
198
201 setOperationAction(Op, MVT::f32, Legal);
202 setOperationAction(Op, MVT::f64, Legal);
203 }
204 }
205
206 // Targets with 64bits integer registers, but no 64bit floating point register
207 // do not support conversion between them
208 if (Subtarget.isGP64bit() && Subtarget.isSingleFloat() &&
209 !Subtarget.useSoftFloat()) {
214 }
215
220
221 if (Subtarget.hasCnMips())
223 else if (Subtarget.isR5900()) {
224 // R5900 doesn't have DMULT/DMULTU/DDIV/DDIVU - expand to 32-bit ops
232 } else if (Subtarget.isGP64bit())
234
235 if (Subtarget.isGP64bit() && !Subtarget.isR5900()) {
242 }
243
246
250 if (Subtarget.hasMips32r6()) {
253 } else {
256 }
257
259
263
264 if (Subtarget.hasMips32r2() && !Subtarget.useSoftFloat() &&
265 !Subtarget.hasMips64()) {
267 }
268
269 if (Subtarget.getCLOpts().mno_ldc1_sdc1 ||
270 (Subtarget.hasMips1() && !Subtarget.hasMips2())) {
273 }
274
275 if (Subtarget.hasMips32r6()) {
276 // MIPS32r6 replaces the accumulator-based multiplies with a three register
277 // instruction
283
284 // MIPS32r6 replaces the accumulator-based division/remainder with separate
285 // three register division and remainder instructions.
292
293 // MIPS32r6 replaces conditional moves with an equivalent that removes the
294 // need for three GPR read ports.
298
302
303 assert(Subtarget.isFP64bit() && "FR=1 is required for MIPS32r6");
307
309
310 // Floating point > and >= are supported via < and <=
319
328 }
329
330 if (Subtarget.hasMips64r6()) {
331 // MIPS64r6 replaces the accumulator-based multiplies with a three register
332 // instruction
338
339 // MIPS32r6 replaces the accumulator-based division/remainder with separate
340 // three register division and remainder instructions.
347
348 // MIPS64r6 replaces conditional moves with an equivalent that removes the
349 // need for three GPR read ports.
353 }
354
355 if (Subtarget.isR5900()) {
356 // R5900 FPU only supports 4 compare conditions: C.F, C.EQ, C.OLT, C.OLE
357 // (and their inversions via bc1t/bc1f). Expand all conditions that would
358 // require C.UN, C.UEQ, C.ULT, or C.ULE instructions (not available on
359 // R5900). The legalizer resolves these via operand swapping, condition
360 // inversion, and decomposition into supported conditions.
372
373 // R5900 FPU does not support IEEE 754 special values (NaN, infinity). Use
374 // custom lowering to decide per-instruction: hardware when nnan+ninf flags
375 // guarantee no NaN or infinity, software libcall otherwise.
381 }
382
383 computeRegisterProperties(Subtarget.getRegisterInfo());
384}
385
386const MipsTargetLowering *
388 const MipsSubtarget &STI) {
389 return new MipsSETargetLowering(TM, STI);
390}
391
394 if (VT == MVT::Untyped)
395 return Subtarget.hasDSP() ? &Mips::ACC64DSPRegClass : &Mips::ACC64RegClass;
396
398}
399
400// Enable MSA support for the given integer type and Register class.
403 addRegisterClass(Ty, RC);
404
405 // Expand all builtin opcodes.
406 for (unsigned Opc = 0; Opc < ISD::BUILTIN_OP_END; ++Opc)
408
416
438
439 if (Ty == MVT::v4i32 || Ty == MVT::v2i64) {
444 }
445
452}
453
454// Enable MSA support for the given floating-point type and Register class.
457 addRegisterClass(Ty, RC);
458
459 // Expand all builtin opcodes.
460 for (unsigned Opc = 0; Opc < ISD::BUILTIN_OP_END; ++Opc)
462
470
471 if (Ty != MVT::v8f16) {
483
491 }
492}
493
494// Lower FP16_TO_FP (the soft-promote-half representation of an f16 -> f32/f64
495// conversion).
496SDValue MipsSETargetLowering::lowerFP16_TO_FP(SDValue Op,
497 SelectionDAG &DAG) const {
498 SDLoc DL(Op);
499 EVT ResTy = Op.getValueType();
500 assert((ResTy == MVT::f32 || ResTy == MVT::f64) && "Unexpected FP16_TO_FP");
501
502 // The operand type is i32 because i16 isn't actually legal on MIPS.
503 SDValue In = Op.getOperand(0);
504 assert(In.getValueType() == MVT::i32 && "Unexpected FP16_TO_FP operand type");
505
506 // Splat into a v8i16 (the 32-bit In value is truncated to the lower 16 bits).
507 SDValue Splatted = DAG.getSplatBuildVector(MVT::v8i16, DL, In);
508
509 // Bitcast from v8i16 to v8f16.
510 SDValue HVec = DAG.getNode(ISD::BITCAST, DL, MVT::v8f16, Splatted);
511
512 // Convert from v8f16 to v4f32.
513 SDValue F32Vec = DAG.getNode(
514 ISD::INTRINSIC_WO_CHAIN, DL, MVT::v4f32,
515 DAG.getConstant(Intrinsic::mips_fexupr_w, DL, MVT::i32), HVec);
516 SDValue Res;
517 if (ResTy == MVT::f32) {
518 // Every lane has the converted value, just read it from lane 0.
519 Res = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, F32Vec,
520 DAG.getVectorIdxConstant(0, DL));
521 } else {
522 // Convert from v4f32 to v2f64.
523 SDValue F64Vec = DAG.getNode(
524 ISD::INTRINSIC_WO_CHAIN, DL, MVT::v2f64,
525 DAG.getConstant(Intrinsic::mips_fexupr_d, DL, MVT::i32), F32Vec);
526 // Every lane has the converted value, just read it from lane 0.
527 Res = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f64, F64Vec,
528 DAG.getVectorIdxConstant(0, DL));
529 }
530
531 return Res;
532}
533
534// Lower FP_TO_FP16 (the soft-promote-half representation of an f32/f64 -> f16
535// conversion)
536SDValue MipsSETargetLowering::lowerFP_TO_FP16(SDValue Op,
537 SelectionDAG &DAG) const {
538 SDLoc DL(Op);
539 EVT ResTy = Op.getValueType();
540 SDValue In = Op.getOperand(0);
541 assert((In.getValueType() == MVT::f32 || In.getValueType() == MVT::f64) &&
542 "Unexpected FP_TO_FP16");
543
544 SDValue F32Vec;
545 if (In.getValueType() == MVT::f64) {
546 // Splat f64 to v2f64, then convert to v4f32.
547 SDValue F64Vec = DAG.getSplatBuildVector(MVT::v2f64, DL, In);
548 F32Vec = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, DL, MVT::v4f32,
549 DAG.getConstant(Intrinsic::mips_fexdo_w, DL, MVT::i32),
550 F64Vec, F64Vec);
551 } else {
552 // Splat f32 to v4f32.
553 F32Vec = DAG.getSplatBuildVector(MVT::v4f32, DL, In);
554 }
555
556 // Then convert from v4f32 to v8f16.
557 SDValue HVec = DAG.getNode(
558 ISD::INTRINSIC_WO_CHAIN, DL, MVT::v8f16,
559 DAG.getConstant(Intrinsic::mips_fexdo_h, DL, MVT::i32), F32Vec, F32Vec);
560
561 // Finally cast to v8i16 (f16 is soft-promoted).
562 SDValue IVec = DAG.getNode(ISD::BITCAST, DL, MVT::v8i16, HVec);
563 SDValue Res = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, ResTy, IVec,
564 DAG.getVectorIdxConstant(0, DL));
565
566 return Res;
567}
568
570 EVT VT, unsigned, Align, MachineMemOperand::Flags, unsigned *Fast) const {
572
573 if (Subtarget.systemSupportsUnalignedAccess()) {
574 // MIPS32r6/MIPS64r6 is required to support unaligned access. It's
575 // implementation defined whether this is handled by hardware, software, or
576 // a hybrid of the two but it's expected that most implementations will
577 // handle the majority of cases in hardware.
578 if (Fast)
579 *Fast = 1;
580 return true;
581 } else if (Subtarget.hasMips32r6()) {
582 return false;
583 }
584
585 switch (SVT) {
586 case MVT::i64:
587 case MVT::i32:
588 if (Fast)
589 *Fast = 1;
590 return true;
591 default:
592 return false;
593 }
594}
595
597 SelectionDAG &DAG) const {
598 switch(Op.getOpcode()) {
599 case ISD::LOAD: return lowerLOAD(Op, DAG);
600 case ISD::STORE: return lowerSTORE(Op, DAG);
601 case ISD::SMUL_LOHI: return lowerMulDiv(Op, MipsISD::Mult, true, true, DAG);
602 case ISD::UMUL_LOHI: return lowerMulDiv(Op, MipsISD::Multu, true, true, DAG);
603 case ISD::MULHS: return lowerMulDiv(Op, MipsISD::Mult, false, true, DAG);
604 case ISD::MULHU: return lowerMulDiv(Op, MipsISD::Multu, false, true, DAG);
605 case ISD::MUL: return lowerMulDiv(Op, MipsISD::Mult, true, false, DAG);
606 case ISD::SDIVREM: return lowerMulDiv(Op, MipsISD::DivRem, true, true, DAG);
607 case ISD::UDIVREM: return lowerMulDiv(Op, MipsISD::DivRemU, true, true,
608 DAG);
609 case ISD::INTRINSIC_WO_CHAIN: return lowerINTRINSIC_WO_CHAIN(Op, DAG);
610 case ISD::INTRINSIC_W_CHAIN: return lowerINTRINSIC_W_CHAIN(Op, DAG);
611 case ISD::INTRINSIC_VOID: return lowerINTRINSIC_VOID(Op, DAG);
612 case ISD::EXTRACT_VECTOR_ELT: return lowerEXTRACT_VECTOR_ELT(Op, DAG);
613 case ISD::BUILD_VECTOR: return lowerBUILD_VECTOR(Op, DAG);
615 return lowerVECTOR_SHUFFLE(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 {
640 assert(Subtarget.isR5900());
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, N->getOperandCondCode(2)))
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))
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::getOpndList(
1351 std::deque<std::pair<unsigned, SDValue>> &RegsToPass, bool IsPICCall,
1352 bool GlobalOrExternal, bool LocalLinkage, bool IsCallReloc,
1353 CallLoweringInfo &CLI, SDValue Callee, SDValue Chain) const {
1354 Ops.push_back(Callee);
1355 MipsTargetLowering::getOpndList(Ops, RegsToPass, IsPICCall, GlobalOrExternal,
1356 LocalLinkage, IsCallReloc, CLI, Callee,
1357 Chain);
1358}
1359
1360SDValue MipsSETargetLowering::lowerLOAD(SDValue Op, SelectionDAG &DAG) const {
1361 LoadSDNode &Nd = *cast<LoadSDNode>(Op);
1362
1363 if (Nd.getMemoryVT() != MVT::f64 ||
1364 (!Subtarget.getCLOpts().mno_ldc1_sdc1 && 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 ||
1400 (!Subtarget.getCLOpts().mno_ldc1_sdc1 && Subtarget.hasMips2()))
1402
1403 // Replace a double precision store with two extractelement64s and i32 stores.
1404 SDLoc DL(Op);
1405 SDValue Val = Nd.getValue(), Ptr = Nd.getBasePtr(), Chain = Nd.getChain();
1406 EVT PtrVT = Ptr.getValueType();
1407 EVT VT = Subtarget.hasMips2() ? MVT::i32 : MVT::f32;
1408
1409 unsigned ExtractOp = Subtarget.hasMips2() ? MipsISD::ExtractElementF64
1410 : MipsISD::ExtractElementF64_FPR;
1411 SDValue Lo =
1412 DAG.getNode(ExtractOp, DL, VT, Val, DAG.getConstant(0, DL, MVT::i32));
1413 SDValue Hi =
1414 DAG.getNode(ExtractOp, DL, VT, Val, DAG.getConstant(1, DL, MVT::i32));
1415
1416 if (!Subtarget.isLittle())
1417 std::swap(Lo, Hi);
1418
1419 // i32 store to lower address.
1420 Chain = DAG.getStore(Chain, DL, Lo, Ptr, MachinePointerInfo(), Nd.getAlign(),
1421 Nd.getMemOperand()->getFlags(), Nd.getAAInfo());
1422
1423 // i32 store to higher address.
1424 Ptr = DAG.getNode(ISD::ADD, DL, PtrVT, Ptr, DAG.getConstant(4, DL, PtrVT));
1425 return DAG.getStore(Chain, DL, Hi, Ptr, MachinePointerInfo(),
1426 commonAlignment(Nd.getAlign(), 4),
1427 Nd.getMemOperand()->getFlags(), Nd.getAAInfo());
1428}
1429
1430SDValue MipsSETargetLowering::lowerBITCAST(SDValue Op,
1431 SelectionDAG &DAG) const {
1432 SDLoc DL(Op);
1433 MVT Src = Op.getOperand(0).getValueType().getSimpleVT();
1434 MVT Dest = Op.getValueType().getSimpleVT();
1435
1436 // Bitcast i64 to double.
1437 if (Src == MVT::i64 && Dest == MVT::f64) {
1438 SDValue Lo, Hi;
1439 std::tie(Lo, Hi) =
1440 DAG.SplitScalar(Op.getOperand(0), DL, MVT::i32, MVT::i32);
1441 return DAG.getNode(MipsISD::BuildPairF64, DL, MVT::f64, Lo, Hi);
1442 }
1443
1444 // Bitcast double to i64.
1445 if (Src == MVT::f64 && Dest == MVT::i64) {
1446 // Skip lower bitcast when operand0 has converted float results to integer
1447 // which was done by function SoftenFloatResult.
1448 if (getTypeAction(*DAG.getContext(), Op.getOperand(0).getValueType()) ==
1450 return SDValue();
1451 SDValue Lo =
1452 DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, Op.getOperand(0),
1453 DAG.getConstant(0, DL, MVT::i32));
1454 SDValue Hi =
1455 DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, Op.getOperand(0),
1456 DAG.getConstant(1, DL, MVT::i32));
1457 return DAG.getNode(ISD::BUILD_PAIR, DL, MVT::i64, Lo, Hi);
1458 }
1459
1460 // Skip other cases of bitcast and use default lowering.
1461 return SDValue();
1462}
1463
1464SDValue MipsSETargetLowering::lowerMulDiv(SDValue Op, unsigned NewOpc,
1465 bool HasLo, bool HasHi,
1466 SelectionDAG &DAG) const {
1467 // MIPS32r6/MIPS64r6 removed accumulator based multiplies.
1468 assert(!Subtarget.hasMips32r6());
1469
1470 EVT Ty = Op.getOperand(0).getValueType();
1471 SDLoc DL(Op);
1472 SDValue Mult = DAG.getNode(NewOpc, DL, MVT::Untyped,
1473 Op.getOperand(0), Op.getOperand(1));
1474 SDValue Lo, Hi;
1475
1476 if (HasLo)
1477 Lo = DAG.getNode(MipsISD::MFLO, DL, Ty, Mult);
1478 if (HasHi)
1479 Hi = DAG.getNode(MipsISD::MFHI, DL, Ty, Mult);
1480
1481 if (!HasLo || !HasHi)
1482 return HasLo ? Lo : Hi;
1483
1484 SDValue Vals[] = { Lo, Hi };
1485 return DAG.getMergeValues(Vals, DL);
1486}
1487
1489 SDValue InLo, InHi;
1490 std::tie(InLo, InHi) = DAG.SplitScalar(In, DL, MVT::i32, MVT::i32);
1491 return DAG.getNode(MipsISD::MTLOHI, DL, MVT::Untyped, InLo, InHi);
1492}
1493
1495 SDValue Lo = DAG.getNode(MipsISD::MFLO, DL, MVT::i32, Op);
1496 SDValue Hi = DAG.getNode(MipsISD::MFHI, DL, MVT::i32, Op);
1497 return DAG.getNode(ISD::BUILD_PAIR, DL, MVT::i64, Lo, Hi);
1498}
1499
1500// This function expands mips intrinsic nodes which have 64-bit input operands
1501// or output values.
1502//
1503// out64 = intrinsic-node in64
1504// =>
1505// lo = copy (extract-element (in64, 0))
1506// hi = copy (extract-element (in64, 1))
1507// mips-specific-node
1508// v0 = copy lo
1509// v1 = copy hi
1510// out64 = merge-values (v0, v1)
1511//
1513 SDLoc DL(Op);
1514 bool HasChainIn = Op->getOperand(0).getValueType() == MVT::Other;
1516 unsigned OpNo = 0;
1517
1518 // See if Op has a chain input.
1519 if (HasChainIn)
1520 Ops.push_back(Op->getOperand(OpNo++));
1521
1522 // The next operand is the intrinsic opcode.
1523 assert(Op->getOperand(OpNo).getOpcode() == ISD::TargetConstant);
1524
1525 // See if the next operand has type i64.
1526 SDValue Opnd = Op->getOperand(++OpNo), In64;
1527
1528 if (Opnd.getValueType() == MVT::i64)
1529 In64 = initAccumulator(Opnd, DL, DAG);
1530 else
1531 Ops.push_back(Opnd);
1532
1533 // Push the remaining operands.
1534 for (++OpNo ; OpNo < Op->getNumOperands(); ++OpNo)
1535 Ops.push_back(Op->getOperand(OpNo));
1536
1537 // Add In64 to the end of the list.
1538 if (In64.getNode())
1539 Ops.push_back(In64);
1540
1541 // Scan output.
1542 SmallVector<EVT, 2> ResTys;
1543
1544 for (EVT Ty : Op->values())
1545 ResTys.push_back((Ty == MVT::i64) ? MVT::Untyped : Ty);
1546
1547 // Create node.
1548 SDValue Val = DAG.getNode(Opc, DL, ResTys, Ops);
1549 SDValue Out = (ResTys[0] == MVT::Untyped) ? extractLOHI(Val, DL, DAG) : Val;
1550
1551 if (!HasChainIn)
1552 return Out;
1553
1554 assert(Val->getValueType(1) == MVT::Other);
1555 SDValue Vals[] = { Out, SDValue(Val.getNode(), 1) };
1556 return DAG.getMergeValues(Vals, DL);
1557}
1558
1559// Lower an MSA copy intrinsic into the specified SelectionDAG node
1561 SDLoc DL(Op);
1562 SDValue Vec = Op->getOperand(1);
1564 SDValue Idx = DAG.getZExtOrTrunc(Op->getOperand(2), DL,
1565 TLI.getVectorIdxTy(DAG.getDataLayout()));
1566 EVT ResTy = Op->getValueType(0);
1567 EVT EltTy = Vec->getValueType(0).getVectorElementType();
1568
1569 SDValue Result = DAG.getNode(Opc, DL, ResTy, Vec, Idx,
1570 DAG.getValueType(EltTy));
1571
1572 return Result;
1573}
1574
1575static SDValue lowerMSASplatZExt(SDValue Op, unsigned OpNr, SelectionDAG &DAG) {
1576 EVT ResVecTy = Op->getValueType(0);
1577 EVT ViaVecTy = ResVecTy;
1578 bool BigEndian = !DAG.getSubtarget().getTargetTriple().isLittleEndian();
1579 SDLoc DL(Op);
1580
1581 // When ResVecTy == MVT::v2i64, LaneA is the upper 32 bits of the lane and
1582 // LaneB is the lower 32-bits. Otherwise LaneA and LaneB are alternating
1583 // lanes.
1584 SDValue LaneA = Op->getOperand(OpNr);
1585 SDValue LaneB;
1586
1587 if (ResVecTy == MVT::v2i64) {
1588 // In case of the index being passed as an immediate value, set the upper
1589 // lane to 0 so that the splati.d instruction can be matched.
1590 if (isa<ConstantSDNode>(LaneA))
1591 LaneB = DAG.getConstant(0, DL, MVT::i32);
1592 // Having the index passed in a register, set the upper lane to the same
1593 // value as the lower - this results in the BUILD_VECTOR node not being
1594 // expanded through stack. This way we are able to pattern match the set of
1595 // nodes created here to splat.d.
1596 else
1597 LaneB = LaneA;
1598 ViaVecTy = MVT::v4i32;
1599 if(BigEndian)
1600 std::swap(LaneA, LaneB);
1601 } else
1602 LaneB = LaneA;
1603
1604 SDValue Ops[16] = { LaneA, LaneB, LaneA, LaneB, LaneA, LaneB, LaneA, LaneB,
1605 LaneA, LaneB, LaneA, LaneB, LaneA, LaneB, LaneA, LaneB };
1606
1607 SDValue Result = DAG.getBuildVector(
1608 ViaVecTy, DL, ArrayRef(Ops, ViaVecTy.getVectorNumElements()));
1609
1610 if (ViaVecTy != ResVecTy) {
1611 SDValue One = DAG.getConstant(1, DL, ViaVecTy);
1612 Result = DAG.getNode(ISD::BITCAST, DL, ResVecTy,
1613 DAG.getNode(ISD::AND, DL, ViaVecTy, Result, One));
1614 }
1615
1616 return Result;
1617}
1618
1619static SDValue lowerMSASplatImm(SDValue Op, unsigned ImmOp, SelectionDAG &DAG,
1620 bool IsSigned = false) {
1621 auto *CImm = cast<ConstantSDNode>(Op->getOperand(ImmOp));
1622 return DAG.getConstant(
1623 APInt(Op->getValueType(0).getScalarType().getSizeInBits(),
1624 IsSigned ? CImm->getSExtValue() : CImm->getZExtValue(), IsSigned),
1625 SDLoc(Op), Op->getValueType(0));
1626}
1627
1628static SDValue getBuildVectorSplat(EVT VecTy, SDValue SplatValue,
1629 bool BigEndian, SelectionDAG &DAG) {
1630 EVT ViaVecTy = VecTy;
1631 SDValue SplatValueA = SplatValue;
1632 SDValue SplatValueB = SplatValue;
1633 SDLoc DL(SplatValue);
1634
1635 if (VecTy == MVT::v2i64) {
1636 // v2i64 BUILD_VECTOR must be performed via v4i32 so split into i32's.
1637 ViaVecTy = MVT::v4i32;
1638
1639 SplatValueA = DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, SplatValue);
1640 SplatValueB = DAG.getNode(ISD::SRL, DL, MVT::i64, SplatValue,
1641 DAG.getConstant(32, DL, MVT::i32));
1642 SplatValueB = DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, SplatValueB);
1643 }
1644
1645 // We currently hold the parts in little endian order. Swap them if
1646 // necessary.
1647 if (BigEndian)
1648 std::swap(SplatValueA, SplatValueB);
1649
1650 SDValue Ops[16] = { SplatValueA, SplatValueB, SplatValueA, SplatValueB,
1651 SplatValueA, SplatValueB, SplatValueA, SplatValueB,
1652 SplatValueA, SplatValueB, SplatValueA, SplatValueB,
1653 SplatValueA, SplatValueB, SplatValueA, SplatValueB };
1654
1655 SDValue Result = DAG.getBuildVector(
1656 ViaVecTy, DL, ArrayRef(Ops, ViaVecTy.getVectorNumElements()));
1657
1658 if (VecTy != ViaVecTy)
1659 Result = DAG.getNode(ISD::BITCAST, DL, VecTy, Result);
1660
1661 return Result;
1662}
1663
1665 unsigned Opc, SDValue Imm,
1666 bool BigEndian) {
1667 EVT VecTy = Op->getValueType(0);
1668 SDValue Exp2Imm;
1669 SDLoc DL(Op);
1670
1671 // The DAG Combiner can't constant fold bitcasted vectors yet so we must do it
1672 // here for now.
1673 if (VecTy == MVT::v2i64) {
1675 APInt BitImm = APInt(64, 1) << CImm->getAPIntValue();
1676
1677 SDValue BitImmHiOp = DAG.getConstant(BitImm.lshr(32).trunc(32), DL,
1678 MVT::i32);
1679 SDValue BitImmLoOp = DAG.getConstant(BitImm.trunc(32), DL, MVT::i32);
1680
1681 if (BigEndian)
1682 std::swap(BitImmLoOp, BitImmHiOp);
1683
1684 Exp2Imm = DAG.getNode(
1685 ISD::BITCAST, DL, MVT::v2i64,
1686 DAG.getBuildVector(MVT::v4i32, DL,
1687 {BitImmLoOp, BitImmHiOp, BitImmLoOp, BitImmHiOp}));
1688 }
1689 }
1690
1691 if (!Exp2Imm.getNode()) {
1692 // We couldnt constant fold, do a vector shift instead
1693
1694 // Extend i32 to i64 if necessary. Sign or zero extend doesn't matter since
1695 // only values 0-63 are valid.
1696 if (VecTy == MVT::v2i64)
1697 Imm = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i64, Imm);
1698
1699 Exp2Imm = getBuildVectorSplat(VecTy, Imm, BigEndian, DAG);
1700
1701 Exp2Imm = DAG.getNode(ISD::SHL, DL, VecTy, DAG.getConstant(1, DL, VecTy),
1702 Exp2Imm);
1703 }
1704
1705 return DAG.getNode(Opc, DL, VecTy, Op->getOperand(1), Exp2Imm);
1706}
1707
1709 SDLoc DL(Op);
1710 EVT ResTy = Op->getValueType(0);
1711 SDValue Vec = Op->getOperand(2);
1712 bool BigEndian = !DAG.getSubtarget().getTargetTriple().isLittleEndian();
1713 MVT ResEltTy = ResTy == MVT::v2i64 ? MVT::i64 : MVT::i32;
1714 SDValue ConstValue = DAG.getConstant(Vec.getScalarValueSizeInBits() - 1,
1715 DL, ResEltTy);
1716 SDValue SplatVec = getBuildVectorSplat(ResTy, ConstValue, BigEndian, DAG);
1717
1718 return DAG.getNode(ISD::AND, DL, ResTy, Vec, SplatVec);
1719}
1720
1722 EVT ResTy = Op->getValueType(0);
1723 SDLoc DL(Op);
1724 SDValue One = DAG.getConstant(1, DL, ResTy);
1725 SDValue Bit = DAG.getNode(ISD::SHL, DL, ResTy, One, truncateVecElts(Op, DAG));
1726
1727 return DAG.getNode(ISD::AND, DL, ResTy, Op->getOperand(1),
1728 DAG.getNOT(DL, Bit, ResTy));
1729}
1730
1732 SDLoc DL(Op);
1733 EVT ResTy = Op->getValueType(0);
1734 APInt BitImm = APInt(ResTy.getScalarSizeInBits(), 1)
1735 << Op->getConstantOperandAPInt(2);
1736 SDValue BitMask = DAG.getConstant(~BitImm, DL, ResTy);
1737
1738 return DAG.getNode(ISD::AND, DL, ResTy, Op->getOperand(1), BitMask);
1739}
1740
1741SDValue MipsSETargetLowering::lowerINTRINSIC_WO_CHAIN(SDValue Op,
1742 SelectionDAG &DAG) const {
1743 SDLoc DL(Op);
1744 unsigned Intrinsic = Op->getConstantOperandVal(0);
1745 switch (Intrinsic) {
1746 default:
1747 return SDValue();
1748 case Intrinsic::mips_shilo:
1749 return lowerDSPIntr(Op, DAG, MipsISD::SHILO);
1750 case Intrinsic::mips_dpau_h_qbl:
1751 return lowerDSPIntr(Op, DAG, MipsISD::DPAU_H_QBL);
1752 case Intrinsic::mips_dpau_h_qbr:
1753 return lowerDSPIntr(Op, DAG, MipsISD::DPAU_H_QBR);
1754 case Intrinsic::mips_dpsu_h_qbl:
1755 return lowerDSPIntr(Op, DAG, MipsISD::DPSU_H_QBL);
1756 case Intrinsic::mips_dpsu_h_qbr:
1757 return lowerDSPIntr(Op, DAG, MipsISD::DPSU_H_QBR);
1758 case Intrinsic::mips_dpa_w_ph:
1759 return lowerDSPIntr(Op, DAG, MipsISD::DPA_W_PH);
1760 case Intrinsic::mips_dps_w_ph:
1761 return lowerDSPIntr(Op, DAG, MipsISD::DPS_W_PH);
1762 case Intrinsic::mips_dpax_w_ph:
1763 return lowerDSPIntr(Op, DAG, MipsISD::DPAX_W_PH);
1764 case Intrinsic::mips_dpsx_w_ph:
1765 return lowerDSPIntr(Op, DAG, MipsISD::DPSX_W_PH);
1766 case Intrinsic::mips_mulsa_w_ph:
1767 return lowerDSPIntr(Op, DAG, MipsISD::MULSA_W_PH);
1768 case Intrinsic::mips_mult:
1769 return lowerDSPIntr(Op, DAG, MipsISD::Mult);
1770 case Intrinsic::mips_multu:
1771 return lowerDSPIntr(Op, DAG, MipsISD::Multu);
1772 case Intrinsic::mips_madd:
1773 return lowerDSPIntr(Op, DAG, MipsISD::MAdd);
1774 case Intrinsic::mips_maddu:
1775 return lowerDSPIntr(Op, DAG, MipsISD::MAddu);
1776 case Intrinsic::mips_msub:
1777 return lowerDSPIntr(Op, DAG, MipsISD::MSub);
1778 case Intrinsic::mips_msubu:
1779 return lowerDSPIntr(Op, DAG, MipsISD::MSubu);
1780 case Intrinsic::mips_addv_b:
1781 case Intrinsic::mips_addv_h:
1782 case Intrinsic::mips_addv_w:
1783 case Intrinsic::mips_addv_d:
1784 return DAG.getNode(ISD::ADD, DL, Op->getValueType(0), Op->getOperand(1),
1785 Op->getOperand(2));
1786 case Intrinsic::mips_addvi_b:
1787 case Intrinsic::mips_addvi_h:
1788 case Intrinsic::mips_addvi_w:
1789 case Intrinsic::mips_addvi_d:
1790 return DAG.getNode(ISD::ADD, DL, Op->getValueType(0), Op->getOperand(1),
1791 lowerMSASplatImm(Op, 2, DAG));
1792 case Intrinsic::mips_and_v:
1793 return DAG.getNode(ISD::AND, DL, Op->getValueType(0), Op->getOperand(1),
1794 Op->getOperand(2));
1795 case Intrinsic::mips_andi_b:
1796 return DAG.getNode(ISD::AND, DL, Op->getValueType(0), Op->getOperand(1),
1797 lowerMSASplatImm(Op, 2, DAG));
1798 case Intrinsic::mips_bclr_b:
1799 case Intrinsic::mips_bclr_h:
1800 case Intrinsic::mips_bclr_w:
1801 case Intrinsic::mips_bclr_d:
1802 return lowerMSABitClear(Op, DAG);
1803 case Intrinsic::mips_bclri_b:
1804 case Intrinsic::mips_bclri_h:
1805 case Intrinsic::mips_bclri_w:
1806 case Intrinsic::mips_bclri_d:
1807 return lowerMSABitClearImm(Op, DAG);
1808 case Intrinsic::mips_binsli_b:
1809 case Intrinsic::mips_binsli_h:
1810 case Intrinsic::mips_binsli_w:
1811 case Intrinsic::mips_binsli_d: {
1812 // binsli_x(IfClear, IfSet, nbits) -> (vselect LBitsMask, IfSet, IfClear)
1813 EVT VecTy = Op->getValueType(0);
1814 EVT EltTy = VecTy.getVectorElementType();
1815 if (Op->getConstantOperandVal(3) >= EltTy.getSizeInBits())
1816 report_fatal_error("Immediate out of range");
1818 Op->getConstantOperandVal(3) + 1);
1819 return DAG.getNode(ISD::VSELECT, DL, VecTy,
1820 DAG.getConstant(Mask, DL, VecTy, true),
1821 Op->getOperand(2), Op->getOperand(1));
1822 }
1823 case Intrinsic::mips_binsri_b:
1824 case Intrinsic::mips_binsri_h:
1825 case Intrinsic::mips_binsri_w:
1826 case Intrinsic::mips_binsri_d: {
1827 // binsri_x(IfClear, IfSet, nbits) -> (vselect RBitsMask, IfSet, IfClear)
1828 EVT VecTy = Op->getValueType(0);
1829 EVT EltTy = VecTy.getVectorElementType();
1830 if (Op->getConstantOperandVal(3) >= EltTy.getSizeInBits())
1831 report_fatal_error("Immediate out of range");
1832 APInt Mask = APInt::getLowBitsSet(EltTy.getSizeInBits(),
1833 Op->getConstantOperandVal(3) + 1);
1834 return DAG.getNode(ISD::VSELECT, DL, VecTy,
1835 DAG.getConstant(Mask, DL, VecTy, true),
1836 Op->getOperand(2), Op->getOperand(1));
1837 }
1838 case Intrinsic::mips_bmnz_v:
1839 return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0), Op->getOperand(3),
1840 Op->getOperand(2), Op->getOperand(1));
1841 case Intrinsic::mips_bmnzi_b:
1842 return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0),
1843 lowerMSASplatImm(Op, 3, DAG), Op->getOperand(2),
1844 Op->getOperand(1));
1845 case Intrinsic::mips_bmz_v:
1846 return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0), Op->getOperand(3),
1847 Op->getOperand(1), Op->getOperand(2));
1848 case Intrinsic::mips_bmzi_b:
1849 return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0),
1850 lowerMSASplatImm(Op, 3, DAG), Op->getOperand(1),
1851 Op->getOperand(2));
1852 case Intrinsic::mips_bneg_b:
1853 case Intrinsic::mips_bneg_h:
1854 case Intrinsic::mips_bneg_w:
1855 case Intrinsic::mips_bneg_d: {
1856 EVT VecTy = Op->getValueType(0);
1857 SDValue One = DAG.getConstant(1, DL, VecTy);
1858
1859 return DAG.getNode(ISD::XOR, DL, VecTy, Op->getOperand(1),
1860 DAG.getNode(ISD::SHL, DL, VecTy, One,
1861 truncateVecElts(Op, DAG)));
1862 }
1863 case Intrinsic::mips_bnegi_b:
1864 case Intrinsic::mips_bnegi_h:
1865 case Intrinsic::mips_bnegi_w:
1866 case Intrinsic::mips_bnegi_d:
1867 return lowerMSABinaryBitImmIntr(Op, DAG, ISD::XOR, Op->getOperand(2),
1868 !Subtarget.isLittle());
1869 case Intrinsic::mips_bnz_b:
1870 case Intrinsic::mips_bnz_h:
1871 case Intrinsic::mips_bnz_w:
1872 case Intrinsic::mips_bnz_d:
1873 return DAG.getNode(MipsISD::VALL_NONZERO, DL, Op->getValueType(0),
1874 Op->getOperand(1));
1875 case Intrinsic::mips_bnz_v:
1876 return DAG.getNode(MipsISD::VANY_NONZERO, DL, Op->getValueType(0),
1877 Op->getOperand(1));
1878 case Intrinsic::mips_bsel_v:
1879 // bsel_v(Mask, IfClear, IfSet) -> (vselect Mask, IfSet, IfClear)
1880 return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0),
1881 Op->getOperand(1), Op->getOperand(3),
1882 Op->getOperand(2));
1883 case Intrinsic::mips_bseli_b:
1884 // bseli_v(Mask, IfClear, IfSet) -> (vselect Mask, IfSet, IfClear)
1885 return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0),
1886 Op->getOperand(1), lowerMSASplatImm(Op, 3, DAG),
1887 Op->getOperand(2));
1888 case Intrinsic::mips_bset_b:
1889 case Intrinsic::mips_bset_h:
1890 case Intrinsic::mips_bset_w:
1891 case Intrinsic::mips_bset_d: {
1892 EVT VecTy = Op->getValueType(0);
1893 SDValue One = DAG.getConstant(1, DL, VecTy);
1894
1895 return DAG.getNode(ISD::OR, DL, VecTy, Op->getOperand(1),
1896 DAG.getNode(ISD::SHL, DL, VecTy, One,
1897 truncateVecElts(Op, DAG)));
1898 }
1899 case Intrinsic::mips_bseti_b:
1900 case Intrinsic::mips_bseti_h:
1901 case Intrinsic::mips_bseti_w:
1902 case Intrinsic::mips_bseti_d:
1903 return lowerMSABinaryBitImmIntr(Op, DAG, ISD::OR, Op->getOperand(2),
1904 !Subtarget.isLittle());
1905 case Intrinsic::mips_bz_b:
1906 case Intrinsic::mips_bz_h:
1907 case Intrinsic::mips_bz_w:
1908 case Intrinsic::mips_bz_d:
1909 return DAG.getNode(MipsISD::VALL_ZERO, DL, Op->getValueType(0),
1910 Op->getOperand(1));
1911 case Intrinsic::mips_bz_v:
1912 return DAG.getNode(MipsISD::VANY_ZERO, DL, Op->getValueType(0),
1913 Op->getOperand(1));
1914 case Intrinsic::mips_ceq_b:
1915 case Intrinsic::mips_ceq_h:
1916 case Intrinsic::mips_ceq_w:
1917 case Intrinsic::mips_ceq_d:
1918 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1919 Op->getOperand(2), ISD::SETEQ);
1920 case Intrinsic::mips_ceqi_b:
1921 case Intrinsic::mips_ceqi_h:
1922 case Intrinsic::mips_ceqi_w:
1923 case Intrinsic::mips_ceqi_d:
1924 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1925 lowerMSASplatImm(Op, 2, DAG, true), ISD::SETEQ);
1926 case Intrinsic::mips_cle_s_b:
1927 case Intrinsic::mips_cle_s_h:
1928 case Intrinsic::mips_cle_s_w:
1929 case Intrinsic::mips_cle_s_d:
1930 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1931 Op->getOperand(2), ISD::SETLE);
1932 case Intrinsic::mips_clei_s_b:
1933 case Intrinsic::mips_clei_s_h:
1934 case Intrinsic::mips_clei_s_w:
1935 case Intrinsic::mips_clei_s_d:
1936 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1937 lowerMSASplatImm(Op, 2, DAG, true), ISD::SETLE);
1938 case Intrinsic::mips_cle_u_b:
1939 case Intrinsic::mips_cle_u_h:
1940 case Intrinsic::mips_cle_u_w:
1941 case Intrinsic::mips_cle_u_d:
1942 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1943 Op->getOperand(2), ISD::SETULE);
1944 case Intrinsic::mips_clei_u_b:
1945 case Intrinsic::mips_clei_u_h:
1946 case Intrinsic::mips_clei_u_w:
1947 case Intrinsic::mips_clei_u_d:
1948 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1949 lowerMSASplatImm(Op, 2, DAG), ISD::SETULE);
1950 case Intrinsic::mips_clt_s_b:
1951 case Intrinsic::mips_clt_s_h:
1952 case Intrinsic::mips_clt_s_w:
1953 case Intrinsic::mips_clt_s_d:
1954 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1955 Op->getOperand(2), ISD::SETLT);
1956 case Intrinsic::mips_clti_s_b:
1957 case Intrinsic::mips_clti_s_h:
1958 case Intrinsic::mips_clti_s_w:
1959 case Intrinsic::mips_clti_s_d:
1960 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1961 lowerMSASplatImm(Op, 2, DAG, true), ISD::SETLT);
1962 case Intrinsic::mips_clt_u_b:
1963 case Intrinsic::mips_clt_u_h:
1964 case Intrinsic::mips_clt_u_w:
1965 case Intrinsic::mips_clt_u_d:
1966 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1967 Op->getOperand(2), ISD::SETULT);
1968 case Intrinsic::mips_clti_u_b:
1969 case Intrinsic::mips_clti_u_h:
1970 case Intrinsic::mips_clti_u_w:
1971 case Intrinsic::mips_clti_u_d:
1972 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1973 lowerMSASplatImm(Op, 2, DAG), ISD::SETULT);
1974 case Intrinsic::mips_copy_s_b:
1975 case Intrinsic::mips_copy_s_h:
1976 case Intrinsic::mips_copy_s_w:
1977 return lowerMSACopyIntr(Op, DAG, MipsISD::VEXTRACT_SEXT_ELT);
1978 case Intrinsic::mips_copy_s_d:
1979 if (Subtarget.hasMips64())
1980 // Lower directly into VEXTRACT_SEXT_ELT since i64 is legal on Mips64.
1981 return lowerMSACopyIntr(Op, DAG, MipsISD::VEXTRACT_SEXT_ELT);
1982 else {
1983 // Lower into the generic EXTRACT_VECTOR_ELT node and let the type
1984 // legalizer and EXTRACT_VECTOR_ELT lowering sort it out.
1985 return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SDLoc(Op),
1986 Op->getValueType(0), Op->getOperand(1),
1987 Op->getOperand(2));
1988 }
1989 case Intrinsic::mips_copy_u_b:
1990 case Intrinsic::mips_copy_u_h:
1991 case Intrinsic::mips_copy_u_w:
1992 return lowerMSACopyIntr(Op, DAG, MipsISD::VEXTRACT_ZEXT_ELT);
1993 case Intrinsic::mips_copy_u_d:
1994 if (Subtarget.hasMips64())
1995 // Lower directly into VEXTRACT_ZEXT_ELT since i64 is legal on Mips64.
1996 return lowerMSACopyIntr(Op, DAG, MipsISD::VEXTRACT_ZEXT_ELT);
1997 else {
1998 // Lower into the generic EXTRACT_VECTOR_ELT node and let the type
1999 // legalizer and EXTRACT_VECTOR_ELT lowering sort it out.
2000 // Note: When i64 is illegal, this results in copy_s.w instructions
2001 // instead of copy_u.w instructions. This makes no difference to the
2002 // behaviour since i64 is only illegal when the register file is 32-bit.
2003 return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SDLoc(Op),
2004 Op->getValueType(0), Op->getOperand(1),
2005 Op->getOperand(2));
2006 }
2007 case Intrinsic::mips_div_s_b:
2008 case Intrinsic::mips_div_s_h:
2009 case Intrinsic::mips_div_s_w:
2010 case Intrinsic::mips_div_s_d:
2011 return DAG.getNode(ISD::SDIV, DL, Op->getValueType(0), Op->getOperand(1),
2012 Op->getOperand(2));
2013 case Intrinsic::mips_div_u_b:
2014 case Intrinsic::mips_div_u_h:
2015 case Intrinsic::mips_div_u_w:
2016 case Intrinsic::mips_div_u_d:
2017 return DAG.getNode(ISD::UDIV, DL, Op->getValueType(0), Op->getOperand(1),
2018 Op->getOperand(2));
2019 case Intrinsic::mips_fadd_w:
2020 case Intrinsic::mips_fadd_d:
2021 return DAG.getNode(ISD::FADD, DL, Op->getValueType(0), Op->getOperand(1),
2022 Op->getOperand(2), Op->getFlags());
2023 // Don't lower mips_fcaf_[wd] since LLVM folds SETFALSE condcodes away
2024 case Intrinsic::mips_fceq_w:
2025 case Intrinsic::mips_fceq_d:
2026 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2027 Op->getOperand(2), ISD::SETOEQ);
2028 case Intrinsic::mips_fcle_w:
2029 case Intrinsic::mips_fcle_d:
2030 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2031 Op->getOperand(2), ISD::SETOLE);
2032 case Intrinsic::mips_fclt_w:
2033 case Intrinsic::mips_fclt_d:
2034 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2035 Op->getOperand(2), ISD::SETOLT);
2036 case Intrinsic::mips_fcne_w:
2037 case Intrinsic::mips_fcne_d:
2038 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2039 Op->getOperand(2), ISD::SETONE);
2040 case Intrinsic::mips_fcor_w:
2041 case Intrinsic::mips_fcor_d:
2042 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2043 Op->getOperand(2), ISD::SETO);
2044 case Intrinsic::mips_fcueq_w:
2045 case Intrinsic::mips_fcueq_d:
2046 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2047 Op->getOperand(2), ISD::SETUEQ);
2048 case Intrinsic::mips_fcule_w:
2049 case Intrinsic::mips_fcule_d:
2050 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2051 Op->getOperand(2), ISD::SETULE);
2052 case Intrinsic::mips_fcult_w:
2053 case Intrinsic::mips_fcult_d:
2054 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2055 Op->getOperand(2), ISD::SETULT);
2056 case Intrinsic::mips_fcun_w:
2057 case Intrinsic::mips_fcun_d:
2058 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2059 Op->getOperand(2), ISD::SETUO);
2060 case Intrinsic::mips_fcune_w:
2061 case Intrinsic::mips_fcune_d:
2062 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2063 Op->getOperand(2), ISD::SETUNE);
2064 case Intrinsic::mips_fdiv_w:
2065 case Intrinsic::mips_fdiv_d:
2066 // TODO: If intrinsics have fast-math-flags, propagate them.
2067 return DAG.getNode(ISD::FDIV, DL, Op->getValueType(0), Op->getOperand(1),
2068 Op->getOperand(2));
2069 case Intrinsic::mips_ffint_u_w:
2070 case Intrinsic::mips_ffint_u_d:
2071 return DAG.getNode(ISD::UINT_TO_FP, DL, Op->getValueType(0),
2072 Op->getOperand(1));
2073 case Intrinsic::mips_ffint_s_w:
2074 case Intrinsic::mips_ffint_s_d:
2075 return DAG.getNode(ISD::SINT_TO_FP, DL, Op->getValueType(0),
2076 Op->getOperand(1));
2077 case Intrinsic::mips_fill_b:
2078 case Intrinsic::mips_fill_h:
2079 case Intrinsic::mips_fill_w:
2080 case Intrinsic::mips_fill_d: {
2081 EVT ResTy = Op->getValueType(0);
2083 Op->getOperand(1));
2084
2085 // If ResTy is v2i64 then the type legalizer will break this node down into
2086 // an equivalent v4i32.
2087 return DAG.getBuildVector(ResTy, DL, Ops);
2088 }
2089 case Intrinsic::mips_fexp2_w:
2090 case Intrinsic::mips_fexp2_d: {
2091 // TODO: If intrinsics have fast-math-flags, propagate them.
2092 EVT ResTy = Op->getValueType(0);
2093 return DAG.getNode(
2094 ISD::FMUL, SDLoc(Op), ResTy, Op->getOperand(1),
2095 DAG.getNode(ISD::FEXP2, SDLoc(Op), ResTy, Op->getOperand(2)));
2096 }
2097 case Intrinsic::mips_flog2_w:
2098 case Intrinsic::mips_flog2_d:
2099 return DAG.getNode(ISD::FLOG2, DL, Op->getValueType(0), Op->getOperand(1));
2100 case Intrinsic::mips_fmadd_w:
2101 case Intrinsic::mips_fmadd_d:
2102 return DAG.getNode(ISD::FMA, SDLoc(Op), Op->getValueType(0),
2103 Op->getOperand(1), Op->getOperand(2), Op->getOperand(3));
2104 case Intrinsic::mips_fmul_w:
2105 case Intrinsic::mips_fmul_d:
2106 return DAG.getNode(ISD::FMUL, DL, Op->getValueType(0), Op->getOperand(1),
2107 Op->getOperand(2), Op->getFlags());
2108 case Intrinsic::mips_fmsub_w:
2109 case Intrinsic::mips_fmsub_d: {
2110 // TODO: If intrinsics have fast-math-flags, propagate them.
2111 return DAG.getNode(MipsISD::FMS, SDLoc(Op), Op->getValueType(0),
2112 Op->getOperand(1), Op->getOperand(2), Op->getOperand(3));
2113 }
2114 case Intrinsic::mips_frint_w:
2115 case Intrinsic::mips_frint_d:
2116 return DAG.getNode(ISD::FRINT, DL, Op->getValueType(0), Op->getOperand(1));
2117 case Intrinsic::mips_fsqrt_w:
2118 case Intrinsic::mips_fsqrt_d:
2119 return DAG.getNode(ISD::FSQRT, DL, Op->getValueType(0), Op->getOperand(1));
2120 case Intrinsic::mips_fsub_w:
2121 case Intrinsic::mips_fsub_d:
2122 return DAG.getNode(ISD::FSUB, DL, Op->getValueType(0), Op->getOperand(1),
2123 Op->getOperand(2), Op->getFlags());
2124 case Intrinsic::mips_ftrunc_u_w:
2125 case Intrinsic::mips_ftrunc_u_d:
2126 return DAG.getNode(ISD::FP_TO_UINT, DL, Op->getValueType(0),
2127 Op->getOperand(1));
2128 case Intrinsic::mips_ftrunc_s_w:
2129 case Intrinsic::mips_ftrunc_s_d:
2130 return DAG.getNode(ISD::FP_TO_SINT, DL, Op->getValueType(0),
2131 Op->getOperand(1));
2132 case Intrinsic::mips_ilvev_b:
2133 case Intrinsic::mips_ilvev_h:
2134 case Intrinsic::mips_ilvev_w:
2135 case Intrinsic::mips_ilvev_d:
2136 return DAG.getNode(MipsISD::ILVEV, DL, Op->getValueType(0),
2137 Op->getOperand(1), Op->getOperand(2));
2138 case Intrinsic::mips_ilvl_b:
2139 case Intrinsic::mips_ilvl_h:
2140 case Intrinsic::mips_ilvl_w:
2141 case Intrinsic::mips_ilvl_d:
2142 return DAG.getNode(MipsISD::ILVL, DL, Op->getValueType(0),
2143 Op->getOperand(1), Op->getOperand(2));
2144 case Intrinsic::mips_ilvod_b:
2145 case Intrinsic::mips_ilvod_h:
2146 case Intrinsic::mips_ilvod_w:
2147 case Intrinsic::mips_ilvod_d:
2148 return DAG.getNode(MipsISD::ILVOD, DL, Op->getValueType(0),
2149 Op->getOperand(1), Op->getOperand(2));
2150 case Intrinsic::mips_ilvr_b:
2151 case Intrinsic::mips_ilvr_h:
2152 case Intrinsic::mips_ilvr_w:
2153 case Intrinsic::mips_ilvr_d:
2154 return DAG.getNode(MipsISD::ILVR, DL, Op->getValueType(0),
2155 Op->getOperand(1), Op->getOperand(2));
2156 case Intrinsic::mips_insert_b:
2157 case Intrinsic::mips_insert_h:
2158 case Intrinsic::mips_insert_w:
2159 case Intrinsic::mips_insert_d:
2160 return DAG.getNode(ISD::INSERT_VECTOR_ELT, SDLoc(Op), Op->getValueType(0),
2161 Op->getOperand(1), Op->getOperand(3), Op->getOperand(2));
2162 case Intrinsic::mips_insve_b:
2163 case Intrinsic::mips_insve_h:
2164 case Intrinsic::mips_insve_w:
2165 case Intrinsic::mips_insve_d: {
2166 // Report an error for out of range values.
2167 int64_t Max;
2168 switch (Intrinsic) {
2169 case Intrinsic::mips_insve_b: Max = 15; break;
2170 case Intrinsic::mips_insve_h: Max = 7; break;
2171 case Intrinsic::mips_insve_w: Max = 3; break;
2172 case Intrinsic::mips_insve_d: Max = 1; break;
2173 default: llvm_unreachable("Unmatched intrinsic");
2174 }
2175 int64_t Value = cast<ConstantSDNode>(Op->getOperand(2))->getSExtValue();
2176 if (Value < 0 || Value > Max)
2177 report_fatal_error("Immediate out of range");
2178 return DAG.getNode(MipsISD::INSVE, DL, Op->getValueType(0),
2179 Op->getOperand(1), Op->getOperand(2), Op->getOperand(3),
2180 DAG.getConstant(0, DL, MVT::i32));
2181 }
2182 case Intrinsic::mips_ldi_b:
2183 case Intrinsic::mips_ldi_h:
2184 case Intrinsic::mips_ldi_w:
2185 case Intrinsic::mips_ldi_d:
2186 return lowerMSASplatImm(Op, 1, DAG, true);
2187 case Intrinsic::mips_lsa:
2188 case Intrinsic::mips_dlsa: {
2189 EVT ResTy = Op->getValueType(0);
2190 return DAG.getNode(ISD::ADD, SDLoc(Op), ResTy, Op->getOperand(1),
2191 DAG.getNode(ISD::SHL, SDLoc(Op), ResTy,
2192 Op->getOperand(2), Op->getOperand(3)));
2193 }
2194 case Intrinsic::mips_maddv_b:
2195 case Intrinsic::mips_maddv_h:
2196 case Intrinsic::mips_maddv_w:
2197 case Intrinsic::mips_maddv_d: {
2198 EVT ResTy = Op->getValueType(0);
2199 return DAG.getNode(ISD::ADD, SDLoc(Op), ResTy, Op->getOperand(1),
2200 DAG.getNode(ISD::MUL, SDLoc(Op), ResTy,
2201 Op->getOperand(2), Op->getOperand(3)));
2202 }
2203 case Intrinsic::mips_max_s_b:
2204 case Intrinsic::mips_max_s_h:
2205 case Intrinsic::mips_max_s_w:
2206 case Intrinsic::mips_max_s_d:
2207 return DAG.getNode(ISD::SMAX, DL, Op->getValueType(0),
2208 Op->getOperand(1), Op->getOperand(2));
2209 case Intrinsic::mips_max_u_b:
2210 case Intrinsic::mips_max_u_h:
2211 case Intrinsic::mips_max_u_w:
2212 case Intrinsic::mips_max_u_d:
2213 return DAG.getNode(ISD::UMAX, DL, Op->getValueType(0),
2214 Op->getOperand(1), Op->getOperand(2));
2215 case Intrinsic::mips_maxi_s_b:
2216 case Intrinsic::mips_maxi_s_h:
2217 case Intrinsic::mips_maxi_s_w:
2218 case Intrinsic::mips_maxi_s_d:
2219 return DAG.getNode(ISD::SMAX, DL, Op->getValueType(0),
2220 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG, true));
2221 case Intrinsic::mips_maxi_u_b:
2222 case Intrinsic::mips_maxi_u_h:
2223 case Intrinsic::mips_maxi_u_w:
2224 case Intrinsic::mips_maxi_u_d:
2225 return DAG.getNode(ISD::UMAX, DL, Op->getValueType(0),
2226 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
2227 case Intrinsic::mips_min_s_b:
2228 case Intrinsic::mips_min_s_h:
2229 case Intrinsic::mips_min_s_w:
2230 case Intrinsic::mips_min_s_d:
2231 return DAG.getNode(ISD::SMIN, DL, Op->getValueType(0),
2232 Op->getOperand(1), Op->getOperand(2));
2233 case Intrinsic::mips_min_u_b:
2234 case Intrinsic::mips_min_u_h:
2235 case Intrinsic::mips_min_u_w:
2236 case Intrinsic::mips_min_u_d:
2237 return DAG.getNode(ISD::UMIN, DL, Op->getValueType(0),
2238 Op->getOperand(1), Op->getOperand(2));
2239 case Intrinsic::mips_mini_s_b:
2240 case Intrinsic::mips_mini_s_h:
2241 case Intrinsic::mips_mini_s_w:
2242 case Intrinsic::mips_mini_s_d:
2243 return DAG.getNode(ISD::SMIN, DL, Op->getValueType(0),
2244 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG, true));
2245 case Intrinsic::mips_mini_u_b:
2246 case Intrinsic::mips_mini_u_h:
2247 case Intrinsic::mips_mini_u_w:
2248 case Intrinsic::mips_mini_u_d:
2249 return DAG.getNode(ISD::UMIN, DL, Op->getValueType(0),
2250 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
2251 case Intrinsic::mips_mod_s_b:
2252 case Intrinsic::mips_mod_s_h:
2253 case Intrinsic::mips_mod_s_w:
2254 case Intrinsic::mips_mod_s_d:
2255 return DAG.getNode(ISD::SREM, DL, Op->getValueType(0), Op->getOperand(1),
2256 Op->getOperand(2));
2257 case Intrinsic::mips_mod_u_b:
2258 case Intrinsic::mips_mod_u_h:
2259 case Intrinsic::mips_mod_u_w:
2260 case Intrinsic::mips_mod_u_d:
2261 return DAG.getNode(ISD::UREM, DL, Op->getValueType(0), Op->getOperand(1),
2262 Op->getOperand(2));
2263 case Intrinsic::mips_mulv_b:
2264 case Intrinsic::mips_mulv_h:
2265 case Intrinsic::mips_mulv_w:
2266 case Intrinsic::mips_mulv_d:
2267 return DAG.getNode(ISD::MUL, DL, Op->getValueType(0), Op->getOperand(1),
2268 Op->getOperand(2));
2269 case Intrinsic::mips_msubv_b:
2270 case Intrinsic::mips_msubv_h:
2271 case Intrinsic::mips_msubv_w:
2272 case Intrinsic::mips_msubv_d: {
2273 EVT ResTy = Op->getValueType(0);
2274 return DAG.getNode(ISD::SUB, SDLoc(Op), ResTy, Op->getOperand(1),
2275 DAG.getNode(ISD::MUL, SDLoc(Op), ResTy,
2276 Op->getOperand(2), Op->getOperand(3)));
2277 }
2278 case Intrinsic::mips_nlzc_b:
2279 case Intrinsic::mips_nlzc_h:
2280 case Intrinsic::mips_nlzc_w:
2281 case Intrinsic::mips_nlzc_d:
2282 return DAG.getNode(ISD::CTLZ, DL, Op->getValueType(0), Op->getOperand(1));
2283 case Intrinsic::mips_nor_v: {
2284 SDValue Res = DAG.getNode(ISD::OR, DL, Op->getValueType(0),
2285 Op->getOperand(1), Op->getOperand(2));
2286 return DAG.getNOT(DL, Res, Res->getValueType(0));
2287 }
2288 case Intrinsic::mips_nori_b: {
2289 SDValue Res = DAG.getNode(ISD::OR, DL, Op->getValueType(0),
2290 Op->getOperand(1),
2291 lowerMSASplatImm(Op, 2, DAG));
2292 return DAG.getNOT(DL, Res, Res->getValueType(0));
2293 }
2294 case Intrinsic::mips_or_v:
2295 return DAG.getNode(ISD::OR, DL, Op->getValueType(0), Op->getOperand(1),
2296 Op->getOperand(2));
2297 case Intrinsic::mips_ori_b:
2298 return DAG.getNode(ISD::OR, DL, Op->getValueType(0),
2299 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
2300 case Intrinsic::mips_pckev_b:
2301 case Intrinsic::mips_pckev_h:
2302 case Intrinsic::mips_pckev_w:
2303 case Intrinsic::mips_pckev_d:
2304 return DAG.getNode(MipsISD::PCKEV, DL, Op->getValueType(0),
2305 Op->getOperand(1), Op->getOperand(2));
2306 case Intrinsic::mips_pckod_b:
2307 case Intrinsic::mips_pckod_h:
2308 case Intrinsic::mips_pckod_w:
2309 case Intrinsic::mips_pckod_d:
2310 return DAG.getNode(MipsISD::PCKOD, DL, Op->getValueType(0),
2311 Op->getOperand(1), Op->getOperand(2));
2312 case Intrinsic::mips_pcnt_b:
2313 case Intrinsic::mips_pcnt_h:
2314 case Intrinsic::mips_pcnt_w:
2315 case Intrinsic::mips_pcnt_d:
2316 return DAG.getNode(ISD::CTPOP, DL, Op->getValueType(0), Op->getOperand(1));
2317 case Intrinsic::mips_sat_s_b:
2318 case Intrinsic::mips_sat_s_h:
2319 case Intrinsic::mips_sat_s_w:
2320 case Intrinsic::mips_sat_s_d:
2321 case Intrinsic::mips_sat_u_b:
2322 case Intrinsic::mips_sat_u_h:
2323 case Intrinsic::mips_sat_u_w:
2324 case Intrinsic::mips_sat_u_d: {
2325 // Report an error for out of range values.
2326 int64_t Max;
2327 switch (Intrinsic) {
2328 case Intrinsic::mips_sat_s_b:
2329 case Intrinsic::mips_sat_u_b: Max = 7; break;
2330 case Intrinsic::mips_sat_s_h:
2331 case Intrinsic::mips_sat_u_h: Max = 15; break;
2332 case Intrinsic::mips_sat_s_w:
2333 case Intrinsic::mips_sat_u_w: Max = 31; break;
2334 case Intrinsic::mips_sat_s_d:
2335 case Intrinsic::mips_sat_u_d: Max = 63; break;
2336 default: llvm_unreachable("Unmatched intrinsic");
2337 }
2338 int64_t Value = cast<ConstantSDNode>(Op->getOperand(2))->getSExtValue();
2339 if (Value < 0 || Value > Max)
2340 report_fatal_error("Immediate out of range");
2341 return SDValue();
2342 }
2343 case Intrinsic::mips_shf_b:
2344 case Intrinsic::mips_shf_h:
2345 case Intrinsic::mips_shf_w: {
2346 int64_t Value = cast<ConstantSDNode>(Op->getOperand(2))->getSExtValue();
2347 if (Value < 0 || Value > 255)
2348 report_fatal_error("Immediate out of range");
2349 return DAG.getNode(MipsISD::SHF, DL, Op->getValueType(0),
2350 Op->getOperand(2), Op->getOperand(1));
2351 }
2352 case Intrinsic::mips_sldi_b:
2353 case Intrinsic::mips_sldi_h:
2354 case Intrinsic::mips_sldi_w:
2355 case Intrinsic::mips_sldi_d: {
2356 // Report an error for out of range values.
2357 int64_t Max;
2358 switch (Intrinsic) {
2359 case Intrinsic::mips_sldi_b: Max = 15; break;
2360 case Intrinsic::mips_sldi_h: Max = 7; break;
2361 case Intrinsic::mips_sldi_w: Max = 3; break;
2362 case Intrinsic::mips_sldi_d: Max = 1; break;
2363 default: llvm_unreachable("Unmatched intrinsic");
2364 }
2365 int64_t Value = cast<ConstantSDNode>(Op->getOperand(3))->getSExtValue();
2366 if (Value < 0 || Value > Max)
2367 report_fatal_error("Immediate out of range");
2368 return SDValue();
2369 }
2370 case Intrinsic::mips_sll_b:
2371 case Intrinsic::mips_sll_h:
2372 case Intrinsic::mips_sll_w:
2373 case Intrinsic::mips_sll_d:
2374 return DAG.getNode(ISD::SHL, DL, Op->getValueType(0), Op->getOperand(1),
2375 truncateVecElts(Op, DAG));
2376 case Intrinsic::mips_slli_b:
2377 case Intrinsic::mips_slli_h:
2378 case Intrinsic::mips_slli_w:
2379 case Intrinsic::mips_slli_d:
2380 return DAG.getNode(ISD::SHL, DL, Op->getValueType(0),
2381 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
2382 case Intrinsic::mips_splat_b:
2383 case Intrinsic::mips_splat_h:
2384 case Intrinsic::mips_splat_w:
2385 case Intrinsic::mips_splat_d:
2386 // We can't lower via VECTOR_SHUFFLE because it requires constant shuffle
2387 // masks, nor can we lower via BUILD_VECTOR & EXTRACT_VECTOR_ELT because
2388 // EXTRACT_VECTOR_ELT can't extract i64's on MIPS32.
2389 // Instead we lower to MipsISD::VSHF and match from there.
2390 return DAG.getNode(MipsISD::VSHF, DL, Op->getValueType(0),
2391 lowerMSASplatZExt(Op, 2, DAG), Op->getOperand(1),
2392 Op->getOperand(1));
2393 case Intrinsic::mips_splati_b:
2394 case Intrinsic::mips_splati_h:
2395 case Intrinsic::mips_splati_w:
2396 case Intrinsic::mips_splati_d:
2397 return DAG.getNode(MipsISD::VSHF, DL, Op->getValueType(0),
2398 lowerMSASplatImm(Op, 2, DAG), Op->getOperand(1),
2399 Op->getOperand(1));
2400 case Intrinsic::mips_sra_b:
2401 case Intrinsic::mips_sra_h:
2402 case Intrinsic::mips_sra_w:
2403 case Intrinsic::mips_sra_d:
2404 return DAG.getNode(ISD::SRA, DL, Op->getValueType(0), Op->getOperand(1),
2405 truncateVecElts(Op, DAG));
2406 case Intrinsic::mips_srai_b:
2407 case Intrinsic::mips_srai_h:
2408 case Intrinsic::mips_srai_w:
2409 case Intrinsic::mips_srai_d:
2410 return DAG.getNode(ISD::SRA, DL, Op->getValueType(0),
2411 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
2412 case Intrinsic::mips_srari_b:
2413 case Intrinsic::mips_srari_h:
2414 case Intrinsic::mips_srari_w:
2415 case Intrinsic::mips_srari_d: {
2416 // Report an error for out of range values.
2417 int64_t Max;
2418 switch (Intrinsic) {
2419 case Intrinsic::mips_srari_b: Max = 7; break;
2420 case Intrinsic::mips_srari_h: Max = 15; break;
2421 case Intrinsic::mips_srari_w: Max = 31; break;
2422 case Intrinsic::mips_srari_d: Max = 63; break;
2423 default: llvm_unreachable("Unmatched intrinsic");
2424 }
2425 int64_t Value = cast<ConstantSDNode>(Op->getOperand(2))->getSExtValue();
2426 if (Value < 0 || Value > Max)
2427 report_fatal_error("Immediate out of range");
2428 return SDValue();
2429 }
2430 case Intrinsic::mips_srl_b:
2431 case Intrinsic::mips_srl_h:
2432 case Intrinsic::mips_srl_w:
2433 case Intrinsic::mips_srl_d:
2434 return DAG.getNode(ISD::SRL, DL, Op->getValueType(0), Op->getOperand(1),
2435 truncateVecElts(Op, DAG));
2436 case Intrinsic::mips_srli_b:
2437 case Intrinsic::mips_srli_h:
2438 case Intrinsic::mips_srli_w:
2439 case Intrinsic::mips_srli_d:
2440 return DAG.getNode(ISD::SRL, DL, Op->getValueType(0),
2441 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
2442 case Intrinsic::mips_srlri_b:
2443 case Intrinsic::mips_srlri_h:
2444 case Intrinsic::mips_srlri_w:
2445 case Intrinsic::mips_srlri_d: {
2446 // Report an error for out of range values.
2447 int64_t Max;
2448 switch (Intrinsic) {
2449 case Intrinsic::mips_srlri_b: Max = 7; break;
2450 case Intrinsic::mips_srlri_h: Max = 15; break;
2451 case Intrinsic::mips_srlri_w: Max = 31; break;
2452 case Intrinsic::mips_srlri_d: Max = 63; break;
2453 default: llvm_unreachable("Unmatched intrinsic");
2454 }
2455 int64_t Value = cast<ConstantSDNode>(Op->getOperand(2))->getSExtValue();
2456 if (Value < 0 || Value > Max)
2457 report_fatal_error("Immediate out of range");
2458 return SDValue();
2459 }
2460 case Intrinsic::mips_subv_b:
2461 case Intrinsic::mips_subv_h:
2462 case Intrinsic::mips_subv_w:
2463 case Intrinsic::mips_subv_d:
2464 return DAG.getNode(ISD::SUB, DL, Op->getValueType(0), Op->getOperand(1),
2465 Op->getOperand(2));
2466 case Intrinsic::mips_subvi_b:
2467 case Intrinsic::mips_subvi_h:
2468 case Intrinsic::mips_subvi_w:
2469 case Intrinsic::mips_subvi_d:
2470 return DAG.getNode(ISD::SUB, DL, Op->getValueType(0),
2471 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
2472 case Intrinsic::mips_vshf_b:
2473 case Intrinsic::mips_vshf_h:
2474 case Intrinsic::mips_vshf_w:
2475 case Intrinsic::mips_vshf_d:
2476 return DAG.getNode(MipsISD::VSHF, DL, Op->getValueType(0),
2477 Op->getOperand(1), Op->getOperand(2), Op->getOperand(3));
2478 case Intrinsic::mips_xor_v:
2479 return DAG.getNode(ISD::XOR, DL, Op->getValueType(0), Op->getOperand(1),
2480 Op->getOperand(2));
2481 case Intrinsic::mips_xori_b:
2482 return DAG.getNode(ISD::XOR, DL, Op->getValueType(0),
2483 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
2484 case Intrinsic::thread_pointer: {
2485 EVT PtrVT = getPointerTy(DAG.getDataLayout());
2486 return DAG.getNode(MipsISD::ThreadPointer, DL, PtrVT);
2487 }
2488 }
2489}
2490
2491static SDValue lowerMSALoadIntr(SDValue Op, SelectionDAG &DAG, unsigned Intr,
2492 const MipsSubtarget &Subtarget) {
2493 SDLoc DL(Op);
2494 SDValue ChainIn = Op->getOperand(0);
2495 SDValue Address = Op->getOperand(2);
2496 SDValue Offset = Op->getOperand(3);
2497 EVT ResTy = Op->getValueType(0);
2498 EVT PtrTy = Address->getValueType(0);
2499
2500 // For N64 addresses have the underlying type MVT::i64. This intrinsic
2501 // however takes an i32 signed constant offset. The actual type of the
2502 // intrinsic is a scaled signed i10.
2503 if (Subtarget.isABI_N64())
2504 Offset = DAG.getNode(ISD::SIGN_EXTEND, DL, PtrTy, Offset);
2505
2506 Address = DAG.getNode(ISD::ADD, DL, PtrTy, Address, Offset);
2507 return DAG.getLoad(ResTy, DL, ChainIn, Address, MachinePointerInfo(),
2508 Align(16));
2509}
2510
2511SDValue MipsSETargetLowering::lowerINTRINSIC_W_CHAIN(SDValue Op,
2512 SelectionDAG &DAG) const {
2513 unsigned Intr = Op->getConstantOperandVal(1);
2514 switch (Intr) {
2515 default:
2516 return SDValue();
2517 case Intrinsic::mips_extp:
2518 return lowerDSPIntr(Op, DAG, MipsISD::EXTP);
2519 case Intrinsic::mips_extpdp:
2520 return lowerDSPIntr(Op, DAG, MipsISD::EXTPDP);
2521 case Intrinsic::mips_extr_w:
2522 return lowerDSPIntr(Op, DAG, MipsISD::EXTR_W);
2523 case Intrinsic::mips_extr_r_w:
2524 return lowerDSPIntr(Op, DAG, MipsISD::EXTR_R_W);
2525 case Intrinsic::mips_extr_rs_w:
2526 return lowerDSPIntr(Op, DAG, MipsISD::EXTR_RS_W);
2527 case Intrinsic::mips_extr_s_h:
2528 return lowerDSPIntr(Op, DAG, MipsISD::EXTR_S_H);
2529 case Intrinsic::mips_mthlip:
2530 return lowerDSPIntr(Op, DAG, MipsISD::MTHLIP);
2531 case Intrinsic::mips_mulsaq_s_w_ph:
2532 return lowerDSPIntr(Op, DAG, MipsISD::MULSAQ_S_W_PH);
2533 case Intrinsic::mips_maq_s_w_phl:
2534 return lowerDSPIntr(Op, DAG, MipsISD::MAQ_S_W_PHL);
2535 case Intrinsic::mips_maq_s_w_phr:
2536 return lowerDSPIntr(Op, DAG, MipsISD::MAQ_S_W_PHR);
2537 case Intrinsic::mips_maq_sa_w_phl:
2538 return lowerDSPIntr(Op, DAG, MipsISD::MAQ_SA_W_PHL);
2539 case Intrinsic::mips_maq_sa_w_phr:
2540 return lowerDSPIntr(Op, DAG, MipsISD::MAQ_SA_W_PHR);
2541 case Intrinsic::mips_dpaq_s_w_ph:
2542 return lowerDSPIntr(Op, DAG, MipsISD::DPAQ_S_W_PH);
2543 case Intrinsic::mips_dpsq_s_w_ph:
2544 return lowerDSPIntr(Op, DAG, MipsISD::DPSQ_S_W_PH);
2545 case Intrinsic::mips_dpaq_sa_l_w:
2546 return lowerDSPIntr(Op, DAG, MipsISD::DPAQ_SA_L_W);
2547 case Intrinsic::mips_dpsq_sa_l_w:
2548 return lowerDSPIntr(Op, DAG, MipsISD::DPSQ_SA_L_W);
2549 case Intrinsic::mips_dpaqx_s_w_ph:
2550 return lowerDSPIntr(Op, DAG, MipsISD::DPAQX_S_W_PH);
2551 case Intrinsic::mips_dpaqx_sa_w_ph:
2552 return lowerDSPIntr(Op, DAG, MipsISD::DPAQX_SA_W_PH);
2553 case Intrinsic::mips_dpsqx_s_w_ph:
2554 return lowerDSPIntr(Op, DAG, MipsISD::DPSQX_S_W_PH);
2555 case Intrinsic::mips_dpsqx_sa_w_ph:
2556 return lowerDSPIntr(Op, DAG, MipsISD::DPSQX_SA_W_PH);
2557 case Intrinsic::mips_ld_b:
2558 case Intrinsic::mips_ld_h:
2559 case Intrinsic::mips_ld_w:
2560 case Intrinsic::mips_ld_d:
2561 return lowerMSALoadIntr(Op, DAG, Intr, Subtarget);
2562 }
2563}
2564
2566 const MipsSubtarget &Subtarget) {
2567 SDLoc DL(Op);
2568 SDValue ChainIn = Op->getOperand(0);
2569 SDValue Value = Op->getOperand(2);
2570 SDValue Address = Op->getOperand(3);
2571 SDValue Offset = Op->getOperand(4);
2572 EVT PtrTy = Address->getValueType(0);
2573
2574 // For N64 addresses have the underlying type MVT::i64. This intrinsic
2575 // however takes an i32 signed constant offset. The actual type of the
2576 // intrinsic is a scaled signed i10.
2577 if (Subtarget.isABI_N64())
2578 Offset = DAG.getNode(ISD::SIGN_EXTEND, DL, PtrTy, Offset);
2579
2580 Address = DAG.getNode(ISD::ADD, DL, PtrTy, Address, Offset);
2581
2582 return DAG.getStore(ChainIn, DL, Value, Address, MachinePointerInfo(),
2583 Align(16));
2584}
2585
2586SDValue MipsSETargetLowering::lowerINTRINSIC_VOID(SDValue Op,
2587 SelectionDAG &DAG) const {
2588 unsigned Intr = Op->getConstantOperandVal(1);
2589 switch (Intr) {
2590 default:
2591 return SDValue();
2592 case Intrinsic::mips_st_b:
2593 case Intrinsic::mips_st_h:
2594 case Intrinsic::mips_st_w:
2595 case Intrinsic::mips_st_d:
2596 return lowerMSAStoreIntr(Op, DAG, Intr, Subtarget);
2597 }
2598}
2599
2600// Lower ISD::EXTRACT_VECTOR_ELT into MipsISD::VEXTRACT_SEXT_ELT.
2601//
2602// The non-value bits resulting from ISD::EXTRACT_VECTOR_ELT are undefined. We
2603// choose to sign-extend but we could have equally chosen zero-extend. The
2604// DAGCombiner will fold any sign/zero extension of the ISD::EXTRACT_VECTOR_ELT
2605// result into this node later (possibly changing it to a zero-extend in the
2606// process).
2607SDValue MipsSETargetLowering::
2608lowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const {
2609 SDLoc DL(Op);
2610 EVT ResTy = Op->getValueType(0);
2611 SDValue Op0 = Op->getOperand(0);
2612 EVT VecTy = Op0->getValueType(0);
2613
2614 if (!VecTy.is128BitVector())
2615 return SDValue();
2616
2617 if (ResTy.isInteger()) {
2618 SDValue Op1 = Op->getOperand(1);
2619 EVT EltTy = VecTy.getVectorElementType();
2620 return DAG.getNode(MipsISD::VEXTRACT_SEXT_ELT, DL, ResTy, Op0, Op1,
2621 DAG.getValueType(EltTy));
2622 }
2623
2624 return Op;
2625}
2626
2627static bool isConstantOrUndef(const SDValue Op) {
2628 if (Op->isUndef())
2629 return true;
2631 return true;
2633 return true;
2634 return false;
2635}
2636
2638 for (unsigned i = 0; i < Op->getNumOperands(); ++i)
2639 if (isConstantOrUndef(Op->getOperand(i)))
2640 return true;
2641 return false;
2642}
2643
2644// Lowers ISD::BUILD_VECTOR into appropriate SelectionDAG nodes for the
2645// backend.
2646//
2647// Lowers according to the following rules:
2648// - Constant splats are legal as-is as long as the SplatBitSize is a power of
2649// 2 less than or equal to 64 and the value fits into a signed 10-bit
2650// immediate
2651// - Constant splats are lowered to bitconverted BUILD_VECTORs if SplatBitSize
2652// is a power of 2 less than or equal to 64 and the value does not fit into a
2653// signed 10-bit immediate
2654// - Non-constant splats are legal as-is.
2655// - Non-constant non-splats are lowered to sequences of INSERT_VECTOR_ELT.
2656// - All others are illegal and must be expanded.
2657SDValue MipsSETargetLowering::lowerBUILD_VECTOR(SDValue Op,
2658 SelectionDAG &DAG) const {
2659 BuildVectorSDNode *Node = cast<BuildVectorSDNode>(Op);
2660 EVT ResTy = Op->getValueType(0);
2661 SDLoc DL(Op);
2662 APInt SplatValue, SplatUndef;
2663 unsigned SplatBitSize;
2664 bool HasAnyUndefs;
2665
2666 if (!Subtarget.hasMSA() || !ResTy.is128BitVector())
2667 return SDValue();
2668
2669 if (Node->isConstantSplat(SplatValue, SplatUndef, SplatBitSize,
2670 HasAnyUndefs, 8,
2671 !Subtarget.isLittle()) && SplatBitSize <= 64) {
2672 // We can only cope with 8, 16, 32, or 64-bit elements
2673 if (SplatBitSize != 8 && SplatBitSize != 16 && SplatBitSize != 32 &&
2674 SplatBitSize != 64)
2675 return SDValue();
2676
2677 // If the value isn't an integer type we will have to bitcast
2678 // from an integer type first. Also, if there are any undefs, we must
2679 // lower them to defined values first.
2680 if (ResTy.isInteger() && !HasAnyUndefs)
2681 return Op;
2682
2683 EVT ViaVecTy;
2684
2685 switch (SplatBitSize) {
2686 default:
2687 return SDValue();
2688 case 8:
2689 ViaVecTy = MVT::v16i8;
2690 break;
2691 case 16:
2692 ViaVecTy = MVT::v8i16;
2693 break;
2694 case 32:
2695 ViaVecTy = MVT::v4i32;
2696 break;
2697 case 64:
2698 // There's no fill.d to fall back on for 64-bit values
2699 return SDValue();
2700 }
2701
2702 // SelectionDAG::getConstant will promote SplatValue appropriately.
2703 SDValue Result = DAG.getConstant(SplatValue, DL, ViaVecTy);
2704
2705 // Bitcast to the type we originally wanted
2706 if (ViaVecTy != ResTy)
2707 Result = DAG.getNode(ISD::BITCAST, SDLoc(Node), ResTy, Result);
2708
2709 return Result;
2710 } else if (DAG.isSplatValue(Op, /* AllowUndefs */ false))
2711 return Op;
2712 else if (!isConstantOrUndefBUILD_VECTOR(Node)) {
2713 // Use INSERT_VECTOR_ELT operations rather than expand to stores.
2714 // The resulting code is the same length as the expansion, but it doesn't
2715 // use memory operations
2716 EVT ResTy = Node->getValueType(0);
2717
2718 assert(ResTy.isVector());
2719
2720 unsigned NumElts = ResTy.getVectorNumElements();
2721 SDValue Vector = DAG.getUNDEF(ResTy);
2722 for (unsigned i = 0; i < NumElts; ++i) {
2724 Node->getOperand(i),
2725 DAG.getConstant(i, DL, MVT::i32));
2726 }
2727 return Vector;
2728 }
2729
2730 return SDValue();
2731}
2732
2733// Lower VECTOR_SHUFFLE into SHF (if possible).
2734//
2735// SHF splits the vector into blocks of four elements, then shuffles these
2736// elements according to a <4 x i2> constant (encoded as an integer immediate).
2737//
2738// It is therefore possible to lower into SHF when the mask takes the form:
2739// <a, b, c, d, a+4, b+4, c+4, d+4, a+8, b+8, c+8, d+8, ...>
2740// When undef's appear they are treated as if they were whatever value is
2741// necessary in order to fit the above forms.
2742//
2743// For example:
2744// %2 = shufflevector <8 x i16> %0, <8 x i16> undef,
2745// <8 x i32> <i32 3, i32 2, i32 1, i32 0,
2746// i32 7, i32 6, i32 5, i32 4>
2747// is lowered to:
2748// (SHF_H $w0, $w1, 27)
2749// where the 27 comes from:
2750// 3 + (2 << 2) + (1 << 4) + (0 << 6)
2752 SmallVector<int, 16> Indices,
2753 SelectionDAG &DAG) {
2754 int SHFIndices[4] = { -1, -1, -1, -1 };
2755
2756 if (Indices.size() < 4)
2757 return SDValue();
2758
2759 for (unsigned i = 0; i < 4; ++i) {
2760 for (unsigned j = i; j < Indices.size(); j += 4) {
2761 int Idx = Indices[j];
2762
2763 // Convert from vector index to 4-element subvector index
2764 // If an index refers to an element outside of the subvector then give up
2765 if (Idx != -1) {
2766 Idx -= 4 * (j / 4);
2767 if (Idx < 0 || Idx >= 4)
2768 return SDValue();
2769 }
2770
2771 // If the mask has an undef, replace it with the current index.
2772 // Note that it might still be undef if the current index is also undef
2773 if (SHFIndices[i] == -1)
2774 SHFIndices[i] = Idx;
2775
2776 // Check that non-undef values are the same as in the mask. If they
2777 // aren't then give up
2778 if (!(Idx == -1 || Idx == SHFIndices[i]))
2779 return SDValue();
2780 }
2781 }
2782
2783 // Calculate the immediate. Replace any remaining undefs with zero
2784 APInt Imm(32, 0);
2785 for (int i = 3; i >= 0; --i) {
2786 int Idx = SHFIndices[i];
2787
2788 if (Idx == -1)
2789 Idx = 0;
2790
2791 Imm <<= 2;
2792 Imm |= Idx & 0x3;
2793 }
2794
2795 SDLoc DL(Op);
2796 return DAG.getNode(MipsISD::SHF, DL, ResTy,
2797 DAG.getTargetConstant(Imm, DL, MVT::i32),
2798 Op->getOperand(0));
2799}
2800
2801/// Determine whether a range fits a regular pattern of values.
2802/// This function accounts for the possibility of jumping over the End iterator.
2803template <typename ValType>
2804static bool
2806 unsigned CheckStride,
2808 ValType ExpectedIndex, unsigned ExpectedIndexStride) {
2809 auto &I = Begin;
2810
2811 while (I != End) {
2812 if (*I != -1 && *I != ExpectedIndex)
2813 return false;
2814 ExpectedIndex += ExpectedIndexStride;
2815
2816 // Incrementing past End is undefined behaviour so we must increment one
2817 // step at a time and check for End at each step.
2818 for (unsigned n = 0; n < CheckStride && I != End; ++n, ++I)
2819 ; // Empty loop body.
2820 }
2821 return true;
2822}
2823
2824// Determine whether VECTOR_SHUFFLE is a SPLATI.
2825//
2826// It is a SPLATI when the mask is:
2827// <x, x, x, ...>
2828// where x is any valid index.
2829//
2830// When undef's appear in the mask they are treated as if they were whatever
2831// value is necessary in order to fit the above form.
2833 SmallVector<int, 16> Indices,
2834 SelectionDAG &DAG) {
2835 assert((Indices.size() % 2) == 0);
2836
2837 int SplatIndex = -1;
2838 for (const auto &V : Indices) {
2839 if (V != -1) {
2840 SplatIndex = V;
2841 break;
2842 }
2843 }
2844
2845 return fitsRegularPattern<int>(Indices.begin(), 1, Indices.end(), SplatIndex,
2846 0);
2847}
2848
2849// Lower VECTOR_SHUFFLE into ILVEV (if possible).
2850//
2851// ILVEV interleaves the even elements from each vector.
2852//
2853// It is possible to lower into ILVEV when the mask consists of two of the
2854// following forms interleaved:
2855// <0, 2, 4, ...>
2856// <n, n+2, n+4, ...>
2857// where n is the number of elements in the vector.
2858// For example:
2859// <0, 0, 2, 2, 4, 4, ...>
2860// <0, n, 2, n+2, 4, n+4, ...>
2861//
2862// When undef's appear in the mask they are treated as if they were whatever
2863// value is necessary in order to fit the above forms.
2865 SmallVector<int, 16> Indices,
2866 SelectionDAG &DAG) {
2867 assert((Indices.size() % 2) == 0);
2868
2869 SDValue Wt;
2870 SDValue Ws;
2871 const auto &Begin = Indices.begin();
2872 const auto &End = Indices.end();
2873
2874 // Check even elements are taken from the even elements of one half or the
2875 // other and pick an operand accordingly.
2876 if (fitsRegularPattern<int>(Begin, 2, End, 0, 2))
2877 Wt = Op->getOperand(0);
2878 else if (fitsRegularPattern<int>(Begin, 2, End, Indices.size(), 2))
2879 Wt = Op->getOperand(1);
2880 else
2881 return SDValue();
2882
2883 // Check odd elements are taken from the even elements of one half or the
2884 // other and pick an operand accordingly.
2885 if (fitsRegularPattern<int>(Begin + 1, 2, End, 0, 2))
2886 Ws = Op->getOperand(0);
2887 else if (fitsRegularPattern<int>(Begin + 1, 2, End, Indices.size(), 2))
2888 Ws = Op->getOperand(1);
2889 else
2890 return SDValue();
2891
2892 return DAG.getNode(MipsISD::ILVEV, SDLoc(Op), ResTy, Ws, Wt);
2893}
2894
2895// Lower VECTOR_SHUFFLE into ILVOD (if possible).
2896//
2897// ILVOD interleaves the odd elements from each vector.
2898//
2899// It is possible to lower into ILVOD when the mask consists of two of the
2900// following forms interleaved:
2901// <1, 3, 5, ...>
2902// <n+1, n+3, n+5, ...>
2903// where n is the number of elements in the vector.
2904// For example:
2905// <1, 1, 3, 3, 5, 5, ...>
2906// <1, n+1, 3, n+3, 5, n+5, ...>
2907//
2908// When undef's appear in the mask they are treated as if they were whatever
2909// value is necessary in order to fit the above forms.
2911 SmallVector<int, 16> Indices,
2912 SelectionDAG &DAG) {
2913 assert((Indices.size() % 2) == 0);
2914
2915 SDValue Wt;
2916 SDValue Ws;
2917 const auto &Begin = Indices.begin();
2918 const auto &End = Indices.end();
2919
2920 // Check even elements are taken from the odd elements of one half or the
2921 // other and pick an operand accordingly.
2922 if (fitsRegularPattern<int>(Begin, 2, End, 1, 2))
2923 Wt = Op->getOperand(0);
2924 else if (fitsRegularPattern<int>(Begin, 2, End, Indices.size() + 1, 2))
2925 Wt = Op->getOperand(1);
2926 else
2927 return SDValue();
2928
2929 // Check odd elements are taken from the odd elements of one half or the
2930 // other and pick an operand accordingly.
2931 if (fitsRegularPattern<int>(Begin + 1, 2, End, 1, 2))
2932 Ws = Op->getOperand(0);
2933 else if (fitsRegularPattern<int>(Begin + 1, 2, End, Indices.size() + 1, 2))
2934 Ws = Op->getOperand(1);
2935 else
2936 return SDValue();
2937
2938 return DAG.getNode(MipsISD::ILVOD, SDLoc(Op), ResTy, Ws, Wt);
2939}
2940
2941// Lower VECTOR_SHUFFLE into ILVR (if possible).
2942//
2943// ILVR interleaves consecutive elements from the right (lowest-indexed) half of
2944// each vector.
2945//
2946// It is possible to lower into ILVR when the mask consists of two of the
2947// following forms interleaved:
2948// <0, 1, 2, ...>
2949// <n, n+1, n+2, ...>
2950// where n is the number of elements in the vector.
2951// For example:
2952// <0, 0, 1, 1, 2, 2, ...>
2953// <0, n, 1, n+1, 2, n+2, ...>
2954//
2955// When undef's appear in the mask they are treated as if they were whatever
2956// value is necessary in order to fit the above forms.
2958 SmallVector<int, 16> Indices,
2959 SelectionDAG &DAG) {
2960 assert((Indices.size() % 2) == 0);
2961
2962 SDValue Wt;
2963 SDValue Ws;
2964 const auto &Begin = Indices.begin();
2965 const auto &End = Indices.end();
2966
2967 // Check even elements are taken from the right (lowest-indexed) elements of
2968 // one half or the other and pick an operand accordingly.
2969 if (fitsRegularPattern<int>(Begin, 2, End, 0, 1))
2970 Wt = Op->getOperand(0);
2971 else if (fitsRegularPattern<int>(Begin, 2, End, Indices.size(), 1))
2972 Wt = Op->getOperand(1);
2973 else
2974 return SDValue();
2975
2976 // Check odd elements are taken from the right (lowest-indexed) elements of
2977 // one half or the other and pick an operand accordingly.
2978 if (fitsRegularPattern<int>(Begin + 1, 2, End, 0, 1))
2979 Ws = Op->getOperand(0);
2980 else if (fitsRegularPattern<int>(Begin + 1, 2, End, Indices.size(), 1))
2981 Ws = Op->getOperand(1);
2982 else
2983 return SDValue();
2984
2985 return DAG.getNode(MipsISD::ILVR, SDLoc(Op), ResTy, Ws, Wt);
2986}
2987
2988// Lower VECTOR_SHUFFLE into ILVL (if possible).
2989//
2990// ILVL interleaves consecutive elements from the left (highest-indexed) half
2991// of each vector.
2992//
2993// It is possible to lower into ILVL when the mask consists of two of the
2994// following forms interleaved:
2995// <x, x+1, x+2, ...>
2996// <n+x, n+x+1, n+x+2, ...>
2997// where n is the number of elements in the vector and x is half n.
2998// For example:
2999// <x, x, x+1, x+1, x+2, x+2, ...>
3000// <x, n+x, x+1, n+x+1, x+2, n+x+2, ...>
3001//
3002// When undef's appear in the mask they are treated as if they were whatever
3003// value is necessary in order to fit the above forms.
3005 SmallVector<int, 16> Indices,
3006 SelectionDAG &DAG) {
3007 assert((Indices.size() % 2) == 0);
3008
3009 unsigned HalfSize = Indices.size() / 2;
3010 SDValue Wt;
3011 SDValue Ws;
3012 const auto &Begin = Indices.begin();
3013 const auto &End = Indices.end();
3014
3015 // Check even elements are taken from the left (highest-indexed) elements of
3016 // one half or the other and pick an operand accordingly.
3017 if (fitsRegularPattern<int>(Begin, 2, End, HalfSize, 1))
3018 Wt = Op->getOperand(0);
3019 else if (fitsRegularPattern<int>(Begin, 2, End, Indices.size() + HalfSize, 1))
3020 Wt = Op->getOperand(1);
3021 else
3022 return SDValue();
3023
3024 // Check odd elements are taken from the left (highest-indexed) elements of
3025 // one half or the other and pick an operand accordingly.
3026 if (fitsRegularPattern<int>(Begin + 1, 2, End, HalfSize, 1))
3027 Ws = Op->getOperand(0);
3028 else if (fitsRegularPattern<int>(Begin + 1, 2, End, Indices.size() + HalfSize,
3029 1))
3030 Ws = Op->getOperand(1);
3031 else
3032 return SDValue();
3033
3034 return DAG.getNode(MipsISD::ILVL, SDLoc(Op), ResTy, Ws, Wt);
3035}
3036
3037// Lower VECTOR_SHUFFLE into PCKEV (if possible).
3038//
3039// PCKEV copies the even elements of each vector into the result vector.
3040//
3041// It is possible to lower into PCKEV when the mask consists of two of the
3042// following forms concatenated:
3043// <0, 2, 4, ...>
3044// <n, n+2, n+4, ...>
3045// where n is the number of elements in the vector.
3046// For example:
3047// <0, 2, 4, ..., 0, 2, 4, ...>
3048// <0, 2, 4, ..., n, n+2, n+4, ...>
3049//
3050// When undef's appear in the mask they are treated as if they were whatever
3051// value is necessary in order to fit the above forms.
3053 SmallVector<int, 16> Indices,
3054 SelectionDAG &DAG) {
3055 assert((Indices.size() % 2) == 0);
3056
3057 SDValue Wt;
3058 SDValue Ws;
3059 const auto &Begin = Indices.begin();
3060 const auto &Mid = Indices.begin() + Indices.size() / 2;
3061 const auto &End = Indices.end();
3062
3063 if (fitsRegularPattern<int>(Begin, 1, Mid, 0, 2))
3064 Wt = Op->getOperand(0);
3065 else if (fitsRegularPattern<int>(Begin, 1, Mid, Indices.size(), 2))
3066 Wt = Op->getOperand(1);
3067 else
3068 return SDValue();
3069
3070 if (fitsRegularPattern<int>(Mid, 1, End, 0, 2))
3071 Ws = Op->getOperand(0);
3072 else if (fitsRegularPattern<int>(Mid, 1, End, Indices.size(), 2))
3073 Ws = Op->getOperand(1);
3074 else
3075 return SDValue();
3076
3077 return DAG.getNode(MipsISD::PCKEV, SDLoc(Op), ResTy, Ws, Wt);
3078}
3079
3080// Lower VECTOR_SHUFFLE into PCKOD (if possible).
3081//
3082// PCKOD copies the odd elements of each vector into the result vector.
3083//
3084// It is possible to lower into PCKOD when the mask consists of two of the
3085// following forms concatenated:
3086// <1, 3, 5, ...>
3087// <n+1, n+3, n+5, ...>
3088// where n is the number of elements in the vector.
3089// For example:
3090// <1, 3, 5, ..., 1, 3, 5, ...>
3091// <1, 3, 5, ..., n+1, n+3, n+5, ...>
3092//
3093// When undef's appear in the mask they are treated as if they were whatever
3094// value is necessary in order to fit the above forms.
3096 SmallVector<int, 16> Indices,
3097 SelectionDAG &DAG) {
3098 assert((Indices.size() % 2) == 0);
3099
3100 SDValue Wt;
3101 SDValue Ws;
3102 const auto &Begin = Indices.begin();
3103 const auto &Mid = Indices.begin() + Indices.size() / 2;
3104 const auto &End = Indices.end();
3105
3106 if (fitsRegularPattern<int>(Begin, 1, Mid, 1, 2))
3107 Wt = Op->getOperand(0);
3108 else if (fitsRegularPattern<int>(Begin, 1, Mid, Indices.size() + 1, 2))
3109 Wt = Op->getOperand(1);
3110 else
3111 return SDValue();
3112
3113 if (fitsRegularPattern<int>(Mid, 1, End, 1, 2))
3114 Ws = Op->getOperand(0);
3115 else if (fitsRegularPattern<int>(Mid, 1, End, Indices.size() + 1, 2))
3116 Ws = Op->getOperand(1);
3117 else
3118 return SDValue();
3119
3120 return DAG.getNode(MipsISD::PCKOD, SDLoc(Op), ResTy, Ws, Wt);
3121}
3122
3123// Lower VECTOR_SHUFFLE into VSHF.
3124//
3125// This mostly consists of converting the shuffle indices in Indices into a
3126// BUILD_VECTOR and adding it as an operand to the resulting VSHF. There is
3127// also code to eliminate unused operands of the VECTOR_SHUFFLE. For example,
3128// if the type is v8i16 and all the indices are less than 8 then the second
3129// operand is unused and can be replaced with anything. We choose to replace it
3130// with the used operand since this reduces the number of instructions overall.
3131//
3132// NOTE: SPLATI shuffle masks may contain UNDEFs, since isSPLATI() treats
3133// UNDEFs as same as SPLATI index.
3134// For other instances we use the last valid index if UNDEF is
3135// encountered.
3137 const SmallVector<int, 16> &Indices,
3138 const bool isSPLATI,
3139 SelectionDAG &DAG) {
3141 SDValue Op0;
3142 SDValue Op1;
3143 EVT MaskVecTy = ResTy.changeVectorElementTypeToInteger();
3144 EVT MaskEltTy = MaskVecTy.getVectorElementType();
3145 bool Using1stVec = false;
3146 bool Using2ndVec = false;
3147 SDLoc DL(Op);
3148 int ResTyNumElts = ResTy.getVectorNumElements();
3149
3150 for (int i = 0; i < ResTyNumElts; ++i) {
3151 // Idx == -1 means UNDEF/poison
3152 int Idx = Indices[i];
3153
3154 if (0 <= Idx && Idx < ResTyNumElts)
3155 Using1stVec = true;
3156 if (ResTyNumElts <= Idx && Idx < ResTyNumElts * 2)
3157 Using2ndVec = true;
3158 }
3159
3160 // Find the first non-undef index. This index is used as a default when there
3161 // is a leading UNDEF/poison.
3162 int SplatIndex = 0;
3163 for (int Idx : Indices)
3164 if (Idx >= 0) {
3165 SplatIndex = Idx;
3166 break;
3167 }
3168
3169 int LastValidIndex = SplatIndex;
3170 for (size_t i = 0; i < Indices.size(); i++) {
3171 int Idx = Indices[i];
3172 if (Idx < 0) {
3173 // Continue using splati index or use the last valid index.
3174 Idx = isSPLATI ? SplatIndex : LastValidIndex;
3175 } else {
3176 LastValidIndex = Idx;
3177 }
3178 Ops.push_back(DAG.getTargetConstant(Idx, DL, MaskEltTy));
3179 }
3180
3181 SDValue MaskVec = DAG.getBuildVector(MaskVecTy, DL, Ops);
3182
3183 if (Using1stVec && Using2ndVec) {
3184 Op0 = Op->getOperand(0);
3185 Op1 = Op->getOperand(1);
3186 } else if (Using1stVec)
3187 Op0 = Op1 = Op->getOperand(0);
3188 else if (Using2ndVec)
3189 Op0 = Op1 = Op->getOperand(1);
3190 else
3191 llvm_unreachable("shuffle vector mask references neither vector operand?");
3192
3193 // VECTOR_SHUFFLE concatenates the vectors in an vectorwise fashion.
3194 // <0b00, 0b01> + <0b10, 0b11> -> <0b00, 0b01, 0b10, 0b11>
3195 // VSHF concatenates the vectors in a bitwise fashion:
3196 // <0b00, 0b01> + <0b10, 0b11> ->
3197 // 0b0100 + 0b1110 -> 0b01001110
3198 // <0b10, 0b11, 0b00, 0b01>
3199 // We must therefore swap the operands to get the correct result.
3200 return DAG.getNode(MipsISD::VSHF, DL, ResTy, MaskVec, Op1, Op0);
3201}
3202
3203// Lower VECTOR_SHUFFLE into one of a number of instructions depending on the
3204// indices in the shuffle.
3205SDValue MipsSETargetLowering::lowerVECTOR_SHUFFLE(SDValue Op,
3206 SelectionDAG &DAG) const {
3207 ShuffleVectorSDNode *Node = cast<ShuffleVectorSDNode>(Op);
3208 EVT ResTy = Op->getValueType(0);
3209
3210 if (!ResTy.is128BitVector())
3211 return SDValue();
3212
3213 int ResTyNumElts = ResTy.getVectorNumElements();
3214 SmallVector<int, 16> Indices;
3215
3216 for (int i = 0; i < ResTyNumElts; ++i)
3217 Indices.push_back(Node->getMaskElt(i));
3218
3219 // splati.[bhwd] is preferable to the others but is matched from
3220 // MipsISD::VSHF.
3221 if (isVECTOR_SHUFFLE_SPLATI(Op, ResTy, Indices, DAG))
3222 return lowerVECTOR_SHUFFLE_VSHF(Op, ResTy, Indices, true, DAG);
3224 if ((Result = lowerVECTOR_SHUFFLE_ILVEV(Op, ResTy, Indices, DAG)))
3225 return Result;
3226 if ((Result = lowerVECTOR_SHUFFLE_ILVOD(Op, ResTy, Indices, DAG)))
3227 return Result;
3228 if ((Result = lowerVECTOR_SHUFFLE_ILVL(Op, ResTy, Indices, DAG)))
3229 return Result;
3230 if ((Result = lowerVECTOR_SHUFFLE_ILVR(Op, ResTy, Indices, DAG)))
3231 return Result;
3232 if ((Result = lowerVECTOR_SHUFFLE_PCKEV(Op, ResTy, Indices, DAG)))
3233 return Result;
3234 if ((Result = lowerVECTOR_SHUFFLE_PCKOD(Op, ResTy, Indices, DAG)))
3235 return Result;
3236 if ((Result = lowerVECTOR_SHUFFLE_SHF(Op, ResTy, Indices, DAG)))
3237 return Result;
3238 return lowerVECTOR_SHUFFLE_VSHF(Op, ResTy, Indices, false, DAG);
3239}
3240
3242MipsSETargetLowering::emitBPOSGE32(MachineInstr &MI,
3243 MachineBasicBlock *BB) const {
3244 // $bb:
3245 // bposge32_pseudo $vr0
3246 // =>
3247 // $bb:
3248 // bposge32 $tbb
3249 // $fbb:
3250 // li $vr2, 0
3251 // b $sink
3252 // $tbb:
3253 // li $vr1, 1
3254 // $sink:
3255 // $vr0 = phi($vr2, $fbb, $vr1, $tbb)
3256
3257 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3258 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3259 const TargetRegisterClass *RC = &Mips::GPR32RegClass;
3260 DebugLoc DL = MI.getDebugLoc();
3261 const BasicBlock *LLVM_BB = BB->getBasicBlock();
3263 MachineFunction *F = BB->getParent();
3264 MachineBasicBlock *FBB = F->CreateMachineBasicBlock(LLVM_BB);
3265 MachineBasicBlock *TBB = F->CreateMachineBasicBlock(LLVM_BB);
3266 MachineBasicBlock *Sink = F->CreateMachineBasicBlock(LLVM_BB);
3267 F->insert(It, FBB);
3268 F->insert(It, TBB);
3269 F->insert(It, Sink);
3270
3271 // Transfer the remainder of BB and its successor edges to Sink.
3272 Sink->splice(Sink->begin(), BB, std::next(MachineBasicBlock::iterator(MI)),
3273 BB->end());
3275
3276 // Add successors.
3277 BB->addSuccessor(FBB);
3278 BB->addSuccessor(TBB);
3279 FBB->addSuccessor(Sink);
3280 TBB->addSuccessor(Sink);
3281
3282 // Insert the real bposge32 instruction to $BB.
3283 BuildMI(BB, DL, TII->get(Mips::BPOSGE32)).addMBB(TBB);
3284 // Insert the real bposge32c instruction to $BB.
3285 BuildMI(BB, DL, TII->get(Mips::BPOSGE32C_MMR3)).addMBB(TBB);
3286
3287 // Fill $FBB.
3288 Register VR2 = RegInfo.createVirtualRegister(RC);
3289 BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::ADDiu), VR2)
3290 .addReg(Mips::R0)
3291 .addImm(0);
3292 BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::B)).addMBB(Sink);
3293
3294 // Fill $TBB.
3295 Register VR1 = RegInfo.createVirtualRegister(RC);
3296 BuildMI(*TBB, TBB->end(), DL, TII->get(Mips::ADDiu), VR1)
3297 .addReg(Mips::R0)
3298 .addImm(1);
3299
3300 // Insert phi function to $Sink.
3301 BuildMI(*Sink, Sink->begin(), DL, TII->get(Mips::PHI),
3302 MI.getOperand(0).getReg())
3303 .addReg(VR2)
3304 .addMBB(FBB)
3305 .addReg(VR1)
3306 .addMBB(TBB);
3307
3308 MI.eraseFromParent(); // The pseudo instruction is gone now.
3309 return Sink;
3310}
3311
3312MachineBasicBlock *MipsSETargetLowering::emitMSACBranchPseudo(
3313 MachineInstr &MI, MachineBasicBlock *BB, unsigned BranchOp) const {
3314 // $bb:
3315 // vany_nonzero $rd, $ws
3316 // =>
3317 // $bb:
3318 // bnz.b $ws, $tbb
3319 // b $fbb
3320 // $fbb:
3321 // li $rd1, 0
3322 // b $sink
3323 // $tbb:
3324 // li $rd2, 1
3325 // $sink:
3326 // $rd = phi($rd1, $fbb, $rd2, $tbb)
3327
3328 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3329 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3330 const TargetRegisterClass *RC = &Mips::GPR32RegClass;
3331 DebugLoc DL = MI.getDebugLoc();
3332 const BasicBlock *LLVM_BB = BB->getBasicBlock();
3334 MachineFunction *F = BB->getParent();
3335 MachineBasicBlock *FBB = F->CreateMachineBasicBlock(LLVM_BB);
3336 MachineBasicBlock *TBB = F->CreateMachineBasicBlock(LLVM_BB);
3337 MachineBasicBlock *Sink = F->CreateMachineBasicBlock(LLVM_BB);
3338 F->insert(It, FBB);
3339 F->insert(It, TBB);
3340 F->insert(It, Sink);
3341
3342 // Transfer the remainder of BB and its successor edges to Sink.
3343 Sink->splice(Sink->begin(), BB, std::next(MachineBasicBlock::iterator(MI)),
3344 BB->end());
3346
3347 // Add successors.
3348 BB->addSuccessor(FBB);
3349 BB->addSuccessor(TBB);
3350 FBB->addSuccessor(Sink);
3351 TBB->addSuccessor(Sink);
3352
3353 // Insert the real bnz.b instruction to $BB.
3354 BuildMI(BB, DL, TII->get(BranchOp))
3355 .addReg(MI.getOperand(1).getReg())
3356 .addMBB(TBB);
3357
3358 // Fill $FBB.
3359 Register RD1 = RegInfo.createVirtualRegister(RC);
3360 BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::ADDiu), RD1)
3361 .addReg(Mips::R0)
3362 .addImm(0);
3363 BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::B)).addMBB(Sink);
3364
3365 // Fill $TBB.
3366 Register RD2 = RegInfo.createVirtualRegister(RC);
3367 BuildMI(*TBB, TBB->end(), DL, TII->get(Mips::ADDiu), RD2)
3368 .addReg(Mips::R0)
3369 .addImm(1);
3370
3371 // Insert phi function to $Sink.
3372 BuildMI(*Sink, Sink->begin(), DL, TII->get(Mips::PHI),
3373 MI.getOperand(0).getReg())
3374 .addReg(RD1)
3375 .addMBB(FBB)
3376 .addReg(RD2)
3377 .addMBB(TBB);
3378
3379 MI.eraseFromParent(); // The pseudo instruction is gone now.
3380 return Sink;
3381}
3382
3383// Emit the COPY_FW pseudo instruction.
3384//
3385// copy_fw_pseudo $fd, $ws, n
3386// =>
3387// copy_u_w $rt, $ws, $n
3388// mtc1 $rt, $fd
3389//
3390// When n is zero, the equivalent operation can be performed with (potentially)
3391// zero instructions due to register overlaps. This optimization is never valid
3392// for lane 1 because it would require FR=0 mode which isn't supported by MSA.
3394MipsSETargetLowering::emitCOPY_FW(MachineInstr &MI,
3395 MachineBasicBlock *BB) const {
3396 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3397 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3398 DebugLoc DL = MI.getDebugLoc();
3399 Register Fd = MI.getOperand(0).getReg();
3400 Register Ws = MI.getOperand(1).getReg();
3401 unsigned Lane = MI.getOperand(2).getImm();
3402
3403 if (Lane == 0) {
3404 unsigned Wt = Ws;
3405 if (!Subtarget.useOddSPReg()) {
3406 // We must copy to an even-numbered MSA register so that the
3407 // single-precision sub-register is also guaranteed to be even-numbered.
3408 Wt = RegInfo.createVirtualRegister(&Mips::MSA128WEvensRegClass);
3409
3410 BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Wt).addReg(Ws);
3411 }
3412
3413 BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Fd).addReg(Wt, {}, Mips::sub_lo);
3414 } else {
3415 Register Wt = RegInfo.createVirtualRegister(
3416 Subtarget.useOddSPReg() ? &Mips::MSA128WRegClass
3417 : &Mips::MSA128WEvensRegClass);
3418
3419 BuildMI(*BB, MI, DL, TII->get(Mips::SPLATI_W), Wt).addReg(Ws).addImm(Lane);
3420 BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Fd).addReg(Wt, {}, Mips::sub_lo);
3421 }
3422
3423 MI.eraseFromParent(); // The pseudo instruction is gone now.
3424 return BB;
3425}
3426
3427// Emit the COPY_FD pseudo instruction.
3428//
3429// copy_fd_pseudo $fd, $ws, n
3430// =>
3431// splati.d $wt, $ws, $n
3432// copy $fd, $wt:sub_64
3433//
3434// When n is zero, the equivalent operation can be performed with (potentially)
3435// zero instructions due to register overlaps. This optimization is always
3436// valid because FR=1 mode which is the only supported mode in MSA.
3438MipsSETargetLowering::emitCOPY_FD(MachineInstr &MI,
3439 MachineBasicBlock *BB) const {
3440 assert(Subtarget.isFP64bit());
3441
3442 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3443 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3444 Register Fd = MI.getOperand(0).getReg();
3445 Register Ws = MI.getOperand(1).getReg();
3446 unsigned Lane = MI.getOperand(2).getImm() * 2;
3447 DebugLoc DL = MI.getDebugLoc();
3448
3449 if (Lane == 0)
3450 BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Fd).addReg(Ws, {}, Mips::sub_64);
3451 else {
3452 Register Wt = RegInfo.createVirtualRegister(&Mips::MSA128DRegClass);
3453
3454 BuildMI(*BB, MI, DL, TII->get(Mips::SPLATI_D), Wt).addReg(Ws).addImm(1);
3455 BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Fd).addReg(Wt, {}, Mips::sub_64);
3456 }
3457
3458 MI.eraseFromParent(); // The pseudo instruction is gone now.
3459 return BB;
3460}
3461
3462// Emit the INSERT_FW pseudo instruction.
3463//
3464// insert_fw_pseudo $wd, $wd_in, $n, $fs
3465// =>
3466// subreg_to_reg $wt:sub_lo, $fs
3467// insve_w $wd[$n], $wd_in, $wt[0]
3469MipsSETargetLowering::emitINSERT_FW(MachineInstr &MI,
3470 MachineBasicBlock *BB) const {
3471 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3472 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3473 DebugLoc DL = MI.getDebugLoc();
3474 Register Wd = MI.getOperand(0).getReg();
3475 Register Wd_in = MI.getOperand(1).getReg();
3476 unsigned Lane = MI.getOperand(2).getImm();
3477 Register Fs = MI.getOperand(3).getReg();
3478 Register Wt = RegInfo.createVirtualRegister(
3479 Subtarget.useOddSPReg() ? &Mips::MSA128WRegClass
3480 : &Mips::MSA128WEvensRegClass);
3481
3482 BuildMI(*BB, MI, DL, TII->get(Mips::SUBREG_TO_REG), Wt)
3483 .addReg(Fs)
3484 .addImm(Mips::sub_lo);
3485 BuildMI(*BB, MI, DL, TII->get(Mips::INSVE_W), Wd)
3486 .addReg(Wd_in)
3487 .addImm(Lane)
3488 .addReg(Wt)
3489 .addImm(0);
3490
3491 MI.eraseFromParent(); // The pseudo instruction is gone now.
3492 return BB;
3493}
3494
3495// Emit the INSERT_FD pseudo instruction.
3496//
3497// insert_fd_pseudo $wd, $fs, n
3498// =>
3499// subreg_to_reg $wt:sub_64, $fs
3500// insve_d $wd[$n], $wd_in, $wt[0]
3502MipsSETargetLowering::emitINSERT_FD(MachineInstr &MI,
3503 MachineBasicBlock *BB) const {
3504 assert(Subtarget.isFP64bit());
3505
3506 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3507 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3508 DebugLoc DL = MI.getDebugLoc();
3509 Register Wd = MI.getOperand(0).getReg();
3510 Register Wd_in = MI.getOperand(1).getReg();
3511 unsigned Lane = MI.getOperand(2).getImm();
3512 Register Fs = MI.getOperand(3).getReg();
3513 Register Wt = RegInfo.createVirtualRegister(&Mips::MSA128DRegClass);
3514
3515 BuildMI(*BB, MI, DL, TII->get(Mips::SUBREG_TO_REG), Wt)
3516 .addReg(Fs)
3517 .addImm(Mips::sub_64);
3518 BuildMI(*BB, MI, DL, TII->get(Mips::INSVE_D), Wd)
3519 .addReg(Wd_in)
3520 .addImm(Lane)
3521 .addReg(Wt)
3522 .addImm(0);
3523
3524 MI.eraseFromParent(); // The pseudo instruction is gone now.
3525 return BB;
3526}
3527
3528// Emit the INSERT_([BHWD]|F[WD])_VIDX pseudo instruction.
3529//
3530// For integer:
3531// (INSERT_([BHWD]|F[WD])_PSEUDO $wd, $wd_in, $n, $rs)
3532// =>
3533// (SLL $lanetmp1, $lane, <log2size)
3534// (SLD_B $wdtmp1, $wd_in, $wd_in, $lanetmp1)
3535// (INSERT_[BHWD], $wdtmp2, $wdtmp1, 0, $rs)
3536// (NEG $lanetmp2, $lanetmp1)
3537// (SLD_B $wd, $wdtmp2, $wdtmp2, $lanetmp2)
3538//
3539// For floating point:
3540// (INSERT_([BHWD]|F[WD])_PSEUDO $wd, $wd_in, $n, $fs)
3541// =>
3542// (SUBREG_TO_REG $wt, $fs, <subreg>)
3543// (SLL $lanetmp1, $lane, <log2size)
3544// (SLD_B $wdtmp1, $wd_in, $wd_in, $lanetmp1)
3545// (INSVE_[WD], $wdtmp2, 0, $wdtmp1, 0)
3546// (NEG $lanetmp2, $lanetmp1)
3547// (SLD_B $wd, $wdtmp2, $wdtmp2, $lanetmp2)
3548MachineBasicBlock *MipsSETargetLowering::emitINSERT_DF_VIDX(
3549 MachineInstr &MI, MachineBasicBlock *BB, unsigned EltSizeInBytes,
3550 bool IsFP) const {
3551 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3552 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3553 DebugLoc DL = MI.getDebugLoc();
3554 Register Wd = MI.getOperand(0).getReg();
3555 Register SrcVecReg = MI.getOperand(1).getReg();
3556 Register LaneReg = MI.getOperand(2).getReg();
3557 Register SrcValReg = MI.getOperand(3).getReg();
3558
3559 const TargetRegisterClass *VecRC = nullptr;
3560 // FIXME: This should be true for N32 too.
3561 const TargetRegisterClass *GPRRC =
3562 Subtarget.isABI_N64() ? &Mips::GPR64RegClass : &Mips::GPR32RegClass;
3563 unsigned SubRegIdx = Subtarget.isABI_N64() ? Mips::sub_32 : 0;
3564 unsigned ShiftOp = Subtarget.isABI_N64() ? Mips::DSLL : Mips::SLL;
3565 unsigned EltLog2Size;
3566 unsigned InsertOp = 0;
3567 unsigned InsveOp = 0;
3568 switch (EltSizeInBytes) {
3569 default:
3570 llvm_unreachable("Unexpected size");
3571 case 1:
3572 EltLog2Size = 0;
3573 InsertOp = Mips::INSERT_B;
3574 InsveOp = Mips::INSVE_B;
3575 VecRC = &Mips::MSA128BRegClass;
3576 break;
3577 case 2:
3578 EltLog2Size = 1;
3579 InsertOp = Mips::INSERT_H;
3580 InsveOp = Mips::INSVE_H;
3581 VecRC = &Mips::MSA128HRegClass;
3582 break;
3583 case 4:
3584 EltLog2Size = 2;
3585 InsertOp = Mips::INSERT_W;
3586 InsveOp = Mips::INSVE_W;
3587 VecRC = &Mips::MSA128WRegClass;
3588 break;
3589 case 8:
3590 EltLog2Size = 3;
3591 InsertOp = Mips::INSERT_D;
3592 InsveOp = Mips::INSVE_D;
3593 VecRC = &Mips::MSA128DRegClass;
3594 break;
3595 }
3596
3597 if (IsFP) {
3598 Register Wt = RegInfo.createVirtualRegister(VecRC);
3599 BuildMI(*BB, MI, DL, TII->get(Mips::SUBREG_TO_REG), Wt)
3600 .addReg(SrcValReg)
3601 .addImm(EltSizeInBytes == 8 ? Mips::sub_64 : Mips::sub_lo);
3602 SrcValReg = Wt;
3603 }
3604
3605 // Convert the lane index into a byte index
3606 if (EltSizeInBytes != 1) {
3607 Register LaneTmp1 = RegInfo.createVirtualRegister(GPRRC);
3608 BuildMI(*BB, MI, DL, TII->get(ShiftOp), LaneTmp1)
3609 .addReg(LaneReg)
3610 .addImm(EltLog2Size);
3611 LaneReg = LaneTmp1;
3612 }
3613
3614 // Rotate bytes around so that the desired lane is element zero
3615 Register WdTmp1 = RegInfo.createVirtualRegister(VecRC);
3616 BuildMI(*BB, MI, DL, TII->get(Mips::SLD_B), WdTmp1)
3617 .addReg(SrcVecReg)
3618 .addReg(SrcVecReg)
3619 .addReg(LaneReg, {}, SubRegIdx);
3620
3621 Register WdTmp2 = RegInfo.createVirtualRegister(VecRC);
3622 if (IsFP) {
3623 // Use insve.df to insert to element zero
3624 BuildMI(*BB, MI, DL, TII->get(InsveOp), WdTmp2)
3625 .addReg(WdTmp1)
3626 .addImm(0)
3627 .addReg(SrcValReg)
3628 .addImm(0);
3629 } else {
3630 // Use insert.df to insert to element zero
3631 BuildMI(*BB, MI, DL, TII->get(InsertOp), WdTmp2)
3632 .addReg(WdTmp1)
3633 .addReg(SrcValReg)
3634 .addImm(0);
3635 }
3636
3637 // Rotate elements the rest of the way for a full rotation.
3638 // sld.df inteprets $rt modulo the number of columns so we only need to negate
3639 // the lane index to do this.
3640 Register LaneTmp2 = RegInfo.createVirtualRegister(GPRRC);
3641 BuildMI(*BB, MI, DL, TII->get(Subtarget.isABI_N64() ? Mips::DSUB : Mips::SUB),
3642 LaneTmp2)
3643 .addReg(Subtarget.isABI_N64() ? Mips::R0_64 : Mips::R0)
3644 .addReg(LaneReg);
3645 BuildMI(*BB, MI, DL, TII->get(Mips::SLD_B), Wd)
3646 .addReg(WdTmp2)
3647 .addReg(WdTmp2)
3648 .addReg(LaneTmp2, {}, SubRegIdx);
3649
3650 MI.eraseFromParent(); // The pseudo instruction is gone now.
3651 return BB;
3652}
3653
3654// Emit the FILL_FW pseudo instruction.
3655//
3656// fill_fw_pseudo $wd, $fs
3657// =>
3658// implicit_def $wt1
3659// insert_subreg $wt2:subreg_lo, $wt1, $fs
3660// splati.w $wd, $wt2[0]
3662MipsSETargetLowering::emitFILL_FW(MachineInstr &MI,
3663 MachineBasicBlock *BB) const {
3664 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3665 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3666 DebugLoc DL = MI.getDebugLoc();
3667 Register Wd = MI.getOperand(0).getReg();
3668 Register Fs = MI.getOperand(1).getReg();
3669 Register Wt1 = RegInfo.createVirtualRegister(
3670 Subtarget.useOddSPReg() ? &Mips::MSA128WRegClass
3671 : &Mips::MSA128WEvensRegClass);
3672 Register Wt2 = RegInfo.createVirtualRegister(
3673 Subtarget.useOddSPReg() ? &Mips::MSA128WRegClass
3674 : &Mips::MSA128WEvensRegClass);
3675
3676 BuildMI(*BB, MI, DL, TII->get(Mips::IMPLICIT_DEF), Wt1);
3677 BuildMI(*BB, MI, DL, TII->get(Mips::INSERT_SUBREG), Wt2)
3678 .addReg(Wt1)
3679 .addReg(Fs)
3680 .addImm(Mips::sub_lo);
3681 BuildMI(*BB, MI, DL, TII->get(Mips::SPLATI_W), Wd).addReg(Wt2).addImm(0);
3682
3683 MI.eraseFromParent(); // The pseudo instruction is gone now.
3684 return BB;
3685}
3686
3687// Emit the FILL_FD pseudo instruction.
3688//
3689// fill_fd_pseudo $wd, $fs
3690// =>
3691// implicit_def $wt1
3692// insert_subreg $wt2:subreg_64, $wt1, $fs
3693// splati.d $wd, $wt2[0]
3695MipsSETargetLowering::emitFILL_FD(MachineInstr &MI,
3696 MachineBasicBlock *BB) const {
3697 assert(Subtarget.isFP64bit());
3698
3699 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3700 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3701 DebugLoc DL = MI.getDebugLoc();
3702 Register Wd = MI.getOperand(0).getReg();
3703 Register Fs = MI.getOperand(1).getReg();
3704 Register Wt1 = RegInfo.createVirtualRegister(&Mips::MSA128DRegClass);
3705 Register Wt2 = RegInfo.createVirtualRegister(&Mips::MSA128DRegClass);
3706
3707 BuildMI(*BB, MI, DL, TII->get(Mips::IMPLICIT_DEF), Wt1);
3708 BuildMI(*BB, MI, DL, TII->get(Mips::INSERT_SUBREG), Wt2)
3709 .addReg(Wt1)
3710 .addReg(Fs)
3711 .addImm(Mips::sub_64);
3712 BuildMI(*BB, MI, DL, TII->get(Mips::SPLATI_D), Wd).addReg(Wt2).addImm(0);
3713
3714 MI.eraseFromParent(); // The pseudo instruction is gone now.
3715 return BB;
3716}
3717
3718// Emit the FEXP2_W_1 pseudo instructions.
3719//
3720// fexp2_w_1_pseudo $wd, $wt
3721// =>
3722// ldi.w $ws, 1
3723// fexp2.w $wd, $ws, $wt
3725MipsSETargetLowering::emitFEXP2_W_1(MachineInstr &MI,
3726 MachineBasicBlock *BB) const {
3727 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3728 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3729 const TargetRegisterClass *RC = &Mips::MSA128WRegClass;
3730 Register Ws1 = RegInfo.createVirtualRegister(RC);
3731 Register Ws2 = RegInfo.createVirtualRegister(RC);
3732 DebugLoc DL = MI.getDebugLoc();
3733
3734 // Splat 1.0 into a vector
3735 BuildMI(*BB, MI, DL, TII->get(Mips::LDI_W), Ws1).addImm(1);
3736 BuildMI(*BB, MI, DL, TII->get(Mips::FFINT_U_W), Ws2).addReg(Ws1);
3737
3738 // Emit 1.0 * fexp2(Wt)
3739 BuildMI(*BB, MI, DL, TII->get(Mips::FEXP2_W), MI.getOperand(0).getReg())
3740 .addReg(Ws2)
3741 .addReg(MI.getOperand(1).getReg());
3742
3743 MI.eraseFromParent(); // The pseudo instruction is gone now.
3744 return BB;
3745}
3746
3747// Emit the FEXP2_D_1 pseudo instructions.
3748//
3749// fexp2_d_1_pseudo $wd, $wt
3750// =>
3751// ldi.d $ws, 1
3752// fexp2.d $wd, $ws, $wt
3754MipsSETargetLowering::emitFEXP2_D_1(MachineInstr &MI,
3755 MachineBasicBlock *BB) const {
3756 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3757 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3758 const TargetRegisterClass *RC = &Mips::MSA128DRegClass;
3759 Register Ws1 = RegInfo.createVirtualRegister(RC);
3760 Register Ws2 = RegInfo.createVirtualRegister(RC);
3761 DebugLoc DL = MI.getDebugLoc();
3762
3763 // Splat 1.0 into a vector
3764 BuildMI(*BB, MI, DL, TII->get(Mips::LDI_D), Ws1).addImm(1);
3765 BuildMI(*BB, MI, DL, TII->get(Mips::FFINT_U_D), Ws2).addReg(Ws1);
3766
3767 // Emit 1.0 * fexp2(Wt)
3768 BuildMI(*BB, MI, DL, TII->get(Mips::FEXP2_D), MI.getOperand(0).getReg())
3769 .addReg(Ws2)
3770 .addReg(MI.getOperand(1).getReg());
3771
3772 MI.eraseFromParent(); // The pseudo instruction is gone now.
3773 return BB;
3774}
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)
return SDValue()
static SDValue performANDCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI)
static SDValue performSETCCCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI, SelectionDAG &DAG)
const AArch64Subtarget & Subtarget
const TargetLowering & TLI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const AArch64InstrInfo & TII
uint64_t 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:665
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
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 performXORCombine(SDNode *N, SelectionDAG &DAG, const LoongArchSubtarget &Subtarget)
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)
static SDValue performMULCombine(SDNode *N, SelectionDAG &DAG, TargetLowering::DAGCombinerInfo &DCI, const LoongArchSubtarget &Subtarget)
#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 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 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)
SmallVector< MachineOperand, 4 > Cond
RISCVCC::CondCode CC
MachineInstr *& Lo
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
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)
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...
virtual void getOpndList(SmallVectorImpl< SDValue > &Ops, std::deque< std::pair< unsigned, SDValue > > &RegsToPass, bool IsPICCall, bool GlobalOrExternal, bool LocalLinkage, 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 lowerSTORE(SDValue Op, SelectionDAG &DAG) const
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)
LLVM_NO_SANITIZE_CFI_UNRELATED_CAST iterator begin()
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...
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:2228
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:851
@ 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:912
@ 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:876
@ SELECT
Select(COND, TRUEVAL, FALSEVAL).
Definition ISDOpcodes.h:828
@ 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:720
@ STRICT_FP16_TO_FP
@ SHL
Shift and rotation operations.
Definition ISDOpcodes.h:793
@ 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:882
@ SELECT_CC
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
Definition ISDOpcodes.h:843
@ SMIN
[US]{MIN/MAX} - Binary minimum or maximum of signed or unsigned integers.
Definition ISDOpcodes.h:751
@ VSELECT
Select with a vector condition (op #0) and two vector operands (ops #1 and #2), returning a vector re...
Definition ISDOpcodes.h:837
@ FP_TO_SINT
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition ISDOpcodes.h:958
@ 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:763
@ 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:888
@ 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
LLVM_ABI bool isBuildVectorAllOnes(SDValue V)
Return true if the specified value is a BUILD_VECTOR where all of the elements are ~0 or undef.
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
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:206
unsigned Log2(Align A)
Returns the log2 of the alignment.
Definition Alignment.h:202
@ End
Run the machine verifier once, at the end of the pipeline.
Definition CodeGen.h:320
@ 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:881
#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:411
uint64_t getScalarSizeInBits() const
Definition ValueTypes.h:423
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition ValueTypes.h:354
bool is128BitVector() const
Return true if this is a 128-bit vector type.
Definition ValueTypes.h:245
bool isVector() const
Return true if this is a vector value type.
Definition ValueTypes.h:191
EVT getVectorElementType() const
Given a vector type, return the type of each element.
Definition ValueTypes.h:366
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
Definition ValueTypes.h:374
bool isInteger() const
Return true if this is an integer or a vector integer type.
Definition ValueTypes.h:175
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.