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