This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Precommit test to show wrong way to pass scalable FP vector on stack
ClosedPublic

Authored by kito-cheng on Mar 13 2023, 7:04 AM.

Details

Summary

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> zeroinitializer,
                    <vscale x 16 x float> zeroinitializer)

foo take 13 arguments, first 8 argument pass in GPR, and next 2 LMUL 8 vector
arguments passed in v8-v23, and now we run out of argument register for GPR and
vector register, so we must pass last LMUL 8 vector argument by 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.

Diff Detail

Event Timeline

kito-cheng created this revision.Mar 13 2023, 7:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 13 2023, 7:04 AM
kito-cheng requested review of this revision.Mar 13 2023, 7:04 AM

Add comments for easier understand what's wrong for the current code gen.

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

-treat-scalable-fixed-error-as-warning to prevent llvm crash

5

This should not happened, will turn into CHECK-NOT in follow up patch.

10

Stack only reserve 16 byte, 8 byte for backup sp...which mean only left 8 byte for a LMUL 8 value.

12

Set vl to vlmax here

14

And then store an LMUL 8 value to stack, stack corruption here.

craig.topper retitled this revision from [RISCV] Precommit test to show wrong way to pass scaleable vector on stack to [RISCV] Precommit test to show wrong way to pass scalable FP vector on stack.Mar 13 2023, 2:11 PM
craig.topper added inline comments.Mar 13 2023, 2:14 PM
llvm/test/CodeGen/RISCV/calling-conv-vector-on-stack.ll
2

This wasn't fully generated by the script. You have a custom line for the warning. I think the script would delete that? I'd remove this comment.

Chagnes:

  • Drop UTC_ARGS: --version 2
kito-cheng added inline comments.Mar 13 2023, 6:59 PM
llvm/test/CodeGen/RISCV/calling-conv-vector-on-stack.ll
2

You mean the ; CHECK: warning: Invalid size request on a scalable vector? the file other than the check is generated by update_llc_test_checks.py, and it will preserved :)

craig.topper added inline comments.Mar 13 2023, 7:41 PM
llvm/test/CodeGen/RISCV/calling-conv-vector-on-stack.ll
2

I meant the comment about being generated by the script so that people won't naively run the script. But if the script doesn't delete the warning check then its fine. I just the script was pretty aggressive about deleting things it doesn't know about.

This revision is now accepted and ready to land.Mar 14 2023, 8:46 AM
This revision was landed with ongoing or failed builds.Mar 15 2023, 2:21 AM
This revision was automatically updated to reflect the committed changes.