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