Skip to content

Commit e818bad

Browse files
toppercyuxuanchen1997
authored andcommitted
[SelectionDAGBuilder][RISCV] Fix crash when using a memory constraint with scalable vector type. (#99821)
Summary: We need to use the minimum size of the scalable type and the correct stack ID. The code in the PR is still invalid because the instruction used doesn't have a pointer operand. This is diagnosed later when the assembler parses it. Fixes #99782 Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251084
1 parent 37564f4 commit e818bad

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9566,10 +9566,15 @@ static SDValue getAddressForMemoryInput(SDValue Chain, const SDLoc &Location,
95669566
// Otherwise, create a stack slot and emit a store to it before the asm.
95679567
Type *Ty = OpVal->getType();
95689568
auto &DL = DAG.getDataLayout();
9569-
uint64_t TySize = DL.getTypeAllocSize(Ty);
9569+
TypeSize TySize = DL.getTypeAllocSize(Ty);
95709570
MachineFunction &MF = DAG.getMachineFunction();
9571-
int SSFI = MF.getFrameInfo().CreateStackObject(
9572-
TySize, DL.getPrefTypeAlign(Ty), false);
9571+
const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering();
9572+
int StackID = 0;
9573+
if (TySize.isScalable())
9574+
StackID = TFI->getStackIDForScalableVectors();
9575+
int SSFI = MF.getFrameInfo().CreateStackObject(TySize.getKnownMinValue(),
9576+
DL.getPrefTypeAlign(Ty), false,
9577+
nullptr, StackID);
95739578
SDValue StackSlot = DAG.getFrameIndex(SSFI, TLI.getFrameIndexTy(DL));
95749579
Chain = DAG.getTruncStore(Chain, Location, OpInfo.CallOperand, StackSlot,
95759580
MachinePointerInfo::getFixedStack(MF, SSFI),
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc < %s -mtriple=riscv64 -mattr=+v -stop-after=finalize-isel | FileCheck %s
3+
4+
define void @vslidedown() {
5+
; CHECK-LABEL: name: vslidedown
6+
; CHECK: bb.0.entry:
7+
; CHECK-NEXT: [[ADDI:%[0-9]+]]:gpr = ADDI %stack.0.v, 0
8+
; CHECK-NEXT: [[VL8RE8_V:%[0-9]+]]:vrm8 = VL8RE8_V killed [[ADDI]] :: (load (<vscale x 1 x s512>) from %ir.v, align 1)
9+
; CHECK-NEXT: [[ADDI1:%[0-9]+]]:gpr = ADDI %stack.1, 0
10+
; CHECK-NEXT: VS8R_V killed [[VL8RE8_V]], killed [[ADDI1]] :: (store (<vscale x 1 x s512>) into %stack.1)
11+
; CHECK-NEXT: INLINEASM &"vadd.vv $0, $0, $0", 25 /* sideeffect mayload maystore attdialect */, 262166 /* mem:m */, %stack.0.v, 0, 262166 /* mem:m */, %stack.1, 0
12+
; CHECK-NEXT: PseudoRET
13+
entry:
14+
%v = alloca <vscale x 64 x i8>, align 1
15+
%0 = load <vscale x 64 x i8>, ptr %v, align 1
16+
call void asm sideeffect "vadd.vv $0, $0, $0", "=*imr,imr"(ptr elementtype(<vscale x 64 x i8>) %v, <vscale x 64 x i8> %0)
17+
ret void
18+
}

0 commit comments

Comments
 (0)