diff --git a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp index 4981d7b80b0b2..2b8d683dd7d0d 100644 --- a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp +++ b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp @@ -3357,8 +3357,8 @@ LegalizerHelper::LegalizeResult LegalizerHelper::lowerLoad(GAnyLoad &LoadMI) { LLT MemTy = MMO.getMemoryType(); MachineFunction &MF = MIRBuilder.getMF(); - unsigned MemSizeInBits = MemTy.getSizeInBits(); - unsigned MemStoreSizeInBits = 8 * MemTy.getSizeInBytes(); + TypeSize MemSizeInBits = MemTy.getSizeInBits(); + TypeSize MemStoreSizeInBits = MemTy.getSizeInBytes().multiplyCoefficientBy(8); if (MemSizeInBits != MemStoreSizeInBits) { if (MemTy.isVector()) @@ -3422,7 +3422,7 @@ LegalizerHelper::LegalizeResult LegalizerHelper::lowerLoad(GAnyLoad &LoadMI) { if (!isPowerOf2_32(MemSizeInBits)) { // This load needs splitting into power of 2 sized loads. - LargeSplitSize = llvm::bit_floor(MemSizeInBits); + LargeSplitSize = llvm::bit_floor(MemSizeInBits.getKnownMinValue()); SmallSplitSize = MemSizeInBits - LargeSplitSize; } else { // This is already a power of 2, but we still need to split this in half. diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp index 95924f0566283..1cbc4e408b86f 100644 --- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp @@ -3421,7 +3421,7 @@ bool MIParser::parseMachineMemoryOperand(MachineMemOperand *&Dest) { if (expectAndConsume(MIToken::rparen)) return true; - Size = MemoryType.getSizeInBytes(); + Size = MemoryType.getSizeInBytes().getKnownMinValue(); } MachinePointerInfo Ptr = MachinePointerInfo(); diff --git a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp index 9a388f4cd2717..88d5ad4b3d7da 100644 --- a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp +++ b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp @@ -249,7 +249,15 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST) .legalForTypesWithMemDesc({{s32, p0, s8, 8}, {s32, p0, s16, 16}, {s32, p0, s32, 32}, - {p0, p0, sXLen, XLen}}); + {p0, p0, sXLen, XLen}, + {nxv1s8, p0, nxv1s8, 8}, + {nxv2s8, p0, nxv2s8, 8}, + {nxv4s8, p0, nxv4s8, 8}, + {nxv8s8, p0, nxv8s8, 8}, + {nxv16s8, p0, nxv16s8, 8}}) + .widenScalarToNextPow2(0, /* MinSize = */ 8) + .lowerIfMemSizeNotByteSizePow2(); + auto &ExtLoadActions = getActionDefinitionsBuilder({G_SEXTLOAD, G_ZEXTLOAD}) .legalForTypesWithMemDesc({{s32, p0, s8, 8}, {s32, p0, s16, 16}}); diff --git a/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rvv/legalize-load.mir b/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rvv/legalize-load.mir new file mode 100644 index 0000000000000..1b62f55520716 --- /dev/null +++ b/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rvv/legalize-load.mir @@ -0,0 +1,29 @@ +# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py +# RUN: llc -mtriple=riscv32 -mattr=+v -run-pass=legalizer %s -o - | FileCheck %s +# RUN: llc -mtriple=riscv64 -mattr=+v -run-pass=legalizer %s -o - | FileCheck %s +--- | + + define @vload_nx1i8(ptr %pa) { + %va = load , ptr %pa + ret %va + } + +... +--- +name: vload_nx1i8 +body: | + bb.1 (%ir-block.0): + liveins: $x10 + + ; CHECK-LABEL: name: vload_nx1i8 + ; CHECK: liveins: $x10 + ; CHECK-NEXT: {{ $}} + ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY $x10 + ; CHECK-NEXT: [[LOAD:%[0-9]+]]:_() = G_LOAD [[COPY]](p0) :: (load () from %ir.pa) + ; CHECK-NEXT: $v8 = COPY [[LOAD]]() + ; CHECK-NEXT: PseudoRET implicit $v8 + %0:_(p0) = COPY $x10 + %1:_() = G_LOAD %0(p0) :: (load () from %ir.pa) + $v8 = COPY %1() + PseudoRET implicit $v8 + diff --git a/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rvv/legalize-store.mir b/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rvv/legalize-store.mir new file mode 100644 index 0000000000000..66df14b6635d3 --- /dev/null +++ b/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rvv/legalize-store.mir @@ -0,0 +1,98 @@ +# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py +# RUN: llc -mtriple=riscv32 -mattr=+v -run-pass=legalizer %s -o - | FileCheck %s +# RUN: llc -mtriple=riscv64 -mattr=+v -run-pass=legalizer %s -o - | FileCheck %s +--- | + + define void @vstore_nx1i8(ptr %pa, %b) { + store %b, ptr %pa, align 1 + ret void + } + + define @vload_nx2i8(ptr %pa) { + %va = load , ptr %pa, align 2 + ret %va + } + + define @vload_nx4i8(ptr %pa) { + %va = load , ptr %pa, align 4 + ret %va + } + + define @vload_nx8i8(ptr %pa) { + %va = load , ptr %pa, align 8 + ret %va + } + + define @vload_nx16i8(ptr %pa) { + %va = load , ptr %pa, align 16 + ret %va + } + +... +--- +name: vstore_nx1i8 +body: | + bb.1 (%ir-block.0): + liveins: $v8, $x10 + + ; CHECK-LABEL: name: vstore_nx1i8 + ; CHECK: liveins: $v8, $x10 + ; CHECK-NEXT: {{ $}} + ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY $x10 + ; CHECK-NEXT: [[COPY1:%[0-9]+]]:_() = COPY $v8 + ; CHECK-NEXT: G_STORE [[COPY1]](), [[COPY]](p0) :: (store () into %ir.pa) + ; CHECK-NEXT: PseudoRET + %0:_(p0) = COPY $x10 + %1:_() = COPY $v8 + G_STORE %1(), %0(p0) :: (store () into %ir.pa) + PseudoRET + +... +--- +name: vload_nx2i8 +body: | + bb.1 (%ir-block.0): + liveins: $x10 + + %0:_(p0) = COPY $x10 + %1:_() = G_LOAD %0(p0) :: (load () from %ir.pa) + $v8 = COPY %1() + PseudoRET implicit $v8 + +... +--- +name: vload_nx4i8 +body: | + bb.1 (%ir-block.0): + liveins: $x10 + + %0:_(p0) = COPY $x10 + %1:_() = G_LOAD %0(p0) :: (load () from %ir.pa) + $v8 = COPY %1() + PseudoRET implicit $v8 + +... +--- +name: vload_nx8i8 +body: | + bb.1 (%ir-block.0): + liveins: $x10 + + %0:_(p0) = COPY $x10 + %1:_() = G_LOAD %0(p0) :: (load () from %ir.pa) + $v8 = COPY %1() + PseudoRET implicit $v8 + +... +--- +name: vload_nx16i8 +body: | + bb.1 (%ir-block.0): + liveins: $x10 + + %0:_(p0) = COPY $x10 + %1:_() = G_LOAD %0(p0) :: (load () from %ir.pa) + $v8m2 = COPY %1() + PseudoRET implicit $v8m2 + +...