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::PseudoTRUNC_W_S_M1:
1278 return emitTRUNC_W_M1(MI, BB, Mips::CVT_W_S);
1279 case Mips::PseudoTRUNC_W_D32_M1:
1280 return emitTRUNC_W_M1(MI, BB, Mips::CVT_W_D32);
1281 case Mips::SNZ_B_PSEUDO:
1282 return emitMSACBranchPseudo(MI, BB, Mips::BNZ_B);
1283 case Mips::SNZ_H_PSEUDO:
1284 return emitMSACBranchPseudo(MI, BB, Mips::BNZ_H);
1285 case Mips::SNZ_W_PSEUDO:
1286 return emitMSACBranchPseudo(MI, BB, Mips::BNZ_W);
1287 case Mips::SNZ_D_PSEUDO:
1288 return emitMSACBranchPseudo(MI, BB, Mips::BNZ_D);
1289 case Mips::SNZ_V_PSEUDO:
1290 return emitMSACBranchPseudo(MI, BB, Mips::BNZ_V);
1291 case Mips::SZ_B_PSEUDO:
1292 return emitMSACBranchPseudo(MI, BB, Mips::BZ_B);
1293 case Mips::SZ_H_PSEUDO:
1294 return emitMSACBranchPseudo(MI, BB, Mips::BZ_H);
1295 case Mips::SZ_W_PSEUDO:
1296 return emitMSACBranchPseudo(MI, BB, Mips::BZ_W);
1297 case Mips::SZ_D_PSEUDO:
1298 return emitMSACBranchPseudo(MI, BB, Mips::BZ_D);
1299 case Mips::SZ_V_PSEUDO:
1300 return emitMSACBranchPseudo(MI, BB, Mips::BZ_V);
1301 case Mips::COPY_FW_PSEUDO:
1302 return emitCOPY_FW(MI, BB);
1303 case Mips::COPY_FD_PSEUDO:
1304 return emitCOPY_FD(MI, BB);
1305 case Mips::INSERT_FW_PSEUDO:
1306 return emitINSERT_FW(MI, BB);
1307 case Mips::INSERT_FD_PSEUDO:
1308 return emitINSERT_FD(MI, BB);
1309 case Mips::INSERT_B_VIDX_PSEUDO:
1310 case Mips::INSERT_B_VIDX64_PSEUDO:
1311 return emitINSERT_DF_VIDX(MI, BB, 1, false);
1312 case Mips::INSERT_H_VIDX_PSEUDO:
1313 case Mips::INSERT_H_VIDX64_PSEUDO:
1314 return emitINSERT_DF_VIDX(MI, BB, 2, false);
1315 case Mips::INSERT_W_VIDX_PSEUDO:
1316 case Mips::INSERT_W_VIDX64_PSEUDO:
1317 return emitINSERT_DF_VIDX(MI, BB, 4, false);
1318 case Mips::INSERT_D_VIDX_PSEUDO:
1319 case Mips::INSERT_D_VIDX64_PSEUDO:
1320 return emitINSERT_DF_VIDX(MI, BB, 8, false);
1321 case Mips::INSERT_FW_VIDX_PSEUDO:
1322 case Mips::INSERT_FW_VIDX64_PSEUDO:
1323 return emitINSERT_DF_VIDX(MI, BB, 4, true);
1324 case Mips::INSERT_FD_VIDX_PSEUDO:
1325 case Mips::INSERT_FD_VIDX64_PSEUDO:
1326 return emitINSERT_DF_VIDX(MI, BB, 8, true);
1327 case Mips::FILL_FW_PSEUDO:
1328 return emitFILL_FW(MI, BB);
1329 case Mips::FILL_FD_PSEUDO:
1330 return emitFILL_FD(MI, BB);
1331 case Mips::FEXP2_W_1_PSEUDO:
1332 return emitFEXP2_W_1(MI, BB);
1333 case Mips::FEXP2_D_1_PSEUDO:
1334 return emitFEXP2_D_1(MI, BB);
1335 }
1336}
1337
1338bool MipsSETargetLowering::isEligibleForTailCallOptimization(
1339 const CCState &CCInfo, unsigned NextStackOffset,
1340 const MipsFunctionInfo &FI) const {
1341 // Exception has to be cleared with eret.
1342 if (FI.isISR())
1343 return false;
1344
1345 // Return false if either the callee or caller has a byval argument.
1346 if (CCInfo.getInRegsParamsCount() > 0 || FI.hasByvalArg())
1347 return false;
1348
1349 // Return true if the callee's argument area is no larger than the caller's.
1350 return NextStackOffset <= FI.getIncomingArgSize();
1351}
1352
1353void MipsSETargetLowering::getOpndList(
1355 std::deque<std::pair<unsigned, SDValue>> &RegsToPass, bool IsPICCall,
1356 bool GlobalOrExternal, bool LocalLinkage, bool IsCallReloc,
1357 CallLoweringInfo &CLI, SDValue Callee, SDValue Chain) const {
1358 Ops.push_back(Callee);
1359 MipsTargetLowering::getOpndList(Ops, RegsToPass, IsPICCall, GlobalOrExternal,
1360 LocalLinkage, IsCallReloc, CLI, Callee,
1361 Chain);
1362}
1363
1364SDValue MipsSETargetLowering::lowerLOAD(SDValue Op, SelectionDAG &DAG) const {
1365 LoadSDNode &Nd = *cast<LoadSDNode>(Op);
1366
1367 if (Nd.getMemoryVT() != MVT::f64 ||
1368 (!Subtarget.getCLOpts().mno_ldc1_sdc1 && Subtarget.hasMips2()))
1369 return MipsTargetLowering::lowerLOAD(Op, DAG);
1370
1371 // Replace a double precision load with two i32 loads and a buildpair64.
1372 SDLoc DL(Op);
1373 SDValue Ptr = Nd.getBasePtr(), Chain = Nd.getChain();
1374 EVT PtrVT = Ptr.getValueType();
1375 EVT VT = Subtarget.hasMips2() ? MVT::i32 : MVT::f32;
1376
1377 // i32 load from lower address.
1378 SDValue Lo = DAG.getLoad(VT, DL, Chain, Ptr, MachinePointerInfo(),
1379 Nd.getAlign(), Nd.getMemOperand()->getFlags());
1380
1381 // i32 load from higher address.
1382 Ptr = DAG.getNode(ISD::ADD, DL, PtrVT, Ptr, DAG.getConstant(4, DL, PtrVT));
1383 SDValue Hi = DAG.getLoad(VT, DL, Lo.getValue(1), Ptr, MachinePointerInfo(),
1384 commonAlignment(Nd.getAlign(), 4),
1385 Nd.getMemOperand()->getFlags());
1386
1387 if (!Subtarget.isLittle())
1388 std::swap(Lo, Hi);
1389
1390 SDValue BP;
1391 if (Subtarget.hasMips2())
1392 BP = DAG.getNode(MipsISD::BuildPairF64, DL, MVT::f64, Lo, Hi);
1393 else
1394 BP = DAG.getNode(MipsISD::BuildPairF64_FPR, DL, MVT::f64, Hi, Lo);
1395
1396 SDValue Ops[2] = {BP, Hi.getValue(1)};
1397 return DAG.getMergeValues(Ops, DL);
1398}
1399
1400SDValue MipsSETargetLowering::lowerSTORE(SDValue Op, SelectionDAG &DAG) const {
1401 StoreSDNode &Nd = *cast<StoreSDNode>(Op);
1402
1403 if (Nd.getMemoryVT() != MVT::f64 ||
1404 (!Subtarget.getCLOpts().mno_ldc1_sdc1 && Subtarget.hasMips2()))
1406
1407 // Replace a double precision store with two extractelement64s and i32 stores.
1408 SDLoc DL(Op);
1409 SDValue Val = Nd.getValue(), Ptr = Nd.getBasePtr(), Chain = Nd.getChain();
1410 EVT PtrVT = Ptr.getValueType();
1411 EVT VT = Subtarget.hasMips2() ? MVT::i32 : MVT::f32;
1412
1413 unsigned ExtractOp = Subtarget.hasMips2() ? MipsISD::ExtractElementF64
1414 : MipsISD::ExtractElementF64_FPR;
1415 SDValue Lo =
1416 DAG.getNode(ExtractOp, DL, VT, Val, DAG.getConstant(0, DL, MVT::i32));
1417 SDValue Hi =
1418 DAG.getNode(ExtractOp, DL, VT, Val, DAG.getConstant(1, DL, MVT::i32));
1419
1420 if (!Subtarget.isLittle())
1421 std::swap(Lo, Hi);
1422
1423 // i32 store to lower address.
1424 Chain = DAG.getStore(Chain, DL, Lo, Ptr, MachinePointerInfo(), Nd.getAlign(),
1425 Nd.getMemOperand()->getFlags(), Nd.getAAInfo());
1426
1427 // i32 store to higher address.
1428 Ptr = DAG.getNode(ISD::ADD, DL, PtrVT, Ptr, DAG.getConstant(4, DL, PtrVT));
1429 return DAG.getStore(Chain, DL, Hi, Ptr, MachinePointerInfo(),
1430 commonAlignment(Nd.getAlign(), 4),
1431 Nd.getMemOperand()->getFlags(), Nd.getAAInfo());
1432}
1433
1434SDValue MipsSETargetLowering::lowerBITCAST(SDValue Op,
1435 SelectionDAG &DAG) const {
1436 SDLoc DL(Op);
1437 MVT Src = Op.getOperand(0).getValueType().getSimpleVT();
1438 MVT Dest = Op.getValueType().getSimpleVT();
1439
1440 // Bitcast i64 to double.
1441 if (Src == MVT::i64 && Dest == MVT::f64) {
1442 SDValue Lo, Hi;
1443 std::tie(Lo, Hi) =
1444 DAG.SplitScalar(Op.getOperand(0), DL, MVT::i32, MVT::i32);
1445 return DAG.getNode(MipsISD::BuildPairF64, DL, MVT::f64, Lo, Hi);
1446 }
1447
1448 // Bitcast double to i64.
1449 if (Src == MVT::f64 && Dest == MVT::i64) {
1450 // Skip lower bitcast when operand0 has converted float results to integer
1451 // which was done by function SoftenFloatResult.
1452 if (getTypeAction(*DAG.getContext(), Op.getOperand(0).getValueType()) ==
1454 return SDValue();
1455 SDValue Lo =
1456 DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, Op.getOperand(0),
1457 DAG.getConstant(0, DL, MVT::i32));
1458 SDValue Hi =
1459 DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, Op.getOperand(0),
1460 DAG.getConstant(1, DL, MVT::i32));
1461 return DAG.getNode(ISD::BUILD_PAIR, DL, MVT::i64, Lo, Hi);
1462 }
1463
1464 // Skip other cases of bitcast and use default lowering.
1465 return SDValue();
1466}
1467
1468SDValue MipsSETargetLowering::lowerMulDiv(SDValue Op, unsigned NewOpc,
1469 bool HasLo, bool HasHi,
1470 SelectionDAG &DAG) const {
1471 // MIPS32r6/MIPS64r6 removed accumulator based multiplies.
1472 assert(!Subtarget.hasMips32r6());
1473
1474 EVT Ty = Op.getOperand(0).getValueType();
1475 SDLoc DL(Op);
1476 SDValue Mult = DAG.getNode(NewOpc, DL, MVT::Untyped,
1477 Op.getOperand(0), Op.getOperand(1));
1478 SDValue Lo, Hi;
1479
1480 if (HasLo)
1481 Lo = DAG.getNode(MipsISD::MFLO, DL, Ty, Mult);
1482 if (HasHi)
1483 Hi = DAG.getNode(MipsISD::MFHI, DL, Ty, Mult);
1484
1485 if (!HasLo || !HasHi)
1486 return HasLo ? Lo : Hi;
1487
1488 SDValue Vals[] = { Lo, Hi };
1489 return DAG.getMergeValues(Vals, DL);
1490}
1491
1493 SDValue InLo, InHi;
1494 std::tie(InLo, InHi) = DAG.SplitScalar(In, DL, MVT::i32, MVT::i32);
1495 return DAG.getNode(MipsISD::MTLOHI, DL, MVT::Untyped, InLo, InHi);
1496}
1497
1499 SDValue Lo = DAG.getNode(MipsISD::MFLO, DL, MVT::i32, Op);
1500 SDValue Hi = DAG.getNode(MipsISD::MFHI, DL, MVT::i32, Op);
1501 return DAG.getNode(ISD::BUILD_PAIR, DL, MVT::i64, Lo, Hi);
1502}
1503
1504// This function expands mips intrinsic nodes which have 64-bit input operands
1505// or output values.
1506//
1507// out64 = intrinsic-node in64
1508// =>
1509// lo = copy (extract-element (in64, 0))
1510// hi = copy (extract-element (in64, 1))
1511// mips-specific-node
1512// v0 = copy lo
1513// v1 = copy hi
1514// out64 = merge-values (v0, v1)
1515//
1517 SDLoc DL(Op);
1518 bool HasChainIn = Op->getOperand(0).getValueType() == MVT::Other;
1520 unsigned OpNo = 0;
1521
1522 // See if Op has a chain input.
1523 if (HasChainIn)
1524 Ops.push_back(Op->getOperand(OpNo++));
1525
1526 // The next operand is the intrinsic opcode.
1527 assert(Op->getOperand(OpNo).getOpcode() == ISD::TargetConstant);
1528
1529 // See if the next operand has type i64.
1530 SDValue Opnd = Op->getOperand(++OpNo), In64;
1531
1532 if (Opnd.getValueType() == MVT::i64)
1533 In64 = initAccumulator(Opnd, DL, DAG);
1534 else
1535 Ops.push_back(Opnd);
1536
1537 // Push the remaining operands.
1538 for (++OpNo ; OpNo < Op->getNumOperands(); ++OpNo)
1539 Ops.push_back(Op->getOperand(OpNo));
1540
1541 // Add In64 to the end of the list.
1542 if (In64.getNode())
1543 Ops.push_back(In64);
1544
1545 // Scan output.
1546 SmallVector<EVT, 2> ResTys;
1547
1548 for (EVT Ty : Op->values())
1549 ResTys.push_back((Ty == MVT::i64) ? MVT::Untyped : Ty);
1550
1551 // Create node.
1552 SDValue Val = DAG.getNode(Opc, DL, ResTys, Ops);
1553 SDValue Out = (ResTys[0] == MVT::Untyped) ? extractLOHI(Val, DL, DAG) : Val;
1554
1555 if (!HasChainIn)
1556 return Out;
1557
1558 assert(Val->getValueType(1) == MVT::Other);
1559 SDValue Vals[] = { Out, SDValue(Val.getNode(), 1) };
1560 return DAG.getMergeValues(Vals, DL);
1561}
1562
1563// Lower an MSA copy intrinsic into the specified SelectionDAG node
1565 SDLoc DL(Op);
1566 SDValue Vec = Op->getOperand(1);
1568 SDValue Idx = DAG.getZExtOrTrunc(Op->getOperand(2), DL,
1569 TLI.getVectorIdxTy(DAG.getDataLayout()));
1570 EVT ResTy = Op->getValueType(0);
1571 EVT EltTy = Vec->getValueType(0).getVectorElementType();
1572
1573 SDValue Result = DAG.getNode(Opc, DL, ResTy, Vec, Idx,
1574 DAG.getValueType(EltTy));
1575
1576 return Result;
1577}
1578
1579static SDValue lowerMSASplatZExt(SDValue Op, unsigned OpNr, SelectionDAG &DAG) {
1580 EVT ResVecTy = Op->getValueType(0);
1581 EVT ViaVecTy = ResVecTy;
1582 bool BigEndian = !DAG.getSubtarget().getTargetTriple().isLittleEndian();
1583 SDLoc DL(Op);
1584
1585 // When ResVecTy == MVT::v2i64, LaneA is the upper 32 bits of the lane and
1586 // LaneB is the lower 32-bits. Otherwise LaneA and LaneB are alternating
1587 // lanes.
1588 SDValue LaneA = Op->getOperand(OpNr);
1589 SDValue LaneB;
1590
1591 if (ResVecTy == MVT::v2i64) {
1592 // In case of the index being passed as an immediate value, set the upper
1593 // lane to 0 so that the splati.d instruction can be matched.
1594 if (isa<ConstantSDNode>(LaneA))
1595 LaneB = DAG.getConstant(0, DL, MVT::i32);
1596 // Having the index passed in a register, set the upper lane to the same
1597 // value as the lower - this results in the BUILD_VECTOR node not being
1598 // expanded through stack. This way we are able to pattern match the set of
1599 // nodes created here to splat.d.
1600 else
1601 LaneB = LaneA;
1602 ViaVecTy = MVT::v4i32;
1603 if(BigEndian)
1604 std::swap(LaneA, LaneB);
1605 } else
1606 LaneB = LaneA;
1607
1608 SDValue Ops[16] = { LaneA, LaneB, LaneA, LaneB, LaneA, LaneB, LaneA, LaneB,
1609 LaneA, LaneB, LaneA, LaneB, LaneA, LaneB, LaneA, LaneB };
1610
1611 SDValue Result = DAG.getBuildVector(
1612 ViaVecTy, DL, ArrayRef(Ops, ViaVecTy.getVectorNumElements()));
1613
1614 if (ViaVecTy != ResVecTy) {
1615 SDValue One = DAG.getConstant(1, DL, ViaVecTy);
1616 Result = DAG.getNode(ISD::BITCAST, DL, ResVecTy,
1617 DAG.getNode(ISD::AND, DL, ViaVecTy, Result, One));
1618 }
1619
1620 return Result;
1621}
1622
1623static SDValue lowerMSASplatImm(SDValue Op, unsigned ImmOp, SelectionDAG &DAG,
1624 bool IsSigned = false) {
1625 auto *CImm = cast<ConstantSDNode>(Op->getOperand(ImmOp));
1626 return DAG.getConstant(
1627 APInt(Op->getValueType(0).getScalarType().getSizeInBits(),
1628 IsSigned ? CImm->getSExtValue() : CImm->getZExtValue(), IsSigned),
1629 SDLoc(Op), Op->getValueType(0));
1630}
1631
1632static SDValue getBuildVectorSplat(EVT VecTy, SDValue SplatValue,
1633 bool BigEndian, SelectionDAG &DAG) {
1634 EVT ViaVecTy = VecTy;
1635 SDValue SplatValueA = SplatValue;
1636 SDValue SplatValueB = SplatValue;
1637 SDLoc DL(SplatValue);
1638
1639 if (VecTy == MVT::v2i64) {
1640 // v2i64 BUILD_VECTOR must be performed via v4i32 so split into i32's.
1641 ViaVecTy = MVT::v4i32;
1642
1643 SplatValueA = DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, SplatValue);
1644 SplatValueB = DAG.getNode(ISD::SRL, DL, MVT::i64, SplatValue,
1645 DAG.getConstant(32, DL, MVT::i32));
1646 SplatValueB = DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, SplatValueB);
1647 }
1648
1649 // We currently hold the parts in little endian order. Swap them if
1650 // necessary.
1651 if (BigEndian)
1652 std::swap(SplatValueA, SplatValueB);
1653
1654 SDValue Ops[16] = { SplatValueA, SplatValueB, SplatValueA, SplatValueB,
1655 SplatValueA, SplatValueB, SplatValueA, SplatValueB,
1656 SplatValueA, SplatValueB, SplatValueA, SplatValueB,
1657 SplatValueA, SplatValueB, SplatValueA, SplatValueB };
1658
1659 SDValue Result = DAG.getBuildVector(
1660 ViaVecTy, DL, ArrayRef(Ops, ViaVecTy.getVectorNumElements()));
1661
1662 if (VecTy != ViaVecTy)
1663 Result = DAG.getNode(ISD::BITCAST, DL, VecTy, Result);
1664
1665 return Result;
1666}
1667
1669 unsigned Opc, SDValue Imm,
1670 bool BigEndian) {
1671 EVT VecTy = Op->getValueType(0);
1672 SDValue Exp2Imm;
1673 SDLoc DL(Op);
1674
1675 // The DAG Combiner can't constant fold bitcasted vectors yet so we must do it
1676 // here for now.
1677 if (VecTy == MVT::v2i64) {
1679 APInt BitImm = APInt(64, 1) << CImm->getAPIntValue();
1680
1681 SDValue BitImmHiOp = DAG.getConstant(BitImm.lshr(32).trunc(32), DL,
1682 MVT::i32);
1683 SDValue BitImmLoOp = DAG.getConstant(BitImm.trunc(32), DL, MVT::i32);
1684
1685 if (BigEndian)
1686 std::swap(BitImmLoOp, BitImmHiOp);
1687
1688 Exp2Imm = DAG.getNode(
1689 ISD::BITCAST, DL, MVT::v2i64,
1690 DAG.getBuildVector(MVT::v4i32, DL,
1691 {BitImmLoOp, BitImmHiOp, BitImmLoOp, BitImmHiOp}));
1692 }
1693 }
1694
1695 if (!Exp2Imm.getNode()) {
1696 // We couldnt constant fold, do a vector shift instead
1697
1698 // Extend i32 to i64 if necessary. Sign or zero extend doesn't matter since
1699 // only values 0-63 are valid.
1700 if (VecTy == MVT::v2i64)
1701 Imm = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i64, Imm);
1702
1703 Exp2Imm = getBuildVectorSplat(VecTy, Imm, BigEndian, DAG);
1704
1705 Exp2Imm = DAG.getNode(ISD::SHL, DL, VecTy, DAG.getConstant(1, DL, VecTy),
1706 Exp2Imm);
1707 }
1708
1709 return DAG.getNode(Opc, DL, VecTy, Op->getOperand(1), Exp2Imm);
1710}
1711
1713 SDLoc DL(Op);
1714 EVT ResTy = Op->getValueType(0);
1715 SDValue Vec = Op->getOperand(2);
1716 bool BigEndian = !DAG.getSubtarget().getTargetTriple().isLittleEndian();
1717 MVT ResEltTy = ResTy == MVT::v2i64 ? MVT::i64 : MVT::i32;
1718 SDValue ConstValue = DAG.getConstant(Vec.getScalarValueSizeInBits() - 1,
1719 DL, ResEltTy);
1720 SDValue SplatVec = getBuildVectorSplat(ResTy, ConstValue, BigEndian, DAG);
1721
1722 return DAG.getNode(ISD::AND, DL, ResTy, Vec, SplatVec);
1723}
1724
1726 EVT ResTy = Op->getValueType(0);
1727 SDLoc DL(Op);
1728 SDValue One = DAG.getConstant(1, DL, ResTy);
1729 SDValue Bit = DAG.getNode(ISD::SHL, DL, ResTy, One, truncateVecElts(Op, DAG));
1730
1731 return DAG.getNode(ISD::AND, DL, ResTy, Op->getOperand(1),
1732 DAG.getNOT(DL, Bit, ResTy));
1733}
1734
1736 SDLoc DL(Op);
1737 EVT ResTy = Op->getValueType(0);
1738 APInt BitImm = APInt(ResTy.getScalarSizeInBits(), 1)
1739 << Op->getConstantOperandAPInt(2);
1740 SDValue BitMask = DAG.getConstant(~BitImm, DL, ResTy);
1741
1742 return DAG.getNode(ISD::AND, DL, ResTy, Op->getOperand(1), BitMask);
1743}
1744
1745SDValue MipsSETargetLowering::lowerINTRINSIC_WO_CHAIN(SDValue Op,
1746 SelectionDAG &DAG) const {
1747 SDLoc DL(Op);
1748 unsigned Intrinsic = Op->getConstantOperandVal(0);
1749 switch (Intrinsic) {
1750 default:
1751 return SDValue();
1752 case Intrinsic::mips_shilo:
1753 return lowerDSPIntr(Op, DAG, MipsISD::SHILO);
1754 case Intrinsic::mips_dpau_h_qbl:
1755 return lowerDSPIntr(Op, DAG, MipsISD::DPAU_H_QBL);
1756 case Intrinsic::mips_dpau_h_qbr:
1757 return lowerDSPIntr(Op, DAG, MipsISD::DPAU_H_QBR);
1758 case Intrinsic::mips_dpsu_h_qbl:
1759 return lowerDSPIntr(Op, DAG, MipsISD::DPSU_H_QBL);
1760 case Intrinsic::mips_dpsu_h_qbr:
1761 return lowerDSPIntr(Op, DAG, MipsISD::DPSU_H_QBR);
1762 case Intrinsic::mips_dpa_w_ph:
1763 return lowerDSPIntr(Op, DAG, MipsISD::DPA_W_PH);
1764 case Intrinsic::mips_dps_w_ph:
1765 return lowerDSPIntr(Op, DAG, MipsISD::DPS_W_PH);
1766 case Intrinsic::mips_dpax_w_ph:
1767 return lowerDSPIntr(Op, DAG, MipsISD::DPAX_W_PH);
1768 case Intrinsic::mips_dpsx_w_ph:
1769 return lowerDSPIntr(Op, DAG, MipsISD::DPSX_W_PH);
1770 case Intrinsic::mips_mulsa_w_ph:
1771 return lowerDSPIntr(Op, DAG, MipsISD::MULSA_W_PH);
1772 case Intrinsic::mips_mult:
1773 return lowerDSPIntr(Op, DAG, MipsISD::Mult);
1774 case Intrinsic::mips_multu:
1775 return lowerDSPIntr(Op, DAG, MipsISD::Multu);
1776 case Intrinsic::mips_madd:
1777 return lowerDSPIntr(Op, DAG, MipsISD::MAdd);
1778 case Intrinsic::mips_maddu:
1779 return lowerDSPIntr(Op, DAG, MipsISD::MAddu);
1780 case Intrinsic::mips_msub:
1781 return lowerDSPIntr(Op, DAG, MipsISD::MSub);
1782 case Intrinsic::mips_msubu:
1783 return lowerDSPIntr(Op, DAG, MipsISD::MSubu);
1784 case Intrinsic::mips_addv_b:
1785 case Intrinsic::mips_addv_h:
1786 case Intrinsic::mips_addv_w:
1787 case Intrinsic::mips_addv_d:
1788 return DAG.getNode(ISD::ADD, DL, Op->getValueType(0), Op->getOperand(1),
1789 Op->getOperand(2));
1790 case Intrinsic::mips_addvi_b:
1791 case Intrinsic::mips_addvi_h:
1792 case Intrinsic::mips_addvi_w:
1793 case Intrinsic::mips_addvi_d:
1794 return DAG.getNode(ISD::ADD, DL, Op->getValueType(0), Op->getOperand(1),
1795 lowerMSASplatImm(Op, 2, DAG));
1796 case Intrinsic::mips_and_v:
1797 return DAG.getNode(ISD::AND, DL, Op->getValueType(0), Op->getOperand(1),
1798 Op->getOperand(2));
1799 case Intrinsic::mips_andi_b:
1800 return DAG.getNode(ISD::AND, DL, Op->getValueType(0), Op->getOperand(1),
1801 lowerMSASplatImm(Op, 2, DAG));
1802 case Intrinsic::mips_bclr_b:
1803 case Intrinsic::mips_bclr_h:
1804 case Intrinsic::mips_bclr_w:
1805 case Intrinsic::mips_bclr_d:
1806 return lowerMSABitClear(Op, DAG);
1807 case Intrinsic::mips_bclri_b:
1808 case Intrinsic::mips_bclri_h:
1809 case Intrinsic::mips_bclri_w:
1810 case Intrinsic::mips_bclri_d:
1811 return lowerMSABitClearImm(Op, DAG);
1812 case Intrinsic::mips_binsli_b:
1813 case Intrinsic::mips_binsli_h:
1814 case Intrinsic::mips_binsli_w:
1815 case Intrinsic::mips_binsli_d: {
1816 // binsli_x(IfClear, IfSet, nbits) -> (vselect LBitsMask, IfSet, IfClear)
1817 EVT VecTy = Op->getValueType(0);
1818 EVT EltTy = VecTy.getVectorElementType();
1819 if (Op->getConstantOperandVal(3) >= EltTy.getSizeInBits())
1820 report_fatal_error("Immediate out of range");
1822 Op->getConstantOperandVal(3) + 1);
1823 return DAG.getNode(ISD::VSELECT, DL, VecTy,
1824 DAG.getConstant(Mask, DL, VecTy, true),
1825 Op->getOperand(2), Op->getOperand(1));
1826 }
1827 case Intrinsic::mips_binsri_b:
1828 case Intrinsic::mips_binsri_h:
1829 case Intrinsic::mips_binsri_w:
1830 case Intrinsic::mips_binsri_d: {
1831 // binsri_x(IfClear, IfSet, nbits) -> (vselect RBitsMask, IfSet, IfClear)
1832 EVT VecTy = Op->getValueType(0);
1833 EVT EltTy = VecTy.getVectorElementType();
1834 if (Op->getConstantOperandVal(3) >= EltTy.getSizeInBits())
1835 report_fatal_error("Immediate out of range");
1836 APInt Mask = APInt::getLowBitsSet(EltTy.getSizeInBits(),
1837 Op->getConstantOperandVal(3) + 1);
1838 return DAG.getNode(ISD::VSELECT, DL, VecTy,
1839 DAG.getConstant(Mask, DL, VecTy, true),
1840 Op->getOperand(2), Op->getOperand(1));
1841 }
1842 case Intrinsic::mips_bmnz_v:
1843 return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0), Op->getOperand(3),
1844 Op->getOperand(2), Op->getOperand(1));
1845 case Intrinsic::mips_bmnzi_b:
1846 return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0),
1847 lowerMSASplatImm(Op, 3, DAG), Op->getOperand(2),
1848 Op->getOperand(1));
1849 case Intrinsic::mips_bmz_v:
1850 return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0), Op->getOperand(3),
1851 Op->getOperand(1), Op->getOperand(2));
1852 case Intrinsic::mips_bmzi_b:
1853 return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0),
1854 lowerMSASplatImm(Op, 3, DAG), Op->getOperand(1),
1855 Op->getOperand(2));
1856 case Intrinsic::mips_bneg_b:
1857 case Intrinsic::mips_bneg_h:
1858 case Intrinsic::mips_bneg_w:
1859 case Intrinsic::mips_bneg_d: {
1860 EVT VecTy = Op->getValueType(0);
1861 SDValue One = DAG.getConstant(1, DL, VecTy);
1862
1863 return DAG.getNode(ISD::XOR, DL, VecTy, Op->getOperand(1),
1864 DAG.getNode(ISD::SHL, DL, VecTy, One,
1865 truncateVecElts(Op, DAG)));
1866 }
1867 case Intrinsic::mips_bnegi_b:
1868 case Intrinsic::mips_bnegi_h:
1869 case Intrinsic::mips_bnegi_w:
1870 case Intrinsic::mips_bnegi_d:
1871 return lowerMSABinaryBitImmIntr(Op, DAG, ISD::XOR, Op->getOperand(2),
1872 !Subtarget.isLittle());
1873 case Intrinsic::mips_bnz_b:
1874 case Intrinsic::mips_bnz_h:
1875 case Intrinsic::mips_bnz_w:
1876 case Intrinsic::mips_bnz_d:
1877 return DAG.getNode(MipsISD::VALL_NONZERO, DL, Op->getValueType(0),
1878 Op->getOperand(1));
1879 case Intrinsic::mips_bnz_v:
1880 return DAG.getNode(MipsISD::VANY_NONZERO, DL, Op->getValueType(0),
1881 Op->getOperand(1));
1882 case Intrinsic::mips_bsel_v:
1883 // bsel_v(Mask, IfClear, IfSet) -> (vselect Mask, IfSet, IfClear)
1884 return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0),
1885 Op->getOperand(1), Op->getOperand(3),
1886 Op->getOperand(2));
1887 case Intrinsic::mips_bseli_b:
1888 // bseli_v(Mask, IfClear, IfSet) -> (vselect Mask, IfSet, IfClear)
1889 return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0),
1890 Op->getOperand(1), lowerMSASplatImm(Op, 3, DAG),
1891 Op->getOperand(2));
1892 case Intrinsic::mips_bset_b:
1893 case Intrinsic::mips_bset_h:
1894 case Intrinsic::mips_bset_w:
1895 case Intrinsic::mips_bset_d: {
1896 EVT VecTy = Op->getValueType(0);
1897 SDValue One = DAG.getConstant(1, DL, VecTy);
1898
1899 return DAG.getNode(ISD::OR, DL, VecTy, Op->getOperand(1),
1900 DAG.getNode(ISD::SHL, DL, VecTy, One,
1901 truncateVecElts(Op, DAG)));
1902 }
1903 case Intrinsic::mips_bseti_b:
1904 case Intrinsic::mips_bseti_h:
1905 case Intrinsic::mips_bseti_w:
1906 case Intrinsic::mips_bseti_d:
1907 return lowerMSABinaryBitImmIntr(Op, DAG, ISD::OR, Op->getOperand(2),
1908 !Subtarget.isLittle());
1909 case Intrinsic::mips_bz_b:
1910 case Intrinsic::mips_bz_h:
1911 case Intrinsic::mips_bz_w:
1912 case Intrinsic::mips_bz_d:
1913 return DAG.getNode(MipsISD::VALL_ZERO, DL, Op->getValueType(0),
1914 Op->getOperand(1));
1915 case Intrinsic::mips_bz_v:
1916 return DAG.getNode(MipsISD::VANY_ZERO, DL, Op->getValueType(0),
1917 Op->getOperand(1));
1918 case Intrinsic::mips_ceq_b:
1919 case Intrinsic::mips_ceq_h:
1920 case Intrinsic::mips_ceq_w:
1921 case Intrinsic::mips_ceq_d:
1922 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1923 Op->getOperand(2), ISD::SETEQ);
1924 case Intrinsic::mips_ceqi_b:
1925 case Intrinsic::mips_ceqi_h:
1926 case Intrinsic::mips_ceqi_w:
1927 case Intrinsic::mips_ceqi_d:
1928 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1929 lowerMSASplatImm(Op, 2, DAG, true), ISD::SETEQ);
1930 case Intrinsic::mips_cle_s_b:
1931 case Intrinsic::mips_cle_s_h:
1932 case Intrinsic::mips_cle_s_w:
1933 case Intrinsic::mips_cle_s_d:
1934 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1935 Op->getOperand(2), ISD::SETLE);
1936 case Intrinsic::mips_clei_s_b:
1937 case Intrinsic::mips_clei_s_h:
1938 case Intrinsic::mips_clei_s_w:
1939 case Intrinsic::mips_clei_s_d:
1940 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1941 lowerMSASplatImm(Op, 2, DAG, true), ISD::SETLE);
1942 case Intrinsic::mips_cle_u_b:
1943 case Intrinsic::mips_cle_u_h:
1944 case Intrinsic::mips_cle_u_w:
1945 case Intrinsic::mips_cle_u_d:
1946 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1947 Op->getOperand(2), ISD::SETULE);
1948 case Intrinsic::mips_clei_u_b:
1949 case Intrinsic::mips_clei_u_h:
1950 case Intrinsic::mips_clei_u_w:
1951 case Intrinsic::mips_clei_u_d:
1952 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1953 lowerMSASplatImm(Op, 2, DAG), ISD::SETULE);
1954 case Intrinsic::mips_clt_s_b:
1955 case Intrinsic::mips_clt_s_h:
1956 case Intrinsic::mips_clt_s_w:
1957 case Intrinsic::mips_clt_s_d:
1958 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1959 Op->getOperand(2), ISD::SETLT);
1960 case Intrinsic::mips_clti_s_b:
1961 case Intrinsic::mips_clti_s_h:
1962 case Intrinsic::mips_clti_s_w:
1963 case Intrinsic::mips_clti_s_d:
1964 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1965 lowerMSASplatImm(Op, 2, DAG, true), ISD::SETLT);
1966 case Intrinsic::mips_clt_u_b:
1967 case Intrinsic::mips_clt_u_h:
1968 case Intrinsic::mips_clt_u_w:
1969 case Intrinsic::mips_clt_u_d:
1970 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1971 Op->getOperand(2), ISD::SETULT);
1972 case Intrinsic::mips_clti_u_b:
1973 case Intrinsic::mips_clti_u_h:
1974 case Intrinsic::mips_clti_u_w:
1975 case Intrinsic::mips_clti_u_d:
1976 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
1977 lowerMSASplatImm(Op, 2, DAG), ISD::SETULT);
1978 case Intrinsic::mips_copy_s_b:
1979 case Intrinsic::mips_copy_s_h:
1980 case Intrinsic::mips_copy_s_w:
1981 return lowerMSACopyIntr(Op, DAG, MipsISD::VEXTRACT_SEXT_ELT);
1982 case Intrinsic::mips_copy_s_d:
1983 if (Subtarget.hasMips64())
1984 // Lower directly into VEXTRACT_SEXT_ELT since i64 is legal on Mips64.
1985 return lowerMSACopyIntr(Op, DAG, MipsISD::VEXTRACT_SEXT_ELT);
1986 else {
1987 // Lower into the generic EXTRACT_VECTOR_ELT node and let the type
1988 // legalizer and EXTRACT_VECTOR_ELT lowering sort it out.
1989 return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SDLoc(Op),
1990 Op->getValueType(0), Op->getOperand(1),
1991 Op->getOperand(2));
1992 }
1993 case Intrinsic::mips_copy_u_b:
1994 case Intrinsic::mips_copy_u_h:
1995 case Intrinsic::mips_copy_u_w:
1996 return lowerMSACopyIntr(Op, DAG, MipsISD::VEXTRACT_ZEXT_ELT);
1997 case Intrinsic::mips_copy_u_d:
1998 if (Subtarget.hasMips64())
1999 // Lower directly into VEXTRACT_ZEXT_ELT since i64 is legal on Mips64.
2000 return lowerMSACopyIntr(Op, DAG, MipsISD::VEXTRACT_ZEXT_ELT);
2001 else {
2002 // Lower into the generic EXTRACT_VECTOR_ELT node and let the type
2003 // legalizer and EXTRACT_VECTOR_ELT lowering sort it out.
2004 // Note: When i64 is illegal, this results in copy_s.w instructions
2005 // instead of copy_u.w instructions. This makes no difference to the
2006 // behaviour since i64 is only illegal when the register file is 32-bit.
2007 return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SDLoc(Op),
2008 Op->getValueType(0), Op->getOperand(1),
2009 Op->getOperand(2));
2010 }
2011 case Intrinsic::mips_div_s_b:
2012 case Intrinsic::mips_div_s_h:
2013 case Intrinsic::mips_div_s_w:
2014 case Intrinsic::mips_div_s_d:
2015 return DAG.getNode(ISD::SDIV, DL, Op->getValueType(0), Op->getOperand(1),
2016 Op->getOperand(2));
2017 case Intrinsic::mips_div_u_b:
2018 case Intrinsic::mips_div_u_h:
2019 case Intrinsic::mips_div_u_w:
2020 case Intrinsic::mips_div_u_d:
2021 return DAG.getNode(ISD::UDIV, DL, Op->getValueType(0), Op->getOperand(1),
2022 Op->getOperand(2));
2023 case Intrinsic::mips_fadd_w:
2024 case Intrinsic::mips_fadd_d:
2025 return DAG.getNode(ISD::FADD, DL, Op->getValueType(0), Op->getOperand(1),
2026 Op->getOperand(2), Op->getFlags());
2027 // Don't lower mips_fcaf_[wd] since LLVM folds SETFALSE condcodes away
2028 case Intrinsic::mips_fceq_w:
2029 case Intrinsic::mips_fceq_d:
2030 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2031 Op->getOperand(2), ISD::SETOEQ);
2032 case Intrinsic::mips_fcle_w:
2033 case Intrinsic::mips_fcle_d:
2034 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2035 Op->getOperand(2), ISD::SETOLE);
2036 case Intrinsic::mips_fclt_w:
2037 case Intrinsic::mips_fclt_d:
2038 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2039 Op->getOperand(2), ISD::SETOLT);
2040 case Intrinsic::mips_fcne_w:
2041 case Intrinsic::mips_fcne_d:
2042 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2043 Op->getOperand(2), ISD::SETONE);
2044 case Intrinsic::mips_fcor_w:
2045 case Intrinsic::mips_fcor_d:
2046 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2047 Op->getOperand(2), ISD::SETO);
2048 case Intrinsic::mips_fcueq_w:
2049 case Intrinsic::mips_fcueq_d:
2050 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2051 Op->getOperand(2), ISD::SETUEQ);
2052 case Intrinsic::mips_fcule_w:
2053 case Intrinsic::mips_fcule_d:
2054 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2055 Op->getOperand(2), ISD::SETULE);
2056 case Intrinsic::mips_fcult_w:
2057 case Intrinsic::mips_fcult_d:
2058 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2059 Op->getOperand(2), ISD::SETULT);
2060 case Intrinsic::mips_fcun_w:
2061 case Intrinsic::mips_fcun_d:
2062 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2063 Op->getOperand(2), ISD::SETUO);
2064 case Intrinsic::mips_fcune_w:
2065 case Intrinsic::mips_fcune_d:
2066 return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1),
2067 Op->getOperand(2), ISD::SETUNE);
2068 case Intrinsic::mips_fdiv_w:
2069 case Intrinsic::mips_fdiv_d:
2070 // TODO: If intrinsics have fast-math-flags, propagate them.
2071 return DAG.getNode(ISD::FDIV, DL, Op->getValueType(0), Op->getOperand(1),
2072 Op->getOperand(2));
2073 case Intrinsic::mips_ffint_u_w:
2074 case Intrinsic::mips_ffint_u_d:
2075 return DAG.getNode(ISD::UINT_TO_FP, DL, Op->getValueType(0),
2076 Op->getOperand(1));
2077 case Intrinsic::mips_ffint_s_w:
2078 case Intrinsic::mips_ffint_s_d:
2079 return DAG.getNode(ISD::SINT_TO_FP, DL, Op->getValueType(0),
2080 Op->getOperand(1));
2081 case Intrinsic::mips_fill_b:
2082 case Intrinsic::mips_fill_h:
2083 case Intrinsic::mips_fill_w:
2084 case Intrinsic::mips_fill_d: {
2085 EVT ResTy = Op->getValueType(0);
2087 Op->getOperand(1));
2088
2089 // If ResTy is v2i64 then the type legalizer will break this node down into
2090 // an equivalent v4i32.
2091 return DAG.getBuildVector(ResTy, DL, Ops);
2092 }
2093 case Intrinsic::mips_fexp2_w:
2094 case Intrinsic::mips_fexp2_d: {
2095 // TODO: If intrinsics have fast-math-flags, propagate them.
2096 EVT ResTy = Op->getValueType(0);
2097 return DAG.getNode(
2098 ISD::FMUL, SDLoc(Op), ResTy, Op->getOperand(1),
2099 DAG.getNode(ISD::FEXP2, SDLoc(Op), ResTy, Op->getOperand(2)));
2100 }
2101 case Intrinsic::mips_flog2_w:
2102 case Intrinsic::mips_flog2_d:
2103 return DAG.getNode(ISD::FLOG2, DL, Op->getValueType(0), Op->getOperand(1));
2104 case Intrinsic::mips_fmadd_w:
2105 case Intrinsic::mips_fmadd_d: {
2106 // The mips intrinsics compute `a + b*c`, which is `fma(b, c, a)`.
2107 return DAG.getNode(ISD::FMA, SDLoc(Op), Op->getValueType(0),
2108 Op->getOperand(2), Op->getOperand(3), Op->getOperand(1));
2109 }
2110 case Intrinsic::mips_fmul_w:
2111 case Intrinsic::mips_fmul_d:
2112 return DAG.getNode(ISD::FMUL, DL, Op->getValueType(0), Op->getOperand(1),
2113 Op->getOperand(2), Op->getFlags());
2114 case Intrinsic::mips_fmsub_w:
2115 case Intrinsic::mips_fmsub_d: {
2116 // TODO: If intrinsics have fast-math-flags, propagate them.
2117 return DAG.getNode(MipsISD::FMS, SDLoc(Op), Op->getValueType(0),
2118 Op->getOperand(1), Op->getOperand(2), Op->getOperand(3));
2119 }
2120 case Intrinsic::mips_frint_w:
2121 case Intrinsic::mips_frint_d:
2122 return DAG.getNode(ISD::FRINT, DL, Op->getValueType(0), Op->getOperand(1));
2123 case Intrinsic::mips_fsqrt_w:
2124 case Intrinsic::mips_fsqrt_d:
2125 return DAG.getNode(ISD::FSQRT, DL, Op->getValueType(0), Op->getOperand(1));
2126 case Intrinsic::mips_fsub_w:
2127 case Intrinsic::mips_fsub_d:
2128 return DAG.getNode(ISD::FSUB, DL, Op->getValueType(0), Op->getOperand(1),
2129 Op->getOperand(2), Op->getFlags());
2130 case Intrinsic::mips_ftrunc_u_w:
2131 case Intrinsic::mips_ftrunc_u_d:
2132 return DAG.getNode(ISD::FP_TO_UINT, DL, Op->getValueType(0),
2133 Op->getOperand(1));
2134 case Intrinsic::mips_ftrunc_s_w:
2135 case Intrinsic::mips_ftrunc_s_d:
2136 return DAG.getNode(ISD::FP_TO_SINT, DL, Op->getValueType(0),
2137 Op->getOperand(1));
2138 case Intrinsic::mips_ilvev_b:
2139 case Intrinsic::mips_ilvev_h:
2140 case Intrinsic::mips_ilvev_w:
2141 case Intrinsic::mips_ilvev_d:
2142 return DAG.getNode(MipsISD::ILVEV, DL, Op->getValueType(0),
2143 Op->getOperand(1), Op->getOperand(2));
2144 case Intrinsic::mips_ilvl_b:
2145 case Intrinsic::mips_ilvl_h:
2146 case Intrinsic::mips_ilvl_w:
2147 case Intrinsic::mips_ilvl_d:
2148 return DAG.getNode(MipsISD::ILVL, DL, Op->getValueType(0),
2149 Op->getOperand(1), Op->getOperand(2));
2150 case Intrinsic::mips_ilvod_b:
2151 case Intrinsic::mips_ilvod_h:
2152 case Intrinsic::mips_ilvod_w:
2153 case Intrinsic::mips_ilvod_d:
2154 return DAG.getNode(MipsISD::ILVOD, DL, Op->getValueType(0),
2155 Op->getOperand(1), Op->getOperand(2));
2156 case Intrinsic::mips_ilvr_b:
2157 case Intrinsic::mips_ilvr_h:
2158 case Intrinsic::mips_ilvr_w:
2159 case Intrinsic::mips_ilvr_d:
2160 return DAG.getNode(MipsISD::ILVR, DL, Op->getValueType(0),
2161 Op->getOperand(1), Op->getOperand(2));
2162 case Intrinsic::mips_insert_b:
2163 case Intrinsic::mips_insert_h:
2164 case Intrinsic::mips_insert_w:
2165 case Intrinsic::mips_insert_d:
2166 return DAG.getNode(ISD::INSERT_VECTOR_ELT, SDLoc(Op), Op->getValueType(0),
2167 Op->getOperand(1), Op->getOperand(3), Op->getOperand(2));
2168 case Intrinsic::mips_insve_b:
2169 case Intrinsic::mips_insve_h:
2170 case Intrinsic::mips_insve_w:
2171 case Intrinsic::mips_insve_d: {
2172 // Report an error for out of range values.
2173 int64_t Max;
2174 switch (Intrinsic) {
2175 case Intrinsic::mips_insve_b: Max = 15; break;
2176 case Intrinsic::mips_insve_h: Max = 7; break;
2177 case Intrinsic::mips_insve_w: Max = 3; break;
2178 case Intrinsic::mips_insve_d: Max = 1; break;
2179 default: llvm_unreachable("Unmatched intrinsic");
2180 }
2181 int64_t Value = cast<ConstantSDNode>(Op->getOperand(2))->getSExtValue();
2182 if (Value < 0 || Value > Max)
2183 report_fatal_error("Immediate out of range");
2184 return DAG.getNode(MipsISD::INSVE, DL, Op->getValueType(0),
2185 Op->getOperand(1), Op->getOperand(2), Op->getOperand(3),
2186 DAG.getConstant(0, DL, MVT::i32));
2187 }
2188 case Intrinsic::mips_ldi_b:
2189 case Intrinsic::mips_ldi_h:
2190 case Intrinsic::mips_ldi_w:
2191 case Intrinsic::mips_ldi_d:
2192 return lowerMSASplatImm(Op, 1, DAG, true);
2193 case Intrinsic::mips_lsa:
2194 case Intrinsic::mips_dlsa: {
2195 EVT ResTy = Op->getValueType(0);
2196 return DAG.getNode(ISD::ADD, SDLoc(Op), ResTy, Op->getOperand(1),
2197 DAG.getNode(ISD::SHL, SDLoc(Op), ResTy,
2198 Op->getOperand(2), Op->getOperand(3)));
2199 }
2200 case Intrinsic::mips_maddv_b:
2201 case Intrinsic::mips_maddv_h:
2202 case Intrinsic::mips_maddv_w:
2203 case Intrinsic::mips_maddv_d: {
2204 EVT ResTy = Op->getValueType(0);
2205 return DAG.getNode(ISD::ADD, SDLoc(Op), ResTy, Op->getOperand(1),
2206 DAG.getNode(ISD::MUL, SDLoc(Op), ResTy,
2207 Op->getOperand(2), Op->getOperand(3)));
2208 }
2209 case Intrinsic::mips_max_s_b:
2210 case Intrinsic::mips_max_s_h:
2211 case Intrinsic::mips_max_s_w:
2212 case Intrinsic::mips_max_s_d:
2213 return DAG.getNode(ISD::SMAX, DL, Op->getValueType(0),
2214 Op->getOperand(1), Op->getOperand(2));
2215 case Intrinsic::mips_max_u_b:
2216 case Intrinsic::mips_max_u_h:
2217 case Intrinsic::mips_max_u_w:
2218 case Intrinsic::mips_max_u_d:
2219 return DAG.getNode(ISD::UMAX, DL, Op->getValueType(0),
2220 Op->getOperand(1), Op->getOperand(2));
2221 case Intrinsic::mips_maxi_s_b:
2222 case Intrinsic::mips_maxi_s_h:
2223 case Intrinsic::mips_maxi_s_w:
2224 case Intrinsic::mips_maxi_s_d:
2225 return DAG.getNode(ISD::SMAX, DL, Op->getValueType(0),
2226 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG, true));
2227 case Intrinsic::mips_maxi_u_b:
2228 case Intrinsic::mips_maxi_u_h:
2229 case Intrinsic::mips_maxi_u_w:
2230 case Intrinsic::mips_maxi_u_d:
2231 return DAG.getNode(ISD::UMAX, DL, Op->getValueType(0),
2232 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
2233 case Intrinsic::mips_min_s_b:
2234 case Intrinsic::mips_min_s_h:
2235 case Intrinsic::mips_min_s_w:
2236 case Intrinsic::mips_min_s_d:
2237 return DAG.getNode(ISD::SMIN, DL, Op->getValueType(0),
2238 Op->getOperand(1), Op->getOperand(2));
2239 case Intrinsic::mips_min_u_b:
2240 case Intrinsic::mips_min_u_h:
2241 case Intrinsic::mips_min_u_w:
2242 case Intrinsic::mips_min_u_d:
2243 return DAG.getNode(ISD::UMIN, DL, Op->getValueType(0),
2244 Op->getOperand(1), Op->getOperand(2));
2245 case Intrinsic::mips_mini_s_b:
2246 case Intrinsic::mips_mini_s_h:
2247 case Intrinsic::mips_mini_s_w:
2248 case Intrinsic::mips_mini_s_d:
2249 return DAG.getNode(ISD::SMIN, DL, Op->getValueType(0),
2250 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG, true));
2251 case Intrinsic::mips_mini_u_b:
2252 case Intrinsic::mips_mini_u_h:
2253 case Intrinsic::mips_mini_u_w:
2254 case Intrinsic::mips_mini_u_d:
2255 return DAG.getNode(ISD::UMIN, DL, Op->getValueType(0),
2256 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
2257 case Intrinsic::mips_mod_s_b:
2258 case Intrinsic::mips_mod_s_h:
2259 case Intrinsic::mips_mod_s_w:
2260 case Intrinsic::mips_mod_s_d:
2261 return DAG.getNode(ISD::SREM, DL, Op->getValueType(0), Op->getOperand(1),
2262 Op->getOperand(2));
2263 case Intrinsic::mips_mod_u_b:
2264 case Intrinsic::mips_mod_u_h:
2265 case Intrinsic::mips_mod_u_w:
2266 case Intrinsic::mips_mod_u_d:
2267 return DAG.getNode(ISD::UREM, DL, Op->getValueType(0), Op->getOperand(1),
2268 Op->getOperand(2));
2269 case Intrinsic::mips_mulv_b:
2270 case Intrinsic::mips_mulv_h:
2271 case Intrinsic::mips_mulv_w:
2272 case Intrinsic::mips_mulv_d:
2273 return DAG.getNode(ISD::MUL, DL, Op->getValueType(0), Op->getOperand(1),
2274 Op->getOperand(2));
2275 case Intrinsic::mips_msubv_b:
2276 case Intrinsic::mips_msubv_h:
2277 case Intrinsic::mips_msubv_w:
2278 case Intrinsic::mips_msubv_d: {
2279 EVT ResTy = Op->getValueType(0);
2280 return DAG.getNode(ISD::SUB, SDLoc(Op), ResTy, Op->getOperand(1),
2281 DAG.getNode(ISD::MUL, SDLoc(Op), ResTy,
2282 Op->getOperand(2), Op->getOperand(3)));
2283 }
2284 case Intrinsic::mips_nlzc_b:
2285 case Intrinsic::mips_nlzc_h:
2286 case Intrinsic::mips_nlzc_w:
2287 case Intrinsic::mips_nlzc_d:
2288 return DAG.getNode(ISD::CTLZ, DL, Op->getValueType(0), Op->getOperand(1));
2289 case Intrinsic::mips_nor_v: {
2290 SDValue Res = DAG.getNode(ISD::OR, DL, Op->getValueType(0),
2291 Op->getOperand(1), Op->getOperand(2));
2292 return DAG.getNOT(DL, Res, Res->getValueType(0));
2293 }
2294 case Intrinsic::mips_nori_b: {
2295 SDValue Res = DAG.getNode(ISD::OR, DL, Op->getValueType(0),
2296 Op->getOperand(1),
2297 lowerMSASplatImm(Op, 2, DAG));
2298 return DAG.getNOT(DL, Res, Res->getValueType(0));
2299 }
2300 case Intrinsic::mips_or_v:
2301 return DAG.getNode(ISD::OR, DL, Op->getValueType(0), Op->getOperand(1),
2302 Op->getOperand(2));
2303 case Intrinsic::mips_ori_b:
2304 return DAG.getNode(ISD::OR, DL, Op->getValueType(0),
2305 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
2306 case Intrinsic::mips_pckev_b:
2307 case Intrinsic::mips_pckev_h:
2308 case Intrinsic::mips_pckev_w:
2309 case Intrinsic::mips_pckev_d:
2310 return DAG.getNode(MipsISD::PCKEV, DL, Op->getValueType(0),
2311 Op->getOperand(1), Op->getOperand(2));
2312 case Intrinsic::mips_pckod_b:
2313 case Intrinsic::mips_pckod_h:
2314 case Intrinsic::mips_pckod_w:
2315 case Intrinsic::mips_pckod_d:
2316 return DAG.getNode(MipsISD::PCKOD, DL, Op->getValueType(0),
2317 Op->getOperand(1), Op->getOperand(2));
2318 case Intrinsic::mips_pcnt_b:
2319 case Intrinsic::mips_pcnt_h:
2320 case Intrinsic::mips_pcnt_w:
2321 case Intrinsic::mips_pcnt_d:
2322 return DAG.getNode(ISD::CTPOP, DL, Op->getValueType(0), Op->getOperand(1));
2323 case Intrinsic::mips_sat_s_b:
2324 case Intrinsic::mips_sat_s_h:
2325 case Intrinsic::mips_sat_s_w:
2326 case Intrinsic::mips_sat_s_d:
2327 case Intrinsic::mips_sat_u_b:
2328 case Intrinsic::mips_sat_u_h:
2329 case Intrinsic::mips_sat_u_w:
2330 case Intrinsic::mips_sat_u_d: {
2331 // Report an error for out of range values.
2332 int64_t Max;
2333 switch (Intrinsic) {
2334 case Intrinsic::mips_sat_s_b:
2335 case Intrinsic::mips_sat_u_b: Max = 7; break;
2336 case Intrinsic::mips_sat_s_h:
2337 case Intrinsic::mips_sat_u_h: Max = 15; break;
2338 case Intrinsic::mips_sat_s_w:
2339 case Intrinsic::mips_sat_u_w: Max = 31; break;
2340 case Intrinsic::mips_sat_s_d:
2341 case Intrinsic::mips_sat_u_d: Max = 63; break;
2342 default: llvm_unreachable("Unmatched intrinsic");
2343 }
2344 int64_t Value = cast<ConstantSDNode>(Op->getOperand(2))->getSExtValue();
2345 if (Value < 0 || Value > Max)
2346 report_fatal_error("Immediate out of range");
2347 return SDValue();
2348 }
2349 case Intrinsic::mips_shf_b:
2350 case Intrinsic::mips_shf_h:
2351 case Intrinsic::mips_shf_w: {
2352 int64_t Value = cast<ConstantSDNode>(Op->getOperand(2))->getSExtValue();
2353 if (Value < 0 || Value > 255)
2354 report_fatal_error("Immediate out of range");
2355 return DAG.getNode(MipsISD::SHF, DL, Op->getValueType(0),
2356 Op->getOperand(2), Op->getOperand(1));
2357 }
2358 case Intrinsic::mips_sldi_b:
2359 case Intrinsic::mips_sldi_h:
2360 case Intrinsic::mips_sldi_w:
2361 case Intrinsic::mips_sldi_d: {
2362 // Report an error for out of range values.
2363 int64_t Max;
2364 switch (Intrinsic) {
2365 case Intrinsic::mips_sldi_b: Max = 15; break;
2366 case Intrinsic::mips_sldi_h: Max = 7; break;
2367 case Intrinsic::mips_sldi_w: Max = 3; break;
2368 case Intrinsic::mips_sldi_d: Max = 1; break;
2369 default: llvm_unreachable("Unmatched intrinsic");
2370 }
2371 int64_t Value = cast<ConstantSDNode>(Op->getOperand(3))->getSExtValue();
2372 if (Value < 0 || Value > Max)
2373 report_fatal_error("Immediate out of range");
2374 return SDValue();
2375 }
2376 case Intrinsic::mips_sll_b:
2377 case Intrinsic::mips_sll_h:
2378 case Intrinsic::mips_sll_w:
2379 case Intrinsic::mips_sll_d:
2380 return DAG.getNode(ISD::SHL, DL, Op->getValueType(0), Op->getOperand(1),
2381 truncateVecElts(Op, DAG));
2382 case Intrinsic::mips_slli_b:
2383 case Intrinsic::mips_slli_h:
2384 case Intrinsic::mips_slli_w:
2385 case Intrinsic::mips_slli_d:
2386 return DAG.getNode(ISD::SHL, DL, Op->getValueType(0),
2387 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
2388 case Intrinsic::mips_splat_b:
2389 case Intrinsic::mips_splat_h:
2390 case Intrinsic::mips_splat_w:
2391 case Intrinsic::mips_splat_d:
2392 // We can't lower via VECTOR_SHUFFLE because it requires constant shuffle
2393 // masks, nor can we lower via BUILD_VECTOR & EXTRACT_VECTOR_ELT because
2394 // EXTRACT_VECTOR_ELT can't extract i64's on MIPS32.
2395 // Instead we lower to MipsISD::VSHF and match from there.
2396 return DAG.getNode(MipsISD::VSHF, DL, Op->getValueType(0),
2397 lowerMSASplatZExt(Op, 2, DAG), Op->getOperand(1),
2398 Op->getOperand(1));
2399 case Intrinsic::mips_splati_b:
2400 case Intrinsic::mips_splati_h:
2401 case Intrinsic::mips_splati_w:
2402 case Intrinsic::mips_splati_d:
2403 return DAG.getNode(MipsISD::VSHF, DL, Op->getValueType(0),
2404 lowerMSASplatImm(Op, 2, DAG), Op->getOperand(1),
2405 Op->getOperand(1));
2406 case Intrinsic::mips_sra_b:
2407 case Intrinsic::mips_sra_h:
2408 case Intrinsic::mips_sra_w:
2409 case Intrinsic::mips_sra_d:
2410 return DAG.getNode(ISD::SRA, DL, Op->getValueType(0), Op->getOperand(1),
2411 truncateVecElts(Op, DAG));
2412 case Intrinsic::mips_srai_b:
2413 case Intrinsic::mips_srai_h:
2414 case Intrinsic::mips_srai_w:
2415 case Intrinsic::mips_srai_d:
2416 return DAG.getNode(ISD::SRA, DL, Op->getValueType(0),
2417 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
2418 case Intrinsic::mips_srari_b:
2419 case Intrinsic::mips_srari_h:
2420 case Intrinsic::mips_srari_w:
2421 case Intrinsic::mips_srari_d: {
2422 // Report an error for out of range values.
2423 int64_t Max;
2424 switch (Intrinsic) {
2425 case Intrinsic::mips_srari_b: Max = 7; break;
2426 case Intrinsic::mips_srari_h: Max = 15; break;
2427 case Intrinsic::mips_srari_w: Max = 31; break;
2428 case Intrinsic::mips_srari_d: Max = 63; break;
2429 default: llvm_unreachable("Unmatched intrinsic");
2430 }
2431 int64_t Value = cast<ConstantSDNode>(Op->getOperand(2))->getSExtValue();
2432 if (Value < 0 || Value > Max)
2433 report_fatal_error("Immediate out of range");
2434 return SDValue();
2435 }
2436 case Intrinsic::mips_srl_b:
2437 case Intrinsic::mips_srl_h:
2438 case Intrinsic::mips_srl_w:
2439 case Intrinsic::mips_srl_d:
2440 return DAG.getNode(ISD::SRL, DL, Op->getValueType(0), Op->getOperand(1),
2441 truncateVecElts(Op, DAG));
2442 case Intrinsic::mips_srli_b:
2443 case Intrinsic::mips_srli_h:
2444 case Intrinsic::mips_srli_w:
2445 case Intrinsic::mips_srli_d:
2446 return DAG.getNode(ISD::SRL, DL, Op->getValueType(0),
2447 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
2448 case Intrinsic::mips_srlri_b:
2449 case Intrinsic::mips_srlri_h:
2450 case Intrinsic::mips_srlri_w:
2451 case Intrinsic::mips_srlri_d: {
2452 // Report an error for out of range values.
2453 int64_t Max;
2454 switch (Intrinsic) {
2455 case Intrinsic::mips_srlri_b: Max = 7; break;
2456 case Intrinsic::mips_srlri_h: Max = 15; break;
2457 case Intrinsic::mips_srlri_w: Max = 31; break;
2458 case Intrinsic::mips_srlri_d: Max = 63; break;
2459 default: llvm_unreachable("Unmatched intrinsic");
2460 }
2461 int64_t Value = cast<ConstantSDNode>(Op->getOperand(2))->getSExtValue();
2462 if (Value < 0 || Value > Max)
2463 report_fatal_error("Immediate out of range");
2464 return SDValue();
2465 }
2466 case Intrinsic::mips_subv_b:
2467 case Intrinsic::mips_subv_h:
2468 case Intrinsic::mips_subv_w:
2469 case Intrinsic::mips_subv_d:
2470 return DAG.getNode(ISD::SUB, DL, Op->getValueType(0), Op->getOperand(1),
2471 Op->getOperand(2));
2472 case Intrinsic::mips_subvi_b:
2473 case Intrinsic::mips_subvi_h:
2474 case Intrinsic::mips_subvi_w:
2475 case Intrinsic::mips_subvi_d:
2476 return DAG.getNode(ISD::SUB, DL, Op->getValueType(0),
2477 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
2478 case Intrinsic::mips_vshf_b:
2479 case Intrinsic::mips_vshf_h:
2480 case Intrinsic::mips_vshf_w:
2481 case Intrinsic::mips_vshf_d:
2482 return DAG.getNode(MipsISD::VSHF, DL, Op->getValueType(0),
2483 Op->getOperand(1), Op->getOperand(2), Op->getOperand(3));
2484 case Intrinsic::mips_xor_v:
2485 return DAG.getNode(ISD::XOR, DL, Op->getValueType(0), Op->getOperand(1),
2486 Op->getOperand(2));
2487 case Intrinsic::mips_xori_b:
2488 return DAG.getNode(ISD::XOR, DL, Op->getValueType(0),
2489 Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG));
2490 case Intrinsic::thread_pointer: {
2491 EVT PtrVT = getPointerTy(DAG.getDataLayout());
2492 return DAG.getNode(MipsISD::ThreadPointer, DL, PtrVT);
2493 }
2494 }
2495}
2496
2497static SDValue lowerMSALoadIntr(SDValue Op, SelectionDAG &DAG, unsigned Intr,
2498 const MipsSubtarget &Subtarget) {
2499 SDLoc DL(Op);
2500 SDValue ChainIn = Op->getOperand(0);
2501 SDValue Address = Op->getOperand(2);
2502 SDValue Offset = Op->getOperand(3);
2503 EVT ResTy = Op->getValueType(0);
2504 EVT PtrTy = Address->getValueType(0);
2505
2506 // For N64 addresses have the underlying type MVT::i64. This intrinsic
2507 // however takes an i32 signed constant offset. The actual type of the
2508 // intrinsic is a scaled signed i10.
2509 if (Subtarget.isABI_N64())
2510 Offset = DAG.getNode(ISD::SIGN_EXTEND, DL, PtrTy, Offset);
2511
2512 Address = DAG.getNode(ISD::ADD, DL, PtrTy, Address, Offset);
2513 return DAG.getLoad(ResTy, DL, ChainIn, Address, MachinePointerInfo(),
2514 Align(16));
2515}
2516
2517SDValue MipsSETargetLowering::lowerINTRINSIC_W_CHAIN(SDValue Op,
2518 SelectionDAG &DAG) const {
2519 unsigned Intr = Op->getConstantOperandVal(1);
2520 switch (Intr) {
2521 default:
2522 return SDValue();
2523 case Intrinsic::mips_extp:
2524 return lowerDSPIntr(Op, DAG, MipsISD::EXTP);
2525 case Intrinsic::mips_extpdp:
2526 return lowerDSPIntr(Op, DAG, MipsISD::EXTPDP);
2527 case Intrinsic::mips_extr_w:
2528 return lowerDSPIntr(Op, DAG, MipsISD::EXTR_W);
2529 case Intrinsic::mips_extr_r_w:
2530 return lowerDSPIntr(Op, DAG, MipsISD::EXTR_R_W);
2531 case Intrinsic::mips_extr_rs_w:
2532 return lowerDSPIntr(Op, DAG, MipsISD::EXTR_RS_W);
2533 case Intrinsic::mips_extr_s_h:
2534 return lowerDSPIntr(Op, DAG, MipsISD::EXTR_S_H);
2535 case Intrinsic::mips_mthlip:
2536 return lowerDSPIntr(Op, DAG, MipsISD::MTHLIP);
2537 case Intrinsic::mips_mulsaq_s_w_ph:
2538 return lowerDSPIntr(Op, DAG, MipsISD::MULSAQ_S_W_PH);
2539 case Intrinsic::mips_maq_s_w_phl:
2540 return lowerDSPIntr(Op, DAG, MipsISD::MAQ_S_W_PHL);
2541 case Intrinsic::mips_maq_s_w_phr:
2542 return lowerDSPIntr(Op, DAG, MipsISD::MAQ_S_W_PHR);
2543 case Intrinsic::mips_maq_sa_w_phl:
2544 return lowerDSPIntr(Op, DAG, MipsISD::MAQ_SA_W_PHL);
2545 case Intrinsic::mips_maq_sa_w_phr:
2546 return lowerDSPIntr(Op, DAG, MipsISD::MAQ_SA_W_PHR);
2547 case Intrinsic::mips_dpaq_s_w_ph:
2548 return lowerDSPIntr(Op, DAG, MipsISD::DPAQ_S_W_PH);
2549 case Intrinsic::mips_dpsq_s_w_ph:
2550 return lowerDSPIntr(Op, DAG, MipsISD::DPSQ_S_W_PH);
2551 case Intrinsic::mips_dpaq_sa_l_w:
2552 return lowerDSPIntr(Op, DAG, MipsISD::DPAQ_SA_L_W);
2553 case Intrinsic::mips_dpsq_sa_l_w:
2554 return lowerDSPIntr(Op, DAG, MipsISD::DPSQ_SA_L_W);
2555 case Intrinsic::mips_dpaqx_s_w_ph:
2556 return lowerDSPIntr(Op, DAG, MipsISD::DPAQX_S_W_PH);
2557 case Intrinsic::mips_dpaqx_sa_w_ph:
2558 return lowerDSPIntr(Op, DAG, MipsISD::DPAQX_SA_W_PH);
2559 case Intrinsic::mips_dpsqx_s_w_ph:
2560 return lowerDSPIntr(Op, DAG, MipsISD::DPSQX_S_W_PH);
2561 case Intrinsic::mips_dpsqx_sa_w_ph:
2562 return lowerDSPIntr(Op, DAG, MipsISD::DPSQX_SA_W_PH);
2563 case Intrinsic::mips_ld_b:
2564 case Intrinsic::mips_ld_h:
2565 case Intrinsic::mips_ld_w:
2566 case Intrinsic::mips_ld_d:
2567 return lowerMSALoadIntr(Op, DAG, Intr, Subtarget);
2568 }
2569}
2570
2572 const MipsSubtarget &Subtarget) {
2573 SDLoc DL(Op);
2574 SDValue ChainIn = Op->getOperand(0);
2575 SDValue Value = Op->getOperand(2);
2576 SDValue Address = Op->getOperand(3);
2577 SDValue Offset = Op->getOperand(4);
2578 EVT PtrTy = Address->getValueType(0);
2579
2580 // For N64 addresses have the underlying type MVT::i64. This intrinsic
2581 // however takes an i32 signed constant offset. The actual type of the
2582 // intrinsic is a scaled signed i10.
2583 if (Subtarget.isABI_N64())
2584 Offset = DAG.getNode(ISD::SIGN_EXTEND, DL, PtrTy, Offset);
2585
2586 Address = DAG.getNode(ISD::ADD, DL, PtrTy, Address, Offset);
2587
2588 return DAG.getStore(ChainIn, DL, Value, Address, MachinePointerInfo(),
2589 Align(16));
2590}
2591
2592SDValue MipsSETargetLowering::lowerINTRINSIC_VOID(SDValue Op,
2593 SelectionDAG &DAG) const {
2594 unsigned Intr = Op->getConstantOperandVal(1);
2595 switch (Intr) {
2596 default:
2597 return SDValue();
2598 case Intrinsic::mips_st_b:
2599 case Intrinsic::mips_st_h:
2600 case Intrinsic::mips_st_w:
2601 case Intrinsic::mips_st_d:
2602 return lowerMSAStoreIntr(Op, DAG, Intr, Subtarget);
2603 }
2604}
2605
2606// Lower ISD::EXTRACT_VECTOR_ELT into MipsISD::VEXTRACT_SEXT_ELT.
2607//
2608// The non-value bits resulting from ISD::EXTRACT_VECTOR_ELT are undefined. We
2609// choose to sign-extend but we could have equally chosen zero-extend. The
2610// DAGCombiner will fold any sign/zero extension of the ISD::EXTRACT_VECTOR_ELT
2611// result into this node later (possibly changing it to a zero-extend in the
2612// process).
2613SDValue MipsSETargetLowering::
2614lowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const {
2615 SDLoc DL(Op);
2616 EVT ResTy = Op->getValueType(0);
2617 SDValue Op0 = Op->getOperand(0);
2618 EVT VecTy = Op0->getValueType(0);
2619
2620 if (!VecTy.is128BitVector())
2621 return SDValue();
2622
2623 if (ResTy.isInteger()) {
2624 SDValue Op1 = Op->getOperand(1);
2625 EVT EltTy = VecTy.getVectorElementType();
2626 return DAG.getNode(MipsISD::VEXTRACT_SEXT_ELT, DL, ResTy, Op0, Op1,
2627 DAG.getValueType(EltTy));
2628 }
2629
2630 return Op;
2631}
2632
2633static bool isConstantOrUndef(const SDValue Op) {
2634 if (Op->isUndef())
2635 return true;
2637 return true;
2639 return true;
2640 return false;
2641}
2642
2644 for (unsigned i = 0; i < Op->getNumOperands(); ++i)
2645 if (isConstantOrUndef(Op->getOperand(i)))
2646 return true;
2647 return false;
2648}
2649
2650// Lowers ISD::BUILD_VECTOR into appropriate SelectionDAG nodes for the
2651// backend.
2652//
2653// Lowers according to the following rules:
2654// - Constant splats are legal as-is as long as the SplatBitSize is a power of
2655// 2 less than or equal to 64 and the value fits into a signed 10-bit
2656// immediate
2657// - Constant splats are lowered to bitconverted BUILD_VECTORs if SplatBitSize
2658// is a power of 2 less than or equal to 64 and the value does not fit into a
2659// signed 10-bit immediate
2660// - Non-constant splats are legal as-is.
2661// - Non-constant non-splats are lowered to sequences of INSERT_VECTOR_ELT.
2662// - All others are illegal and must be expanded.
2663SDValue MipsSETargetLowering::lowerBUILD_VECTOR(SDValue Op,
2664 SelectionDAG &DAG) const {
2665 BuildVectorSDNode *Node = cast<BuildVectorSDNode>(Op);
2666 EVT ResTy = Op->getValueType(0);
2667 SDLoc DL(Op);
2668 APInt SplatValue, SplatUndef;
2669 unsigned SplatBitSize;
2670 bool HasAnyUndefs;
2671
2672 if (!Subtarget.hasMSA() || !ResTy.is128BitVector())
2673 return SDValue();
2674
2675 if (Node->isConstantSplat(SplatValue, SplatUndef, SplatBitSize,
2676 HasAnyUndefs, 8,
2677 !Subtarget.isLittle()) && SplatBitSize <= 64) {
2678 // We can only cope with 8, 16, 32, or 64-bit elements
2679 if (SplatBitSize != 8 && SplatBitSize != 16 && SplatBitSize != 32 &&
2680 SplatBitSize != 64)
2681 return SDValue();
2682
2683 // If the value isn't an integer type we will have to bitcast
2684 // from an integer type first. Also, if there are any undefs, we must
2685 // lower them to defined values first.
2686 if (ResTy.isInteger() && !HasAnyUndefs)
2687 return Op;
2688
2689 EVT ViaVecTy;
2690
2691 switch (SplatBitSize) {
2692 default:
2693 return SDValue();
2694 case 8:
2695 ViaVecTy = MVT::v16i8;
2696 break;
2697 case 16:
2698 ViaVecTy = MVT::v8i16;
2699 break;
2700 case 32:
2701 ViaVecTy = MVT::v4i32;
2702 break;
2703 case 64:
2704 // There's no fill.d to fall back on for 64-bit values
2705 return SDValue();
2706 }
2707
2708 // SelectionDAG::getConstant will promote SplatValue appropriately.
2709 SDValue Result = DAG.getConstant(SplatValue, DL, ViaVecTy);
2710
2711 // Bitcast to the type we originally wanted
2712 if (ViaVecTy != ResTy)
2713 Result = DAG.getNode(ISD::BITCAST, SDLoc(Node), ResTy, Result);
2714
2715 return Result;
2716 } else if (DAG.isSplatValue(Op, /* AllowUndefs */ false))
2717 return Op;
2718 else if (!isConstantOrUndefBUILD_VECTOR(Node)) {
2719 // Use INSERT_VECTOR_ELT operations rather than expand to stores.
2720 // The resulting code is the same length as the expansion, but it doesn't
2721 // use memory operations
2722 EVT ResTy = Node->getValueType(0);
2723
2724 assert(ResTy.isVector());
2725
2726 unsigned NumElts = ResTy.getVectorNumElements();
2727 SDValue Vector = DAG.getUNDEF(ResTy);
2728 for (unsigned i = 0; i < NumElts; ++i) {
2730 Node->getOperand(i),
2731 DAG.getConstant(i, DL, MVT::i32));
2732 }
2733 return Vector;
2734 }
2735
2736 return SDValue();
2737}
2738
2739// Lower VECTOR_SHUFFLE into SHF (if possible).
2740//
2741// SHF splits the vector into blocks of four elements, then shuffles these
2742// elements according to a <4 x i2> constant (encoded as an integer immediate).
2743//
2744// It is therefore possible to lower into SHF when the mask takes the form:
2745// <a, b, c, d, a+4, b+4, c+4, d+4, a+8, b+8, c+8, d+8, ...>
2746// When undef's appear they are treated as if they were whatever value is
2747// necessary in order to fit the above forms.
2748//
2749// For example:
2750// %2 = shufflevector <8 x i16> %0, <8 x i16> undef,
2751// <8 x i32> <i32 3, i32 2, i32 1, i32 0,
2752// i32 7, i32 6, i32 5, i32 4>
2753// is lowered to:
2754// (SHF_H $w0, $w1, 27)
2755// where the 27 comes from:
2756// 3 + (2 << 2) + (1 << 4) + (0 << 6)
2758 SmallVector<int, 16> Indices,
2759 SelectionDAG &DAG) {
2760 int SHFIndices[4] = { -1, -1, -1, -1 };
2761
2762 if (Indices.size() < 4)
2763 return SDValue();
2764
2765 for (unsigned i = 0; i < 4; ++i) {
2766 for (unsigned j = i; j < Indices.size(); j += 4) {
2767 int Idx = Indices[j];
2768
2769 // Convert from vector index to 4-element subvector index
2770 // If an index refers to an element outside of the subvector then give up
2771 if (Idx != -1) {
2772 Idx -= 4 * (j / 4);
2773 if (Idx < 0 || Idx >= 4)
2774 return SDValue();
2775 }
2776
2777 // If the mask has an undef, replace it with the current index.
2778 // Note that it might still be undef if the current index is also undef
2779 if (SHFIndices[i] == -1)
2780 SHFIndices[i] = Idx;
2781
2782 // Check that non-undef values are the same as in the mask. If they
2783 // aren't then give up
2784 if (!(Idx == -1 || Idx == SHFIndices[i]))
2785 return SDValue();
2786 }
2787 }
2788
2789 // Calculate the immediate. Replace any remaining undefs with zero
2790 APInt Imm(32, 0);
2791 for (int i = 3; i >= 0; --i) {
2792 int Idx = SHFIndices[i];
2793
2794 if (Idx == -1)
2795 Idx = 0;
2796
2797 Imm <<= 2;
2798 Imm |= Idx & 0x3;
2799 }
2800
2801 SDLoc DL(Op);
2802 return DAG.getNode(MipsISD::SHF, DL, ResTy,
2803 DAG.getTargetConstant(Imm, DL, MVT::i32),
2804 Op->getOperand(0));
2805}
2806
2807/// Determine whether a range fits a regular pattern of values.
2808/// This function accounts for the possibility of jumping over the End iterator.
2809template <typename ValType>
2810static bool
2812 unsigned CheckStride,
2814 ValType ExpectedIndex, unsigned ExpectedIndexStride) {
2815 auto &I = Begin;
2816
2817 while (I != End) {
2818 if (*I != -1 && *I != ExpectedIndex)
2819 return false;
2820 ExpectedIndex += ExpectedIndexStride;
2821
2822 // Incrementing past End is undefined behaviour so we must increment one
2823 // step at a time and check for End at each step.
2824 for (unsigned n = 0; n < CheckStride && I != End; ++n, ++I)
2825 ; // Empty loop body.
2826 }
2827 return true;
2828}
2829
2830// Determine whether VECTOR_SHUFFLE is a SPLATI.
2831//
2832// It is a SPLATI when the mask is:
2833// <x, x, x, ...>
2834// where x is any valid index.
2835//
2836// When undef's appear in the mask they are treated as if they were whatever
2837// value is necessary in order to fit the above form.
2839 SmallVector<int, 16> Indices,
2840 SelectionDAG &DAG) {
2841 assert((Indices.size() % 2) == 0);
2842
2843 int SplatIndex = -1;
2844 for (const auto &V : Indices) {
2845 if (V != -1) {
2846 SplatIndex = V;
2847 break;
2848 }
2849 }
2850
2851 return fitsRegularPattern<int>(Indices.begin(), 1, Indices.end(), SplatIndex,
2852 0);
2853}
2854
2855// Lower VECTOR_SHUFFLE into ILVEV (if possible).
2856//
2857// ILVEV interleaves the even elements from each vector.
2858//
2859// It is possible to lower into ILVEV when the mask consists of two of the
2860// following forms interleaved:
2861// <0, 2, 4, ...>
2862// <n, n+2, n+4, ...>
2863// where n is the number of elements in the vector.
2864// For example:
2865// <0, 0, 2, 2, 4, 4, ...>
2866// <0, n, 2, n+2, 4, n+4, ...>
2867//
2868// When undef's appear in the mask they are treated as if they were whatever
2869// value is necessary in order to fit the above forms.
2871 SmallVector<int, 16> Indices,
2872 SelectionDAG &DAG) {
2873 assert((Indices.size() % 2) == 0);
2874
2875 SDValue Wt;
2876 SDValue Ws;
2877 const auto &Begin = Indices.begin();
2878 const auto &End = Indices.end();
2879
2880 // Check even elements are taken from the even elements of one half or the
2881 // other and pick an operand accordingly.
2882 if (fitsRegularPattern<int>(Begin, 2, End, 0, 2))
2883 Wt = Op->getOperand(0);
2884 else if (fitsRegularPattern<int>(Begin, 2, End, Indices.size(), 2))
2885 Wt = Op->getOperand(1);
2886 else
2887 return SDValue();
2888
2889 // Check odd elements are taken from the even elements of one half or the
2890 // other and pick an operand accordingly.
2891 if (fitsRegularPattern<int>(Begin + 1, 2, End, 0, 2))
2892 Ws = Op->getOperand(0);
2893 else if (fitsRegularPattern<int>(Begin + 1, 2, End, Indices.size(), 2))
2894 Ws = Op->getOperand(1);
2895 else
2896 return SDValue();
2897
2898 return DAG.getNode(MipsISD::ILVEV, SDLoc(Op), ResTy, Ws, Wt);
2899}
2900
2901// Lower VECTOR_SHUFFLE into ILVOD (if possible).
2902//
2903// ILVOD interleaves the odd elements from each vector.
2904//
2905// It is possible to lower into ILVOD when the mask consists of two of the
2906// following forms interleaved:
2907// <1, 3, 5, ...>
2908// <n+1, n+3, n+5, ...>
2909// where n is the number of elements in the vector.
2910// For example:
2911// <1, 1, 3, 3, 5, 5, ...>
2912// <1, n+1, 3, n+3, 5, n+5, ...>
2913//
2914// When undef's appear in the mask they are treated as if they were whatever
2915// value is necessary in order to fit the above forms.
2917 SmallVector<int, 16> Indices,
2918 SelectionDAG &DAG) {
2919 assert((Indices.size() % 2) == 0);
2920
2921 SDValue Wt;
2922 SDValue Ws;
2923 const auto &Begin = Indices.begin();
2924 const auto &End = Indices.end();
2925
2926 // Check even elements are taken from the odd elements of one half or the
2927 // other and pick an operand accordingly.
2928 if (fitsRegularPattern<int>(Begin, 2, End, 1, 2))
2929 Wt = Op->getOperand(0);
2930 else if (fitsRegularPattern<int>(Begin, 2, End, Indices.size() + 1, 2))
2931 Wt = Op->getOperand(1);
2932 else
2933 return SDValue();
2934
2935 // Check odd elements are taken from the odd elements of one half or the
2936 // other and pick an operand accordingly.
2937 if (fitsRegularPattern<int>(Begin + 1, 2, End, 1, 2))
2938 Ws = Op->getOperand(0);
2939 else if (fitsRegularPattern<int>(Begin + 1, 2, End, Indices.size() + 1, 2))
2940 Ws = Op->getOperand(1);
2941 else
2942 return SDValue();
2943
2944 return DAG.getNode(MipsISD::ILVOD, SDLoc(Op), ResTy, Ws, Wt);
2945}
2946
2947// Lower VECTOR_SHUFFLE into ILVR (if possible).
2948//
2949// ILVR interleaves consecutive elements from the right (lowest-indexed) half of
2950// each vector.
2951//
2952// It is possible to lower into ILVR when the mask consists of two of the
2953// following forms interleaved:
2954// <0, 1, 2, ...>
2955// <n, n+1, n+2, ...>
2956// where n is the number of elements in the vector.
2957// For example:
2958// <0, 0, 1, 1, 2, 2, ...>
2959// <0, n, 1, n+1, 2, n+2, ...>
2960//
2961// When undef's appear in the mask they are treated as if they were whatever
2962// value is necessary in order to fit the above forms.
2964 SmallVector<int, 16> Indices,
2965 SelectionDAG &DAG) {
2966 assert((Indices.size() % 2) == 0);
2967
2968 SDValue Wt;
2969 SDValue Ws;
2970 const auto &Begin = Indices.begin();
2971 const auto &End = Indices.end();
2972
2973 // Check even elements are taken from the right (lowest-indexed) elements of
2974 // one half or the other and pick an operand accordingly.
2975 if (fitsRegularPattern<int>(Begin, 2, End, 0, 1))
2976 Wt = Op->getOperand(0);
2977 else if (fitsRegularPattern<int>(Begin, 2, End, Indices.size(), 1))
2978 Wt = Op->getOperand(1);
2979 else
2980 return SDValue();
2981
2982 // Check odd elements are taken from the right (lowest-indexed) elements of
2983 // one half or the other and pick an operand accordingly.
2984 if (fitsRegularPattern<int>(Begin + 1, 2, End, 0, 1))
2985 Ws = Op->getOperand(0);
2986 else if (fitsRegularPattern<int>(Begin + 1, 2, End, Indices.size(), 1))
2987 Ws = Op->getOperand(1);
2988 else
2989 return SDValue();
2990
2991 return DAG.getNode(MipsISD::ILVR, SDLoc(Op), ResTy, Ws, Wt);
2992}
2993
2994// Lower VECTOR_SHUFFLE into ILVL (if possible).
2995//
2996// ILVL interleaves consecutive elements from the left (highest-indexed) half
2997// of each vector.
2998//
2999// It is possible to lower into ILVL when the mask consists of two of the
3000// following forms interleaved:
3001// <x, x+1, x+2, ...>
3002// <n+x, n+x+1, n+x+2, ...>
3003// where n is the number of elements in the vector and x is half n.
3004// For example:
3005// <x, x, x+1, x+1, x+2, x+2, ...>
3006// <x, n+x, x+1, n+x+1, x+2, n+x+2, ...>
3007//
3008// When undef's appear in the mask they are treated as if they were whatever
3009// value is necessary in order to fit the above forms.
3011 SmallVector<int, 16> Indices,
3012 SelectionDAG &DAG) {
3013 assert((Indices.size() % 2) == 0);
3014
3015 unsigned HalfSize = Indices.size() / 2;
3016 SDValue Wt;
3017 SDValue Ws;
3018 const auto &Begin = Indices.begin();
3019 const auto &End = Indices.end();
3020
3021 // Check even elements are taken from the left (highest-indexed) elements of
3022 // one half or the other and pick an operand accordingly.
3023 if (fitsRegularPattern<int>(Begin, 2, End, HalfSize, 1))
3024 Wt = Op->getOperand(0);
3025 else if (fitsRegularPattern<int>(Begin, 2, End, Indices.size() + HalfSize, 1))
3026 Wt = Op->getOperand(1);
3027 else
3028 return SDValue();
3029
3030 // Check odd elements are taken from the left (highest-indexed) elements of
3031 // one half or the other and pick an operand accordingly.
3032 if (fitsRegularPattern<int>(Begin + 1, 2, End, HalfSize, 1))
3033 Ws = Op->getOperand(0);
3034 else if (fitsRegularPattern<int>(Begin + 1, 2, End, Indices.size() + HalfSize,
3035 1))
3036 Ws = Op->getOperand(1);
3037 else
3038 return SDValue();
3039
3040 return DAG.getNode(MipsISD::ILVL, SDLoc(Op), ResTy, Ws, Wt);
3041}
3042
3043// Lower VECTOR_SHUFFLE into PCKEV (if possible).
3044//
3045// PCKEV copies the even elements of each vector into the result vector.
3046//
3047// It is possible to lower into PCKEV when the mask consists of two of the
3048// following forms concatenated:
3049// <0, 2, 4, ...>
3050// <n, n+2, n+4, ...>
3051// where n is the number of elements in the vector.
3052// For example:
3053// <0, 2, 4, ..., 0, 2, 4, ...>
3054// <0, 2, 4, ..., n, n+2, n+4, ...>
3055//
3056// When undef's appear in the mask they are treated as if they were whatever
3057// value is necessary in order to fit the above forms.
3059 SmallVector<int, 16> Indices,
3060 SelectionDAG &DAG) {
3061 assert((Indices.size() % 2) == 0);
3062
3063 SDValue Wt;
3064 SDValue Ws;
3065 const auto &Begin = Indices.begin();
3066 const auto &Mid = Indices.begin() + Indices.size() / 2;
3067 const auto &End = Indices.end();
3068
3069 if (fitsRegularPattern<int>(Begin, 1, Mid, 0, 2))
3070 Wt = Op->getOperand(0);
3071 else if (fitsRegularPattern<int>(Begin, 1, Mid, Indices.size(), 2))
3072 Wt = Op->getOperand(1);
3073 else
3074 return SDValue();
3075
3076 if (fitsRegularPattern<int>(Mid, 1, End, 0, 2))
3077 Ws = Op->getOperand(0);
3078 else if (fitsRegularPattern<int>(Mid, 1, End, Indices.size(), 2))
3079 Ws = Op->getOperand(1);
3080 else
3081 return SDValue();
3082
3083 return DAG.getNode(MipsISD::PCKEV, SDLoc(Op), ResTy, Ws, Wt);
3084}
3085
3086// Lower VECTOR_SHUFFLE into PCKOD (if possible).
3087//
3088// PCKOD copies the odd elements of each vector into the result vector.
3089//
3090// It is possible to lower into PCKOD when the mask consists of two of the
3091// following forms concatenated:
3092// <1, 3, 5, ...>
3093// <n+1, n+3, n+5, ...>
3094// where n is the number of elements in the vector.
3095// For example:
3096// <1, 3, 5, ..., 1, 3, 5, ...>
3097// <1, 3, 5, ..., n+1, n+3, n+5, ...>
3098//
3099// When undef's appear in the mask they are treated as if they were whatever
3100// value is necessary in order to fit the above forms.
3102 SmallVector<int, 16> Indices,
3103 SelectionDAG &DAG) {
3104 assert((Indices.size() % 2) == 0);
3105
3106 SDValue Wt;
3107 SDValue Ws;
3108 const auto &Begin = Indices.begin();
3109 const auto &Mid = Indices.begin() + Indices.size() / 2;
3110 const auto &End = Indices.end();
3111
3112 if (fitsRegularPattern<int>(Begin, 1, Mid, 1, 2))
3113 Wt = Op->getOperand(0);
3114 else if (fitsRegularPattern<int>(Begin, 1, Mid, Indices.size() + 1, 2))
3115 Wt = Op->getOperand(1);
3116 else
3117 return SDValue();
3118
3119 if (fitsRegularPattern<int>(Mid, 1, End, 1, 2))
3120 Ws = Op->getOperand(0);
3121 else if (fitsRegularPattern<int>(Mid, 1, End, Indices.size() + 1, 2))
3122 Ws = Op->getOperand(1);
3123 else
3124 return SDValue();
3125
3126 return DAG.getNode(MipsISD::PCKOD, SDLoc(Op), ResTy, Ws, Wt);
3127}
3128
3129// Lower VECTOR_SHUFFLE into VSHF.
3130//
3131// This mostly consists of converting the shuffle indices in Indices into a
3132// BUILD_VECTOR and adding it as an operand to the resulting VSHF. There is
3133// also code to eliminate unused operands of the VECTOR_SHUFFLE. For example,
3134// if the type is v8i16 and all the indices are less than 8 then the second
3135// operand is unused and can be replaced with anything. We choose to replace it
3136// with the used operand since this reduces the number of instructions overall.
3137//
3138// NOTE: SPLATI shuffle masks may contain UNDEFs, since isSPLATI() treats
3139// UNDEFs as same as SPLATI index.
3140// For other instances we use the last valid index if UNDEF is
3141// encountered.
3143 const SmallVector<int, 16> &Indices,
3144 const bool isSPLATI,
3145 SelectionDAG &DAG) {
3147 SDValue Op0;
3148 SDValue Op1;
3149 EVT MaskVecTy = ResTy.changeVectorElementTypeToInteger();
3150 EVT MaskEltTy = MaskVecTy.getVectorElementType();
3151 bool Using1stVec = false;
3152 bool Using2ndVec = false;
3153 SDLoc DL(Op);
3154 int ResTyNumElts = ResTy.getVectorNumElements();
3155
3156 for (int i = 0; i < ResTyNumElts; ++i) {
3157 // Idx == -1 means UNDEF/poison
3158 int Idx = Indices[i];
3159
3160 if (0 <= Idx && Idx < ResTyNumElts)
3161 Using1stVec = true;
3162 if (ResTyNumElts <= Idx && Idx < ResTyNumElts * 2)
3163 Using2ndVec = true;
3164 }
3165
3166 // Find the first non-undef index. This index is used as a default when there
3167 // is a leading UNDEF/poison.
3168 int SplatIndex = 0;
3169 for (int Idx : Indices)
3170 if (Idx >= 0) {
3171 SplatIndex = Idx;
3172 break;
3173 }
3174
3175 int LastValidIndex = SplatIndex;
3176 for (size_t i = 0; i < Indices.size(); i++) {
3177 int Idx = Indices[i];
3178 if (Idx < 0) {
3179 // Continue using splati index or use the last valid index.
3180 Idx = isSPLATI ? SplatIndex : LastValidIndex;
3181 } else {
3182 LastValidIndex = Idx;
3183 }
3184 Ops.push_back(DAG.getTargetConstant(Idx, DL, MaskEltTy));
3185 }
3186
3187 SDValue MaskVec = DAG.getBuildVector(MaskVecTy, DL, Ops);
3188
3189 if (Using1stVec && Using2ndVec) {
3190 Op0 = Op->getOperand(0);
3191 Op1 = Op->getOperand(1);
3192 } else if (Using1stVec)
3193 Op0 = Op1 = Op->getOperand(0);
3194 else if (Using2ndVec)
3195 Op0 = Op1 = Op->getOperand(1);
3196 else
3197 llvm_unreachable("shuffle vector mask references neither vector operand?");
3198
3199 // VECTOR_SHUFFLE concatenates the vectors in an vectorwise fashion.
3200 // <0b00, 0b01> + <0b10, 0b11> -> <0b00, 0b01, 0b10, 0b11>
3201 // VSHF concatenates the vectors in a bitwise fashion:
3202 // <0b00, 0b01> + <0b10, 0b11> ->
3203 // 0b0100 + 0b1110 -> 0b01001110
3204 // <0b10, 0b11, 0b00, 0b01>
3205 // We must therefore swap the operands to get the correct result.
3206 return DAG.getNode(MipsISD::VSHF, DL, ResTy, MaskVec, Op1, Op0);
3207}
3208
3209// Lower VECTOR_SHUFFLE into one of a number of instructions depending on the
3210// indices in the shuffle.
3211SDValue MipsSETargetLowering::lowerVECTOR_SHUFFLE(SDValue Op,
3212 SelectionDAG &DAG) const {
3213 ShuffleVectorSDNode *Node = cast<ShuffleVectorSDNode>(Op);
3214 EVT ResTy = Op->getValueType(0);
3215
3216 if (!ResTy.is128BitVector())
3217 return SDValue();
3218
3219 int ResTyNumElts = ResTy.getVectorNumElements();
3220 SmallVector<int, 16> Indices;
3221
3222 for (int i = 0; i < ResTyNumElts; ++i)
3223 Indices.push_back(Node->getMaskElt(i));
3224
3225 // splati.[bhwd] is preferable to the others but is matched from
3226 // MipsISD::VSHF.
3227 if (isVECTOR_SHUFFLE_SPLATI(Op, ResTy, Indices, DAG))
3228 return lowerVECTOR_SHUFFLE_VSHF(Op, ResTy, Indices, true, DAG);
3230 if ((Result = lowerVECTOR_SHUFFLE_ILVEV(Op, ResTy, Indices, DAG)))
3231 return Result;
3232 if ((Result = lowerVECTOR_SHUFFLE_ILVOD(Op, ResTy, Indices, DAG)))
3233 return Result;
3234 if ((Result = lowerVECTOR_SHUFFLE_ILVL(Op, ResTy, Indices, DAG)))
3235 return Result;
3236 if ((Result = lowerVECTOR_SHUFFLE_ILVR(Op, ResTy, Indices, DAG)))
3237 return Result;
3238 if ((Result = lowerVECTOR_SHUFFLE_PCKEV(Op, ResTy, Indices, DAG)))
3239 return Result;
3240 if ((Result = lowerVECTOR_SHUFFLE_PCKOD(Op, ResTy, Indices, DAG)))
3241 return Result;
3242 if ((Result = lowerVECTOR_SHUFFLE_SHF(Op, ResTy, Indices, DAG)))
3243 return Result;
3244 return lowerVECTOR_SHUFFLE_VSHF(Op, ResTy, Indices, false, DAG);
3245}
3246
3247// MIPS I has no trunc.w.fmt. Do the conversion with cvt.w.fmt and the
3248// rounding mode set to round toward zero, then restore the FCSR. This is the
3249// same sequence the assembler uses for the trunc.w.fmt macro.
3250//
3251// cfc1 $old, $31
3252// ori $tmp, $old, 3
3253// xori $tmp, $tmp, 2
3254// ctc1 $tmp, $31
3255// cvt.w.fmt $dst, $src
3256// ctc1 $old, $31
3257MachineBasicBlock *MipsSETargetLowering::emitTRUNC_W_M1(MachineInstr &MI,
3259 unsigned CvtOpc) const {
3260 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3261 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3262 const TargetRegisterClass *RC = &Mips::GPR32RegClass;
3263 DebugLoc DL = MI.getDebugLoc();
3264 Register Dst = MI.getOperand(0).getReg();
3265 Register Src = MI.getOperand(1).getReg();
3266 Register Old = RegInfo.createVirtualRegister(RC);
3267 Register Tmp0 = RegInfo.createVirtualRegister(RC);
3268 Register Tmp1 = RegInfo.createVirtualRegister(RC);
3269
3270 BuildMI(*BB, MI, DL, TII->get(Mips::CFC1), Old).addReg(Mips::FCR31);
3271 BuildMI(*BB, MI, DL, TII->get(Mips::ORi), Tmp0).addReg(Old).addImm(3);
3272 BuildMI(*BB, MI, DL, TII->get(Mips::XORi), Tmp1).addReg(Tmp0).addImm(2);
3273 BuildMI(*BB, MI, DL, TII->get(Mips::CTC1), Mips::FCR31).addReg(Tmp1);
3274 BuildMI(*BB, MI, DL, TII->get(CvtOpc), Dst).addReg(Src);
3275 BuildMI(*BB, MI, DL, TII->get(Mips::CTC1), Mips::FCR31).addReg(Old);
3276
3277 MI.eraseFromParent();
3278 return BB;
3279}
3280
3282MipsSETargetLowering::emitBPOSGE32(MachineInstr &MI,
3283 MachineBasicBlock *BB) const {
3284 // $bb:
3285 // bposge32_pseudo $vr0
3286 // =>
3287 // $bb:
3288 // bposge32 $tbb
3289 // $fbb:
3290 // li $vr2, 0
3291 // b $sink
3292 // $tbb:
3293 // li $vr1, 1
3294 // $sink:
3295 // $vr0 = phi($vr2, $fbb, $vr1, $tbb)
3296
3297 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3298 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3299 const TargetRegisterClass *RC = &Mips::GPR32RegClass;
3300 DebugLoc DL = MI.getDebugLoc();
3301 const BasicBlock *LLVM_BB = BB->getBasicBlock();
3303 MachineFunction *F = BB->getParent();
3304 MachineBasicBlock *FBB = F->CreateMachineBasicBlock(LLVM_BB);
3305 MachineBasicBlock *TBB = F->CreateMachineBasicBlock(LLVM_BB);
3306 MachineBasicBlock *Sink = F->CreateMachineBasicBlock(LLVM_BB);
3307 F->insert(It, FBB);
3308 F->insert(It, TBB);
3309 F->insert(It, Sink);
3310
3311 // Transfer the remainder of BB and its successor edges to Sink.
3312 Sink->splice(Sink->begin(), BB, std::next(MachineBasicBlock::iterator(MI)),
3313 BB->end());
3315
3316 // Add successors.
3317 BB->addSuccessor(FBB);
3318 BB->addSuccessor(TBB);
3319 FBB->addSuccessor(Sink);
3320 TBB->addSuccessor(Sink);
3321
3322 // Insert the real bposge32 instruction to $BB.
3323 BuildMI(BB, DL, TII->get(Mips::BPOSGE32)).addMBB(TBB);
3324 // Insert the real bposge32c instruction to $BB.
3325 BuildMI(BB, DL, TII->get(Mips::BPOSGE32C_MMR3)).addMBB(TBB);
3326
3327 // Fill $FBB.
3328 Register VR2 = RegInfo.createVirtualRegister(RC);
3329 BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::ADDiu), VR2)
3330 .addReg(Mips::R0)
3331 .addImm(0);
3332 BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::B)).addMBB(Sink);
3333
3334 // Fill $TBB.
3335 Register VR1 = RegInfo.createVirtualRegister(RC);
3336 BuildMI(*TBB, TBB->end(), DL, TII->get(Mips::ADDiu), VR1)
3337 .addReg(Mips::R0)
3338 .addImm(1);
3339
3340 // Insert phi function to $Sink.
3341 BuildMI(*Sink, Sink->begin(), DL, TII->get(Mips::PHI),
3342 MI.getOperand(0).getReg())
3343 .addReg(VR2)
3344 .addMBB(FBB)
3345 .addReg(VR1)
3346 .addMBB(TBB);
3347
3348 MI.eraseFromParent(); // The pseudo instruction is gone now.
3349 return Sink;
3350}
3351
3352MachineBasicBlock *MipsSETargetLowering::emitMSACBranchPseudo(
3353 MachineInstr &MI, MachineBasicBlock *BB, unsigned BranchOp) const {
3354 // $bb:
3355 // vany_nonzero $rd, $ws
3356 // =>
3357 // $bb:
3358 // bnz.b $ws, $tbb
3359 // b $fbb
3360 // $fbb:
3361 // li $rd1, 0
3362 // b $sink
3363 // $tbb:
3364 // li $rd2, 1
3365 // $sink:
3366 // $rd = phi($rd1, $fbb, $rd2, $tbb)
3367
3368 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3369 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3370 const TargetRegisterClass *RC = &Mips::GPR32RegClass;
3371 DebugLoc DL = MI.getDebugLoc();
3372 const BasicBlock *LLVM_BB = BB->getBasicBlock();
3374 MachineFunction *F = BB->getParent();
3375 MachineBasicBlock *FBB = F->CreateMachineBasicBlock(LLVM_BB);
3376 MachineBasicBlock *TBB = F->CreateMachineBasicBlock(LLVM_BB);
3377 MachineBasicBlock *Sink = F->CreateMachineBasicBlock(LLVM_BB);
3378 F->insert(It, FBB);
3379 F->insert(It, TBB);
3380 F->insert(It, Sink);
3381
3382 // Transfer the remainder of BB and its successor edges to Sink.
3383 Sink->splice(Sink->begin(), BB, std::next(MachineBasicBlock::iterator(MI)),
3384 BB->end());
3386
3387 // Add successors.
3388 BB->addSuccessor(FBB);
3389 BB->addSuccessor(TBB);
3390 FBB->addSuccessor(Sink);
3391 TBB->addSuccessor(Sink);
3392
3393 // Insert the real bnz.b instruction to $BB.
3394 BuildMI(BB, DL, TII->get(BranchOp))
3395 .addReg(MI.getOperand(1).getReg())
3396 .addMBB(TBB);
3397
3398 // Fill $FBB.
3399 Register RD1 = RegInfo.createVirtualRegister(RC);
3400 BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::ADDiu), RD1)
3401 .addReg(Mips::R0)
3402 .addImm(0);
3403 BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::B)).addMBB(Sink);
3404
3405 // Fill $TBB.
3406 Register RD2 = RegInfo.createVirtualRegister(RC);
3407 BuildMI(*TBB, TBB->end(), DL, TII->get(Mips::ADDiu), RD2)
3408 .addReg(Mips::R0)
3409 .addImm(1);
3410
3411 // Insert phi function to $Sink.
3412 BuildMI(*Sink, Sink->begin(), DL, TII->get(Mips::PHI),
3413 MI.getOperand(0).getReg())
3414 .addReg(RD1)
3415 .addMBB(FBB)
3416 .addReg(RD2)
3417 .addMBB(TBB);
3418
3419 MI.eraseFromParent(); // The pseudo instruction is gone now.
3420 return Sink;
3421}
3422
3423// Emit the COPY_FW pseudo instruction.
3424//
3425// copy_fw_pseudo $fd, $ws, n
3426// =>
3427// copy_u_w $rt, $ws, $n
3428// mtc1 $rt, $fd
3429//
3430// When n is zero, the equivalent operation can be performed with (potentially)
3431// zero instructions due to register overlaps. This optimization is never valid
3432// for lane 1 because it would require FR=0 mode which isn't supported by MSA.
3434MipsSETargetLowering::emitCOPY_FW(MachineInstr &MI,
3435 MachineBasicBlock *BB) const {
3436 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3437 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3438 DebugLoc DL = MI.getDebugLoc();
3439 Register Fd = MI.getOperand(0).getReg();
3440 Register Ws = MI.getOperand(1).getReg();
3441 unsigned Lane = MI.getOperand(2).getImm();
3442
3443 if (Lane == 0) {
3444 unsigned Wt = Ws;
3445 if (!Subtarget.useOddSPReg()) {
3446 // We must copy to an even-numbered MSA register so that the
3447 // single-precision sub-register is also guaranteed to be even-numbered.
3448 Wt = RegInfo.createVirtualRegister(&Mips::MSA128WEvensRegClass);
3449
3450 BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Wt).addReg(Ws);
3451 }
3452
3453 BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Fd).addReg(Wt, {}, Mips::sub_lo);
3454 } else {
3455 Register Wt = RegInfo.createVirtualRegister(
3456 Subtarget.useOddSPReg() ? &Mips::MSA128WRegClass
3457 : &Mips::MSA128WEvensRegClass);
3458
3459 BuildMI(*BB, MI, DL, TII->get(Mips::SPLATI_W), Wt).addReg(Ws).addImm(Lane);
3460 BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Fd).addReg(Wt, {}, Mips::sub_lo);
3461 }
3462
3463 MI.eraseFromParent(); // The pseudo instruction is gone now.
3464 return BB;
3465}
3466
3467// Emit the COPY_FD pseudo instruction.
3468//
3469// copy_fd_pseudo $fd, $ws, n
3470// =>
3471// splati.d $wt, $ws, $n
3472// copy $fd, $wt:sub_64
3473//
3474// When n is zero, the equivalent operation can be performed with (potentially)
3475// zero instructions due to register overlaps. This optimization is always
3476// valid because FR=1 mode which is the only supported mode in MSA.
3478MipsSETargetLowering::emitCOPY_FD(MachineInstr &MI,
3479 MachineBasicBlock *BB) const {
3480 assert(Subtarget.isFP64bit());
3481
3482 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3483 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3484 Register Fd = MI.getOperand(0).getReg();
3485 Register Ws = MI.getOperand(1).getReg();
3486 unsigned Lane = MI.getOperand(2).getImm() * 2;
3487 DebugLoc DL = MI.getDebugLoc();
3488
3489 if (Lane == 0)
3490 BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Fd).addReg(Ws, {}, Mips::sub_64);
3491 else {
3492 Register Wt = RegInfo.createVirtualRegister(&Mips::MSA128DRegClass);
3493
3494 BuildMI(*BB, MI, DL, TII->get(Mips::SPLATI_D), Wt).addReg(Ws).addImm(1);
3495 BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Fd).addReg(Wt, {}, Mips::sub_64);
3496 }
3497
3498 MI.eraseFromParent(); // The pseudo instruction is gone now.
3499 return BB;
3500}
3501
3502// Emit the INSERT_FW pseudo instruction.
3503//
3504// insert_fw_pseudo $wd, $wd_in, $n, $fs
3505// =>
3506// subreg_to_reg $wt:sub_lo, $fs
3507// insve_w $wd[$n], $wd_in, $wt[0]
3509MipsSETargetLowering::emitINSERT_FW(MachineInstr &MI,
3510 MachineBasicBlock *BB) const {
3511 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3512 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3513 DebugLoc DL = MI.getDebugLoc();
3514 Register Wd = MI.getOperand(0).getReg();
3515 Register Wd_in = MI.getOperand(1).getReg();
3516 unsigned Lane = MI.getOperand(2).getImm();
3517 Register Fs = MI.getOperand(3).getReg();
3518 Register Wt = RegInfo.createVirtualRegister(
3519 Subtarget.useOddSPReg() ? &Mips::MSA128WRegClass
3520 : &Mips::MSA128WEvensRegClass);
3521
3522 BuildMI(*BB, MI, DL, TII->get(Mips::SUBREG_TO_REG), Wt)
3523 .addReg(Fs)
3524 .addImm(Mips::sub_lo);
3525 BuildMI(*BB, MI, DL, TII->get(Mips::INSVE_W), Wd)
3526 .addReg(Wd_in)
3527 .addImm(Lane)
3528 .addReg(Wt)
3529 .addImm(0);
3530
3531 MI.eraseFromParent(); // The pseudo instruction is gone now.
3532 return BB;
3533}
3534
3535// Emit the INSERT_FD pseudo instruction.
3536//
3537// insert_fd_pseudo $wd, $fs, n
3538// =>
3539// subreg_to_reg $wt:sub_64, $fs
3540// insve_d $wd[$n], $wd_in, $wt[0]
3542MipsSETargetLowering::emitINSERT_FD(MachineInstr &MI,
3543 MachineBasicBlock *BB) const {
3544 assert(Subtarget.isFP64bit());
3545
3546 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3547 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3548 DebugLoc DL = MI.getDebugLoc();
3549 Register Wd = MI.getOperand(0).getReg();
3550 Register Wd_in = MI.getOperand(1).getReg();
3551 unsigned Lane = MI.getOperand(2).getImm();
3552 Register Fs = MI.getOperand(3).getReg();
3553 Register Wt = RegInfo.createVirtualRegister(&Mips::MSA128DRegClass);
3554
3555 BuildMI(*BB, MI, DL, TII->get(Mips::SUBREG_TO_REG), Wt)
3556 .addReg(Fs)
3557 .addImm(Mips::sub_64);
3558 BuildMI(*BB, MI, DL, TII->get(Mips::INSVE_D), Wd)
3559 .addReg(Wd_in)
3560 .addImm(Lane)
3561 .addReg(Wt)
3562 .addImm(0);
3563
3564 MI.eraseFromParent(); // The pseudo instruction is gone now.
3565 return BB;
3566}
3567
3568// Emit the INSERT_([BHWD]|F[WD])_VIDX pseudo instruction.
3569//
3570// For integer:
3571// (INSERT_([BHWD]|F[WD])_PSEUDO $wd, $wd_in, $n, $rs)
3572// =>
3573// (SLL $lanetmp1, $lane, <log2size)
3574// (SLD_B $wdtmp1, $wd_in, $wd_in, $lanetmp1)
3575// (INSERT_[BHWD], $wdtmp2, $wdtmp1, 0, $rs)
3576// (NEG $lanetmp2, $lanetmp1)
3577// (SLD_B $wd, $wdtmp2, $wdtmp2, $lanetmp2)
3578//
3579// For floating point:
3580// (INSERT_([BHWD]|F[WD])_PSEUDO $wd, $wd_in, $n, $fs)
3581// =>
3582// (SUBREG_TO_REG $wt, $fs, <subreg>)
3583// (SLL $lanetmp1, $lane, <log2size)
3584// (SLD_B $wdtmp1, $wd_in, $wd_in, $lanetmp1)
3585// (INSVE_[WD], $wdtmp2, 0, $wdtmp1, 0)
3586// (NEG $lanetmp2, $lanetmp1)
3587// (SLD_B $wd, $wdtmp2, $wdtmp2, $lanetmp2)
3588MachineBasicBlock *MipsSETargetLowering::emitINSERT_DF_VIDX(
3589 MachineInstr &MI, MachineBasicBlock *BB, unsigned EltSizeInBytes,
3590 bool IsFP) const {
3591 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3592 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3593 DebugLoc DL = MI.getDebugLoc();
3594 Register Wd = MI.getOperand(0).getReg();
3595 Register SrcVecReg = MI.getOperand(1).getReg();
3596 Register LaneReg = MI.getOperand(2).getReg();
3597 Register SrcValReg = MI.getOperand(3).getReg();
3598
3599 const TargetRegisterClass *VecRC = nullptr;
3600 // FIXME: This should be true for N32 too.
3601 const TargetRegisterClass *GPRRC =
3602 Subtarget.isABI_N64() ? &Mips::GPR64RegClass : &Mips::GPR32RegClass;
3603 unsigned SubRegIdx = Subtarget.isABI_N64() ? Mips::sub_32 : 0;
3604 unsigned ShiftOp = Subtarget.isABI_N64() ? Mips::DSLL : Mips::SLL;
3605 unsigned EltLog2Size;
3606 unsigned InsertOp = 0;
3607 unsigned InsveOp = 0;
3608 switch (EltSizeInBytes) {
3609 default:
3610 llvm_unreachable("Unexpected size");
3611 case 1:
3612 EltLog2Size = 0;
3613 InsertOp = Mips::INSERT_B;
3614 InsveOp = Mips::INSVE_B;
3615 VecRC = &Mips::MSA128BRegClass;
3616 break;
3617 case 2:
3618 EltLog2Size = 1;
3619 InsertOp = Mips::INSERT_H;
3620 InsveOp = Mips::INSVE_H;
3621 VecRC = &Mips::MSA128HRegClass;
3622 break;
3623 case 4:
3624 EltLog2Size = 2;
3625 InsertOp = Mips::INSERT_W;
3626 InsveOp = Mips::INSVE_W;
3627 VecRC = &Mips::MSA128WRegClass;
3628 break;
3629 case 8:
3630 EltLog2Size = 3;
3631 InsertOp = Mips::INSERT_D;
3632 InsveOp = Mips::INSVE_D;
3633 VecRC = &Mips::MSA128DRegClass;
3634 break;
3635 }
3636
3637 if (IsFP) {
3638 Register Wt = RegInfo.createVirtualRegister(VecRC);
3639 BuildMI(*BB, MI, DL, TII->get(Mips::SUBREG_TO_REG), Wt)
3640 .addReg(SrcValReg)
3641 .addImm(EltSizeInBytes == 8 ? Mips::sub_64 : Mips::sub_lo);
3642 SrcValReg = Wt;
3643 }
3644
3645 // Convert the lane index into a byte index
3646 if (EltSizeInBytes != 1) {
3647 Register LaneTmp1 = RegInfo.createVirtualRegister(GPRRC);
3648 BuildMI(*BB, MI, DL, TII->get(ShiftOp), LaneTmp1)
3649 .addReg(LaneReg)
3650 .addImm(EltLog2Size);
3651 LaneReg = LaneTmp1;
3652 }
3653
3654 // Rotate bytes around so that the desired lane is element zero
3655 Register WdTmp1 = RegInfo.createVirtualRegister(VecRC);
3656 BuildMI(*BB, MI, DL, TII->get(Mips::SLD_B), WdTmp1)
3657 .addReg(SrcVecReg)
3658 .addReg(SrcVecReg)
3659 .addReg(LaneReg, {}, SubRegIdx);
3660
3661 Register WdTmp2 = RegInfo.createVirtualRegister(VecRC);
3662 if (IsFP) {
3663 // Use insve.df to insert to element zero
3664 BuildMI(*BB, MI, DL, TII->get(InsveOp), WdTmp2)
3665 .addReg(WdTmp1)
3666 .addImm(0)
3667 .addReg(SrcValReg)
3668 .addImm(0);
3669 } else {
3670 // Use insert.df to insert to element zero
3671 BuildMI(*BB, MI, DL, TII->get(InsertOp), WdTmp2)
3672 .addReg(WdTmp1)
3673 .addReg(SrcValReg)
3674 .addImm(0);
3675 }
3676
3677 // Rotate elements the rest of the way for a full rotation.
3678 // sld.df inteprets $rt modulo the number of columns so we only need to negate
3679 // the lane index to do this.
3680 Register LaneTmp2 = RegInfo.createVirtualRegister(GPRRC);
3681 BuildMI(*BB, MI, DL, TII->get(Subtarget.isABI_N64() ? Mips::DSUB : Mips::SUB),
3682 LaneTmp2)
3683 .addReg(Subtarget.isABI_N64() ? Mips::R0_64 : Mips::R0)
3684 .addReg(LaneReg);
3685 BuildMI(*BB, MI, DL, TII->get(Mips::SLD_B), Wd)
3686 .addReg(WdTmp2)
3687 .addReg(WdTmp2)
3688 .addReg(LaneTmp2, {}, SubRegIdx);
3689
3690 MI.eraseFromParent(); // The pseudo instruction is gone now.
3691 return BB;
3692}
3693
3694// Emit the FILL_FW pseudo instruction.
3695//
3696// fill_fw_pseudo $wd, $fs
3697// =>
3698// implicit_def $wt1
3699// insert_subreg $wt2:subreg_lo, $wt1, $fs
3700// splati.w $wd, $wt2[0]
3702MipsSETargetLowering::emitFILL_FW(MachineInstr &MI,
3703 MachineBasicBlock *BB) const {
3704 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3705 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3706 DebugLoc DL = MI.getDebugLoc();
3707 Register Wd = MI.getOperand(0).getReg();
3708 Register Fs = MI.getOperand(1).getReg();
3709 Register Wt1 = RegInfo.createVirtualRegister(
3710 Subtarget.useOddSPReg() ? &Mips::MSA128WRegClass
3711 : &Mips::MSA128WEvensRegClass);
3712 Register Wt2 = RegInfo.createVirtualRegister(
3713 Subtarget.useOddSPReg() ? &Mips::MSA128WRegClass
3714 : &Mips::MSA128WEvensRegClass);
3715
3716 BuildMI(*BB, MI, DL, TII->get(Mips::IMPLICIT_DEF), Wt1);
3717 BuildMI(*BB, MI, DL, TII->get(Mips::INSERT_SUBREG), Wt2)
3718 .addReg(Wt1)
3719 .addReg(Fs)
3720 .addImm(Mips::sub_lo);
3721 BuildMI(*BB, MI, DL, TII->get(Mips::SPLATI_W), Wd).addReg(Wt2).addImm(0);
3722
3723 MI.eraseFromParent(); // The pseudo instruction is gone now.
3724 return BB;
3725}
3726
3727// Emit the FILL_FD pseudo instruction.
3728//
3729// fill_fd_pseudo $wd, $fs
3730// =>
3731// implicit_def $wt1
3732// insert_subreg $wt2:subreg_64, $wt1, $fs
3733// splati.d $wd, $wt2[0]
3735MipsSETargetLowering::emitFILL_FD(MachineInstr &MI,
3736 MachineBasicBlock *BB) const {
3737 assert(Subtarget.isFP64bit());
3738
3739 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3740 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3741 DebugLoc DL = MI.getDebugLoc();
3742 Register Wd = MI.getOperand(0).getReg();
3743 Register Fs = MI.getOperand(1).getReg();
3744 Register Wt1 = RegInfo.createVirtualRegister(&Mips::MSA128DRegClass);
3745 Register Wt2 = RegInfo.createVirtualRegister(&Mips::MSA128DRegClass);
3746
3747 BuildMI(*BB, MI, DL, TII->get(Mips::IMPLICIT_DEF), Wt1);
3748 BuildMI(*BB, MI, DL, TII->get(Mips::INSERT_SUBREG), Wt2)
3749 .addReg(Wt1)
3750 .addReg(Fs)
3751 .addImm(Mips::sub_64);
3752 BuildMI(*BB, MI, DL, TII->get(Mips::SPLATI_D), Wd).addReg(Wt2).addImm(0);
3753
3754 MI.eraseFromParent(); // The pseudo instruction is gone now.
3755 return BB;
3756}
3757
3758// Emit the FEXP2_W_1 pseudo instructions.
3759//
3760// fexp2_w_1_pseudo $wd, $wt
3761// =>
3762// ldi.w $ws, 1
3763// fexp2.w $wd, $ws, $wt
3765MipsSETargetLowering::emitFEXP2_W_1(MachineInstr &MI,
3766 MachineBasicBlock *BB) const {
3767 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3768 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3769 const TargetRegisterClass *RC = &Mips::MSA128WRegClass;
3770 Register Ws1 = RegInfo.createVirtualRegister(RC);
3771 Register Ws2 = RegInfo.createVirtualRegister(RC);
3772 DebugLoc DL = MI.getDebugLoc();
3773
3774 // Splat 1.0 into a vector
3775 BuildMI(*BB, MI, DL, TII->get(Mips::LDI_W), Ws1).addImm(1);
3776 BuildMI(*BB, MI, DL, TII->get(Mips::FFINT_U_W), Ws2).addReg(Ws1);
3777
3778 // Emit 1.0 * fexp2(Wt)
3779 BuildMI(*BB, MI, DL, TII->get(Mips::FEXP2_W), MI.getOperand(0).getReg())
3780 .addReg(Ws2)
3781 .addReg(MI.getOperand(1).getReg());
3782
3783 MI.eraseFromParent(); // The pseudo instruction is gone now.
3784 return BB;
3785}
3786
3787// Emit the FEXP2_D_1 pseudo instructions.
3788//
3789// fexp2_d_1_pseudo $wd, $wt
3790// =>
3791// ldi.d $ws, 1
3792// fexp2.d $wd, $ws, $wt
3794MipsSETargetLowering::emitFEXP2_D_1(MachineInstr &MI,
3795 MachineBasicBlock *BB) const {
3796 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
3797 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
3798 const TargetRegisterClass *RC = &Mips::MSA128DRegClass;
3799 Register Ws1 = RegInfo.createVirtualRegister(RC);
3800 Register Ws2 = RegInfo.createVirtualRegister(RC);
3801 DebugLoc DL = MI.getDebugLoc();
3802
3803 // Splat 1.0 into a vector
3804 BuildMI(*BB, MI, DL, TII->get(Mips::LDI_D), Ws1).addImm(1);
3805 BuildMI(*BB, MI, DL, TII->get(Mips::FFINT_U_D), Ws2).addReg(Ws1);
3806
3807 // Emit 1.0 * fexp2(Wt)
3808 BuildMI(*BB, MI, DL, TII->get(Mips::FEXP2_D), MI.getOperand(0).getReg())
3809 .addReg(Ws2)
3810 .addReg(MI.getOperand(1).getReg());
3811
3812 MI.eraseFromParent(); // The pseudo instruction is gone now.
3813 return BB;
3814}
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!")
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")
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
static bool fitsRegularPattern(typename SmallVectorImpl< ValType >::const_iterator Begin, unsigned CheckStride, typename SmallVectorImpl< ValType >::const_iterator End, ValType ExpectedIndex, unsigned ExpectedIndexStride)
Determine whether a range fits a regular pattern of values.
static SDValue 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.