[llvm] [X86] Insert CALLSEQ when lowering GlobalTLSAddress for ELF targets (PR #113706)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 25 16:19:47 PDT 2024
================
@@ -18841,8 +18842,25 @@ GetTLSADDR(SelectionDAG &DAG, SDValue Chain, GlobalAddressSDNode *GA,
TGA = DAG.getTargetExternalSymbol("_TLS_MODULE_BASE_", PtrVT, OperandFlags);
auto UI = TGA->use_begin();
// Reuse existing GetTLSADDR node if we can find it.
- if (UI != TGA->use_end())
- return SDValue(*UI->use_begin()->use_begin(), 0);
+ if (UI != TGA->use_end()) {
+ // TLSDESC uses TGA.
+ auto TLSDescOp = UI;
+ assert(TLSDescOp->getOpcode() == X86ISD::TLSDESC &&
+ "Unexpected TLSDESC DAG");
+ // CALLSEQ_END uses TGA via a chain and glue.
+ auto CallSeqEndOp = TLSDescOp->use_begin();
+ assert(CallSeqEndOp->getOpcode() == ISD::CALLSEQ_END &&
+ "Unexpected TLSDESC DAG");
+ // CopyFromReg uses CALLSEQ_END via a chain and glue.
+ auto CopyFromRegOp = CallSeqEndOp->use_begin();
+ assert(CopyFromRegOp->getOpcode() == ISD::CopyFromReg &&
+ "Unexpected TLSDESC DAG");
+ // The Add generated at the final return of this function uses
+ // CopyFromReg.
+ auto AddOp = CopyFromRegOp->use_begin();
+ assert(AddOp->getOpcode() == ISD::ADD && "Unexpected TLSDESC DAG");
+ return SDValue(*AddOp, 0);
----------------
arsenm wrote:
Assuming this will be the only use doesn't feel great. Can you just find the root node, and let the auto-CSE property of the DAG take care of this by simply trying to recreate the add at the end?
https://github.com/llvm/llvm-project/pull/113706
More information about the llvm-commits
mailing list