This is an archive of the discontinued LLVM Phabricator instance.

[RISCV][WIP] Enable the local stack allocation pass for RISC-V.
AbandonedPublic

Authored by craig.topper on Sep 28 2022, 9:01 PM.

Details

Summary

While investigating PR58027, I noticed that ARM and AArch64 use
this pass. It creates a virtual base register for the stack accesses
and prevents an emergency spill slot from being needed.

I've done no testing of this other than PR58027. No lit tests were
affected.

Does this patch seem like something we should pursue?

Diff Detail

Event Timeline

craig.topper created this revision.Sep 28 2022, 9:01 PM
craig.topper requested review of this revision.Sep 28 2022, 9:01 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 28 2022, 9:01 PM
jrtc27 added inline comments.Sep 28 2022, 9:45 PM
llvm/lib/Target/RISCV/RISCVFrameLowering.h
77

Bit too Arm-flavoured :)

llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
390–395

These should at least be based on XLEN and FLEN calculations rather than a bunch of hard-coded constants, but can they be calculated purely based on the ABI's callee saved register sets?

Also shouldn't the D/F checks be ABI-based rather than ISA-based? They're all caller-saved in the soft-float ABI, and similarly for the high parts of wider-than-ABI_FLEN registers.

404

Maybe also fudged by XLEN?

craig.topper added inline comments.Sep 28 2022, 9:53 PM
llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
390–395

Thanks I had never looked into the specifics of the soft float ABI.

I'll definitely look into improving this code if we think it's worthwhile to enable this pass.

asb added a comment.Sep 29 2022, 3:32 AM

Hmm, I hadn't realised that this pass might allow us to avoid the need for an emergency spill slot. To answer your question about whether we should try to enable this - I think a definite yes, it should improve generated code slightly too.

D98101 also started to enable it, but the original author unfortunately ran out of time on addressing review feedback - it's probably worth reviewing that implementation and the review comments to see what might be relevant for this patch.

StephenFan added a comment.EditedSep 29 2022, 8:41 AM

Hmm, I hadn't realised that this pass might allow us to avoid the need for an emergency spill slot. To answer your question about whether we should try to enable this - I think a definite yes, it should improve generated code slightly too.

D98101 also started to enable it, but the original author unfortunately ran out of time on addressing review feedback - it's probably worth reviewing that implementation and the review comments to see what might be relevant for this patch.

Glad to hear that this pass fixes some potential bugs. I pre-committed a patch D134884 to add a local stack slot allocation test. I'm happy to continue maintaining that patch. Are you interested in taking a look at that patch? Or do you @craig.topper want to continue with your current patch?

craig.topper abandoned this revision.Sep 29 2022, 1:02 PM

Abandon in favor of pushing forward on D98101 I completely forgot that existed despite reviewing it over a year ago.