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