[PATCH] D157822: [RISCV][GISel] Make G_CONSTANT of pointers legal.
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 13 11:57:13 PDT 2023
craig.topper created this revision.
craig.topper added reviewers: nitinjohnraj, arsenm, asb.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added subscribers: wangpc, eopXD, MaskRay, wdng.
Herald added a project: LLVM.
This is needed to support things like null pointers.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D157822
Files:
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
Index: llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-const.mir
===================================================================
--- llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-const.mir
+++ llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-const.mir
@@ -125,3 +125,16 @@
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
+
+...
Index: llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv32/legalize-const.mir
===================================================================
--- llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv32/legalize-const.mir
+++ llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv32/legalize-const.mir
@@ -111,3 +111,16 @@
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
+
+...
Index: llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
===================================================================
--- llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
+++ llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
@@ -22,6 +22,7 @@
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 @@
}
getActionDefinitionsBuilder({G_CONSTANT, G_IMPLICIT_DEF})
- .legalFor({XLenLLT})
+ .legalFor({XLenLLT, p0})
.widenScalarToNextPow2(0)
.clampScalar(0, XLenLLT, XLenLLT);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157822.549737.patch
Type: text/x-patch
Size: 2132 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230813/6122cfa8/attachment.bin>
More information about the llvm-commits
mailing list