This is an archive of the discontinued LLVM Phabricator instance.

[SPARC] Make calls to function with big return values work
ClosedPublic

Authored by koakuma on Aug 23 2022, 5:41 AM.

Details

Summary

Implement CanLowerReturn and associated CallingConv changes for SPARC/SPARC64.

In particular, for SPARC64 there's new RetCC_Sparc64_* functions that handles the return case of the calling convention.
It uses the same analysis as CC_Sparc64_* family of funtions, but fails if the return value doesn't fit into the return registers.

This makes calls to functions with big return values converted to an sret function as expected, instead of crashing LLVM.

Diff Detail

Event Timeline

koakuma created this revision.Aug 23 2022, 5:41 AM
koakuma requested review of this revision.Aug 23 2022, 5:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 23 2022, 5:41 AM
koakuma updated this revision to Diff 454974.Aug 23 2022, 3:00 PM

Change formatting as suggested by clang-format.

Ping. Is there anything else I should do for this?

MaskRay added inline comments.
llvm/lib/Target/Sparc/SparcISelLowering.cpp
235

OK. This looks similar to X86/PowerPC.

1083

OK. Similar to other targets.

llvm/test/CodeGen/SPARC/bigreturn.ll
2

This checks nearly every instruction. Use PATH=DIR_WITH_LLC:$PATH llvm/utils/update_llc_test_checks.py

5

Add other interesting tests like {i64, i64} ?

10

-NEXT helps catch problems if the code sequence changes. update_llc_test_checks.py generated output uses -NEXT.

MaskRay added inline comments.Oct 16 2022, 1:37 PM
llvm/test/CodeGen/SPARC/bigreturn.ll
2

-unknown-linux-gnu can be deleted as that doesn't affect codegen. Make the target triple general.

koakuma added inline comments.Oct 17 2022, 6:55 AM
llvm/test/CodeGen/SPARC/bigreturn.ll
5

So the {i64, i64} case is already tested in 64abi.ll, but the corresponding {i32, i32} for 32-bit ABI isn't tested yet.
I'll rework the tests so it would directly be inside the main ABI test files instead of in a new file.

koakuma updated this revision to Diff 468204.Oct 17 2022, 7:53 AM

Move all sret-related tests into one file and autogenerate the test cases.

MaskRay accepted this revision.Oct 17 2022, 8:59 AM

LGTM.

llvm/test/CodeGen/SPARC/bigreturn.ll
6

Consider using ;; for non-RUN non-CHECK comments. It makes comments stand out in some editors and helps update_llc_test_checks.py to recognize comments.

This revision is now accepted and ready to land.Oct 17 2022, 8:59 AM

Thanks, can you please commit it to me, @MaskRay?
My email address is koachan@protonmail.com.

This revision was automatically updated to reflect the committed changes.