2017-11-09 22:46:30 +08:00
|
|
|
//===-- RISCVInstrInfoM.td - RISC-V 'M' instructions -------*- tablegen -*-===//
|
|
|
|
//
|
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-11-09 22:46:30 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file describes the RISC-V instructions from the standard 'M', Integer
|
|
|
|
// Multiplication and Division instruction set extension.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2019-01-25 13:11:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// RISC-V specific DAG Nodes.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
def riscv_divw : SDNode<"RISCVISD::DIVW", SDTIntBinOp>;
|
|
|
|
def riscv_divuw : SDNode<"RISCVISD::DIVUW", SDTIntBinOp>;
|
|
|
|
def riscv_remuw : SDNode<"RISCVISD::REMUW", SDTIntBinOp>;
|
|
|
|
|
2017-11-09 22:46:30 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Instructions
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
let Predicates = [HasStdExtM] in {
|
|
|
|
def MUL : ALU_rr<0b0000001, 0b000, "mul">;
|
|
|
|
def MULH : ALU_rr<0b0000001, 0b001, "mulh">;
|
|
|
|
def MULHSU : ALU_rr<0b0000001, 0b010, "mulhsu">;
|
|
|
|
def MULHU : ALU_rr<0b0000001, 0b011, "mulhu">;
|
|
|
|
def DIV : ALU_rr<0b0000001, 0b100, "div">;
|
|
|
|
def DIVU : ALU_rr<0b0000001, 0b101, "divu">;
|
|
|
|
def REM : ALU_rr<0b0000001, 0b110, "rem">;
|
|
|
|
def REMU : ALU_rr<0b0000001, 0b111, "remu">;
|
|
|
|
} // Predicates = [HasStdExtM]
|
2017-12-07 18:56:07 +08:00
|
|
|
|
|
|
|
let Predicates = [HasStdExtM, IsRV64] in {
|
|
|
|
def MULW : ALUW_rr<0b0000001, 0b000, "mulw">;
|
|
|
|
def DIVW : ALUW_rr<0b0000001, 0b100, "divw">;
|
|
|
|
def DIVUW : ALUW_rr<0b0000001, 0b101, "divuw">;
|
|
|
|
def REMW : ALUW_rr<0b0000001, 0b110, "remw">;
|
|
|
|
def REMUW : ALUW_rr<0b0000001, 0b111, "remuw">;
|
|
|
|
} // Predicates = [HasStdExtM, IsRV64]
|
2018-01-18 20:36:38 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Pseudo-instructions and codegen patterns
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
let Predicates = [HasStdExtM] in {
|
|
|
|
def : PatGprGpr<mul, MUL>;
|
|
|
|
def : PatGprGpr<mulhs, MULH>;
|
|
|
|
def : PatGprGpr<mulhu, MULHU>;
|
|
|
|
// No ISDOpcode for mulhsu
|
|
|
|
def : PatGprGpr<sdiv, DIV>;
|
|
|
|
def : PatGprGpr<udiv, DIVU>;
|
|
|
|
def : PatGprGpr<srem, REM>;
|
|
|
|
def : PatGprGpr<urem, REMU>;
|
|
|
|
} // Predicates = [HasStdExtM]
|
2019-01-12 15:43:06 +08:00
|
|
|
|
|
|
|
let Predicates = [HasStdExtM, IsRV64] in {
|
|
|
|
def : Pat<(sext_inreg (mul GPR:$rs1, GPR:$rs2), i32),
|
|
|
|
(MULW GPR:$rs1, GPR:$rs2)>;
|
2019-01-25 13:11:34 +08:00
|
|
|
|
|
|
|
def : PatGprGpr<riscv_divw, DIVW>;
|
|
|
|
def : PatGprGpr<riscv_divuw, DIVUW>;
|
|
|
|
def : PatGprGpr<riscv_remuw, REMUW>;
|
|
|
|
|
|
|
|
// Handle the specific cases where using DIVU/REMU would be correct and result
|
|
|
|
// in fewer instructions than emitting DIVUW/REMUW then zero-extending the
|
|
|
|
// result.
|
|
|
|
def : Pat<(zexti32 (riscv_divuw (zexti32 GPR:$rs1), (zexti32 GPR:$rs2))),
|
|
|
|
(DIVU GPR:$rs1, GPR:$rs2)>;
|
|
|
|
def : Pat<(zexti32 (riscv_remuw (zexti32 GPR:$rs1), (zexti32 GPR:$rs2))),
|
|
|
|
(REMU GPR:$rs1, GPR:$rs2)>;
|
|
|
|
|
2019-01-12 15:43:06 +08:00
|
|
|
// Although the sexti32 operands may not have originated from an i32 srem,
|
|
|
|
// this pattern is safe as it is impossible for two sign extended inputs to
|
|
|
|
// produce a result where res[63:32]=0 and res[31]=1.
|
|
|
|
def : Pat<(srem (sexti32 GPR:$rs1), (sexti32 GPR:$rs2)),
|
|
|
|
(REMW GPR:$rs1, GPR:$rs2)>;
|
|
|
|
def : Pat<(sext_inreg (srem (sexti32 GPR:$rs1),
|
|
|
|
(sexti32 GPR:$rs2)), i32),
|
|
|
|
(REMW GPR:$rs1, GPR:$rs2)>;
|
|
|
|
} // Predicates = [HasStdExtM, IsRV64]
|