[llvm] 1fa858d - [RISCV][GISel] Make G_CONSTANT of pointers legal.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 14 10:11:40 PDT 2023
Author: Craig Topper
Date: 2023-08-14T10:11:29-07:00
New Revision: 1fa858d987ec0ffcc25005012d35eed25fa4c7d1
URL: https://github.com/llvm/llvm-project/commit/1fa858d987ec0ffcc25005012d35eed25fa4c7d1
DIFF: https://github.com/llvm/llvm-project/commit/1fa858d987ec0ffcc25005012d35eed25fa4c7d1.diff
LOG: [RISCV][GISel] Make G_CONSTANT of pointers legal.
This is needed to support things like null pointers.
Reviewed By: reames
Differential Revision: https://reviews.llvm.org/D157822
Added:
Modified:
llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv32/legalize-const.mir
llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-const.mir
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
index b6c212e068f03e..84077a67d156e4 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 817e3ff9175250..e2903b2296ef82 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 e2e3d9df1fac23..e2665b6657ce0e 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
+
+...
More information about the llvm-commits
mailing list