[llvm] [PowerPC][AIX] Refactor existing logic to handle non-zero offsets for aix-small-local-dynamic-tls (PR #89182)
Felix via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 18 01:06:26 PDT 2024
================
@@ -7600,52 +7594,54 @@ static bool isEligibleToFoldADDIForLocalExecAccesses(SelectionDAG *DAG,
if (!GA)
return false;
- // The local-exec TLS variable should only have the MO_TPREL_FLAG target flag,
- // so this optimization is not performed otherwise if the flag is not set.
+ if (DAG->getTarget().getTLSModel(GA->getGlobal()) == TLSModel::LocalExec) {
+ // The first operand of the ADDIToFold should be the thread pointer.
+ // This transformation is only performed if the first operand of the
+ // addi is the thread pointer.
+ SDValue TPRegNode = ADDIToFold.getOperand(0);
+ RegisterSDNode *TPReg = dyn_cast<RegisterSDNode>(TPRegNode.getNode());
+ if (!TPReg || (TPReg->getReg() != Subtarget.getThreadPointerRegister()))
+ return false;
+ }
+
+ // The local-[exec|dynamic] TLS variable should only have the
+ // [MO_TPREL_FLAG|MO_TLSLD_FLAG] target flags, so this optimization is not
+ // performed otherwise if the flag is not set.
unsigned TargetFlags = GA->getTargetFlags();
- if (TargetFlags != PPCII::MO_TPREL_FLAG)
+ if (!(TargetFlags == PPCII::MO_TPREL_FLAG ||
+ TargetFlags == PPCII::MO_TLSLD_FLAG))
return false;
// If all conditions are satisfied, the ADDI is valid for folding.
return true;
}
-// For non-TOC-based local-exec access where an addi is feeding into another
-// addi, fold this sequence into a single addi if possible.
-// Before this optimization, the sequence appears as:
-// addi rN, r13, sym at le
+// For non-TOC-based local-[exec|dynamic] access where an addi is feeding into
+// another addi, fold this sequence into a single addi if possible. Before this
+// optimization, the sequence appears as:
+// addi rN, r13, sym@[le|ld]
// addi rM, rN, imm
// After this optimization, we can fold the two addi into a single one:
-// addi rM, r13, sym at le + imm
-static void foldADDIForLocalExecAccesses(SDNode *N, SelectionDAG *DAG) {
+// addi rM, r13, sym@[le|ld] + imm
+static void foldADDIForFasterLocalAccesses(SDNode *N, SelectionDAG *DAG) {
if (N->getMachineOpcode() != PPC::ADDI8)
return;
// InitialADDI is the addi feeding into N (also an addi), and the addi that
// we want optimized out.
SDValue InitialADDI = N->getOperand(0);
- if (!isEligibleToFoldADDIForLocalExecAccesses(DAG, InitialADDI))
+ if (!isEligibleToFoldADDIForFasterLocalAccesses(DAG, InitialADDI))
return;
- // At this point, InitialADDI can be folded into a non-TOC-based local-exec
----------------
orcguru wrote:
Similar check already exists in isEligible..., so I removed this one.
https://github.com/llvm/llvm-project/pull/89182
More information about the llvm-commits
mailing list