[llvm] [AIX][TLS] Optimize the small local-exec access sequence for non-zero offsets (PR #71485)
Amy Kwan via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 24 11:18:30 PST 2024
================
@@ -1504,11 +1513,37 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
// Verify alignment is legal, so we don't create relocations
// that can't be supported.
unsigned OpNum = (MI->getOpcode() == PPC::STD) ? 2 : 1;
+ // For non-TOC-based local-exec TLS accesses with non-zero offsets, the
+ // machine operand (which is a TargetGlobalTLSAddress) is expected to be
+ // the same operand for both loads and stores.
+ for (const MachineOperand &TempMO : MI->operands()) {
+ if (((TempMO.getTargetFlags() == PPCII::MO_TPREL_FLAG)) &&
+ TempMO.getOperandNo() == 1)
+ OpNum = 1;
+ }
const MachineOperand &MO = MI->getOperand(OpNum);
if (MO.isGlobal()) {
const DataLayout &DL = MO.getGlobal()->getParent()->getDataLayout();
if (MO.getGlobal()->getPointerAlignment(DL) < 4)
llvm_unreachable("Global must be word-aligned for LD, STD, LWA!");
+
+ // A faster non-TOC-based local-exec sequence is represented by
+ // directly loading or storing off of the thread pointer and with
+ // an immediate operand having the MO_TPREL_FLAG.
+ // Such instructions do not otherwise arise.
+ unsigned Flag = MO.getTargetFlags();
+ if (Flag == PPCII::MO_TPREL_FLAG) {
+ assert(HasAIXSmallLocalExecTLS &&
+ "loads/stores with thread-pointer only expected with "
+ "local-exec small TLS");
+ int64_t Offset = MO.getOffset();
+ LowerPPCMachineInstrToMCInst(MI, TmpInst, *this);
+ const MCExpr *Expr = getAdjustedLocalExecExpr(MO, Offset);
+ if (Expr)
+ TmpInst.getOperand(OpNum) = MCOperand::createExpr(Expr);
+ EmitToStreamer(*OutStreamer, TmpInst);
+ return;
----------------
amy-kwan wrote:
Good point. I can try and make this change.
https://github.com/llvm/llvm-project/pull/71485
More information about the llvm-commits
mailing list