Skip to content

Commit 674b53d

Browse files
committed
[RISCV][GISel] Add widenScalarToNextPow2 to G_SEXTLOAD/G_ZEXTLOAD legalization.
This fixes i8->i48 on RV64.
1 parent 7e34ee5 commit 674b53d

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST) {
120120
if (XLen == 64)
121121
ExtLoadActions.legalForTypesWithMemDesc({{XLenLLT, p0, s32, 32}});
122122
ExtLoadActions
123+
.widenScalarToNextPow2(0)
123124
.clampScalar(0, s32, XLenLLT)
124125
.lower();
125126

llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-extload.mir

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,26 @@ body: |
121121
$x10 = COPY %2(s64)
122122
PseudoRET implicit $x10
123123
124+
...
125+
---
126+
name: zextload_i8_i48
127+
body: |
128+
bb.0:
129+
liveins: $x10
130+
131+
; CHECK-LABEL: name: zextload_i8_i48
132+
; CHECK: liveins: $x10
133+
; CHECK-NEXT: {{ $}}
134+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY $x10
135+
; CHECK-NEXT: [[ZEXTLOAD:%[0-9]+]]:_(s64) = G_ZEXTLOAD [[COPY]](p0) :: (load (s8))
136+
; CHECK-NEXT: $x10 = COPY [[ZEXTLOAD]](s64)
137+
; CHECK-NEXT: PseudoRET implicit $x10
138+
%0:_(p0) = COPY $x10
139+
%2:_(s48) = G_ZEXTLOAD %0(p0) :: (load (s8))
140+
%3:_(s64) = G_ANYEXT %2(s48)
141+
$x10 = COPY %3(s64)
142+
PseudoRET implicit $x10
143+
124144
...
125145
---
126146
name: sextload_i8_i16
@@ -242,3 +262,24 @@ body: |
242262
PseudoRET implicit $x10
243263
244264
...
265+
---
266+
name: sextload_i8_i48
267+
alignment: 4
268+
body: |
269+
bb.0:
270+
liveins: $x10
271+
272+
; CHECK-LABEL: name: sextload_i8_i48
273+
; CHECK: liveins: $x10
274+
; CHECK-NEXT: {{ $}}
275+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY $x10
276+
; CHECK-NEXT: [[SEXTLOAD:%[0-9]+]]:_(s64) = G_SEXTLOAD [[COPY]](p0) :: (load (s8))
277+
; CHECK-NEXT: $x10 = COPY [[SEXTLOAD]](s64)
278+
; CHECK-NEXT: PseudoRET implicit $x10
279+
%0:_(p0) = COPY $x10
280+
%2:_(s48) = G_SEXTLOAD %0(p0) :: (load (s8))
281+
%3:_(s64) = G_ANYEXT %2(s48)
282+
$x10 = COPY %3(s64)
283+
PseudoRET implicit $x10
284+
285+
...

0 commit comments

Comments
 (0)