diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.h b/llvm/lib/Target/RISCV/RISCVISelLowering.h --- a/llvm/lib/Target/RISCV/RISCVISelLowering.h +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.h @@ -41,6 +41,12 @@ BuildPairF64, SplitF64, TAIL, + + // Add the Lo 12 bits from an address. Selected to ADDI. + ADD_LO, + // Get the Hi 20 bits from an address. Selected to LUI. + HI, + // Multiply high for signedxunsigned. MULHSU, // RV64I shifts, directly matching the semantics of the named RISC-V diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp --- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp @@ -3631,8 +3631,8 @@ // address space. This generates the pattern (addi (lui %hi(sym)) %lo(sym)). SDValue AddrHi = getTargetNode(N, DL, Ty, DAG, RISCVII::MO_HI); SDValue AddrLo = getTargetNode(N, DL, Ty, DAG, RISCVII::MO_LO); - SDValue MNHi = SDValue(DAG.getMachineNode(RISCV::LUI, DL, Ty, AddrHi), 0); - return SDValue(DAG.getMachineNode(RISCV::ADDI, DL, Ty, MNHi, AddrLo), 0); + SDValue MNHi = DAG.getNode(RISCVISD::HI, DL, Ty, AddrHi); + return DAG.getNode(RISCVISD::ADD_LO, DL, Ty, MNHi, AddrLo); } case CodeModel::Medium: { // Generate a sequence for accessing addresses within any 2GiB range within @@ -11113,6 +11113,8 @@ NODE_NAME_CASE(BuildPairF64) NODE_NAME_CASE(SplitF64) NODE_NAME_CASE(TAIL) + NODE_NAME_CASE(ADD_LO) + NODE_NAME_CASE(HI) NODE_NAME_CASE(MULHSU) NODE_NAME_CASE(SLLW) NODE_NAME_CASE(SRAW) diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.td b/llvm/lib/Target/RISCV/RISCVInstrInfo.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfo.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.td @@ -83,6 +83,9 @@ SDT_RISCVReadCycleWide, [SDNPHasChain, SDNPSideEffect]>; +def riscv_add_lo : SDNode<"RISCVISD::ADD_LO", SDTIntBinOp>; +def riscv_hi : SDNode<"RISCVISD::HI", SDTIntUnaryOp>; + //===----------------------------------------------------------------------===// // Operand and SDNode transformation definitions. //===----------------------------------------------------------------------===// @@ -1207,6 +1210,22 @@ def : Pat<(FrameAddrRegImm GPR:$rs1, simm12:$imm12), (ADDI GPR:$rs1, simm12:$imm12)>; +// HI and ADD_LO address nodes. + +def : Pat<(riscv_hi tglobaladdr:$in), (LUI tglobaladdr:$in)>; +def : Pat<(riscv_hi tblockaddress:$in), (LUI tblockaddress:$in)>; +def : Pat<(riscv_hi tjumptable:$in), (LUI tjumptable:$in)>; +def : Pat<(riscv_hi tconstpool:$in), (LUI tconstpool:$in)>; + +def : Pat<(riscv_add_lo GPR:$hi, tglobaladdr:$lo), + (ADDI GPR:$hi, tglobaladdr:$lo)>; +def : Pat<(riscv_add_lo GPR:$hi, tblockaddress:$lo), + (ADDI GPR:$hi, tblockaddress:$lo)>; +def : Pat<(riscv_add_lo GPR:$hi, tjumptable:$lo), + (ADDI GPR:$hi, tjumptable:$lo)>; +def : Pat<(riscv_add_lo GPR:$hi, tconstpool:$lo), + (ADDI GPR:$hi, tconstpool:$lo)>; + /// Setcc def : PatGprGpr;