This is an archive of the discontinued LLVM Phabricator instance.

[PATCH] [RISCV] Enable -msave-restore by default when optimizing for size
Needs ReviewPublic

Authored by joshua-arch1 on Sep 18 2022, 2:33 AM.

Details

Summary

Since spill and restore code of callee-saved registers has been implemented by common functions to reduce code duplication in the patch https://reviews.llvm.org/D62686, we can enable -msave-restore by default when we are optimizing for size in Oz.

Diff Detail

Event Timeline

joshua-arch1 created this revision.Sep 18 2022, 2:33 AM
joshua-arch1 requested review of this revision.Sep 18 2022, 2:33 AM
llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h
117

Use hasMinSize() if we want this feature enabled in -Oz.

joshua-arch1 marked an inline comment as done.Nov 3 2022, 1:39 AM

Ping.

Can we land this patch. I think this is quite useful at -Oz

Do we still want -mno-save-restore to override this? If so maybe we need to do this in clang driver instead.

asb added a comment.Mar 8 2023, 2:04 AM

Do we still want -mno-save-restore to override this? If so maybe we need to do this in clang driver instead.

FWIW, I think retaining the ability to have -mno-save-restore take effect is useful. So doing this in the clang driver as suggested makes sense.

At least with that this diff shows, the saving is small. I'd hope that we don't toggle -msave-restore for -Os/-Oz. Users can specify -msave-restore themselves.

jrtc27 added a comment.Mar 8 2023, 4:16 PM

At least with that this diff shows, the saving is small. I'd hope that we don't toggle -msave-restore for -Os/-Oz. Users can specify -msave-restore themselves.

Well, tiny tests like this aren't representative of real-world code, so I don't think it's fair to base it off this. Don't know what the figures are for real-world code.

llvm/test/CodeGen/RISCV/saverestore.ll
43–72

Would this break shadow call stack which isn't compatible with save/restore lib calls? Or do we already check that somewhere?

Platforms like Android reserve a register x18(for AArch64). There was a patch for RISC-V that also reserved x18 for shadow callstack. https://reviews.llvm.org/D14599, https://reviews.llvm.org/D143355

Will it be better to reserve a register that doesn't conflict with -msave-restore?

Would this break shadow call stack which isn't compatible with save/restore lib calls? Or do we already check that somewhere?

Will this still be the issue when X3 will be used for SCS?

Would this break shadow call stack which isn't compatible with save/restore lib calls? Or do we already check that somewhere?

Will this still be the issue when X3 will be used for SCS?

I don't think so as long as the error about mixing -msave-restore with SCS was removed from RISCVFrameLowering.cpp when we switched to X3.

reames resigned from this revision.May 8 2023, 7:50 AM

Would this break shadow call stack which isn't compatible with save/restore lib calls? Or do we already check that somewhere?

Will this still be the issue when X3 will be used for SCS?

I don't think so as long as the error about mixing -msave-restore with SCS was removed from RISCVFrameLowering.cpp when we switched to X3.

Seems like https://reviews.llvm.org/D149099 fixed it? cc: @paulkirth for confirmation.

I don't think there is an issue anymore. As @craig.topper pointed out the check in FrameLowering is no longer there, so AFAIK there is no longer a conflict.

pirama added a subscriber: pirama.Jun 28 2023, 3:51 PM
evandro removed a subscriber: evandro.Jun 30 2023, 3:43 PM

should we resurrect this patch?