SLH will fall back to a different technique if X16 is being used,
so there is no need to warn for inline asm use. Only prevent other codegen
from using it.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Event Timeline
I seem to remember that the speculative_load_hardening for AArch64 has a work-around when a user does reserve register X16 in inline assembly, see comment at https://github.com/llvm/llvm-project/blob/b7dae832e61da1f8b48cce1715514cbd5809eb3f/llvm/lib/Target/AArch64/AArch64SpeculationHardening.cpp#L35.
Given that comment and the tests in https://github.com/llvm/llvm-project/blob/main/llvm/test/CodeGen/AArch64/speculation-hardening-dagisel.ll that check that behaviour, the warning/error implemented in this patch is not correct?
llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp | ||
---|---|---|
342 | I see that I've used the term "taint register" in the source code of AArch64SpeculationHardening.cpp; but I don't see the term in the (X86-centric) design document about Speculative Load Hardening at https://llvm.org/docs/SpeculativeLoadHardening.html. I don't immediately see an alternative term to clearly name the register that Speculative Load Hardening reserves. |
the warning/error implemented in this patch is not correct?
I see what you mean. This is a unfortunate crossover where AArch64RegisterInfo::getReservedRegs is not just used for inline assembly but codegen too. So if codegen wants X16 it can't use it but in the codegen for SLH you've actually handled the inline asm case so there's no reason to warn at all.
Running the test you linked we see that it does already warn when it doesn't need to:
-- Exit Code: 0 Command Output (stderr): -- warning: inline asm clobber list contains reserved registers: W16 note: Reserved registers on the clobber list may not be preserved across the asm statement, and clobbering them may lead to undefined behaviour.
f_clobbered_reg_w16: // @f_clobbered_reg_w16 .cfi_startproc // %bb.0: // %entry dsb sy isb cmp w0, w1 b.le .LBB1_3 // %bb.1: dsb sy isb // %bb.2: // %if.then //APP warning: inline asm clobber list contains reserved registers: W16 note: Reserved registers on the clobber list may not be preserved across the asm statement, and clobbering them may lead to undefined behaviour. mov w16, w0 //NO_APP add w0, w1, w0 ret
I think I can make the inline asm check more specific to avoid this but keep the register reserved for codegen.
llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp | ||
---|---|---|
342 | I could just go with "is used as part of Speculative Load Hardening". The point is, you can google something and land on an llvm page. |
llvm/test/CodeGen/AArch64/speculation-hardening-dagisel.ll | ||
---|---|---|
4–7 ↗ | (On Diff #459757) | The patch LGTM. |
llvm/test/CodeGen/AArch64/speculation-hardening-dagisel.ll | ||
---|---|---|
4–7 ↗ | (On Diff #459757) | I might be able to reserve x16 using the equivalent of the command line option, for the non SLH run. Check that you do get the warning. Then the test will fail if someone were to update it. |
llvm/test/CodeGen/AArch64/speculation-hardening-dagisel.ll | ||
---|---|---|
4–7 ↗ | (On Diff #459757) | Turns out the way that option works, you can't use -ffixed-x16 because clang ignores it. It does this for any register deemed too useful aka used in the ABI. (at least clang tells you the argument is unused, gcc is just silent) I guess we hope that future warning editors are smart enough to grep the test folders for the old phrasing. |
clang-format not found in user’s local PATH; not linting file.