@@ -163,11 +163,23 @@ class AArch64AsmPrinter : public AsmPrinter {
163163 void emitPtrauthAuthResign (const MachineInstr *MI);
164164
165165 // Emit the sequence to compute the discriminator.
166+ //
166167 // ScratchReg should be x16/x17.
168+ //
167169 // The returned register is either unmodified AddrDisc or x16/x17.
170+ //
168171 // If the expanded pseudo is allowed to clobber AddrDisc register, setting
169172 // 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
171183 Register emitPtrauthDiscriminator (uint16_t Disc, Register AddrDisc,
172184 Register ScratchReg,
173185 bool MayUseAddrAsScratch = false );
@@ -1737,6 +1749,7 @@ Register AArch64AsmPrinter::emitPtrauthDiscriminator(uint16_t Disc,
17371749 Register AddrDisc,
17381750 Register ScratchReg,
17391751 bool MayUseAddrAsScratch) {
1752+ assert (ScratchReg == AArch64::X16 || ScratchReg == AArch64::X17);
17401753 // So far we've used NoRegister in pseudos. Now we need real encodings.
17411754 if (AddrDisc == AArch64::NoRegister)
17421755 AddrDisc = AArch64::XZR;
@@ -2062,10 +2075,13 @@ void AArch64AsmPrinter::emitPtrauthBranch(const MachineInstr *MI) {
20622075 if (BrTarget == AddrDisc)
20632076 report_fatal_error (" Branch target is signed with its own value" );
20642077
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.
20672083 Register DiscReg = emitPtrauthDiscriminator (Disc, AddrDisc, AArch64::X17,
2068- /* MayUseAddrAsScratch=*/ true );
2084+ /* MayUseAddrAsScratch=*/ IsCall );
20692085 bool IsZeroDisc = DiscReg == AArch64::XZR;
20702086
20712087 unsigned Opc;
0 commit comments