@@ -163,11 +163,23 @@ class AArch64AsmPrinter : public AsmPrinter {
163
163
void emitPtrauthAuthResign (const MachineInstr *MI);
164
164
165
165
// Emit the sequence to compute the discriminator.
166
+ //
166
167
// ScratchReg should be x16/x17.
168
+ //
167
169
// The returned register is either unmodified AddrDisc or x16/x17.
170
+ //
168
171
// If the expanded pseudo is allowed to clobber AddrDisc register, setting
169
172
// MayUseAddrAsScratch may save one MOV instruction, provided the address
170
- // is already in x16/x17.
173
+ // is already in x16/x17 (i.e. return x16/x17 which is the *modified* AddrDisc
174
+ // register at the same time):
175
+ //
176
+ // mov x17, x16
177
+ // movk x17, #1234, lsl #48
178
+ // ; x16 is not used anymore
179
+ //
180
+ // can be replaced by
181
+ //
182
+ // movk x16, #1234, lsl #48
171
183
Register emitPtrauthDiscriminator (uint16_t Disc, Register AddrDisc,
172
184
Register ScratchReg,
173
185
bool MayUseAddrAsScratch = false );
@@ -1737,6 +1749,7 @@ Register AArch64AsmPrinter::emitPtrauthDiscriminator(uint16_t Disc,
1737
1749
Register AddrDisc,
1738
1750
Register ScratchReg,
1739
1751
bool MayUseAddrAsScratch) {
1752
+ assert (ScratchReg == AArch64::X16 || ScratchReg == AArch64::X17);
1740
1753
// So far we've used NoRegister in pseudos. Now we need real encodings.
1741
1754
if (AddrDisc == AArch64::NoRegister)
1742
1755
AddrDisc = AArch64::XZR;
@@ -2062,10 +2075,13 @@ void AArch64AsmPrinter::emitPtrauthBranch(const MachineInstr *MI) {
2062
2075
if (BrTarget == AddrDisc)
2063
2076
report_fatal_error (" Branch target is signed with its own value" );
2064
2077
2065
- // x16 and x17 are implicit-def'ed by MI, and AddrDisc is not used as any
2066
- // other input, so try to save one MOV by setting MayUseAddrAsScratch.
2078
+ // If we are printing BLRA pseudo instruction, then x16 and x17 are
2079
+ // implicit-def'ed by the MI and AddrDisc is not used as any other input, so
2080
+ // try to save one MOV by setting MayUseAddrAsScratch.
2081
+ // Unlike BLRA, BRA pseudo is used to perform computed goto, and thus not
2082
+ // declared as clobbering x16/x17.
2067
2083
Register DiscReg = emitPtrauthDiscriminator (Disc, AddrDisc, AArch64::X17,
2068
- /* MayUseAddrAsScratch=*/ true );
2084
+ /* MayUseAddrAsScratch=*/ IsCall );
2069
2085
bool IsZeroDisc = DiscReg == AArch64::XZR;
2070
2086
2071
2087
unsigned Opc;
0 commit comments