From cc819b233c829083079709d4ffbbee231c231c71 Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Thu, 26 Oct 2023 13:11:02 +0000 Subject: [PATCH 1/2] [SVE] Add reproducer for stack corruption bug. --- llvm/test/CodeGen/AArch64/framelayout-sve.mir | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/llvm/test/CodeGen/AArch64/framelayout-sve.mir b/llvm/test/CodeGen/AArch64/framelayout-sve.mir index 54d6a5fc199766..7b3d17c602bce3 100644 --- a/llvm/test/CodeGen/AArch64/framelayout-sve.mir +++ b/llvm/test/CodeGen/AArch64/framelayout-sve.mir @@ -41,6 +41,7 @@ define aarch64_sve_vector_pcs void @save_restore_sve_realign() uwtable { entry: unreachable } define aarch64_sve_vector_pcs void @frame_layout() uwtable { entry: unreachable } define void @fp_relative_index_with_float_save() uwtable { entry: unreachable } + define void @fp_relative_that_is_not_a_multiple_of_VLx16() uwtable { entry: unreachable } ... # +----------+ @@ -1287,3 +1288,24 @@ body: | RET_ReallyLR --- +... +# CHECK-LABEL: name: fp_relative_that_is_not_a_multiple_of_VLx16 +# CHECK: - { id: 0, name: '', type: default, offset: -156, size: 156, alignment: 1, +# CHECK-NEXT: stack-id: scalable-vector +# CHECK: - { id: 1, name: '', type: variable-sized, offset: -32, alignment: 1, +# CHECK-NEXT: stack-id: default + +# CHECK: $x8 = ADDPL_XXI $fp, -20 +# CHECK-NEXT: $z0 = LD1W_IMM killed renamable $p0, killed $x8, -8 + +name: fp_relative_that_is_not_a_multiple_of_VLx16 +stack: + - { id: 0, stack-id: scalable-vector, size: 156, alignment: 1 } + - { id: 1, stack-id: default, type: variable-sized, alignment: 1 } +body: | + bb.0.entry: + liveins: $p0 + + renamable $z0 = LD1W_IMM killed renamable $p0, %stack.0, 0 + RET_ReallyLR +--- From 8b58ad20a0f37a1230546ccaa8e35f67fae45b2b Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Thu, 26 Oct 2023 10:50:47 +0000 Subject: [PATCH 2/2] [SVE] Fix incorrect offset calculation when rewriting an instruction's frame index. --- llvm/lib/Target/AArch64/AArch64InstrInfo.cpp | 2 +- llvm/test/CodeGen/AArch64/framelayout-sve.mir | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp index 7f1421549b1492..e9b9f8013abeaf 100644 --- a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp @@ -5657,7 +5657,7 @@ int llvm::isAArch64FrameOffsetLegal(const MachineInstr &MI, Offset = Remainder; else { NewOffset = NewOffset < 0 ? MinOff : MaxOff; - Offset = Offset - NewOffset * Scale + Remainder; + Offset = Offset - NewOffset * Scale; } if (EmittableOffset) diff --git a/llvm/test/CodeGen/AArch64/framelayout-sve.mir b/llvm/test/CodeGen/AArch64/framelayout-sve.mir index 7b3d17c602bce3..7c87587c6dc4e2 100644 --- a/llvm/test/CodeGen/AArch64/framelayout-sve.mir +++ b/llvm/test/CodeGen/AArch64/framelayout-sve.mir @@ -1295,7 +1295,7 @@ body: | # CHECK: - { id: 1, name: '', type: variable-sized, offset: -32, alignment: 1, # CHECK-NEXT: stack-id: default -# CHECK: $x8 = ADDPL_XXI $fp, -20 +# CHECK: $x8 = ADDPL_XXI $fp, -14 # CHECK-NEXT: $z0 = LD1W_IMM killed renamable $p0, killed $x8, -8 name: fp_relative_that_is_not_a_multiple_of_VLx16