Skip to content

Commit

Permalink
[SelectionDAG] Use TypeSize variant of ComputeValueVTs to compute cor…
Browse files Browse the repository at this point in the history
…rect offsets for scalable aggregate types.

Differential Revision: https://reviews.llvm.org/D157872
  • Loading branch information
paulwalker-arm committed Aug 16, 2023
1 parent d7efe41 commit 5660652
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
3 changes: 3 additions & 0 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1927,6 +1927,9 @@ SDValue SelectionDAG::getVScale(const SDLoc &DL, EVT VT, APInt MulImm,
assert(MulImm.getBitWidth() == VT.getSizeInBits() &&
"APInt size does not match type size!");

if (MulImm == 0)
return getConstant(0, DL, VT);

if (ConstantFold) {
const MachineFunction &MF = getMachineFunction();
const Function &F = MF.getFunction();
Expand Down
26 changes: 18 additions & 8 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4192,7 +4192,7 @@ void SelectionDAGBuilder::visitLoad(const LoadInst &I) {

Type *Ty = I.getType();
SmallVector<EVT, 4> ValueVTs, MemVTs;
SmallVector<uint64_t, 4> Offsets;
SmallVector<TypeSize, 4> Offsets;
ComputeValueVTs(TLI, DAG.getDataLayout(), Ty, ValueVTs, &MemVTs, &Offsets, 0);
unsigned NumValues = ValueVTs.size();
if (NumValues == 0)
Expand Down Expand Up @@ -4250,9 +4250,14 @@ void SelectionDAGBuilder::visitLoad(const LoadInst &I) {
ChainI = 0;
}

SDValue A = DAG.getObjectPtrOffset(dl, Ptr, TypeSize::Fixed(Offsets[i]));
SDValue L = DAG.getLoad(MemVTs[i], dl, Root, A,
MachinePointerInfo(SV, Offsets[i]), Alignment,
// TODO: MachinePointerInfo only supports a fixed length offset.
MachinePointerInfo PtrInfo =
!Offsets[i].isScalable() || Offsets[i].isZero()
? MachinePointerInfo(SV, Offsets[i].getKnownMinValue())
: MachinePointerInfo();

SDValue A = DAG.getObjectPtrOffset(dl, Ptr, Offsets[i]);
SDValue L = DAG.getLoad(MemVTs[i], dl, Root, A, PtrInfo, Alignment,
MMOFlags, AAInfo, Ranges);
Chains[ChainI] = L.getValue(1);

Expand Down Expand Up @@ -4354,7 +4359,7 @@ void SelectionDAGBuilder::visitStore(const StoreInst &I) {
}

SmallVector<EVT, 4> ValueVTs, MemVTs;
SmallVector<uint64_t, 4> Offsets;
SmallVector<TypeSize, 4> Offsets;
ComputeValueVTs(DAG.getTargetLoweringInfo(), DAG.getDataLayout(),
SrcV->getType(), ValueVTs, &MemVTs, &Offsets, 0);
unsigned NumValues = ValueVTs.size();
Expand Down Expand Up @@ -4385,13 +4390,18 @@ void SelectionDAGBuilder::visitStore(const StoreInst &I) {
ChainI = 0;
}

SDValue Add = DAG.getObjectPtrOffset(dl, Ptr, TypeSize::Fixed(Offsets[i]));
// TODO: MachinePointerInfo only supports a fixed length offset.
MachinePointerInfo PtrInfo =
!Offsets[i].isScalable() || Offsets[i].isZero()
? MachinePointerInfo(PtrV, Offsets[i].getKnownMinValue())
: MachinePointerInfo();

SDValue Add = DAG.getObjectPtrOffset(dl, Ptr, Offsets[i]);
SDValue Val = SDValue(Src.getNode(), Src.getResNo() + i);
if (MemVTs[i] != ValueVTs[i])
Val = DAG.getPtrExtOrTrunc(Val, dl, MemVTs[i]);
SDValue St =
DAG.getStore(Root, dl, Val, Add, MachinePointerInfo(PtrV, Offsets[i]),
Alignment, MMOFlags, AAInfo);
DAG.getStore(Root, dl, Val, Add, PtrInfo, Alignment, MMOFlags, AAInfo);
Chains[ChainI] = St;
}

Expand Down
11 changes: 4 additions & 7 deletions llvm/test/CodeGen/AArch64/alloca-load-store-scalable-struct.ll
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ define void @test(ptr %addr) #0 {
; CHECK-NEXT: addvl sp, sp, #-3
; CHECK-NEXT: .cfi_escape 0x0f, 0x0c, 0x8f, 0x00, 0x11, 0x10, 0x22, 0x11, 0x18, 0x92, 0x2e, 0x00, 0x1e, 0x22 // sp + 16 + 24 * VG
; CHECK-NEXT: .cfi_offset w29, -16
; CHECK-NEXT: mov x8, #2 // =0x2
; CHECK-NEXT: mov x9, #4 // =0x4
; CHECK-NEXT: ptrue p0.d
; CHECK-NEXT: mov x10, sp
; CHECK-NEXT: ld1d { z0.d }, p0/z, [x0, x8, lsl #3]
; CHECK-NEXT: ld1d { z1.d }, p0/z, [x0, x9, lsl #3]
; CHECK-NEXT: ld1d { z0.d }, p0/z, [x0, #1, mul vl]
; CHECK-NEXT: ld1d { z1.d }, p0/z, [x0, #2, mul vl]
; CHECK-NEXT: ld1d { z2.d }, p0/z, [x0]
; CHECK-NEXT: st1d { z0.d }, p0, [x10, x8, lsl #3]
; CHECK-NEXT: st1d { z1.d }, p0, [x10, x9, lsl #3]
; CHECK-NEXT: st1d { z2.d }, p0, [sp]
; CHECK-NEXT: st1d { z1.d }, p0, [sp, #2, mul vl]
; CHECK-NEXT: st1d { z0.d }, p0, [sp, #1, mul vl]
; CHECK-NEXT: addvl sp, sp, #3
; CHECK-NEXT: ldr x29, [sp], #16 // 8-byte Folded Reload
; CHECK-NEXT: ret
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/AArch64/sve-extract-fixed-vector.ll
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ define <4 x i32> @typesize_regression_test_v4i32(i32* %addr, i64 %idx) {
entry:
%ptr = getelementptr inbounds i32, i32* %addr, i64 %idx
%bc = bitcast i32* %ptr to <vscale x 4 x i32>*
%ld = load <vscale x 4 x i32>, <vscale x 4 x i32>* %bc, align 16
%ld = load volatile <vscale x 4 x i32>, <vscale x 4 x i32>* %bc, align 16
%out = call <4 x i32> @llvm.vector.extract.v4i32.nxv4i32(<vscale x 4 x i32> %ld, i64 0)
ret <4 x i32> %out
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ define <vscale x 1 x double> @test(%struct.test* %addr, i64 %vl) {
; CHECK-NEXT: slli a2, a2, 1
; CHECK-NEXT: sub sp, sp, a2
; CHECK-NEXT: .cfi_escape 0x0f, 0x0d, 0x72, 0x00, 0x11, 0x10, 0x22, 0x11, 0x02, 0x92, 0xa2, 0x38, 0x00, 0x1e, 0x22 # sp + 16 + 2 * vlenb
; CHECK-NEXT: csrrs a2, vlenb, zero
; CHECK-NEXT: vl1re64.v v8, (a0)
; CHECK-NEXT: addi a0, a0, 8
; CHECK-NEXT: add a0, a0, a2
; CHECK-NEXT: vl1re64.v v9, (a0)
; CHECK-NEXT: addi a0, sp, 16
; CHECK-NEXT: vs1r.v v8, (a0)
; CHECK-NEXT: addi a2, sp, 24
; CHECK-NEXT: add a2, a0, a2
; CHECK-NEXT: vs1r.v v9, (a2)
; CHECK-NEXT: vl1re64.v v8, (a2)
; CHECK-NEXT: vl1re64.v v9, (a0)
Expand Down

0 comments on commit 5660652

Please sign in to comment.