Skip to content

Commit 9ce3a84

Browse files
committed
legalize vload and vstore nxv1s8
1 parent a5ed4aa commit 9ce3a84

File tree

5 files changed

+74
-11
lines changed

5 files changed

+74
-11
lines changed

llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3334,13 +3334,13 @@ LegalizerHelper::LegalizeResult LegalizerHelper::lowerLoad(GAnyLoad &LoadMI) {
33343334
unsigned MinMemStoreSizeInBits =
33353335
8 * MemTy.getSizeInBytes().getKnownMinValue();
33363336

3337-
if (MemSizeInBits != MemStoreSizeInBits) {
3337+
if (MinMemSizeInBits != MinMemStoreSizeInBits) {
33383338
if (MemTy.isVector())
33393339
return UnableToLegalize;
33403340

33413341
// Promote to a byte-sized load if not loading an integral number of
33423342
// bytes. For example, promote EXTLOAD:i20 -> EXTLOAD:i24.
3343-
LLT WideMemTy = LLT::scalar(MemStoreSizeInBits);
3343+
LLT WideMemTy = LLT::scalar(MinMemStoreSizeInBits);
33443344
MachineMemOperand *NewMMO =
33453345
MF.getMachineMemOperand(&MMO, MMO.getPointerInfo(), WideMemTy);
33463346

@@ -3349,19 +3349,19 @@ LegalizerHelper::LegalizeResult LegalizerHelper::lowerLoad(GAnyLoad &LoadMI) {
33493349

33503350
// If this wasn't already an extending load, we need to widen the result
33513351
// register to avoid creating a load with a narrower result than the source.
3352-
if (MemStoreSizeInBits > DstTy.getSizeInBits()) {
3352+
if (MinMemStoreSizeInBits > DstTy.getSizeInBits()) {
33533353
LoadTy = WideMemTy;
33543354
LoadReg = MRI.createGenericVirtualRegister(WideMemTy);
33553355
}
33563356

33573357
if (isa<GSExtLoad>(LoadMI)) {
33583358
auto NewLoad = MIRBuilder.buildLoad(LoadTy, PtrReg, *NewMMO);
3359-
MIRBuilder.buildSExtInReg(LoadReg, NewLoad, MemSizeInBits);
3359+
MIRBuilder.buildSExtInReg(LoadReg, NewLoad, MinMemSizeInBits);
33603360
} else if (isa<GZExtLoad>(LoadMI) || WideMemTy == LoadTy) {
33613361
auto NewLoad = MIRBuilder.buildLoad(LoadTy, PtrReg, *NewMMO);
33623362
// The extra bits are guaranteed to be zero, since we stored them that
33633363
// way. A zext load from Wide thus automatically gives zext from MemVT.
3364-
MIRBuilder.buildAssertZExt(LoadReg, NewLoad, MemSizeInBits);
3364+
MIRBuilder.buildAssertZExt(LoadReg, NewLoad, MinMemSizeInBits);
33653365
} else {
33663366
MIRBuilder.buildLoad(LoadReg, PtrReg, *NewMMO);
33673367
}
@@ -3394,10 +3394,10 @@ LegalizerHelper::LegalizeResult LegalizerHelper::lowerLoad(GAnyLoad &LoadMI) {
33943394

33953395
uint64_t LargeSplitSize, SmallSplitSize;
33963396

3397-
if (!isPowerOf2_32(MemSizeInBits)) {
3397+
if (!isPowerOf2_32(MinMemSizeInBits)) {
33983398
// This load needs splitting into power of 2 sized loads.
3399-
LargeSplitSize = llvm::bit_floor(MemSizeInBits);
3400-
SmallSplitSize = MemSizeInBits - LargeSplitSize;
3399+
LargeSplitSize = llvm::bit_floor(MinMemSizeInBits);
3400+
SmallSplitSize = MinMemSizeInBits - LargeSplitSize;
34013401
} else {
34023402
// This is already a power of 2, but we still need to split this in half.
34033403
//
@@ -3407,7 +3407,7 @@ LegalizerHelper::LegalizeResult LegalizerHelper::lowerLoad(GAnyLoad &LoadMI) {
34073407
if (TLI.allowsMemoryAccess(Ctx, MIRBuilder.getDataLayout(), MemTy, MMO))
34083408
return UnableToLegalize;
34093409

3410-
SmallSplitSize = LargeSplitSize = MemSizeInBits / 2;
3410+
SmallSplitSize = LargeSplitSize = MinMemSizeInBits / 2;
34113411
}
34123412

34133413
if (MemTy.isVector()) {

llvm/lib/CodeGen/MIRParser/MIParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3421,7 +3421,7 @@ bool MIParser::parseMachineMemoryOperand(MachineMemOperand *&Dest) {
34213421
if (expectAndConsume(MIToken::rparen))
34223422
return true;
34233423

3424-
Size = MemoryType.getSizeInBytes();
3424+
Size = MemoryType.getSizeInBytes().getKnownMinValue();
34253425
}
34263426

34273427
MachinePointerInfo Ptr = MachinePointerInfo();

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,11 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
249249
.legalForTypesWithMemDesc({{s32, p0, s8, 8},
250250
{s32, p0, s16, 16},
251251
{s32, p0, s32, 32},
252-
{p0, p0, sXLen, XLen}});
252+
{p0, p0, sXLen, XLen},
253+
{nxv1s8, p0, nxv1s8, 8}})
254+
.widenScalarToNextPow2(0, /* MinSize = */ 8)
255+
.lowerIfMemSizeNotByteSizePow2();
256+
253257
auto &ExtLoadActions =
254258
getActionDefinitionsBuilder({G_SEXTLOAD, G_ZEXTLOAD})
255259
.legalForTypesWithMemDesc({{s32, p0, s8, 8}, {s32, p0, s16, 16}});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2+
# RUN: llc -mtriple=riscv32 -mattr=+v -run-pass=legalizer %s -o - | FileCheck %s
3+
# RUN: llc -mtriple=riscv64 -mattr=+v -run-pass=legalizer %s -o - | FileCheck %s
4+
--- |
5+
6+
define <vscale x 1 x i8> @vload_nx1i8(ptr %pa) {
7+
%va = load <vscale x 1 x i8>, ptr %pa
8+
ret <vscale x 1 x i8> %va
9+
}
10+
11+
...
12+
---
13+
name: vload_nx1i8
14+
body: |
15+
bb.1 (%ir-block.0):
16+
liveins: $x10
17+
18+
; CHECK-LABEL: name: vload_nx1i8
19+
; CHECK: liveins: $x10
20+
; CHECK-NEXT: {{ $}}
21+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY $x10
22+
; CHECK-NEXT: [[LOAD:%[0-9]+]]:_(<vscale x 1 x s8>) = G_LOAD [[COPY]](p0) :: (load (<vscale x 1 x s8>) from %ir.pa)
23+
; CHECK-NEXT: $v8 = COPY [[LOAD]](<vscale x 1 x s8>)
24+
; CHECK-NEXT: PseudoRET implicit $v8
25+
%0:_(p0) = COPY $x10
26+
%1:_(<vscale x 1 x s8>) = G_LOAD %0(p0) :: (load (<vscale x 1 x s8>) from %ir.pa)
27+
$v8 = COPY %1(<vscale x 1 x s8>)
28+
PseudoRET implicit $v8
29+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2+
# RUN: llc -mtriple=riscv32 -mattr=+v -run-pass=legalizer %s -o - | FileCheck %s
3+
# RUN: llc -mtriple=riscv64 -mattr=+v -run-pass=legalizer %s -o - | FileCheck %s
4+
--- |
5+
6+
define void @vstore_nx1i8(ptr %pa, <vscale x 1 x i8> %b) {
7+
store <vscale x 1 x i8> %b, ptr %pa, align 1
8+
ret void
9+
}
10+
11+
...
12+
---
13+
name: vstore_nx1i8
14+
body: |
15+
bb.1 (%ir-block.0):
16+
liveins: $v8, $x10
17+
18+
; CHECK-LABEL: name: vstore_nx1i8
19+
; CHECK: liveins: $v8, $x10
20+
; CHECK-NEXT: {{ $}}
21+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY $x10
22+
; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(<vscale x 1 x s8>) = COPY $v8
23+
; CHECK-NEXT: G_STORE [[COPY1]](<vscale x 1 x s8>), [[COPY]](p0) :: (store (<vscale x 1 x s8>) into %ir.pa)
24+
; CHECK-NEXT: PseudoRET
25+
%0:_(p0) = COPY $x10
26+
%1:_(<vscale x 1 x s8>) = COPY $v8
27+
G_STORE %1(<vscale x 1 x s8>), %0(p0) :: (store (<vscale x 1 x s8>) into %ir.pa)
28+
PseudoRET
29+
30+
...

0 commit comments

Comments
 (0)