2017-10-20 05:37:38 +08:00
|
|
|
//===-- RISCVISelDAGToDAG.cpp - A dag to dag inst selector for RISCV ------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-10-20 05:37:38 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines an instruction selector for the RISCV target.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2020-03-31 14:28:24 +08:00
|
|
|
#include "RISCVISelDAGToDAG.h"
|
2017-10-20 05:37:38 +08:00
|
|
|
#include "MCTargetDesc/RISCVMCTargetDesc.h"
|
2021-01-15 03:44:02 +08:00
|
|
|
#include "MCTargetDesc/RISCVMatInt.h"
|
2021-02-18 20:48:14 +08:00
|
|
|
#include "RISCVISelLowering.h"
|
2017-12-11 19:53:54 +08:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2020-12-19 04:08:27 +08:00
|
|
|
#include "llvm/IR/IntrinsicsRISCV.h"
|
2020-06-24 20:53:27 +08:00
|
|
|
#include "llvm/Support/Alignment.h"
|
2017-10-20 05:37:38 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2021-01-28 12:36:21 +08:00
|
|
|
#include "llvm/Support/KnownBits.h"
|
2017-10-20 05:37:38 +08:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2020-03-31 14:28:24 +08:00
|
|
|
|
2017-10-20 05:37:38 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "riscv-isel"
|
|
|
|
|
2021-02-19 11:00:48 +08:00
|
|
|
namespace llvm {
|
|
|
|
namespace RISCV {
|
|
|
|
#define GET_RISCVVSSEGTable_IMPL
|
|
|
|
#define GET_RISCVVLSEGTable_IMPL
|
|
|
|
#define GET_RISCVVLXSEGTable_IMPL
|
|
|
|
#define GET_RISCVVSXSEGTable_IMPL
|
2021-02-23 01:39:56 +08:00
|
|
|
#define GET_RISCVVLETable_IMPL
|
|
|
|
#define GET_RISCVVSETable_IMPL
|
2021-02-20 02:08:43 +08:00
|
|
|
#define GET_RISCVVLXTable_IMPL
|
|
|
|
#define GET_RISCVVSXTable_IMPL
|
2021-02-18 03:37:06 +08:00
|
|
|
#include "RISCVGenSearchableTables.inc"
|
2021-02-19 11:00:48 +08:00
|
|
|
} // namespace RISCV
|
|
|
|
} // namespace llvm
|
2021-02-18 03:37:06 +08:00
|
|
|
|
2018-04-12 13:34:25 +08:00
|
|
|
void RISCVDAGToDAGISel::PostprocessISelDAG() {
|
|
|
|
doPeepholeLoadStoreADDI();
|
|
|
|
}
|
2018-03-19 19:54:28 +08:00
|
|
|
|
2018-11-16 18:14:16 +08:00
|
|
|
static SDNode *selectImm(SelectionDAG *CurDAG, const SDLoc &DL, int64_t Imm,
|
|
|
|
MVT XLenVT) {
|
2021-04-01 23:51:28 +08:00
|
|
|
RISCVMatInt::InstSeq Seq = RISCVMatInt::generateInstSeq(Imm, XLenVT == MVT::i64);
|
2018-11-16 18:14:16 +08:00
|
|
|
|
2019-09-20 21:48:02 +08:00
|
|
|
SDNode *Result = nullptr;
|
2018-11-16 18:14:16 +08:00
|
|
|
SDValue SrcReg = CurDAG->getRegister(RISCV::X0, XLenVT);
|
|
|
|
for (RISCVMatInt::Inst &Inst : Seq) {
|
|
|
|
SDValue SDImm = CurDAG->getTargetConstant(Inst.Imm, DL, XLenVT);
|
|
|
|
if (Inst.Opc == RISCV::LUI)
|
|
|
|
Result = CurDAG->getMachineNode(RISCV::LUI, DL, XLenVT, SDImm);
|
|
|
|
else
|
|
|
|
Result = CurDAG->getMachineNode(Inst.Opc, DL, XLenVT, SrcReg, SDImm);
|
|
|
|
|
|
|
|
// Only the first instruction has X0 as its source.
|
|
|
|
SrcReg = SDValue(Result, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
[RISCV] Implement vlseg intrinsics.
For Zvlsseg, we need continuous vector registers for the values. We need
to define new register classes for the different combinations of (number
of fields and LMUL). For example,
when the number of fields(NF) = 3, LMUL = 2, the values will be assigned
to (V0M2, V2M2, V4M2), (V2M2, V4M2, V6M2), (V4M2, V6M2, V8M2), ...
We define the vlseg intrinsics with multiple outputs. There is no way to
describe the codegen patterns with multiple outputs in the tablegen
files. We do the codegen in RISCVISelDAGToDAG and use EXTRACT_SUBREG to
extract the values of output.
The multiple scalable vector values will be put into a struct. This
patch is depended on the support for scalable vector struct.
Differential Revision: https://reviews.llvm.org/D94229
2020-12-31 17:14:15 +08:00
|
|
|
static SDValue createTupleImpl(SelectionDAG &CurDAG, ArrayRef<SDValue> Regs,
|
|
|
|
unsigned RegClassID, unsigned SubReg0) {
|
|
|
|
assert(Regs.size() >= 2 && Regs.size() <= 8);
|
|
|
|
|
|
|
|
SDLoc DL(Regs[0]);
|
|
|
|
SmallVector<SDValue, 8> Ops;
|
|
|
|
|
|
|
|
Ops.push_back(CurDAG.getTargetConstant(RegClassID, DL, MVT::i32));
|
|
|
|
|
|
|
|
for (unsigned I = 0; I < Regs.size(); ++I) {
|
|
|
|
Ops.push_back(Regs[I]);
|
|
|
|
Ops.push_back(CurDAG.getTargetConstant(SubReg0 + I, DL, MVT::i32));
|
|
|
|
}
|
|
|
|
SDNode *N =
|
|
|
|
CurDAG.getMachineNode(TargetOpcode::REG_SEQUENCE, DL, MVT::Untyped, Ops);
|
|
|
|
return SDValue(N, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static SDValue createM1Tuple(SelectionDAG &CurDAG, ArrayRef<SDValue> Regs,
|
|
|
|
unsigned NF) {
|
|
|
|
static const unsigned RegClassIDs[] = {
|
|
|
|
RISCV::VRN2M1RegClassID, RISCV::VRN3M1RegClassID, RISCV::VRN4M1RegClassID,
|
|
|
|
RISCV::VRN5M1RegClassID, RISCV::VRN6M1RegClassID, RISCV::VRN7M1RegClassID,
|
|
|
|
RISCV::VRN8M1RegClassID};
|
|
|
|
|
|
|
|
return createTupleImpl(CurDAG, Regs, RegClassIDs[NF - 2], RISCV::sub_vrm1_0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static SDValue createM2Tuple(SelectionDAG &CurDAG, ArrayRef<SDValue> Regs,
|
|
|
|
unsigned NF) {
|
|
|
|
static const unsigned RegClassIDs[] = {RISCV::VRN2M2RegClassID,
|
|
|
|
RISCV::VRN3M2RegClassID,
|
|
|
|
RISCV::VRN4M2RegClassID};
|
|
|
|
|
|
|
|
return createTupleImpl(CurDAG, Regs, RegClassIDs[NF - 2], RISCV::sub_vrm2_0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static SDValue createM4Tuple(SelectionDAG &CurDAG, ArrayRef<SDValue> Regs,
|
|
|
|
unsigned NF) {
|
|
|
|
return createTupleImpl(CurDAG, Regs, RISCV::VRN2M4RegClassID,
|
|
|
|
RISCV::sub_vrm4_0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static SDValue createTuple(SelectionDAG &CurDAG, ArrayRef<SDValue> Regs,
|
|
|
|
unsigned NF, RISCVVLMUL LMUL) {
|
|
|
|
switch (LMUL) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Invalid LMUL.");
|
|
|
|
case RISCVVLMUL::LMUL_F8:
|
|
|
|
case RISCVVLMUL::LMUL_F4:
|
|
|
|
case RISCVVLMUL::LMUL_F2:
|
|
|
|
case RISCVVLMUL::LMUL_1:
|
|
|
|
return createM1Tuple(CurDAG, Regs, NF);
|
|
|
|
case RISCVVLMUL::LMUL_2:
|
|
|
|
return createM2Tuple(CurDAG, Regs, NF);
|
|
|
|
case RISCVVLMUL::LMUL_4:
|
|
|
|
return createM4Tuple(CurDAG, Regs, NF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-06 13:06:24 +08:00
|
|
|
void RISCVDAGToDAGISel::addVectorLoadStoreOperands(
|
2021-05-03 03:01:18 +08:00
|
|
|
SDNode *Node, unsigned SEW, const SDLoc &DL, unsigned CurOp, bool IsMasked,
|
|
|
|
bool IsStridedOrIndexed, SmallVectorImpl<SDValue> &Operands, MVT *IndexVT) {
|
2021-03-30 01:11:18 +08:00
|
|
|
SDValue Chain = Node->getOperand(0);
|
|
|
|
SDValue Glue;
|
|
|
|
|
2021-02-27 02:53:55 +08:00
|
|
|
SDValue Base;
|
|
|
|
SelectBaseAddr(Node->getOperand(CurOp++), Base);
|
|
|
|
Operands.push_back(Base); // Base pointer.
|
2021-04-06 13:06:24 +08:00
|
|
|
|
|
|
|
if (IsStridedOrIndexed) {
|
|
|
|
Operands.push_back(Node->getOperand(CurOp++)); // Index.
|
|
|
|
if (IndexVT)
|
|
|
|
*IndexVT = Operands.back()->getSimpleValueType(0);
|
|
|
|
}
|
|
|
|
|
2021-03-30 01:11:18 +08:00
|
|
|
if (IsMasked) {
|
|
|
|
// Mask needs to be copied to V0.
|
|
|
|
SDValue Mask = Node->getOperand(CurOp++);
|
|
|
|
Chain = CurDAG->getCopyToReg(Chain, DL, RISCV::V0, Mask, SDValue());
|
|
|
|
Glue = Chain.getValue(1);
|
|
|
|
Operands.push_back(CurDAG->getRegister(RISCV::V0, Mask.getValueType()));
|
|
|
|
}
|
2021-02-20 02:00:13 +08:00
|
|
|
SDValue VL;
|
|
|
|
selectVLOp(Node->getOperand(CurOp++), VL);
|
|
|
|
Operands.push_back(VL);
|
2021-04-06 13:06:24 +08:00
|
|
|
|
|
|
|
MVT XLenVT = Subtarget->getXLenVT();
|
2021-05-03 03:01:18 +08:00
|
|
|
SDValue SEWOp = CurDAG->getTargetConstant(Log2_32(SEW), DL, XLenVT);
|
|
|
|
Operands.push_back(SEWOp);
|
2021-04-06 13:06:24 +08:00
|
|
|
|
2021-03-30 01:11:18 +08:00
|
|
|
Operands.push_back(Chain); // Chain.
|
|
|
|
if (Glue)
|
|
|
|
Operands.push_back(Glue);
|
2021-04-06 13:06:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void RISCVDAGToDAGISel::selectVLSEG(SDNode *Node, bool IsMasked,
|
|
|
|
bool IsStrided) {
|
|
|
|
SDLoc DL(Node);
|
|
|
|
unsigned NF = Node->getNumValues() - 1;
|
|
|
|
MVT VT = Node->getSimpleValueType(0);
|
|
|
|
unsigned ScalarSize = VT.getScalarSizeInBits();
|
|
|
|
RISCVVLMUL LMUL = RISCVTargetLowering::getLMUL(VT);
|
|
|
|
|
|
|
|
unsigned CurOp = 2;
|
|
|
|
SmallVector<SDValue, 8> Operands;
|
|
|
|
if (IsMasked) {
|
|
|
|
SmallVector<SDValue, 8> Regs(Node->op_begin() + CurOp,
|
|
|
|
Node->op_begin() + CurOp + NF);
|
|
|
|
SDValue MaskedOff = createTuple(*CurDAG, Regs, NF, LMUL);
|
|
|
|
Operands.push_back(MaskedOff);
|
|
|
|
CurOp += NF;
|
|
|
|
}
|
|
|
|
|
|
|
|
addVectorLoadStoreOperands(Node, ScalarSize, DL, CurOp, IsMasked, IsStrided,
|
|
|
|
Operands);
|
|
|
|
|
2021-02-19 11:00:48 +08:00
|
|
|
const RISCV::VLSEGPseudo *P =
|
|
|
|
RISCV::getVLSEGPseudo(NF, IsMasked, IsStrided, /*FF*/ false, ScalarSize,
|
|
|
|
static_cast<unsigned>(LMUL));
|
2021-02-20 10:56:08 +08:00
|
|
|
MachineSDNode *Load =
|
2021-01-18 10:02:40 +08:00
|
|
|
CurDAG->getMachineNode(P->Pseudo, DL, MVT::Untyped, MVT::Other, Operands);
|
2021-02-20 10:56:08 +08:00
|
|
|
|
|
|
|
if (auto *MemOp = dyn_cast<MemSDNode>(Node))
|
|
|
|
CurDAG->setNodeMemRefs(Load, {MemOp->getMemOperand()});
|
|
|
|
|
2021-01-18 10:02:40 +08:00
|
|
|
SDValue SuperReg = SDValue(Load, 0);
|
2021-02-18 20:48:14 +08:00
|
|
|
for (unsigned I = 0; I < NF; ++I) {
|
|
|
|
unsigned SubRegIdx = RISCVTargetLowering::getSubregIndexByMVT(VT, I);
|
2021-01-18 10:02:40 +08:00
|
|
|
ReplaceUses(SDValue(Node, I),
|
2021-02-18 20:48:14 +08:00
|
|
|
CurDAG->getTargetExtractSubreg(SubRegIdx, DL, VT, SuperReg));
|
|
|
|
}
|
2021-01-18 10:02:40 +08:00
|
|
|
|
|
|
|
ReplaceUses(SDValue(Node, NF), SDValue(Load, 1));
|
|
|
|
CurDAG->RemoveDeadNode(Node);
|
|
|
|
}
|
|
|
|
|
2021-02-17 14:58:14 +08:00
|
|
|
void RISCVDAGToDAGISel::selectVLSEGFF(SDNode *Node, bool IsMasked) {
|
2021-01-24 13:37:38 +08:00
|
|
|
SDLoc DL(Node);
|
2021-01-28 03:01:07 +08:00
|
|
|
unsigned NF = Node->getNumValues() - 2; // Do not count VL and Chain.
|
2021-01-31 07:57:12 +08:00
|
|
|
MVT VT = Node->getSimpleValueType(0);
|
2021-01-24 13:37:38 +08:00
|
|
|
MVT XLenVT = Subtarget->getXLenVT();
|
|
|
|
unsigned ScalarSize = VT.getScalarSizeInBits();
|
2021-02-18 20:48:14 +08:00
|
|
|
RISCVVLMUL LMUL = RISCVTargetLowering::getLMUL(VT);
|
2021-03-30 01:11:18 +08:00
|
|
|
|
2021-02-17 14:58:14 +08:00
|
|
|
unsigned CurOp = 2;
|
2021-01-24 13:37:38 +08:00
|
|
|
SmallVector<SDValue, 7> Operands;
|
2021-02-17 14:58:14 +08:00
|
|
|
if (IsMasked) {
|
|
|
|
SmallVector<SDValue, 8> Regs(Node->op_begin() + CurOp,
|
|
|
|
Node->op_begin() + CurOp + NF);
|
|
|
|
SDValue MaskedOff = createTuple(*CurDAG, Regs, NF, LMUL);
|
|
|
|
Operands.push_back(MaskedOff);
|
|
|
|
CurOp += NF;
|
|
|
|
}
|
2021-04-06 13:06:24 +08:00
|
|
|
|
|
|
|
addVectorLoadStoreOperands(Node, ScalarSize, DL, CurOp, IsMasked,
|
|
|
|
/*IsStridedOrIndexed*/ false, Operands);
|
|
|
|
|
2021-02-19 11:00:48 +08:00
|
|
|
const RISCV::VLSEGPseudo *P =
|
|
|
|
RISCV::getVLSEGPseudo(NF, IsMasked, /*Strided*/ false, /*FF*/ true,
|
|
|
|
ScalarSize, static_cast<unsigned>(LMUL));
|
2021-02-20 10:56:08 +08:00
|
|
|
MachineSDNode *Load = CurDAG->getMachineNode(P->Pseudo, DL, MVT::Untyped,
|
|
|
|
MVT::Other, MVT::Glue, Operands);
|
2021-01-28 03:01:07 +08:00
|
|
|
SDNode *ReadVL = CurDAG->getMachineNode(RISCV::PseudoReadVL, DL, XLenVT,
|
|
|
|
/*Glue*/ SDValue(Load, 2));
|
|
|
|
|
2021-02-20 10:56:08 +08:00
|
|
|
if (auto *MemOp = dyn_cast<MemSDNode>(Node))
|
|
|
|
CurDAG->setNodeMemRefs(Load, {MemOp->getMemOperand()});
|
|
|
|
|
2021-01-24 13:37:38 +08:00
|
|
|
SDValue SuperReg = SDValue(Load, 0);
|
2021-02-18 20:48:14 +08:00
|
|
|
for (unsigned I = 0; I < NF; ++I) {
|
|
|
|
unsigned SubRegIdx = RISCVTargetLowering::getSubregIndexByMVT(VT, I);
|
2021-01-24 13:37:38 +08:00
|
|
|
ReplaceUses(SDValue(Node, I),
|
2021-02-18 20:48:14 +08:00
|
|
|
CurDAG->getTargetExtractSubreg(SubRegIdx, DL, VT, SuperReg));
|
|
|
|
}
|
2021-01-24 13:37:38 +08:00
|
|
|
|
2021-01-28 03:01:07 +08:00
|
|
|
ReplaceUses(SDValue(Node, NF), SDValue(ReadVL, 0)); // VL
|
|
|
|
ReplaceUses(SDValue(Node, NF + 1), SDValue(Load, 1)); // Chain
|
2021-01-24 13:37:38 +08:00
|
|
|
CurDAG->RemoveDeadNode(Node);
|
|
|
|
}
|
|
|
|
|
2021-02-19 11:00:48 +08:00
|
|
|
void RISCVDAGToDAGISel::selectVLXSEG(SDNode *Node, bool IsMasked,
|
|
|
|
bool IsOrdered) {
|
2021-01-18 10:02:40 +08:00
|
|
|
SDLoc DL(Node);
|
|
|
|
unsigned NF = Node->getNumValues() - 1;
|
2021-01-31 07:57:12 +08:00
|
|
|
MVT VT = Node->getSimpleValueType(0);
|
2021-01-18 10:02:40 +08:00
|
|
|
unsigned ScalarSize = VT.getScalarSizeInBits();
|
2021-02-18 20:48:14 +08:00
|
|
|
RISCVVLMUL LMUL = RISCVTargetLowering::getLMUL(VT);
|
2021-03-30 01:11:18 +08:00
|
|
|
|
2021-02-17 14:58:14 +08:00
|
|
|
unsigned CurOp = 2;
|
2021-03-30 01:11:18 +08:00
|
|
|
SmallVector<SDValue, 8> Operands;
|
2021-02-17 14:58:14 +08:00
|
|
|
if (IsMasked) {
|
|
|
|
SmallVector<SDValue, 8> Regs(Node->op_begin() + CurOp,
|
|
|
|
Node->op_begin() + CurOp + NF);
|
|
|
|
SDValue MaskedOff = createTuple(*CurDAG, Regs, NF, LMUL);
|
|
|
|
Operands.push_back(MaskedOff);
|
|
|
|
CurOp += NF;
|
|
|
|
}
|
2021-04-06 13:06:24 +08:00
|
|
|
|
|
|
|
MVT IndexVT;
|
|
|
|
addVectorLoadStoreOperands(Node, ScalarSize, DL, CurOp, IsMasked,
|
|
|
|
/*IsStridedOrIndexed*/ true, Operands, &IndexVT);
|
2021-01-18 10:02:40 +08:00
|
|
|
|
2021-02-20 02:28:45 +08:00
|
|
|
assert(VT.getVectorElementCount() == IndexVT.getVectorElementCount() &&
|
|
|
|
"Element count mismatch");
|
|
|
|
|
2021-02-18 20:48:14 +08:00
|
|
|
RISCVVLMUL IndexLMUL = RISCVTargetLowering::getLMUL(IndexVT);
|
2021-01-18 10:02:40 +08:00
|
|
|
unsigned IndexScalarSize = IndexVT.getScalarSizeInBits();
|
2021-02-19 11:00:48 +08:00
|
|
|
const RISCV::VLXSEGPseudo *P = RISCV::getVLXSEGPseudo(
|
|
|
|
NF, IsMasked, IsOrdered, IndexScalarSize, static_cast<unsigned>(LMUL),
|
2021-01-18 10:02:40 +08:00
|
|
|
static_cast<unsigned>(IndexLMUL));
|
2021-02-20 10:56:08 +08:00
|
|
|
MachineSDNode *Load =
|
[RISCV] Implement vlseg intrinsics.
For Zvlsseg, we need continuous vector registers for the values. We need
to define new register classes for the different combinations of (number
of fields and LMUL). For example,
when the number of fields(NF) = 3, LMUL = 2, the values will be assigned
to (V0M2, V2M2, V4M2), (V2M2, V4M2, V6M2), (V4M2, V6M2, V8M2), ...
We define the vlseg intrinsics with multiple outputs. There is no way to
describe the codegen patterns with multiple outputs in the tablegen
files. We do the codegen in RISCVISelDAGToDAG and use EXTRACT_SUBREG to
extract the values of output.
The multiple scalable vector values will be put into a struct. This
patch is depended on the support for scalable vector struct.
Differential Revision: https://reviews.llvm.org/D94229
2020-12-31 17:14:15 +08:00
|
|
|
CurDAG->getMachineNode(P->Pseudo, DL, MVT::Untyped, MVT::Other, Operands);
|
2021-02-20 10:56:08 +08:00
|
|
|
|
|
|
|
if (auto *MemOp = dyn_cast<MemSDNode>(Node))
|
|
|
|
CurDAG->setNodeMemRefs(Load, {MemOp->getMemOperand()});
|
|
|
|
|
[RISCV] Implement vlseg intrinsics.
For Zvlsseg, we need continuous vector registers for the values. We need
to define new register classes for the different combinations of (number
of fields and LMUL). For example,
when the number of fields(NF) = 3, LMUL = 2, the values will be assigned
to (V0M2, V2M2, V4M2), (V2M2, V4M2, V6M2), (V4M2, V6M2, V8M2), ...
We define the vlseg intrinsics with multiple outputs. There is no way to
describe the codegen patterns with multiple outputs in the tablegen
files. We do the codegen in RISCVISelDAGToDAG and use EXTRACT_SUBREG to
extract the values of output.
The multiple scalable vector values will be put into a struct. This
patch is depended on the support for scalable vector struct.
Differential Revision: https://reviews.llvm.org/D94229
2020-12-31 17:14:15 +08:00
|
|
|
SDValue SuperReg = SDValue(Load, 0);
|
2021-02-18 20:48:14 +08:00
|
|
|
for (unsigned I = 0; I < NF; ++I) {
|
|
|
|
unsigned SubRegIdx = RISCVTargetLowering::getSubregIndexByMVT(VT, I);
|
[RISCV] Implement vlseg intrinsics.
For Zvlsseg, we need continuous vector registers for the values. We need
to define new register classes for the different combinations of (number
of fields and LMUL). For example,
when the number of fields(NF) = 3, LMUL = 2, the values will be assigned
to (V0M2, V2M2, V4M2), (V2M2, V4M2, V6M2), (V4M2, V6M2, V8M2), ...
We define the vlseg intrinsics with multiple outputs. There is no way to
describe the codegen patterns with multiple outputs in the tablegen
files. We do the codegen in RISCVISelDAGToDAG and use EXTRACT_SUBREG to
extract the values of output.
The multiple scalable vector values will be put into a struct. This
patch is depended on the support for scalable vector struct.
Differential Revision: https://reviews.llvm.org/D94229
2020-12-31 17:14:15 +08:00
|
|
|
ReplaceUses(SDValue(Node, I),
|
2021-02-18 20:48:14 +08:00
|
|
|
CurDAG->getTargetExtractSubreg(SubRegIdx, DL, VT, SuperReg));
|
|
|
|
}
|
[RISCV] Implement vlseg intrinsics.
For Zvlsseg, we need continuous vector registers for the values. We need
to define new register classes for the different combinations of (number
of fields and LMUL). For example,
when the number of fields(NF) = 3, LMUL = 2, the values will be assigned
to (V0M2, V2M2, V4M2), (V2M2, V4M2, V6M2), (V4M2, V6M2, V8M2), ...
We define the vlseg intrinsics with multiple outputs. There is no way to
describe the codegen patterns with multiple outputs in the tablegen
files. We do the codegen in RISCVISelDAGToDAG and use EXTRACT_SUBREG to
extract the values of output.
The multiple scalable vector values will be put into a struct. This
patch is depended on the support for scalable vector struct.
Differential Revision: https://reviews.llvm.org/D94229
2020-12-31 17:14:15 +08:00
|
|
|
|
|
|
|
ReplaceUses(SDValue(Node, NF), SDValue(Load, 1));
|
|
|
|
CurDAG->RemoveDeadNode(Node);
|
|
|
|
}
|
|
|
|
|
2021-02-19 11:00:48 +08:00
|
|
|
void RISCVDAGToDAGISel::selectVSSEG(SDNode *Node, bool IsMasked,
|
2021-01-16 21:40:41 +08:00
|
|
|
bool IsStrided) {
|
2021-01-14 17:07:18 +08:00
|
|
|
SDLoc DL(Node);
|
|
|
|
unsigned NF = Node->getNumOperands() - 4;
|
2021-01-16 21:40:41 +08:00
|
|
|
if (IsStrided)
|
|
|
|
NF--;
|
2021-02-17 14:58:14 +08:00
|
|
|
if (IsMasked)
|
|
|
|
NF--;
|
2021-01-31 07:57:12 +08:00
|
|
|
MVT VT = Node->getOperand(2)->getSimpleValueType(0);
|
2021-01-14 17:07:18 +08:00
|
|
|
unsigned ScalarSize = VT.getScalarSizeInBits();
|
2021-02-18 20:48:14 +08:00
|
|
|
RISCVVLMUL LMUL = RISCVTargetLowering::getLMUL(VT);
|
2021-01-14 17:07:18 +08:00
|
|
|
SmallVector<SDValue, 8> Regs(Node->op_begin() + 2, Node->op_begin() + 2 + NF);
|
|
|
|
SDValue StoreVal = createTuple(*CurDAG, Regs, NF, LMUL);
|
2021-03-30 01:11:18 +08:00
|
|
|
|
|
|
|
SmallVector<SDValue, 8> Operands;
|
2021-01-16 21:40:41 +08:00
|
|
|
Operands.push_back(StoreVal);
|
2021-02-17 14:58:14 +08:00
|
|
|
unsigned CurOp = 2 + NF;
|
2021-04-06 13:06:24 +08:00
|
|
|
|
|
|
|
addVectorLoadStoreOperands(Node, ScalarSize, DL, CurOp, IsMasked, IsStrided,
|
|
|
|
Operands);
|
|
|
|
|
2021-02-19 11:00:48 +08:00
|
|
|
const RISCV::VSSEGPseudo *P = RISCV::getVSSEGPseudo(
|
|
|
|
NF, IsMasked, IsStrided, ScalarSize, static_cast<unsigned>(LMUL));
|
2021-02-20 10:56:08 +08:00
|
|
|
MachineSDNode *Store =
|
2021-01-14 17:07:18 +08:00
|
|
|
CurDAG->getMachineNode(P->Pseudo, DL, Node->getValueType(0), Operands);
|
2021-02-20 10:56:08 +08:00
|
|
|
|
|
|
|
if (auto *MemOp = dyn_cast<MemSDNode>(Node))
|
|
|
|
CurDAG->setNodeMemRefs(Store, {MemOp->getMemOperand()});
|
|
|
|
|
2021-01-14 17:07:18 +08:00
|
|
|
ReplaceNode(Node, Store);
|
|
|
|
}
|
|
|
|
|
2021-02-19 11:00:48 +08:00
|
|
|
void RISCVDAGToDAGISel::selectVSXSEG(SDNode *Node, bool IsMasked,
|
|
|
|
bool IsOrdered) {
|
2021-01-14 17:07:18 +08:00
|
|
|
SDLoc DL(Node);
|
|
|
|
unsigned NF = Node->getNumOperands() - 5;
|
2021-02-17 14:58:14 +08:00
|
|
|
if (IsMasked)
|
|
|
|
--NF;
|
2021-01-31 07:57:12 +08:00
|
|
|
MVT VT = Node->getOperand(2)->getSimpleValueType(0);
|
2021-01-14 17:07:18 +08:00
|
|
|
unsigned ScalarSize = VT.getScalarSizeInBits();
|
2021-02-18 20:48:14 +08:00
|
|
|
RISCVVLMUL LMUL = RISCVTargetLowering::getLMUL(VT);
|
2021-01-14 17:07:18 +08:00
|
|
|
SmallVector<SDValue, 8> Regs(Node->op_begin() + 2, Node->op_begin() + 2 + NF);
|
|
|
|
SDValue StoreVal = createTuple(*CurDAG, Regs, NF, LMUL);
|
2021-03-30 01:11:18 +08:00
|
|
|
|
|
|
|
SmallVector<SDValue, 8> Operands;
|
2021-01-16 21:40:41 +08:00
|
|
|
Operands.push_back(StoreVal);
|
2021-02-17 14:58:14 +08:00
|
|
|
unsigned CurOp = 2 + NF;
|
2021-04-06 13:06:24 +08:00
|
|
|
|
|
|
|
MVT IndexVT;
|
|
|
|
addVectorLoadStoreOperands(Node, ScalarSize, DL, CurOp, IsMasked,
|
|
|
|
/*IsStridedOrIndexed*/ true, Operands, &IndexVT);
|
2021-01-14 17:07:18 +08:00
|
|
|
|
2021-02-20 02:28:45 +08:00
|
|
|
assert(VT.getVectorElementCount() == IndexVT.getVectorElementCount() &&
|
|
|
|
"Element count mismatch");
|
|
|
|
|
2021-02-18 20:48:14 +08:00
|
|
|
RISCVVLMUL IndexLMUL = RISCVTargetLowering::getLMUL(IndexVT);
|
2021-01-19 10:47:44 +08:00
|
|
|
unsigned IndexScalarSize = IndexVT.getScalarSizeInBits();
|
2021-02-19 11:00:48 +08:00
|
|
|
const RISCV::VSXSEGPseudo *P = RISCV::getVSXSEGPseudo(
|
|
|
|
NF, IsMasked, IsOrdered, IndexScalarSize, static_cast<unsigned>(LMUL),
|
2021-01-19 10:47:44 +08:00
|
|
|
static_cast<unsigned>(IndexLMUL));
|
2021-02-20 10:56:08 +08:00
|
|
|
MachineSDNode *Store =
|
2021-01-19 10:47:44 +08:00
|
|
|
CurDAG->getMachineNode(P->Pseudo, DL, Node->getValueType(0), Operands);
|
2021-02-20 10:56:08 +08:00
|
|
|
|
|
|
|
if (auto *MemOp = dyn_cast<MemSDNode>(Node))
|
|
|
|
CurDAG->setNodeMemRefs(Store, {MemOp->getMemOperand()});
|
|
|
|
|
2021-01-19 10:47:44 +08:00
|
|
|
ReplaceNode(Node, Store);
|
|
|
|
}
|
|
|
|
|
2021-02-17 23:57:59 +08:00
|
|
|
|
2017-10-20 05:37:38 +08:00
|
|
|
void RISCVDAGToDAGISel::Select(SDNode *Node) {
|
2018-10-03 21:13:13 +08:00
|
|
|
// If we have a custom node, we have already selected.
|
2017-10-20 05:37:38 +08:00
|
|
|
if (Node->isMachineOpcode()) {
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dbgs() << "== "; Node->dump(CurDAG); dbgs() << "\n");
|
2017-10-20 05:37:38 +08:00
|
|
|
Node->setNodeId(-1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-21 16:23:08 +08:00
|
|
|
// Instruction Selection not handled by the auto-generated tablegen selection
|
|
|
|
// should be handled here.
|
2018-10-03 21:13:13 +08:00
|
|
|
unsigned Opcode = Node->getOpcode();
|
|
|
|
MVT XLenVT = Subtarget->getXLenVT();
|
|
|
|
SDLoc DL(Node);
|
2021-01-31 07:57:12 +08:00
|
|
|
MVT VT = Node->getSimpleValueType(0);
|
2018-10-03 21:13:13 +08:00
|
|
|
|
|
|
|
switch (Opcode) {
|
|
|
|
case ISD::Constant: {
|
2021-02-19 20:09:25 +08:00
|
|
|
auto *ConstNode = cast<ConstantSDNode>(Node);
|
2018-10-03 21:13:13 +08:00
|
|
|
if (VT == XLenVT && ConstNode->isNullValue()) {
|
2020-12-09 13:12:34 +08:00
|
|
|
SDValue New =
|
|
|
|
CurDAG->getCopyFromReg(CurDAG->getEntryNode(), DL, RISCV::X0, XLenVT);
|
2017-11-21 20:00:19 +08:00
|
|
|
ReplaceNode(Node, New.getNode());
|
|
|
|
return;
|
2017-11-21 16:23:08 +08:00
|
|
|
}
|
2021-03-23 23:32:00 +08:00
|
|
|
ReplaceNode(Node, selectImm(CurDAG, DL, ConstNode->getSExtValue(), XLenVT));
|
|
|
|
return;
|
2017-11-21 16:23:08 +08:00
|
|
|
}
|
2018-10-03 21:13:13 +08:00
|
|
|
case ISD::FrameIndex: {
|
2017-12-11 19:53:54 +08:00
|
|
|
SDValue Imm = CurDAG->getTargetConstant(0, DL, XLenVT);
|
2018-05-05 09:57:00 +08:00
|
|
|
int FI = cast<FrameIndexSDNode>(Node)->getIndex();
|
2017-12-11 19:53:54 +08:00
|
|
|
SDValue TFI = CurDAG->getTargetFrameIndex(FI, VT);
|
|
|
|
ReplaceNode(Node, CurDAG->getMachineNode(RISCV::ADDI, DL, VT, TFI, Imm));
|
|
|
|
return;
|
|
|
|
}
|
2021-02-02 01:21:43 +08:00
|
|
|
case ISD::SRL: {
|
2021-04-12 00:51:45 +08:00
|
|
|
// We don't need this transform if zext.h is supported.
|
|
|
|
if (Subtarget->hasStdExtZbb() || Subtarget->hasStdExtZbp())
|
|
|
|
break;
|
2021-04-12 02:57:52 +08:00
|
|
|
// Optimize (srl (and X, 0xffff), C) ->
|
|
|
|
// (srli (slli X, (XLen-16), (XLen-16) + C)
|
2021-02-02 01:40:16 +08:00
|
|
|
// Taking into account that the 0xffff may have had lower bits unset by
|
|
|
|
// SimplifyDemandedBits. This avoids materializing the 0xffff immediate.
|
|
|
|
// This pattern occurs when type legalizing i16 right shifts.
|
2021-02-02 01:21:43 +08:00
|
|
|
// FIXME: This could be extended to other AND masks.
|
|
|
|
auto *N1C = dyn_cast<ConstantSDNode>(Node->getOperand(1));
|
|
|
|
if (N1C) {
|
|
|
|
uint64_t ShAmt = N1C->getZExtValue();
|
|
|
|
SDValue N0 = Node->getOperand(0);
|
|
|
|
if (ShAmt < 16 && N0.getOpcode() == ISD::AND && N0.hasOneUse() &&
|
|
|
|
isa<ConstantSDNode>(N0.getOperand(1))) {
|
|
|
|
uint64_t Mask = N0.getConstantOperandVal(1);
|
|
|
|
Mask |= maskTrailingOnes<uint64_t>(ShAmt);
|
|
|
|
if (Mask == 0xffff) {
|
2021-04-12 02:57:52 +08:00
|
|
|
unsigned LShAmt = Subtarget->getXLen() - 16;
|
2021-02-02 01:21:43 +08:00
|
|
|
SDNode *SLLI =
|
2021-04-12 02:57:52 +08:00
|
|
|
CurDAG->getMachineNode(RISCV::SLLI, DL, VT, N0->getOperand(0),
|
|
|
|
CurDAG->getTargetConstant(LShAmt, DL, VT));
|
2021-02-02 01:21:43 +08:00
|
|
|
SDNode *SRLI = CurDAG->getMachineNode(
|
2021-04-12 02:57:52 +08:00
|
|
|
RISCV::SRLI, DL, VT, SDValue(SLLI, 0),
|
|
|
|
CurDAG->getTargetConstant(LShAmt + ShAmt, DL, VT));
|
2021-02-02 01:21:43 +08:00
|
|
|
ReplaceNode(Node, SRLI);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
[RISCV] Add IR intrinsics for vmsge(u).vv/vx/vi.
These instructions don't really exist, but we have ways we can
emulate them.
.vv will swap operands and use vmsle().vv. .vi will adjust the
immediate and use .vmsgt(u).vi when possible. For .vx we need to
use some of the multiple instruction sequences from the V extension
spec.
For unmasked vmsge(u).vx we use:
vmslt{u}.vx vd, va, x; vmnand.mm vd, vd, vd
For cases where mask and maskedoff are the same value then we have
vmsge{u}.vx v0, va, x, v0.t which is the vd==v0 case that
requires a temporary so we use:
vmslt{u}.vx vt, va, x; vmandnot.mm vd, vd, vt
For other masked cases we use this sequence:
vmslt{u}.vx vd, va, x, v0.t; vmxor.mm vd, vd, v0
We trust that register allocation will prevent vd in vmslt{u}.vx
from being v0 since v0 is still needed by the vmxor.
Differential Revision: https://reviews.llvm.org/D100925
2021-04-23 01:29:36 +08:00
|
|
|
case ISD::INTRINSIC_WO_CHAIN: {
|
|
|
|
unsigned IntNo = Node->getConstantOperandVal(0);
|
|
|
|
switch (IntNo) {
|
|
|
|
// By default we do not custom select any intrinsic.
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case Intrinsic::riscv_vmsgeu:
|
|
|
|
case Intrinsic::riscv_vmsge: {
|
|
|
|
SDValue Src1 = Node->getOperand(1);
|
|
|
|
SDValue Src2 = Node->getOperand(2);
|
|
|
|
// Only custom select scalar second operand.
|
|
|
|
if (Src2.getValueType() != XLenVT)
|
|
|
|
break;
|
|
|
|
// Small constants are handled with patterns.
|
|
|
|
if (auto *C = dyn_cast<ConstantSDNode>(Src2)) {
|
|
|
|
int64_t CVal = C->getSExtValue();
|
|
|
|
if (CVal >= -15 && CVal <= 16)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
bool IsUnsigned = IntNo == Intrinsic::riscv_vmsgeu;
|
|
|
|
MVT Src1VT = Src1.getSimpleValueType();
|
|
|
|
unsigned VMSLTOpcode, VMNANDOpcode;
|
|
|
|
switch (RISCVTargetLowering::getLMUL(Src1VT)) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unexpected LMUL!");
|
|
|
|
case RISCVVLMUL::LMUL_F8:
|
|
|
|
VMSLTOpcode =
|
|
|
|
IsUnsigned ? RISCV::PseudoVMSLTU_VX_MF8 : RISCV::PseudoVMSLT_VX_MF8;
|
|
|
|
VMNANDOpcode = RISCV::PseudoVMNAND_MM_MF8;
|
|
|
|
break;
|
|
|
|
case RISCVVLMUL::LMUL_F4:
|
|
|
|
VMSLTOpcode =
|
|
|
|
IsUnsigned ? RISCV::PseudoVMSLTU_VX_MF4 : RISCV::PseudoVMSLT_VX_MF4;
|
|
|
|
VMNANDOpcode = RISCV::PseudoVMNAND_MM_MF4;
|
|
|
|
break;
|
|
|
|
case RISCVVLMUL::LMUL_F2:
|
|
|
|
VMSLTOpcode =
|
|
|
|
IsUnsigned ? RISCV::PseudoVMSLTU_VX_MF2 : RISCV::PseudoVMSLT_VX_MF2;
|
|
|
|
VMNANDOpcode = RISCV::PseudoVMNAND_MM_MF2;
|
|
|
|
break;
|
|
|
|
case RISCVVLMUL::LMUL_1:
|
|
|
|
VMSLTOpcode =
|
|
|
|
IsUnsigned ? RISCV::PseudoVMSLTU_VX_M1 : RISCV::PseudoVMSLT_VX_M1;
|
|
|
|
VMNANDOpcode = RISCV::PseudoVMNAND_MM_M1;
|
|
|
|
break;
|
|
|
|
case RISCVVLMUL::LMUL_2:
|
|
|
|
VMSLTOpcode =
|
|
|
|
IsUnsigned ? RISCV::PseudoVMSLTU_VX_M2 : RISCV::PseudoVMSLT_VX_M2;
|
|
|
|
VMNANDOpcode = RISCV::PseudoVMNAND_MM_M2;
|
|
|
|
break;
|
|
|
|
case RISCVVLMUL::LMUL_4:
|
|
|
|
VMSLTOpcode =
|
|
|
|
IsUnsigned ? RISCV::PseudoVMSLTU_VX_M4 : RISCV::PseudoVMSLT_VX_M4;
|
|
|
|
VMNANDOpcode = RISCV::PseudoVMNAND_MM_M4;
|
|
|
|
break;
|
|
|
|
case RISCVVLMUL::LMUL_8:
|
|
|
|
VMSLTOpcode =
|
|
|
|
IsUnsigned ? RISCV::PseudoVMSLTU_VX_M8 : RISCV::PseudoVMSLT_VX_M8;
|
|
|
|
VMNANDOpcode = RISCV::PseudoVMNAND_MM_M8;
|
|
|
|
break;
|
|
|
|
}
|
2021-05-03 03:01:18 +08:00
|
|
|
SDValue SEW = CurDAG->getTargetConstant(
|
|
|
|
Log2_32(Src1VT.getScalarSizeInBits()), DL, XLenVT);
|
[RISCV] Add IR intrinsics for vmsge(u).vv/vx/vi.
These instructions don't really exist, but we have ways we can
emulate them.
.vv will swap operands and use vmsle().vv. .vi will adjust the
immediate and use .vmsgt(u).vi when possible. For .vx we need to
use some of the multiple instruction sequences from the V extension
spec.
For unmasked vmsge(u).vx we use:
vmslt{u}.vx vd, va, x; vmnand.mm vd, vd, vd
For cases where mask and maskedoff are the same value then we have
vmsge{u}.vx v0, va, x, v0.t which is the vd==v0 case that
requires a temporary so we use:
vmslt{u}.vx vt, va, x; vmandnot.mm vd, vd, vt
For other masked cases we use this sequence:
vmslt{u}.vx vd, va, x, v0.t; vmxor.mm vd, vd, v0
We trust that register allocation will prevent vd in vmslt{u}.vx
from being v0 since v0 is still needed by the vmxor.
Differential Revision: https://reviews.llvm.org/D100925
2021-04-23 01:29:36 +08:00
|
|
|
SDValue VL;
|
|
|
|
selectVLOp(Node->getOperand(3), VL);
|
|
|
|
|
|
|
|
// Expand to
|
|
|
|
// vmslt{u}.vx vd, va, x; vmnand.mm vd, vd, vd
|
|
|
|
SDValue Cmp = SDValue(
|
|
|
|
CurDAG->getMachineNode(VMSLTOpcode, DL, VT, {Src1, Src2, VL, SEW}),
|
|
|
|
0);
|
|
|
|
ReplaceNode(Node, CurDAG->getMachineNode(VMNANDOpcode, DL, VT,
|
|
|
|
{Cmp, Cmp, VL, SEW}));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case Intrinsic::riscv_vmsgeu_mask:
|
|
|
|
case Intrinsic::riscv_vmsge_mask: {
|
|
|
|
SDValue Src1 = Node->getOperand(2);
|
|
|
|
SDValue Src2 = Node->getOperand(3);
|
|
|
|
// Only custom select scalar second operand.
|
|
|
|
if (Src2.getValueType() != XLenVT)
|
|
|
|
break;
|
|
|
|
// Small constants are handled with patterns.
|
|
|
|
if (auto *C = dyn_cast<ConstantSDNode>(Src2)) {
|
|
|
|
int64_t CVal = C->getSExtValue();
|
|
|
|
if (CVal >= -15 && CVal <= 16)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
bool IsUnsigned = IntNo == Intrinsic::riscv_vmsgeu_mask;
|
|
|
|
MVT Src1VT = Src1.getSimpleValueType();
|
|
|
|
unsigned VMSLTOpcode, VMSLTMaskOpcode, VMXOROpcode, VMANDNOTOpcode;
|
|
|
|
switch (RISCVTargetLowering::getLMUL(Src1VT)) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unexpected LMUL!");
|
|
|
|
case RISCVVLMUL::LMUL_F8:
|
|
|
|
VMSLTOpcode =
|
|
|
|
IsUnsigned ? RISCV::PseudoVMSLTU_VX_MF8 : RISCV::PseudoVMSLT_VX_MF8;
|
|
|
|
VMSLTMaskOpcode = IsUnsigned ? RISCV::PseudoVMSLTU_VX_MF8_MASK
|
|
|
|
: RISCV::PseudoVMSLT_VX_MF8_MASK;
|
|
|
|
VMXOROpcode = RISCV::PseudoVMXOR_MM_MF8;
|
|
|
|
VMANDNOTOpcode = RISCV::PseudoVMANDNOT_MM_MF8;
|
|
|
|
break;
|
|
|
|
case RISCVVLMUL::LMUL_F4:
|
|
|
|
VMSLTOpcode =
|
|
|
|
IsUnsigned ? RISCV::PseudoVMSLTU_VX_MF4 : RISCV::PseudoVMSLT_VX_MF4;
|
|
|
|
VMSLTMaskOpcode = IsUnsigned ? RISCV::PseudoVMSLTU_VX_MF4_MASK
|
|
|
|
: RISCV::PseudoVMSLT_VX_MF4_MASK;
|
|
|
|
VMXOROpcode = RISCV::PseudoVMXOR_MM_MF4;
|
|
|
|
VMANDNOTOpcode = RISCV::PseudoVMANDNOT_MM_MF4;
|
|
|
|
break;
|
|
|
|
case RISCVVLMUL::LMUL_F2:
|
|
|
|
VMSLTOpcode =
|
|
|
|
IsUnsigned ? RISCV::PseudoVMSLTU_VX_MF2 : RISCV::PseudoVMSLT_VX_MF2;
|
|
|
|
VMSLTMaskOpcode = IsUnsigned ? RISCV::PseudoVMSLTU_VX_MF2_MASK
|
|
|
|
: RISCV::PseudoVMSLT_VX_MF2_MASK;
|
|
|
|
VMXOROpcode = RISCV::PseudoVMXOR_MM_MF2;
|
|
|
|
VMANDNOTOpcode = RISCV::PseudoVMANDNOT_MM_MF2;
|
|
|
|
break;
|
|
|
|
case RISCVVLMUL::LMUL_1:
|
|
|
|
VMSLTOpcode =
|
|
|
|
IsUnsigned ? RISCV::PseudoVMSLTU_VX_M1 : RISCV::PseudoVMSLT_VX_M1;
|
|
|
|
VMSLTMaskOpcode = IsUnsigned ? RISCV::PseudoVMSLTU_VX_M1_MASK
|
|
|
|
: RISCV::PseudoVMSLT_VX_M1_MASK;
|
|
|
|
VMXOROpcode = RISCV::PseudoVMXOR_MM_M1;
|
|
|
|
VMANDNOTOpcode = RISCV::PseudoVMANDNOT_MM_M1;
|
|
|
|
break;
|
|
|
|
case RISCVVLMUL::LMUL_2:
|
|
|
|
VMSLTOpcode =
|
|
|
|
IsUnsigned ? RISCV::PseudoVMSLTU_VX_M2 : RISCV::PseudoVMSLT_VX_M2;
|
|
|
|
VMSLTMaskOpcode = IsUnsigned ? RISCV::PseudoVMSLTU_VX_M2_MASK
|
|
|
|
: RISCV::PseudoVMSLT_VX_M2_MASK;
|
|
|
|
VMXOROpcode = RISCV::PseudoVMXOR_MM_M2;
|
|
|
|
VMANDNOTOpcode = RISCV::PseudoVMANDNOT_MM_M2;
|
|
|
|
break;
|
|
|
|
case RISCVVLMUL::LMUL_4:
|
|
|
|
VMSLTOpcode =
|
|
|
|
IsUnsigned ? RISCV::PseudoVMSLTU_VX_M4 : RISCV::PseudoVMSLT_VX_M4;
|
|
|
|
VMSLTMaskOpcode = IsUnsigned ? RISCV::PseudoVMSLTU_VX_M4_MASK
|
|
|
|
: RISCV::PseudoVMSLT_VX_M4_MASK;
|
|
|
|
VMXOROpcode = RISCV::PseudoVMXOR_MM_M4;
|
|
|
|
VMANDNOTOpcode = RISCV::PseudoVMANDNOT_MM_M4;
|
|
|
|
break;
|
|
|
|
case RISCVVLMUL::LMUL_8:
|
|
|
|
VMSLTOpcode =
|
|
|
|
IsUnsigned ? RISCV::PseudoVMSLTU_VX_M8 : RISCV::PseudoVMSLT_VX_M8;
|
|
|
|
VMSLTMaskOpcode = IsUnsigned ? RISCV::PseudoVMSLTU_VX_M8_MASK
|
|
|
|
: RISCV::PseudoVMSLT_VX_M8_MASK;
|
|
|
|
VMXOROpcode = RISCV::PseudoVMXOR_MM_M8;
|
|
|
|
VMANDNOTOpcode = RISCV::PseudoVMANDNOT_MM_M8;
|
|
|
|
break;
|
|
|
|
}
|
2021-05-03 03:01:18 +08:00
|
|
|
SDValue SEW = CurDAG->getTargetConstant(
|
|
|
|
Log2_32(Src1VT.getScalarSizeInBits()), DL, XLenVT);
|
[RISCV] Add IR intrinsics for vmsge(u).vv/vx/vi.
These instructions don't really exist, but we have ways we can
emulate them.
.vv will swap operands and use vmsle().vv. .vi will adjust the
immediate and use .vmsgt(u).vi when possible. For .vx we need to
use some of the multiple instruction sequences from the V extension
spec.
For unmasked vmsge(u).vx we use:
vmslt{u}.vx vd, va, x; vmnand.mm vd, vd, vd
For cases where mask and maskedoff are the same value then we have
vmsge{u}.vx v0, va, x, v0.t which is the vd==v0 case that
requires a temporary so we use:
vmslt{u}.vx vt, va, x; vmandnot.mm vd, vd, vt
For other masked cases we use this sequence:
vmslt{u}.vx vd, va, x, v0.t; vmxor.mm vd, vd, v0
We trust that register allocation will prevent vd in vmslt{u}.vx
from being v0 since v0 is still needed by the vmxor.
Differential Revision: https://reviews.llvm.org/D100925
2021-04-23 01:29:36 +08:00
|
|
|
SDValue VL;
|
|
|
|
selectVLOp(Node->getOperand(5), VL);
|
|
|
|
SDValue MaskedOff = Node->getOperand(1);
|
|
|
|
SDValue Mask = Node->getOperand(4);
|
|
|
|
// If the MaskedOff value and the Mask are the same value use
|
|
|
|
// vmslt{u}.vx vt, va, x; vmandnot.mm vd, vd, vt
|
|
|
|
// This avoids needing to copy v0 to vd before starting the next sequence.
|
|
|
|
if (Mask == MaskedOff) {
|
|
|
|
SDValue Cmp = SDValue(
|
|
|
|
CurDAG->getMachineNode(VMSLTOpcode, DL, VT, {Src1, Src2, VL, SEW}),
|
|
|
|
0);
|
|
|
|
ReplaceNode(Node, CurDAG->getMachineNode(VMANDNOTOpcode, DL, VT,
|
|
|
|
{Mask, Cmp, VL, SEW}));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise use
|
|
|
|
// vmslt{u}.vx vd, va, x, v0.t; vmxor.mm vd, vd, v0
|
|
|
|
SDValue Cmp = SDValue(
|
|
|
|
CurDAG->getMachineNode(VMSLTMaskOpcode, DL, VT,
|
|
|
|
{MaskedOff, Src1, Src2, Mask, VL, SEW}),
|
|
|
|
0);
|
|
|
|
ReplaceNode(Node, CurDAG->getMachineNode(VMXOROpcode, DL, VT,
|
|
|
|
{Cmp, Mask, VL, SEW}));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2020-12-19 04:08:27 +08:00
|
|
|
case ISD::INTRINSIC_W_CHAIN: {
|
|
|
|
unsigned IntNo = cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue();
|
|
|
|
switch (IntNo) {
|
|
|
|
// By default we do not custom select any intrinsic.
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
2021-02-17 11:46:44 +08:00
|
|
|
case Intrinsic::riscv_vsetvli:
|
|
|
|
case Intrinsic::riscv_vsetvlimax: {
|
2020-12-19 04:08:27 +08:00
|
|
|
if (!Subtarget->hasStdExtV())
|
|
|
|
break;
|
|
|
|
|
2021-02-17 11:46:44 +08:00
|
|
|
bool VLMax = IntNo == Intrinsic::riscv_vsetvlimax;
|
|
|
|
unsigned Offset = VLMax ? 2 : 3;
|
|
|
|
|
|
|
|
assert(Node->getNumOperands() == Offset + 2 &&
|
|
|
|
"Unexpected number of operands");
|
2020-12-19 04:08:27 +08:00
|
|
|
|
|
|
|
RISCVVSEW VSEW =
|
2021-02-17 11:46:44 +08:00
|
|
|
static_cast<RISCVVSEW>(Node->getConstantOperandVal(Offset) & 0x7);
|
|
|
|
RISCVVLMUL VLMul = static_cast<RISCVVLMUL>(
|
|
|
|
Node->getConstantOperandVal(Offset + 1) & 0x7);
|
2020-12-19 04:08:27 +08:00
|
|
|
|
|
|
|
unsigned VTypeI = RISCVVType::encodeVTYPE(
|
|
|
|
VLMul, VSEW, /*TailAgnostic*/ true, /*MaskAgnostic*/ false);
|
|
|
|
SDValue VTypeIOp = CurDAG->getTargetConstant(VTypeI, DL, XLenVT);
|
|
|
|
|
2021-02-17 11:46:44 +08:00
|
|
|
SDValue VLOperand;
|
|
|
|
if (VLMax) {
|
|
|
|
VLOperand = CurDAG->getRegister(RISCV::X0, XLenVT);
|
|
|
|
} else {
|
|
|
|
VLOperand = Node->getOperand(2);
|
|
|
|
|
|
|
|
if (auto *C = dyn_cast<ConstantSDNode>(VLOperand)) {
|
|
|
|
uint64_t AVL = C->getZExtValue();
|
|
|
|
if (isUInt<5>(AVL)) {
|
|
|
|
SDValue VLImm = CurDAG->getTargetConstant(AVL, DL, XLenVT);
|
|
|
|
ReplaceNode(
|
|
|
|
Node, CurDAG->getMachineNode(RISCV::PseudoVSETIVLI, DL, XLenVT,
|
2021-02-01 16:08:46 +08:00
|
|
|
MVT::Other, VLImm, VTypeIOp,
|
|
|
|
/* Chain */ Node->getOperand(0)));
|
2021-02-17 11:46:44 +08:00
|
|
|
return;
|
|
|
|
}
|
2020-12-19 04:08:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReplaceNode(Node,
|
|
|
|
CurDAG->getMachineNode(RISCV::PseudoVSETVLI, DL, XLenVT,
|
|
|
|
MVT::Other, VLOperand, VTypeIOp,
|
|
|
|
/* Chain */ Node->getOperand(0)));
|
|
|
|
return;
|
|
|
|
}
|
[RISCV] Implement vlseg intrinsics.
For Zvlsseg, we need continuous vector registers for the values. We need
to define new register classes for the different combinations of (number
of fields and LMUL). For example,
when the number of fields(NF) = 3, LMUL = 2, the values will be assigned
to (V0M2, V2M2, V4M2), (V2M2, V4M2, V6M2), (V4M2, V6M2, V8M2), ...
We define the vlseg intrinsics with multiple outputs. There is no way to
describe the codegen patterns with multiple outputs in the tablegen
files. We do the codegen in RISCVISelDAGToDAG and use EXTRACT_SUBREG to
extract the values of output.
The multiple scalable vector values will be put into a struct. This
patch is depended on the support for scalable vector struct.
Differential Revision: https://reviews.llvm.org/D94229
2020-12-31 17:14:15 +08:00
|
|
|
case Intrinsic::riscv_vlseg2:
|
|
|
|
case Intrinsic::riscv_vlseg3:
|
|
|
|
case Intrinsic::riscv_vlseg4:
|
|
|
|
case Intrinsic::riscv_vlseg5:
|
|
|
|
case Intrinsic::riscv_vlseg6:
|
|
|
|
case Intrinsic::riscv_vlseg7:
|
|
|
|
case Intrinsic::riscv_vlseg8: {
|
2021-02-19 11:00:48 +08:00
|
|
|
selectVLSEG(Node, /*IsMasked*/ false, /*IsStrided*/ false);
|
[RISCV] Implement vlseg intrinsics.
For Zvlsseg, we need continuous vector registers for the values. We need
to define new register classes for the different combinations of (number
of fields and LMUL). For example,
when the number of fields(NF) = 3, LMUL = 2, the values will be assigned
to (V0M2, V2M2, V4M2), (V2M2, V4M2, V6M2), (V4M2, V6M2, V8M2), ...
We define the vlseg intrinsics with multiple outputs. There is no way to
describe the codegen patterns with multiple outputs in the tablegen
files. We do the codegen in RISCVISelDAGToDAG and use EXTRACT_SUBREG to
extract the values of output.
The multiple scalable vector values will be put into a struct. This
patch is depended on the support for scalable vector struct.
Differential Revision: https://reviews.llvm.org/D94229
2020-12-31 17:14:15 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
case Intrinsic::riscv_vlseg2_mask:
|
|
|
|
case Intrinsic::riscv_vlseg3_mask:
|
|
|
|
case Intrinsic::riscv_vlseg4_mask:
|
|
|
|
case Intrinsic::riscv_vlseg5_mask:
|
|
|
|
case Intrinsic::riscv_vlseg6_mask:
|
|
|
|
case Intrinsic::riscv_vlseg7_mask:
|
|
|
|
case Intrinsic::riscv_vlseg8_mask: {
|
2021-02-19 11:00:48 +08:00
|
|
|
selectVLSEG(Node, /*IsMasked*/ true, /*IsStrided*/ false);
|
2021-01-15 19:29:51 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
case Intrinsic::riscv_vlsseg2:
|
|
|
|
case Intrinsic::riscv_vlsseg3:
|
|
|
|
case Intrinsic::riscv_vlsseg4:
|
|
|
|
case Intrinsic::riscv_vlsseg5:
|
|
|
|
case Intrinsic::riscv_vlsseg6:
|
|
|
|
case Intrinsic::riscv_vlsseg7:
|
|
|
|
case Intrinsic::riscv_vlsseg8: {
|
2021-02-19 11:00:48 +08:00
|
|
|
selectVLSEG(Node, /*IsMasked*/ false, /*IsStrided*/ true);
|
2021-01-15 19:29:51 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
case Intrinsic::riscv_vlsseg2_mask:
|
|
|
|
case Intrinsic::riscv_vlsseg3_mask:
|
|
|
|
case Intrinsic::riscv_vlsseg4_mask:
|
|
|
|
case Intrinsic::riscv_vlsseg5_mask:
|
|
|
|
case Intrinsic::riscv_vlsseg6_mask:
|
|
|
|
case Intrinsic::riscv_vlsseg7_mask:
|
|
|
|
case Intrinsic::riscv_vlsseg8_mask: {
|
2021-02-19 11:00:48 +08:00
|
|
|
selectVLSEG(Node, /*IsMasked*/ true, /*IsStrided*/ true);
|
[RISCV] Implement vlseg intrinsics.
For Zvlsseg, we need continuous vector registers for the values. We need
to define new register classes for the different combinations of (number
of fields and LMUL). For example,
when the number of fields(NF) = 3, LMUL = 2, the values will be assigned
to (V0M2, V2M2, V4M2), (V2M2, V4M2, V6M2), (V4M2, V6M2, V8M2), ...
We define the vlseg intrinsics with multiple outputs. There is no way to
describe the codegen patterns with multiple outputs in the tablegen
files. We do the codegen in RISCVISelDAGToDAG and use EXTRACT_SUBREG to
extract the values of output.
The multiple scalable vector values will be put into a struct. This
patch is depended on the support for scalable vector struct.
Differential Revision: https://reviews.llvm.org/D94229
2020-12-31 17:14:15 +08:00
|
|
|
return;
|
|
|
|
}
|
2021-01-18 10:02:40 +08:00
|
|
|
case Intrinsic::riscv_vloxseg2:
|
|
|
|
case Intrinsic::riscv_vloxseg3:
|
|
|
|
case Intrinsic::riscv_vloxseg4:
|
|
|
|
case Intrinsic::riscv_vloxseg5:
|
|
|
|
case Intrinsic::riscv_vloxseg6:
|
|
|
|
case Intrinsic::riscv_vloxseg7:
|
|
|
|
case Intrinsic::riscv_vloxseg8:
|
2021-02-19 11:00:48 +08:00
|
|
|
selectVLXSEG(Node, /*IsMasked*/ false, /*IsOrdered*/ true);
|
|
|
|
return;
|
2021-01-18 10:02:40 +08:00
|
|
|
case Intrinsic::riscv_vluxseg2:
|
|
|
|
case Intrinsic::riscv_vluxseg3:
|
|
|
|
case Intrinsic::riscv_vluxseg4:
|
|
|
|
case Intrinsic::riscv_vluxseg5:
|
|
|
|
case Intrinsic::riscv_vluxseg6:
|
|
|
|
case Intrinsic::riscv_vluxseg7:
|
2021-02-19 11:00:48 +08:00
|
|
|
case Intrinsic::riscv_vluxseg8:
|
|
|
|
selectVLXSEG(Node, /*IsMasked*/ false, /*IsOrdered*/ false);
|
2021-01-18 10:02:40 +08:00
|
|
|
return;
|
|
|
|
case Intrinsic::riscv_vloxseg2_mask:
|
|
|
|
case Intrinsic::riscv_vloxseg3_mask:
|
|
|
|
case Intrinsic::riscv_vloxseg4_mask:
|
|
|
|
case Intrinsic::riscv_vloxseg5_mask:
|
|
|
|
case Intrinsic::riscv_vloxseg6_mask:
|
|
|
|
case Intrinsic::riscv_vloxseg7_mask:
|
|
|
|
case Intrinsic::riscv_vloxseg8_mask:
|
2021-02-19 11:00:48 +08:00
|
|
|
selectVLXSEG(Node, /*IsMasked*/ true, /*IsOrdered*/ true);
|
|
|
|
return;
|
2021-01-18 10:02:40 +08:00
|
|
|
case Intrinsic::riscv_vluxseg2_mask:
|
|
|
|
case Intrinsic::riscv_vluxseg3_mask:
|
|
|
|
case Intrinsic::riscv_vluxseg4_mask:
|
|
|
|
case Intrinsic::riscv_vluxseg5_mask:
|
|
|
|
case Intrinsic::riscv_vluxseg6_mask:
|
|
|
|
case Intrinsic::riscv_vluxseg7_mask:
|
2021-02-19 11:00:48 +08:00
|
|
|
case Intrinsic::riscv_vluxseg8_mask:
|
|
|
|
selectVLXSEG(Node, /*IsMasked*/ true, /*IsOrdered*/ false);
|
2021-01-18 10:02:40 +08:00
|
|
|
return;
|
2021-01-28 03:01:07 +08:00
|
|
|
case Intrinsic::riscv_vlseg8ff:
|
|
|
|
case Intrinsic::riscv_vlseg7ff:
|
|
|
|
case Intrinsic::riscv_vlseg6ff:
|
|
|
|
case Intrinsic::riscv_vlseg5ff:
|
|
|
|
case Intrinsic::riscv_vlseg4ff:
|
|
|
|
case Intrinsic::riscv_vlseg3ff:
|
|
|
|
case Intrinsic::riscv_vlseg2ff: {
|
2021-02-17 14:58:14 +08:00
|
|
|
selectVLSEGFF(Node, /*IsMasked*/ false);
|
2021-01-28 03:01:07 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
case Intrinsic::riscv_vlseg8ff_mask:
|
|
|
|
case Intrinsic::riscv_vlseg7ff_mask:
|
|
|
|
case Intrinsic::riscv_vlseg6ff_mask:
|
|
|
|
case Intrinsic::riscv_vlseg5ff_mask:
|
|
|
|
case Intrinsic::riscv_vlseg4ff_mask:
|
|
|
|
case Intrinsic::riscv_vlseg3ff_mask:
|
|
|
|
case Intrinsic::riscv_vlseg2ff_mask: {
|
2021-02-17 14:58:14 +08:00
|
|
|
selectVLSEGFF(Node, /*IsMasked*/ true);
|
2021-01-28 03:01:07 +08:00
|
|
|
return;
|
|
|
|
}
|
2021-02-20 02:08:43 +08:00
|
|
|
case Intrinsic::riscv_vloxei:
|
|
|
|
case Intrinsic::riscv_vloxei_mask:
|
|
|
|
case Intrinsic::riscv_vluxei:
|
|
|
|
case Intrinsic::riscv_vluxei_mask: {
|
|
|
|
bool IsMasked = IntNo == Intrinsic::riscv_vloxei_mask ||
|
|
|
|
IntNo == Intrinsic::riscv_vluxei_mask;
|
|
|
|
bool IsOrdered = IntNo == Intrinsic::riscv_vloxei ||
|
|
|
|
IntNo == Intrinsic::riscv_vloxei_mask;
|
|
|
|
|
|
|
|
MVT VT = Node->getSimpleValueType(0);
|
|
|
|
unsigned ScalarSize = VT.getScalarSizeInBits();
|
2021-03-30 01:11:18 +08:00
|
|
|
|
2021-02-20 02:08:43 +08:00
|
|
|
unsigned CurOp = 2;
|
2021-03-30 01:11:18 +08:00
|
|
|
SmallVector<SDValue, 8> Operands;
|
2021-02-20 02:08:43 +08:00
|
|
|
if (IsMasked)
|
|
|
|
Operands.push_back(Node->getOperand(CurOp++));
|
2021-04-06 13:06:24 +08:00
|
|
|
|
|
|
|
MVT IndexVT;
|
|
|
|
addVectorLoadStoreOperands(Node, ScalarSize, DL, CurOp, IsMasked,
|
|
|
|
/*IsStridedOrIndexed*/ true, Operands,
|
|
|
|
&IndexVT);
|
2021-02-20 02:08:43 +08:00
|
|
|
|
|
|
|
assert(VT.getVectorElementCount() == IndexVT.getVectorElementCount() &&
|
|
|
|
"Element count mismatch");
|
|
|
|
|
2021-02-18 20:48:14 +08:00
|
|
|
RISCVVLMUL LMUL = RISCVTargetLowering::getLMUL(VT);
|
|
|
|
RISCVVLMUL IndexLMUL = RISCVTargetLowering::getLMUL(IndexVT);
|
2021-02-20 02:08:43 +08:00
|
|
|
unsigned IndexScalarSize = IndexVT.getScalarSizeInBits();
|
|
|
|
const RISCV::VLX_VSXPseudo *P = RISCV::getVLXPseudo(
|
|
|
|
IsMasked, IsOrdered, IndexScalarSize, static_cast<unsigned>(LMUL),
|
|
|
|
static_cast<unsigned>(IndexLMUL));
|
2021-02-20 10:56:08 +08:00
|
|
|
MachineSDNode *Load =
|
2021-02-20 02:08:43 +08:00
|
|
|
CurDAG->getMachineNode(P->Pseudo, DL, Node->getVTList(), Operands);
|
2021-02-20 10:56:08 +08:00
|
|
|
|
|
|
|
if (auto *MemOp = dyn_cast<MemSDNode>(Node))
|
|
|
|
CurDAG->setNodeMemRefs(Load, {MemOp->getMemOperand()});
|
|
|
|
|
2021-02-20 02:08:43 +08:00
|
|
|
ReplaceNode(Node, Load);
|
|
|
|
return;
|
|
|
|
}
|
2021-02-23 01:39:56 +08:00
|
|
|
case Intrinsic::riscv_vle1:
|
|
|
|
case Intrinsic::riscv_vle:
|
|
|
|
case Intrinsic::riscv_vle_mask:
|
|
|
|
case Intrinsic::riscv_vlse:
|
|
|
|
case Intrinsic::riscv_vlse_mask: {
|
|
|
|
bool IsMasked = IntNo == Intrinsic::riscv_vle_mask ||
|
|
|
|
IntNo == Intrinsic::riscv_vlse_mask;
|
|
|
|
bool IsStrided =
|
|
|
|
IntNo == Intrinsic::riscv_vlse || IntNo == Intrinsic::riscv_vlse_mask;
|
|
|
|
|
|
|
|
MVT VT = Node->getSimpleValueType(0);
|
|
|
|
unsigned ScalarSize = VT.getScalarSizeInBits();
|
|
|
|
// VLE1 uses an SEW of 8.
|
2021-05-03 03:01:18 +08:00
|
|
|
unsigned SEW = (IntNo == Intrinsic::riscv_vle1) ? 8 : ScalarSize;
|
2021-03-30 01:11:18 +08:00
|
|
|
|
2021-02-23 01:39:56 +08:00
|
|
|
unsigned CurOp = 2;
|
2021-03-30 01:11:18 +08:00
|
|
|
SmallVector<SDValue, 8> Operands;
|
2021-02-23 01:39:56 +08:00
|
|
|
if (IsMasked)
|
|
|
|
Operands.push_back(Node->getOperand(CurOp++));
|
2021-04-06 13:06:24 +08:00
|
|
|
|
2021-05-03 03:01:18 +08:00
|
|
|
addVectorLoadStoreOperands(Node, SEW, DL, CurOp, IsMasked, IsStrided,
|
2021-04-06 13:06:24 +08:00
|
|
|
Operands);
|
2021-02-23 01:39:56 +08:00
|
|
|
|
|
|
|
RISCVVLMUL LMUL = RISCVTargetLowering::getLMUL(VT);
|
|
|
|
const RISCV::VLEPseudo *P =
|
|
|
|
RISCV::getVLEPseudo(IsMasked, IsStrided, /*FF*/ false, ScalarSize,
|
|
|
|
static_cast<unsigned>(LMUL));
|
|
|
|
MachineSDNode *Load =
|
|
|
|
CurDAG->getMachineNode(P->Pseudo, DL, Node->getVTList(), Operands);
|
|
|
|
|
|
|
|
if (auto *MemOp = dyn_cast<MemSDNode>(Node))
|
|
|
|
CurDAG->setNodeMemRefs(Load, {MemOp->getMemOperand()});
|
|
|
|
|
|
|
|
ReplaceNode(Node, Load);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case Intrinsic::riscv_vleff:
|
|
|
|
case Intrinsic::riscv_vleff_mask: {
|
|
|
|
bool IsMasked = IntNo == Intrinsic::riscv_vleff_mask;
|
|
|
|
|
|
|
|
MVT VT = Node->getSimpleValueType(0);
|
|
|
|
unsigned ScalarSize = VT.getScalarSizeInBits();
|
2021-03-30 01:11:18 +08:00
|
|
|
|
2021-02-23 01:39:56 +08:00
|
|
|
unsigned CurOp = 2;
|
|
|
|
SmallVector<SDValue, 7> Operands;
|
|
|
|
if (IsMasked)
|
|
|
|
Operands.push_back(Node->getOperand(CurOp++));
|
2021-04-06 13:06:24 +08:00
|
|
|
|
|
|
|
addVectorLoadStoreOperands(Node, ScalarSize, DL, CurOp, IsMasked,
|
|
|
|
/*IsStridedOrIndexed*/ false, Operands);
|
2021-02-23 01:39:56 +08:00
|
|
|
|
|
|
|
RISCVVLMUL LMUL = RISCVTargetLowering::getLMUL(VT);
|
|
|
|
const RISCV::VLEPseudo *P =
|
|
|
|
RISCV::getVLEPseudo(IsMasked, /*Strided*/ false, /*FF*/ true,
|
|
|
|
ScalarSize, static_cast<unsigned>(LMUL));
|
|
|
|
MachineSDNode *Load =
|
|
|
|
CurDAG->getMachineNode(P->Pseudo, DL, Node->getValueType(0),
|
|
|
|
MVT::Other, MVT::Glue, Operands);
|
|
|
|
SDNode *ReadVL = CurDAG->getMachineNode(RISCV::PseudoReadVL, DL, XLenVT,
|
|
|
|
/*Glue*/ SDValue(Load, 2));
|
|
|
|
|
|
|
|
if (auto *MemOp = dyn_cast<MemSDNode>(Node))
|
|
|
|
CurDAG->setNodeMemRefs(Load, {MemOp->getMemOperand()});
|
|
|
|
|
|
|
|
ReplaceUses(SDValue(Node, 0), SDValue(Load, 0));
|
|
|
|
ReplaceUses(SDValue(Node, 1), SDValue(ReadVL, 0)); // VL
|
|
|
|
ReplaceUses(SDValue(Node, 2), SDValue(Load, 1)); // Chain
|
|
|
|
CurDAG->RemoveDeadNode(Node);
|
|
|
|
return;
|
|
|
|
}
|
2020-12-19 04:08:27 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2021-01-14 17:07:18 +08:00
|
|
|
case ISD::INTRINSIC_VOID: {
|
|
|
|
unsigned IntNo = cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue();
|
|
|
|
switch (IntNo) {
|
|
|
|
case Intrinsic::riscv_vsseg2:
|
|
|
|
case Intrinsic::riscv_vsseg3:
|
|
|
|
case Intrinsic::riscv_vsseg4:
|
|
|
|
case Intrinsic::riscv_vsseg5:
|
|
|
|
case Intrinsic::riscv_vsseg6:
|
|
|
|
case Intrinsic::riscv_vsseg7:
|
|
|
|
case Intrinsic::riscv_vsseg8: {
|
2021-02-19 11:00:48 +08:00
|
|
|
selectVSSEG(Node, /*IsMasked*/ false, /*IsStrided*/ false);
|
2021-01-14 17:07:18 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
case Intrinsic::riscv_vsseg2_mask:
|
|
|
|
case Intrinsic::riscv_vsseg3_mask:
|
|
|
|
case Intrinsic::riscv_vsseg4_mask:
|
|
|
|
case Intrinsic::riscv_vsseg5_mask:
|
|
|
|
case Intrinsic::riscv_vsseg6_mask:
|
|
|
|
case Intrinsic::riscv_vsseg7_mask:
|
|
|
|
case Intrinsic::riscv_vsseg8_mask: {
|
2021-02-19 11:00:48 +08:00
|
|
|
selectVSSEG(Node, /*IsMasked*/ true, /*IsStrided*/ false);
|
2021-01-16 21:40:41 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
case Intrinsic::riscv_vssseg2:
|
|
|
|
case Intrinsic::riscv_vssseg3:
|
|
|
|
case Intrinsic::riscv_vssseg4:
|
|
|
|
case Intrinsic::riscv_vssseg5:
|
|
|
|
case Intrinsic::riscv_vssseg6:
|
|
|
|
case Intrinsic::riscv_vssseg7:
|
|
|
|
case Intrinsic::riscv_vssseg8: {
|
2021-02-19 11:00:48 +08:00
|
|
|
selectVSSEG(Node, /*IsMasked*/ false, /*IsStrided*/ true);
|
2021-01-16 21:40:41 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
case Intrinsic::riscv_vssseg2_mask:
|
|
|
|
case Intrinsic::riscv_vssseg3_mask:
|
|
|
|
case Intrinsic::riscv_vssseg4_mask:
|
|
|
|
case Intrinsic::riscv_vssseg5_mask:
|
|
|
|
case Intrinsic::riscv_vssseg6_mask:
|
|
|
|
case Intrinsic::riscv_vssseg7_mask:
|
|
|
|
case Intrinsic::riscv_vssseg8_mask: {
|
2021-02-19 11:00:48 +08:00
|
|
|
selectVSSEG(Node, /*IsMasked*/ true, /*IsStrided*/ true);
|
2021-01-14 17:07:18 +08:00
|
|
|
return;
|
|
|
|
}
|
2021-01-19 10:47:44 +08:00
|
|
|
case Intrinsic::riscv_vsoxseg2:
|
|
|
|
case Intrinsic::riscv_vsoxseg3:
|
|
|
|
case Intrinsic::riscv_vsoxseg4:
|
|
|
|
case Intrinsic::riscv_vsoxseg5:
|
|
|
|
case Intrinsic::riscv_vsoxseg6:
|
|
|
|
case Intrinsic::riscv_vsoxseg7:
|
|
|
|
case Intrinsic::riscv_vsoxseg8:
|
2021-02-19 11:00:48 +08:00
|
|
|
selectVSXSEG(Node, /*IsMasked*/ false, /*IsOrdered*/ true);
|
|
|
|
return;
|
2021-01-19 10:47:44 +08:00
|
|
|
case Intrinsic::riscv_vsuxseg2:
|
|
|
|
case Intrinsic::riscv_vsuxseg3:
|
|
|
|
case Intrinsic::riscv_vsuxseg4:
|
|
|
|
case Intrinsic::riscv_vsuxseg5:
|
|
|
|
case Intrinsic::riscv_vsuxseg6:
|
|
|
|
case Intrinsic::riscv_vsuxseg7:
|
2021-02-19 11:00:48 +08:00
|
|
|
case Intrinsic::riscv_vsuxseg8:
|
|
|
|
selectVSXSEG(Node, /*IsMasked*/ false, /*IsOrdered*/ false);
|
2021-01-19 10:47:44 +08:00
|
|
|
return;
|
|
|
|
case Intrinsic::riscv_vsoxseg2_mask:
|
|
|
|
case Intrinsic::riscv_vsoxseg3_mask:
|
|
|
|
case Intrinsic::riscv_vsoxseg4_mask:
|
|
|
|
case Intrinsic::riscv_vsoxseg5_mask:
|
|
|
|
case Intrinsic::riscv_vsoxseg6_mask:
|
|
|
|
case Intrinsic::riscv_vsoxseg7_mask:
|
|
|
|
case Intrinsic::riscv_vsoxseg8_mask:
|
2021-02-19 11:00:48 +08:00
|
|
|
selectVSXSEG(Node, /*IsMasked*/ true, /*IsOrdered*/ true);
|
|
|
|
return;
|
2021-01-19 10:47:44 +08:00
|
|
|
case Intrinsic::riscv_vsuxseg2_mask:
|
|
|
|
case Intrinsic::riscv_vsuxseg3_mask:
|
|
|
|
case Intrinsic::riscv_vsuxseg4_mask:
|
|
|
|
case Intrinsic::riscv_vsuxseg5_mask:
|
|
|
|
case Intrinsic::riscv_vsuxseg6_mask:
|
|
|
|
case Intrinsic::riscv_vsuxseg7_mask:
|
2021-02-19 11:00:48 +08:00
|
|
|
case Intrinsic::riscv_vsuxseg8_mask:
|
|
|
|
selectVSXSEG(Node, /*IsMasked*/ true, /*IsOrdered*/ false);
|
2021-01-19 10:47:44 +08:00
|
|
|
return;
|
2021-02-20 02:08:43 +08:00
|
|
|
case Intrinsic::riscv_vsoxei:
|
|
|
|
case Intrinsic::riscv_vsoxei_mask:
|
|
|
|
case Intrinsic::riscv_vsuxei:
|
|
|
|
case Intrinsic::riscv_vsuxei_mask: {
|
|
|
|
bool IsMasked = IntNo == Intrinsic::riscv_vsoxei_mask ||
|
|
|
|
IntNo == Intrinsic::riscv_vsuxei_mask;
|
|
|
|
bool IsOrdered = IntNo == Intrinsic::riscv_vsoxei ||
|
|
|
|
IntNo == Intrinsic::riscv_vsoxei_mask;
|
|
|
|
|
|
|
|
MVT VT = Node->getOperand(2)->getSimpleValueType(0);
|
|
|
|
unsigned ScalarSize = VT.getScalarSizeInBits();
|
2021-04-06 12:25:52 +08:00
|
|
|
|
2021-02-20 02:08:43 +08:00
|
|
|
unsigned CurOp = 2;
|
2021-04-06 12:25:52 +08:00
|
|
|
SmallVector<SDValue, 8> Operands;
|
2021-02-20 02:08:43 +08:00
|
|
|
Operands.push_back(Node->getOperand(CurOp++)); // Store value.
|
2021-04-06 13:06:24 +08:00
|
|
|
|
|
|
|
MVT IndexVT;
|
|
|
|
addVectorLoadStoreOperands(Node, ScalarSize, DL, CurOp, IsMasked,
|
|
|
|
/*IsStridedOrIndexed*/ true, Operands,
|
|
|
|
&IndexVT);
|
2021-02-20 02:08:43 +08:00
|
|
|
|
|
|
|
assert(VT.getVectorElementCount() == IndexVT.getVectorElementCount() &&
|
|
|
|
"Element count mismatch");
|
|
|
|
|
2021-02-18 20:48:14 +08:00
|
|
|
RISCVVLMUL LMUL = RISCVTargetLowering::getLMUL(VT);
|
|
|
|
RISCVVLMUL IndexLMUL = RISCVTargetLowering::getLMUL(IndexVT);
|
2021-02-20 02:08:43 +08:00
|
|
|
unsigned IndexScalarSize = IndexVT.getScalarSizeInBits();
|
|
|
|
const RISCV::VLX_VSXPseudo *P = RISCV::getVSXPseudo(
|
|
|
|
IsMasked, IsOrdered, IndexScalarSize, static_cast<unsigned>(LMUL),
|
|
|
|
static_cast<unsigned>(IndexLMUL));
|
2021-02-20 10:56:08 +08:00
|
|
|
MachineSDNode *Store =
|
2021-02-20 02:08:43 +08:00
|
|
|
CurDAG->getMachineNode(P->Pseudo, DL, Node->getVTList(), Operands);
|
2021-02-20 10:56:08 +08:00
|
|
|
|
|
|
|
if (auto *MemOp = dyn_cast<MemSDNode>(Node))
|
|
|
|
CurDAG->setNodeMemRefs(Store, {MemOp->getMemOperand()});
|
|
|
|
|
2021-02-20 02:08:43 +08:00
|
|
|
ReplaceNode(Node, Store);
|
|
|
|
return;
|
|
|
|
}
|
2021-02-23 01:39:56 +08:00
|
|
|
case Intrinsic::riscv_vse1:
|
|
|
|
case Intrinsic::riscv_vse:
|
|
|
|
case Intrinsic::riscv_vse_mask:
|
|
|
|
case Intrinsic::riscv_vsse:
|
|
|
|
case Intrinsic::riscv_vsse_mask: {
|
|
|
|
bool IsMasked = IntNo == Intrinsic::riscv_vse_mask ||
|
|
|
|
IntNo == Intrinsic::riscv_vsse_mask;
|
|
|
|
bool IsStrided =
|
|
|
|
IntNo == Intrinsic::riscv_vsse || IntNo == Intrinsic::riscv_vsse_mask;
|
|
|
|
|
|
|
|
MVT VT = Node->getOperand(2)->getSimpleValueType(0);
|
|
|
|
unsigned ScalarSize = VT.getScalarSizeInBits();
|
|
|
|
// VSE1 uses an SEW of 8.
|
2021-05-03 03:01:18 +08:00
|
|
|
unsigned SEW = (IntNo == Intrinsic::riscv_vse1) ? 8 : ScalarSize;
|
2021-04-06 12:25:52 +08:00
|
|
|
|
2021-02-23 01:39:56 +08:00
|
|
|
unsigned CurOp = 2;
|
2021-04-06 12:25:52 +08:00
|
|
|
SmallVector<SDValue, 8> Operands;
|
2021-02-23 01:39:56 +08:00
|
|
|
Operands.push_back(Node->getOperand(CurOp++)); // Store value.
|
2021-04-06 13:06:24 +08:00
|
|
|
|
2021-05-03 03:01:18 +08:00
|
|
|
addVectorLoadStoreOperands(Node, SEW, DL, CurOp, IsMasked, IsStrided,
|
2021-04-06 13:06:24 +08:00
|
|
|
Operands);
|
2021-02-23 01:39:56 +08:00
|
|
|
|
|
|
|
RISCVVLMUL LMUL = RISCVTargetLowering::getLMUL(VT);
|
|
|
|
const RISCV::VSEPseudo *P = RISCV::getVSEPseudo(
|
|
|
|
IsMasked, IsStrided, ScalarSize, static_cast<unsigned>(LMUL));
|
|
|
|
MachineSDNode *Store =
|
|
|
|
CurDAG->getMachineNode(P->Pseudo, DL, Node->getVTList(), Operands);
|
|
|
|
if (auto *MemOp = dyn_cast<MemSDNode>(Node))
|
|
|
|
CurDAG->setNodeMemRefs(Store, {MemOp->getMemOperand()});
|
|
|
|
|
|
|
|
ReplaceNode(Node, Store);
|
|
|
|
return;
|
|
|
|
}
|
2021-01-19 10:47:44 +08:00
|
|
|
}
|
2021-01-14 17:07:18 +08:00
|
|
|
break;
|
|
|
|
}
|
2021-02-23 03:27:51 +08:00
|
|
|
case ISD::BITCAST: {
|
|
|
|
MVT SrcVT = Node->getOperand(0).getSimpleValueType();
|
|
|
|
// Just drop bitcasts between vectors if both are fixed or both are
|
|
|
|
// scalable.
|
|
|
|
if ((VT.isScalableVector() && SrcVT.isScalableVector()) ||
|
|
|
|
(VT.isFixedLengthVector() && SrcVT.isFixedLengthVector())) {
|
2021-02-19 00:54:03 +08:00
|
|
|
ReplaceUses(SDValue(Node, 0), Node->getOperand(0));
|
|
|
|
CurDAG->RemoveDeadNode(Node);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2021-02-23 03:27:51 +08:00
|
|
|
}
|
2021-02-12 06:19:30 +08:00
|
|
|
case ISD::INSERT_SUBVECTOR: {
|
2021-02-17 23:57:59 +08:00
|
|
|
SDValue V = Node->getOperand(0);
|
|
|
|
SDValue SubV = Node->getOperand(1);
|
|
|
|
SDLoc DL(SubV);
|
|
|
|
auto Idx = Node->getConstantOperandVal(2);
|
2021-02-25 13:38:51 +08:00
|
|
|
MVT SubVecVT = SubV.getSimpleValueType();
|
2021-02-17 23:57:59 +08:00
|
|
|
|
2021-04-24 04:05:23 +08:00
|
|
|
const RISCVTargetLowering &TLI = *Subtarget->getTargetLowering();
|
2021-02-26 20:42:52 +08:00
|
|
|
MVT SubVecContainerVT = SubVecVT;
|
|
|
|
// Establish the correct scalable-vector types for any fixed-length type.
|
|
|
|
if (SubVecVT.isFixedLengthVector())
|
2021-04-24 04:05:23 +08:00
|
|
|
SubVecContainerVT = TLI.getContainerForFixedLengthVector(SubVecVT);
|
2021-02-26 20:42:52 +08:00
|
|
|
if (VT.isFixedLengthVector())
|
2021-04-24 04:05:23 +08:00
|
|
|
VT = TLI.getContainerForFixedLengthVector(VT);
|
2021-02-12 06:19:30 +08:00
|
|
|
|
2021-02-26 20:42:52 +08:00
|
|
|
const auto *TRI = Subtarget->getRegisterInfo();
|
|
|
|
unsigned SubRegIdx;
|
|
|
|
std::tie(SubRegIdx, Idx) =
|
|
|
|
RISCVTargetLowering::decomposeSubvectorInsertExtractToSubRegs(
|
|
|
|
VT, SubVecContainerVT, Idx, TRI);
|
2021-02-16 04:42:33 +08:00
|
|
|
|
2021-02-26 20:42:52 +08:00
|
|
|
// If the Idx hasn't been completely eliminated then this is a subvector
|
|
|
|
// insert which doesn't naturally align to a vector register. These must
|
|
|
|
// be handled using instructions to manipulate the vector registers.
|
|
|
|
if (Idx != 0)
|
|
|
|
break;
|
2021-02-17 23:57:59 +08:00
|
|
|
|
2021-03-04 00:39:43 +08:00
|
|
|
RISCVVLMUL SubVecLMUL = RISCVTargetLowering::getLMUL(SubVecContainerVT);
|
2021-02-26 20:42:52 +08:00
|
|
|
bool IsSubVecPartReg = SubVecLMUL == RISCVVLMUL::LMUL_F2 ||
|
|
|
|
SubVecLMUL == RISCVVLMUL::LMUL_F4 ||
|
|
|
|
SubVecLMUL == RISCVVLMUL::LMUL_F8;
|
|
|
|
(void)IsSubVecPartReg; // Silence unused variable warning without asserts.
|
|
|
|
assert((!IsSubVecPartReg || V.isUndef()) &&
|
|
|
|
"Expecting lowering to have created legal INSERT_SUBVECTORs when "
|
|
|
|
"the subvector is smaller than a full-sized register");
|
|
|
|
|
|
|
|
// If we haven't set a SubRegIdx, then we must be going between
|
|
|
|
// equally-sized LMUL groups (e.g. VR -> VR). This can be done as a copy.
|
|
|
|
if (SubRegIdx == RISCV::NoSubRegister) {
|
|
|
|
unsigned InRegClassID = RISCVTargetLowering::getRegClassIDForVecVT(VT);
|
|
|
|
assert(RISCVTargetLowering::getRegClassIDForVecVT(SubVecContainerVT) ==
|
|
|
|
InRegClassID &&
|
|
|
|
"Unexpected subvector extraction");
|
|
|
|
SDValue RC = CurDAG->getTargetConstant(InRegClassID, DL, XLenVT);
|
2021-02-17 23:57:59 +08:00
|
|
|
SDNode *NewNode = CurDAG->getMachineNode(TargetOpcode::COPY_TO_REGCLASS,
|
|
|
|
DL, VT, SubV, RC);
|
2021-04-08 03:17:42 +08:00
|
|
|
ReplaceNode(Node, NewNode);
|
|
|
|
return;
|
2021-02-17 23:57:59 +08:00
|
|
|
}
|
2021-02-26 20:42:52 +08:00
|
|
|
|
2021-03-18 03:09:48 +08:00
|
|
|
SDValue Insert = CurDAG->getTargetInsertSubreg(SubRegIdx, DL, VT, V, SubV);
|
2021-04-08 03:17:42 +08:00
|
|
|
ReplaceNode(Node, Insert.getNode());
|
|
|
|
return;
|
2021-02-17 23:57:59 +08:00
|
|
|
}
|
|
|
|
case ISD::EXTRACT_SUBVECTOR: {
|
2021-02-12 06:19:30 +08:00
|
|
|
SDValue V = Node->getOperand(0);
|
2021-02-17 23:57:59 +08:00
|
|
|
auto Idx = Node->getConstantOperandVal(1);
|
2021-02-25 13:38:51 +08:00
|
|
|
MVT InVT = V.getSimpleValueType();
|
2021-02-12 06:19:30 +08:00
|
|
|
SDLoc DL(V);
|
2021-02-17 23:57:59 +08:00
|
|
|
|
2021-04-24 04:05:23 +08:00
|
|
|
const RISCVTargetLowering &TLI = *Subtarget->getTargetLowering();
|
2021-02-22 22:14:10 +08:00
|
|
|
MVT SubVecContainerVT = VT;
|
|
|
|
// Establish the correct scalable-vector types for any fixed-length type.
|
|
|
|
if (VT.isFixedLengthVector())
|
2021-04-24 04:05:23 +08:00
|
|
|
SubVecContainerVT = TLI.getContainerForFixedLengthVector(VT);
|
2021-02-22 22:14:10 +08:00
|
|
|
if (InVT.isFixedLengthVector())
|
2021-04-24 04:05:23 +08:00
|
|
|
InVT = TLI.getContainerForFixedLengthVector(InVT);
|
2021-02-22 22:14:10 +08:00
|
|
|
|
|
|
|
const auto *TRI = Subtarget->getRegisterInfo();
|
|
|
|
unsigned SubRegIdx;
|
|
|
|
std::tie(SubRegIdx, Idx) =
|
|
|
|
RISCVTargetLowering::decomposeSubvectorInsertExtractToSubRegs(
|
|
|
|
InVT, SubVecContainerVT, Idx, TRI);
|
|
|
|
|
|
|
|
// If the Idx hasn't been completely eliminated then this is a subvector
|
|
|
|
// extract which doesn't naturally align to a vector register. These must
|
|
|
|
// be handled using instructions to manipulate the vector registers.
|
|
|
|
if (Idx != 0)
|
|
|
|
break;
|
2021-02-17 23:57:59 +08:00
|
|
|
|
2021-02-22 22:14:10 +08:00
|
|
|
// If we haven't set a SubRegIdx, then we must be going between
|
|
|
|
// equally-sized LMUL types (e.g. VR -> VR). This can be done as a copy.
|
|
|
|
if (SubRegIdx == RISCV::NoSubRegister) {
|
2021-02-18 20:48:14 +08:00
|
|
|
unsigned InRegClassID = RISCVTargetLowering::getRegClassIDForVecVT(InVT);
|
2021-02-22 22:14:10 +08:00
|
|
|
assert(RISCVTargetLowering::getRegClassIDForVecVT(SubVecContainerVT) ==
|
|
|
|
InRegClassID &&
|
|
|
|
"Unexpected subvector extraction");
|
|
|
|
SDValue RC = CurDAG->getTargetConstant(InRegClassID, DL, XLenVT);
|
2021-02-17 23:57:59 +08:00
|
|
|
SDNode *NewNode =
|
|
|
|
CurDAG->getMachineNode(TargetOpcode::COPY_TO_REGCLASS, DL, VT, V, RC);
|
2021-04-08 03:17:42 +08:00
|
|
|
ReplaceNode(Node, NewNode);
|
|
|
|
return;
|
2021-02-17 23:57:59 +08:00
|
|
|
}
|
2021-02-22 22:14:10 +08:00
|
|
|
|
2021-03-18 03:09:48 +08:00
|
|
|
SDValue Extract = CurDAG->getTargetExtractSubreg(SubRegIdx, DL, VT, V);
|
2021-04-08 03:17:42 +08:00
|
|
|
ReplaceNode(Node, Extract.getNode());
|
|
|
|
return;
|
2021-02-12 06:19:30 +08:00
|
|
|
}
|
2021-04-27 04:23:22 +08:00
|
|
|
case RISCVISD::VMV_V_X_VL:
|
|
|
|
case RISCVISD::VFMV_V_F_VL: {
|
|
|
|
// Try to match splat of a scalar load to a strided load with stride of x0.
|
|
|
|
SDValue Src = Node->getOperand(0);
|
|
|
|
auto *Ld = dyn_cast<LoadSDNode>(Src);
|
|
|
|
if (!Ld)
|
|
|
|
break;
|
|
|
|
EVT MemVT = Ld->getMemoryVT();
|
|
|
|
// The memory VT should be the same size as the element type.
|
|
|
|
if (MemVT.getStoreSize() != VT.getVectorElementType().getStoreSize())
|
|
|
|
break;
|
|
|
|
if (!IsProfitableToFold(Src, Node, Node) ||
|
|
|
|
!IsLegalToFold(Src, Node, Node, TM.getOptLevel()))
|
|
|
|
break;
|
|
|
|
|
|
|
|
SDValue VL;
|
|
|
|
selectVLOp(Node->getOperand(1), VL);
|
|
|
|
|
|
|
|
unsigned ScalarSize = VT.getScalarSizeInBits();
|
2021-05-03 03:01:18 +08:00
|
|
|
SDValue SEW = CurDAG->getTargetConstant(Log2_32(ScalarSize), DL, XLenVT);
|
2021-04-27 04:23:22 +08:00
|
|
|
|
|
|
|
SDValue Operands[] = {Ld->getBasePtr(),
|
|
|
|
CurDAG->getRegister(RISCV::X0, XLenVT), VL, SEW,
|
|
|
|
Ld->getChain()};
|
|
|
|
|
|
|
|
RISCVVLMUL LMUL = RISCVTargetLowering::getLMUL(VT);
|
|
|
|
const RISCV::VLEPseudo *P = RISCV::getVLEPseudo(
|
|
|
|
/*IsMasked*/ false, /*IsStrided*/ true, /*FF*/ false, ScalarSize,
|
|
|
|
static_cast<unsigned>(LMUL));
|
|
|
|
MachineSDNode *Load =
|
|
|
|
CurDAG->getMachineNode(P->Pseudo, DL, Node->getVTList(), Operands);
|
|
|
|
|
|
|
|
if (auto *MemOp = dyn_cast<MemSDNode>(Node))
|
|
|
|
CurDAG->setNodeMemRefs(Load, {MemOp->getMemOperand()});
|
|
|
|
|
|
|
|
ReplaceNode(Node, Load);
|
|
|
|
return;
|
|
|
|
}
|
2018-10-03 21:13:13 +08:00
|
|
|
}
|
2017-11-21 16:23:08 +08:00
|
|
|
|
2017-10-20 05:37:38 +08:00
|
|
|
// Select the default instruction.
|
|
|
|
SelectCode(Node);
|
|
|
|
}
|
|
|
|
|
2018-01-11 04:05:09 +08:00
|
|
|
bool RISCVDAGToDAGISel::SelectInlineAsmMemoryOperand(
|
|
|
|
const SDValue &Op, unsigned ConstraintID, std::vector<SDValue> &OutOps) {
|
|
|
|
switch (ConstraintID) {
|
|
|
|
case InlineAsm::Constraint_m:
|
|
|
|
// We just support simple memory operands that have a single address
|
|
|
|
// operand and need no special handling.
|
|
|
|
OutOps.push_back(Op);
|
|
|
|
return false;
|
2019-08-16 18:28:34 +08:00
|
|
|
case InlineAsm::Constraint_A:
|
|
|
|
OutOps.push_back(Op);
|
|
|
|
return false;
|
2018-01-11 04:05:09 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-11 19:53:54 +08:00
|
|
|
bool RISCVDAGToDAGISel::SelectAddrFI(SDValue Addr, SDValue &Base) {
|
2021-02-03 02:05:33 +08:00
|
|
|
if (auto *FIN = dyn_cast<FrameIndexSDNode>(Addr)) {
|
2017-12-11 19:53:54 +08:00
|
|
|
Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), Subtarget->getXLenVT());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-02-13 16:42:25 +08:00
|
|
|
bool RISCVDAGToDAGISel::SelectBaseAddr(SDValue Addr, SDValue &Base) {
|
2021-02-03 02:05:33 +08:00
|
|
|
// If this is FrameIndex, select it directly. Otherwise just let it get
|
|
|
|
// selected to a register independently.
|
|
|
|
if (auto *FIN = dyn_cast<FrameIndexSDNode>(Addr))
|
|
|
|
Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), Subtarget->getXLenVT());
|
|
|
|
else
|
|
|
|
Base = Addr;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-02-13 06:01:28 +08:00
|
|
|
bool RISCVDAGToDAGISel::selectShiftMask(SDValue N, unsigned ShiftWidth,
|
|
|
|
SDValue &ShAmt) {
|
|
|
|
// Shift instructions on RISCV only read the lower 5 or 6 bits of the shift
|
|
|
|
// amount. If there is an AND on the shift amount, we can bypass it if it
|
|
|
|
// doesn't affect any of those bits.
|
|
|
|
if (N.getOpcode() == ISD::AND && isa<ConstantSDNode>(N.getOperand(1))) {
|
|
|
|
const APInt &AndMask = N->getConstantOperandAPInt(1);
|
|
|
|
|
|
|
|
// Since the max shift amount is a power of 2 we can subtract 1 to make a
|
|
|
|
// mask that covers the bits needed to represent all shift amounts.
|
|
|
|
assert(isPowerOf2_32(ShiftWidth) && "Unexpected max shift amount!");
|
|
|
|
APInt ShMask(AndMask.getBitWidth(), ShiftWidth - 1);
|
|
|
|
|
|
|
|
if (ShMask.isSubsetOf(AndMask)) {
|
|
|
|
ShAmt = N.getOperand(0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// SimplifyDemandedBits may have optimized the mask so try restoring any
|
|
|
|
// bits that are known zero.
|
|
|
|
KnownBits Known = CurDAG->computeKnownBits(N->getOperand(0));
|
|
|
|
if (ShMask.isSubsetOf(AndMask | Known.Zero)) {
|
|
|
|
ShAmt = N.getOperand(0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2021-01-28 12:36:21 +08:00
|
|
|
|
2021-02-13 06:01:28 +08:00
|
|
|
ShAmt = N;
|
|
|
|
return true;
|
2021-01-28 12:36:21 +08:00
|
|
|
}
|
|
|
|
|
2021-02-23 06:36:44 +08:00
|
|
|
bool RISCVDAGToDAGISel::selectSExti32(SDValue N, SDValue &Val) {
|
|
|
|
if (N.getOpcode() == ISD::SIGN_EXTEND_INREG &&
|
|
|
|
cast<VTSDNode>(N.getOperand(1))->getVT() == MVT::i32) {
|
|
|
|
Val = N.getOperand(0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// FIXME: Should we just call computeNumSignBits here?
|
|
|
|
if (N.getOpcode() == ISD::AssertSext &&
|
|
|
|
cast<VTSDNode>(N->getOperand(1))->getVT().bitsLE(MVT::i32)) {
|
|
|
|
Val = N;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (N.getOpcode() == ISD::AssertZext &&
|
|
|
|
cast<VTSDNode>(N->getOperand(1))->getVT().bitsLT(MVT::i32)) {
|
|
|
|
Val = N;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-02-25 07:55:19 +08:00
|
|
|
bool RISCVDAGToDAGISel::selectZExti32(SDValue N, SDValue &Val) {
|
|
|
|
if (N.getOpcode() == ISD::AND) {
|
|
|
|
auto *C = dyn_cast<ConstantSDNode>(N.getOperand(1));
|
2021-03-26 13:04:24 +08:00
|
|
|
if (C && C->getZExtValue() == UINT64_C(0xFFFFFFFF)) {
|
2021-02-25 07:55:19 +08:00
|
|
|
Val = N.getOperand(0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// FIXME: Should we just call computeKnownBits here?
|
|
|
|
if (N.getOpcode() == ISD::AssertZext &&
|
|
|
|
cast<VTSDNode>(N->getOperand(1))->getVT().bitsLE(MVT::i32)) {
|
|
|
|
Val = N;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-04-20 18:04:25 +08:00
|
|
|
// Check if (add r, imm) can be optimized to (ADDI (ADDI r, imm0), imm1),
|
|
|
|
// in which imm = imm0 + imm1 and both imm0 and imm1 are simm12.
|
|
|
|
bool RISCVDAGToDAGISel::selectAddiPair(SDValue N, SDValue &Val) {
|
|
|
|
if (auto *ConstOp = dyn_cast<ConstantSDNode>(N)) {
|
|
|
|
// The immediate operand must have only use.
|
|
|
|
if (!(ConstOp->hasOneUse()))
|
|
|
|
return false;
|
|
|
|
// The immediate operand must be in range [-4096,-2049] or [2048,4094].
|
|
|
|
int64_t Imm = ConstOp->getSExtValue();
|
|
|
|
if ((-4096 <= Imm && Imm <= -2049) || (2048 <= Imm && Imm <= 4094)) {
|
|
|
|
Val = N;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-01-06 03:16:50 +08:00
|
|
|
// Check that it is a SLLIUW (Shift Logical Left Immediate Unsigned i32
|
|
|
|
// on RV64).
|
|
|
|
// SLLIUW is the same as SLLI except for the fact that it clears the bits
|
|
|
|
// XLEN-1:32 of the input RS1 before shifting.
|
|
|
|
// A PatFrag has already checked that it has the right structure:
|
2020-07-15 18:50:03 +08:00
|
|
|
//
|
2021-01-06 03:16:50 +08:00
|
|
|
// (AND (SHL RS1, VC2), VC1)
|
2020-07-15 18:50:03 +08:00
|
|
|
//
|
2021-01-06 03:16:50 +08:00
|
|
|
// We check that VC2, the shamt is less than 32, otherwise the pattern is
|
|
|
|
// exactly the same as SLLI and we give priority to that.
|
|
|
|
// Eventually we check that VC1, the mask used to clear the upper 32 bits
|
|
|
|
// of RS1, is correct:
|
2020-07-15 18:50:03 +08:00
|
|
|
//
|
2021-01-06 03:16:50 +08:00
|
|
|
// VC1 == (0xFFFFFFFF << VC2)
|
2020-11-17 01:22:42 +08:00
|
|
|
//
|
2021-01-06 03:16:50 +08:00
|
|
|
bool RISCVDAGToDAGISel::MatchSLLIUW(SDNode *N) const {
|
|
|
|
assert(N->getOpcode() == ISD::AND);
|
|
|
|
assert(N->getOperand(0).getOpcode() == ISD::SHL);
|
|
|
|
assert(isa<ConstantSDNode>(N->getOperand(1)));
|
|
|
|
assert(isa<ConstantSDNode>(N->getOperand(0).getOperand(1)));
|
|
|
|
|
|
|
|
// The IsRV64 predicate is checked after PatFrag predicates so we can get
|
|
|
|
// here even on RV32.
|
|
|
|
if (!Subtarget->is64Bit())
|
2020-11-17 01:22:42 +08:00
|
|
|
return false;
|
|
|
|
|
2021-01-06 03:16:50 +08:00
|
|
|
SDValue Shl = N->getOperand(0);
|
|
|
|
uint64_t VC1 = N->getConstantOperandVal(1);
|
|
|
|
uint64_t VC2 = Shl.getConstantOperandVal(1);
|
2020-11-17 01:22:42 +08:00
|
|
|
|
2021-01-06 03:16:50 +08:00
|
|
|
// Immediate range should be enforced by uimm5 predicate.
|
|
|
|
assert(VC2 < 32 && "Unexpected immediate");
|
2021-01-24 16:13:12 +08:00
|
|
|
return (VC1 >> VC2) == UINT64_C(0xFFFFFFFF);
|
2020-07-15 18:50:03 +08:00
|
|
|
}
|
|
|
|
|
2021-04-28 03:48:44 +08:00
|
|
|
// Select VL as a 5 bit immediate or a value that will become a register. This
|
|
|
|
// allows us to choose betwen VSETIVLI or VSETVLI later.
|
2021-02-02 15:53:54 +08:00
|
|
|
bool RISCVDAGToDAGISel::selectVLOp(SDValue N, SDValue &VL) {
|
|
|
|
auto *C = dyn_cast<ConstantSDNode>(N);
|
2021-04-28 03:48:44 +08:00
|
|
|
if (C && isUInt<5>(C->getZExtValue()))
|
|
|
|
VL = CurDAG->getTargetConstant(C->getZExtValue(), SDLoc(N),
|
|
|
|
N->getValueType(0));
|
2021-02-02 15:53:54 +08:00
|
|
|
else
|
|
|
|
VL = N;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-12-15 21:05:32 +08:00
|
|
|
bool RISCVDAGToDAGISel::selectVSplat(SDValue N, SDValue &SplatVal) {
|
|
|
|
if (N.getOpcode() != ISD::SPLAT_VECTOR &&
|
2021-02-13 01:09:22 +08:00
|
|
|
N.getOpcode() != RISCVISD::SPLAT_VECTOR_I64 &&
|
|
|
|
N.getOpcode() != RISCVISD::VMV_V_X_VL)
|
2020-12-15 21:05:32 +08:00
|
|
|
return false;
|
|
|
|
SplatVal = N.getOperand(0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-04-08 18:22:46 +08:00
|
|
|
using ValidateFn = bool (*)(int64_t);
|
|
|
|
|
|
|
|
static bool selectVSplatSimmHelper(SDValue N, SDValue &SplatVal,
|
|
|
|
SelectionDAG &DAG,
|
|
|
|
const RISCVSubtarget &Subtarget,
|
|
|
|
ValidateFn ValidateImm) {
|
2020-12-15 21:05:32 +08:00
|
|
|
if ((N.getOpcode() != ISD::SPLAT_VECTOR &&
|
2021-02-13 01:09:22 +08:00
|
|
|
N.getOpcode() != RISCVISD::SPLAT_VECTOR_I64 &&
|
|
|
|
N.getOpcode() != RISCVISD::VMV_V_X_VL) ||
|
2020-12-15 21:05:32 +08:00
|
|
|
!isa<ConstantSDNode>(N.getOperand(0)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
int64_t SplatImm = cast<ConstantSDNode>(N.getOperand(0))->getSExtValue();
|
|
|
|
|
2021-04-08 18:22:46 +08:00
|
|
|
// ISD::SPLAT_VECTOR, RISCVISD::SPLAT_VECTOR_I64 and RISCVISD::VMV_V_X_VL
|
|
|
|
// share semantics when the operand type is wider than the resulting vector
|
|
|
|
// element type: an implicit truncation first takes place. Therefore, perform
|
|
|
|
// a manual truncation/sign-extension in order to ignore any truncated bits
|
|
|
|
// and catch any zero-extended immediate.
|
2020-12-24 21:20:51 +08:00
|
|
|
// For example, we wish to match (i8 -1) -> (XLenVT 255) as a simm5 by first
|
|
|
|
// sign-extending to (XLenVT -1).
|
2021-04-08 18:22:46 +08:00
|
|
|
MVT XLenVT = Subtarget.getXLenVT();
|
2020-12-24 21:20:51 +08:00
|
|
|
assert(XLenVT == N.getOperand(0).getSimpleValueType() &&
|
|
|
|
"Unexpected splat operand type");
|
2021-01-31 07:57:12 +08:00
|
|
|
MVT EltVT = N.getSimpleValueType().getVectorElementType();
|
2021-04-08 18:22:46 +08:00
|
|
|
if (EltVT.bitsLT(XLenVT))
|
2020-12-24 21:20:51 +08:00
|
|
|
SplatImm = SignExtend64(SplatImm, EltVT.getSizeInBits());
|
|
|
|
|
2021-04-08 18:22:46 +08:00
|
|
|
if (!ValidateImm(SplatImm))
|
2020-12-15 21:05:32 +08:00
|
|
|
return false;
|
|
|
|
|
2021-04-08 18:22:46 +08:00
|
|
|
SplatVal = DAG.getTargetConstant(SplatImm, SDLoc(N), XLenVT);
|
2020-12-15 21:05:32 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-04-08 18:22:46 +08:00
|
|
|
bool RISCVDAGToDAGISel::selectVSplatSimm5(SDValue N, SDValue &SplatVal) {
|
|
|
|
return selectVSplatSimmHelper(N, SplatVal, *CurDAG, *Subtarget,
|
|
|
|
[](int64_t Imm) { return isInt<5>(Imm); });
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RISCVDAGToDAGISel::selectVSplatSimm5Plus1(SDValue N, SDValue &SplatVal) {
|
|
|
|
return selectVSplatSimmHelper(
|
|
|
|
N, SplatVal, *CurDAG, *Subtarget,
|
|
|
|
[](int64_t Imm) { return (isInt<5>(Imm) && Imm != -16) || Imm == 16; });
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RISCVDAGToDAGISel::selectVSplatSimm5Plus1NonZero(SDValue N,
|
|
|
|
SDValue &SplatVal) {
|
|
|
|
return selectVSplatSimmHelper(
|
|
|
|
N, SplatVal, *CurDAG, *Subtarget, [](int64_t Imm) {
|
|
|
|
return Imm != 0 && ((isInt<5>(Imm) && Imm != -16) || Imm == 16);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-12-15 21:05:32 +08:00
|
|
|
bool RISCVDAGToDAGISel::selectVSplatUimm5(SDValue N, SDValue &SplatVal) {
|
|
|
|
if ((N.getOpcode() != ISD::SPLAT_VECTOR &&
|
2021-02-13 01:09:22 +08:00
|
|
|
N.getOpcode() != RISCVISD::SPLAT_VECTOR_I64 &&
|
|
|
|
N.getOpcode() != RISCVISD::VMV_V_X_VL) ||
|
2020-12-15 21:05:32 +08:00
|
|
|
!isa<ConstantSDNode>(N.getOperand(0)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
int64_t SplatImm = cast<ConstantSDNode>(N.getOperand(0))->getSExtValue();
|
|
|
|
|
|
|
|
if (!isUInt<5>(SplatImm))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
SplatVal =
|
|
|
|
CurDAG->getTargetConstant(SplatImm, SDLoc(N), Subtarget->getXLenVT());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-02-13 01:09:22 +08:00
|
|
|
bool RISCVDAGToDAGISel::selectRVVSimm5(SDValue N, unsigned Width,
|
|
|
|
SDValue &Imm) {
|
|
|
|
if (auto *C = dyn_cast<ConstantSDNode>(N)) {
|
|
|
|
int64_t ImmVal = SignExtend64(C->getSExtValue(), Width);
|
|
|
|
|
|
|
|
if (!isInt<5>(ImmVal))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Imm = CurDAG->getTargetConstant(ImmVal, SDLoc(N), Subtarget->getXLenVT());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RISCVDAGToDAGISel::selectRVVUimm5(SDValue N, unsigned Width,
|
|
|
|
SDValue &Imm) {
|
|
|
|
if (auto *C = dyn_cast<ConstantSDNode>(N)) {
|
|
|
|
int64_t ImmVal = C->getSExtValue();
|
|
|
|
|
|
|
|
if (!isUInt<5>(ImmVal))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Imm = CurDAG->getTargetConstant(ImmVal, SDLoc(N), Subtarget->getXLenVT());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-03-19 19:54:28 +08:00
|
|
|
// Merge an ADDI into the offset of a load/store instruction where possible.
|
2020-06-24 20:53:27 +08:00
|
|
|
// (load (addi base, off1), off2) -> (load base, off1+off2)
|
|
|
|
// (store val, (addi base, off1), off2) -> (store val, base, off1+off2)
|
|
|
|
// This is possible when off1+off2 fits a 12-bit immediate.
|
2018-03-19 19:54:28 +08:00
|
|
|
void RISCVDAGToDAGISel::doPeepholeLoadStoreADDI() {
|
|
|
|
SelectionDAG::allnodes_iterator Position(CurDAG->getRoot().getNode());
|
|
|
|
++Position;
|
|
|
|
|
|
|
|
while (Position != CurDAG->allnodes_begin()) {
|
|
|
|
SDNode *N = &*--Position;
|
|
|
|
// Skip dead nodes and any non-machine opcodes.
|
|
|
|
if (N->use_empty() || !N->isMachineOpcode())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int OffsetOpIdx;
|
|
|
|
int BaseOpIdx;
|
|
|
|
|
|
|
|
// Only attempt this optimisation for I-type loads and S-type stores.
|
|
|
|
switch (N->getMachineOpcode()) {
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
case RISCV::LB:
|
|
|
|
case RISCV::LH:
|
|
|
|
case RISCV::LW:
|
|
|
|
case RISCV::LBU:
|
|
|
|
case RISCV::LHU:
|
|
|
|
case RISCV::LWU:
|
|
|
|
case RISCV::LD:
|
2020-07-03 22:57:59 +08:00
|
|
|
case RISCV::FLH:
|
2018-03-19 19:54:28 +08:00
|
|
|
case RISCV::FLW:
|
|
|
|
case RISCV::FLD:
|
|
|
|
BaseOpIdx = 0;
|
|
|
|
OffsetOpIdx = 1;
|
|
|
|
break;
|
|
|
|
case RISCV::SB:
|
|
|
|
case RISCV::SH:
|
|
|
|
case RISCV::SW:
|
|
|
|
case RISCV::SD:
|
2020-07-03 22:57:59 +08:00
|
|
|
case RISCV::FSH:
|
2018-03-19 19:54:28 +08:00
|
|
|
case RISCV::FSW:
|
|
|
|
case RISCV::FSD:
|
|
|
|
BaseOpIdx = 1;
|
|
|
|
OffsetOpIdx = 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-06-24 20:53:27 +08:00
|
|
|
if (!isa<ConstantSDNode>(N->getOperand(OffsetOpIdx)))
|
2018-03-19 19:54:28 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
SDValue Base = N->getOperand(BaseOpIdx);
|
|
|
|
|
2018-04-19 03:02:31 +08:00
|
|
|
// If the base is an ADDI, we can merge it in to the load/store.
|
|
|
|
if (!Base.isMachineOpcode() || Base.getMachineOpcode() != RISCV::ADDI)
|
2018-03-19 19:54:28 +08:00
|
|
|
continue;
|
|
|
|
|
2018-04-19 03:02:31 +08:00
|
|
|
SDValue ImmOperand = Base.getOperand(1);
|
2020-06-24 20:53:27 +08:00
|
|
|
uint64_t Offset2 = N->getConstantOperandVal(OffsetOpIdx);
|
2018-04-19 03:02:31 +08:00
|
|
|
|
2021-02-19 20:09:25 +08:00
|
|
|
if (auto *Const = dyn_cast<ConstantSDNode>(ImmOperand)) {
|
2020-06-24 20:53:27 +08:00
|
|
|
int64_t Offset1 = Const->getSExtValue();
|
|
|
|
int64_t CombinedOffset = Offset1 + Offset2;
|
|
|
|
if (!isInt<12>(CombinedOffset))
|
|
|
|
continue;
|
|
|
|
ImmOperand = CurDAG->getTargetConstant(CombinedOffset, SDLoc(ImmOperand),
|
|
|
|
ImmOperand.getValueType());
|
2021-02-19 20:09:25 +08:00
|
|
|
} else if (auto *GA = dyn_cast<GlobalAddressSDNode>(ImmOperand)) {
|
2020-06-24 20:53:27 +08:00
|
|
|
// If the off1 in (addi base, off1) is a global variable's address (its
|
|
|
|
// low part, really), then we can rely on the alignment of that variable
|
|
|
|
// to provide a margin of safety before off1 can overflow the 12 bits.
|
|
|
|
// Check if off2 falls within that margin; if so off1+off2 can't overflow.
|
|
|
|
const DataLayout &DL = CurDAG->getDataLayout();
|
|
|
|
Align Alignment = GA->getGlobal()->getPointerAlignment(DL);
|
|
|
|
if (Offset2 != 0 && Alignment <= Offset2)
|
|
|
|
continue;
|
|
|
|
int64_t Offset1 = GA->getOffset();
|
|
|
|
int64_t CombinedOffset = Offset1 + Offset2;
|
2018-04-19 03:02:31 +08:00
|
|
|
ImmOperand = CurDAG->getTargetGlobalAddress(
|
|
|
|
GA->getGlobal(), SDLoc(ImmOperand), ImmOperand.getValueType(),
|
2020-06-24 20:53:27 +08:00
|
|
|
CombinedOffset, GA->getTargetFlags());
|
2021-02-19 20:09:25 +08:00
|
|
|
} else if (auto *CP = dyn_cast<ConstantPoolSDNode>(ImmOperand)) {
|
2020-06-24 20:53:27 +08:00
|
|
|
// Ditto.
|
|
|
|
Align Alignment = CP->getAlign();
|
|
|
|
if (Offset2 != 0 && Alignment <= Offset2)
|
|
|
|
continue;
|
|
|
|
int64_t Offset1 = CP->getOffset();
|
|
|
|
int64_t CombinedOffset = Offset1 + Offset2;
|
2020-05-12 01:52:42 +08:00
|
|
|
ImmOperand = CurDAG->getTargetConstantPool(
|
|
|
|
CP->getConstVal(), ImmOperand.getValueType(), CP->getAlign(),
|
2020-06-24 20:53:27 +08:00
|
|
|
CombinedOffset, CP->getTargetFlags());
|
2018-03-19 19:54:28 +08:00
|
|
|
} else {
|
2018-04-19 03:02:31 +08:00
|
|
|
continue;
|
2018-03-19 19:54:28 +08:00
|
|
|
}
|
|
|
|
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dbgs() << "Folding add-immediate into mem-op:\nBase: ");
|
|
|
|
LLVM_DEBUG(Base->dump(CurDAG));
|
|
|
|
LLVM_DEBUG(dbgs() << "\nN: ");
|
|
|
|
LLVM_DEBUG(N->dump(CurDAG));
|
|
|
|
LLVM_DEBUG(dbgs() << "\n");
|
2018-03-19 19:54:28 +08:00
|
|
|
|
|
|
|
// Modify the offset operand of the load/store.
|
|
|
|
if (BaseOpIdx == 0) // Load
|
2018-04-19 03:02:31 +08:00
|
|
|
CurDAG->UpdateNodeOperands(N, Base.getOperand(0), ImmOperand,
|
|
|
|
N->getOperand(2));
|
2018-03-19 19:54:28 +08:00
|
|
|
else // Store
|
2018-04-19 03:02:31 +08:00
|
|
|
CurDAG->UpdateNodeOperands(N, N->getOperand(0), Base.getOperand(0),
|
|
|
|
ImmOperand, N->getOperand(3));
|
|
|
|
|
|
|
|
// The add-immediate may now be dead, in which case remove it.
|
|
|
|
if (Base.getNode()->use_empty())
|
|
|
|
CurDAG->RemoveDeadNode(Base.getNode());
|
2018-03-19 19:54:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-20 05:37:38 +08:00
|
|
|
// This pass converts a legalized DAG into a RISCV-specific DAG, ready
|
|
|
|
// for instruction scheduling.
|
|
|
|
FunctionPass *llvm::createRISCVISelDag(RISCVTargetMachine &TM) {
|
|
|
|
return new RISCVDAGToDAGISel(TM);
|
|
|
|
}
|