diff --git a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp index b6c212e068f03..84077a67d156e 100644 --- a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp +++ b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp @@ -22,6 +22,7 @@ using namespace llvm; RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST) { const unsigned XLen = ST.getXLen(); const LLT XLenLLT = LLT::scalar(XLen); + const LLT p0 = LLT::pointer(0, XLen); using namespace TargetOpcode; @@ -81,7 +82,7 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST) { } getActionDefinitionsBuilder({G_CONSTANT, G_IMPLICIT_DEF}) - .legalFor({XLenLLT}) + .legalFor({XLenLLT, p0}) .widenScalarToNextPow2(0) .clampScalar(0, XLenLLT, XLenLLT); diff --git a/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv32/legalize-const.mir b/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv32/legalize-const.mir index 817e3ff917525..e2903b2296ef8 100644 --- a/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv32/legalize-const.mir +++ b/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv32/legalize-const.mir @@ -111,3 +111,16 @@ body: | PseudoRET implicit $x10, implicit $x11, implicit $x12 ... +--- +name: const_null +body: | + bb.0.entry: + ; CHECK-LABEL: name: const_null + ; CHECK: [[C:%[0-9]+]]:_(p0) = G_CONSTANT i32 0 + ; CHECK-NEXT: $x10 = COPY [[C]](p0) + ; CHECK-NEXT: PseudoRET implicit $x10 + %0:_(p0) = G_CONSTANT i32 0 + $x10 = COPY %0(p0) + PseudoRET implicit $x10 + +... diff --git a/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-const.mir b/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-const.mir index e2e3d9df1fac2..e2665b6657ce0 100644 --- a/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-const.mir +++ b/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-const.mir @@ -125,3 +125,16 @@ body: | PseudoRET implicit $x10, implicit $x11, implicit $x12 ... +--- +name: const_null +body: | + bb.0.entry: + ; CHECK-LABEL: name: const_null + ; CHECK: [[C:%[0-9]+]]:_(p0) = G_CONSTANT i64 0 + ; CHECK-NEXT: $x10 = COPY [[C]](p0) + ; CHECK-NEXT: PseudoRET implicit $x10 + %0:_(p0) = G_CONSTANT i64 0 + $x10 = COPY %0(p0) + PseudoRET implicit $x10 + +...