[PATCH] D145934: [RISCV] Precommit test to show wrong way to pass scaleable vector on stack

Kito Cheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 13 07:04:30 PDT 2023


kito-cheng created this revision.
kito-cheng added reviewers: craig.topper, reames, rogfer01, frasercrmck, asb.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, edward-jones, zzheng, jrtc27, shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, arichardson.
Herald added a project: All.
kito-cheng requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead, eopXD, MaskRay.
Herald added a project: LLVM.

Test case to demo scaleable vector on stack will cause stack corruption.

Detail explan what happened:

  tail call void @foo(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, <vscale x 16 x float> zeroinitializer, <vscale x 16 x float> zeroin

`foo` take 13 arguments, first 8 argument pass in GPR, and next 2 LMUL 8 vector
argument passed in v8-v23, and now we run out of argument register for GPR and
vector register  LMUL 8 value, so we must pass last LMUL 8 vector argument in
stack.

However LLVM only reserve 8 byte on stack for the LMUL 8 vector
argument, it will cause stack corruption when we try to store that into
stack.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145934

Files:
  llvm/test/CodeGen/RISCV/calling-conv-vector-on-stack.ll


Index: llvm/test/CodeGen/RISCV/calling-conv-vector-on-stack.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/RISCV/calling-conv-vector-on-stack.ll
@@ -0,0 +1,32 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
+; RUN: llc -mtriple=riscv64 -mattr=+v -verify-machineinstrs -treat-scalable-fixed-error-as-warning < %s 2>&1 | FileCheck %s
+
+; CHECK: warning: Invalid size request on a scalable vector
+
+define void @bar() nounwind {
+; CHECK-LABEL: bar:
+; CHECK:       # %bb.0: # %entry
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    vsetvli a0, zero, e32, m8, ta, ma
+; CHECK-NEXT:    vmv.v.i v8, 0
+; CHECK-NEXT:    vs8r.v v8, (sp)
+; CHECK-NEXT:    li a0, 0
+; CHECK-NEXT:    li a1, 0
+; CHECK-NEXT:    li a2, 0
+; CHECK-NEXT:    li a3, 0
+; CHECK-NEXT:    li a4, 0
+; CHECK-NEXT:    li a5, 0
+; CHECK-NEXT:    li a6, 0
+; CHECK-NEXT:    li a7, 0
+; CHECK-NEXT:    vmv.v.i v16, 0
+; CHECK-NEXT:    call foo at plt
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+entry:
+  tail call void @foo(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, <vscale x 16 x float> zeroinitializer, <vscale x 16 x float> zeroinitializer, <vscale x 16 x float> zeroinitializer)
+  ret void
+}
+
+declare void @foo(i32, i32, i32, i32, i32, i32, i32, i32, <vscale x 16 x float>, <vscale x 16 x float>, <vscale x 16 x float>) nounwind


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145934.504638.patch
Type: text/x-patch
Size: 1553 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230313/099bbc15/attachment.bin>


More information about the llvm-commits mailing list