Skip to content

Commit 0d0514d

Browse files
committed
[RISCV] Add a test showing incorrect codegen
This patch adds a test which shows how the compiler incorrectly sets the size and alignment of a stack object used to indirectly pass vector types to functions. In the particular example, the test passes a <4 x i8> vector type to a function and creates a stack object of size and alignment equal to 4 bytes. However, the code generated to set up that parameter has been scalarized and stores each element as individual XLEN-sized values. Thus on RV32 this stores 16 bytes and on RV64 32 bytes, both of which clobber the stack. Similarly, the alignment is set up as the alignment of the vector type, which is not necessarily the natural alignment of XLEN. Reviewed By: luismarques Differential Revision: https://reviews.llvm.org/D95025
1 parent 36d4f6d commit 0d0514d

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

llvm/test/CodeGen/RISCV/vector-abi.ll

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
; RUN: llc -mtriple=riscv32 -stop-after finalize-isel < %s | FileCheck %s -check-prefix=RV32
2+
; RUN: llc -mtriple=riscv64 -stop-after finalize-isel < %s | FileCheck %s -check-prefix=RV64
3+
4+
; FIXME: The stack location used to pass the parameter to the function has the
5+
; incorrect size and alignment for how we use it, and we clobber the stack.
6+
7+
declare void @callee(<4 x i8> %v)
8+
9+
define void @caller() {
10+
; RV32-LABEL: name: caller
11+
; RV32: stack:
12+
; RV32: - { id: 0, name: '', type: default, offset: 0, size: 4, alignment: 4,
13+
; RV32-NEXT: stack-id: default, callee-saved-register: '', callee-saved-restored: true,
14+
; RV32-NEXT: debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
15+
; RV32: bb.0 (%ir-block.0):
16+
; RV32: ADJCALLSTACKDOWN 0, 0, implicit-def dead $x2, implicit $x2
17+
; RV32: [[ADDI:%[0-9]+]]:gpr = ADDI $x0, 7
18+
; RV32: SW killed [[ADDI]], %stack.0, 12 :: (store 4 into %stack.0)
19+
; RV32: [[ADDI1:%[0-9]+]]:gpr = ADDI $x0, 6
20+
; RV32: SW killed [[ADDI1]], %stack.0, 8 :: (store 4 into %stack.0)
21+
; RV32: [[ADDI2:%[0-9]+]]:gpr = ADDI $x0, 5
22+
; RV32: SW killed [[ADDI2]], %stack.0, 4 :: (store 4 into %stack.0)
23+
; RV32: [[ADDI3:%[0-9]+]]:gpr = ADDI $x0, 4
24+
; RV32: SW killed [[ADDI3]], %stack.0, 0 :: (store 4 into %stack.0)
25+
; RV32: [[ADDI4:%[0-9]+]]:gpr = ADDI %stack.0, 0
26+
; RV32: $x10 = COPY [[ADDI4]]
27+
; RV32: PseudoCALL target-flags(riscv-plt) @callee, csr_ilp32_lp64, implicit-def dead $x1, implicit $x10, implicit-def $x2
28+
; RV32: ADJCALLSTACKUP 0, 0, implicit-def dead $x2, implicit $x2
29+
; RV32: PseudoRET
30+
; RV64-LABEL: name: caller
31+
; RV64: stack:
32+
; RV64: - { id: 0, name: '', type: default, offset: 0, size: 4, alignment: 4,
33+
; RV64-NEXT: stack-id: default, callee-saved-register: '', callee-saved-restored: true,
34+
; RV64-NEXT: debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
35+
; RV64: bb.0 (%ir-block.0):
36+
; RV64: ADJCALLSTACKDOWN 0, 0, implicit-def dead $x2, implicit $x2
37+
; RV64: [[ADDI:%[0-9]+]]:gpr = ADDI $x0, 7
38+
; RV64: SD killed [[ADDI]], %stack.0, 24 :: (store 8 into %stack.0)
39+
; RV64: [[ADDI1:%[0-9]+]]:gpr = ADDI $x0, 6
40+
; RV64: SD killed [[ADDI1]], %stack.0, 16 :: (store 8 into %stack.0)
41+
; RV64: [[ADDI2:%[0-9]+]]:gpr = ADDI $x0, 5
42+
; RV64: SD killed [[ADDI2]], %stack.0, 8 :: (store 8 into %stack.0)
43+
; RV64: [[ADDI3:%[0-9]+]]:gpr = ADDI $x0, 4
44+
; RV64: SD killed [[ADDI3]], %stack.0, 0 :: (store 8 into %stack.0)
45+
; RV64: [[ADDI4:%[0-9]+]]:gpr = ADDI %stack.0, 0
46+
; RV64: $x10 = COPY [[ADDI4]]
47+
; RV64: PseudoCALL target-flags(riscv-plt) @callee, csr_ilp32_lp64, implicit-def dead $x1, implicit $x10, implicit-def $x2
48+
; RV64: ADJCALLSTACKUP 0, 0, implicit-def dead $x2, implicit $x2
49+
; RV64: PseudoRET
50+
call void @callee(<4 x i8> <i8 4, i8 5, i8 6, i8 7>)
51+
ret void
52+
}

0 commit comments

Comments
 (0)