Skip to content

Commit

Permalink
[RISCV][GISel] Make G_CONSTANT of pointers legal.
Browse files Browse the repository at this point in the history
This is needed to support things like null pointers.

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D157822
  • Loading branch information
topperc committed Aug 14, 2023
1 parent 700ca0e commit 1fa858d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
...
Original file line number Diff line number Diff line change
Expand Up @@ -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
...

0 comments on commit 1fa858d

Please sign in to comment.