This is an archive of the discontinued LLVM Phabricator instance.

[StackProtector] Allow targets to specify an instruction is part of terminator sequence
Needs RevisionPublic

Authored by nemanjai on May 17 2022, 7:25 PM.

Details

Reviewers
aemerson
arsenm
Group Reviewers
Restricted Project
Summary

When the basic block is being split up to insert stack protector checks/traps, it is spliced prior to the instructions needed by the terminator. This includes implicit defs and register copies required by the ABI. However, on certain targets, there may be instructions that are part of such a terminator sequence but are not strictly speaking register copies.
Such is the case with the PowerPC "Move to count register" instruction. The instruction implicitly defines the count register that is used by the subsequent branch.

On PowerPC, if the target is not allowed to specify that the instruction is part of the terminator sequence, the block gets spliced between the instruction that sets up the CTR and the instruction that uses it (such as an indirect tail call).

Diff Detail

Event Timeline

nemanjai created this revision.May 17 2022, 7:25 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 17 2022, 7:25 PM
nemanjai requested review of this revision.May 17 2022, 7:25 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 17 2022, 7:25 PM

Can the test be reduced? Do you really need a main()?

Can the test be reduced? Do you really need a main()?

Good point. In the original test case I reduced func1() is static so it needed the caller. I should be able to change the linkage of the function and remove main().

arsenm requested changes to this revision.May 18 2022, 3:26 PM
arsenm added a subscriber: arsenm.

Why can't you just mark these instructions as being terminators? AMDGPU has to glue a lot of ALU instructions to terminators, and we just define terminator and nonterminator pseudo variants

This revision now requires changes to proceed.May 18 2022, 3:26 PM

Why can't you just mark these instructions as being terminators? AMDGPU has to glue a lot of ALU instructions to terminators, and we just define terminator and nonterminator pseudo variants

This seems like a less desirable path. Marking what is inherently a non-terminator instruction as a terminator seems likely to cause problems. I don't have a specific case in mind, but perhaps if some pass makes the assumption that it is safe to split a basic block into two that terminate with two terminators. It might be a safe thing to do except if some terminator is not actually a terminator.

Why can't you just mark these instructions as being terminators? AMDGPU has to glue a lot of ALU instructions to terminators, and we just define terminator and nonterminator pseudo variants

This seems like a less desirable path. Marking what is inherently a non-terminator instruction as a terminator seems likely to cause problems. I don't have a specific case in mind, but perhaps if some pass makes the assumption that it is safe to split a basic block into two that terminate with two terminators. It might be a safe thing to do except if some terminator is not actually a terminator.

Furthermore, this instruction is needed to set up the address for the call. The call itself is only a terminator because it is a tail call. Seems like we would have to have a rather complex set of conditions to decide whether to use a terminator variant or a non-terminator variant.