@@ -7587,29 +7587,23 @@ static bool hasAIXSmallTLSAttr(SDValue Val) {
7587
7587
return false ;
7588
7588
}
7589
7589
7590
- // Is an ADDI eligible for folding for non-TOC-based local-exec accesses?
7591
- static bool isEligibleToFoldADDIForLocalExecAccesses (SelectionDAG *DAG,
7592
- SDValue ADDIToFold) {
7590
+ // Is an ADDI eligible for folding for non-TOC-based local-[exec|dynamic]
7591
+ // accesses?
7592
+ static bool isEligibleToFoldADDIForFasterLocalAccesses (SelectionDAG *DAG,
7593
+ SDValue ADDIToFold) {
7593
7594
// Check if ADDIToFold (the ADDI that we want to fold into local-exec
7594
7595
// accesses), is truly an ADDI.
7595
7596
if (!ADDIToFold.isMachineOpcode () ||
7596
7597
(ADDIToFold.getMachineOpcode () != PPC::ADDI8))
7597
7598
return false ;
7598
7599
7599
- // Folding is only allowed for the AIX small-local-exec TLS target attribute
7600
- // or when the 'aix-small-tls' global variable attribute is present.
7600
+ // Folding is only allowed for the AIX small-local-[ exec|dynamic] TLS target
7601
+ // attribute or when the 'aix-small-tls' global variable attribute is present.
7601
7602
const PPCSubtarget &Subtarget =
7602
7603
DAG->getMachineFunction ().getSubtarget <PPCSubtarget>();
7603
7604
SDValue TLSVarNode = ADDIToFold.getOperand (1 );
7604
- if (!(Subtarget.hasAIXSmallLocalExecTLS () || hasAIXSmallTLSAttr (TLSVarNode)))
7605
- return false ;
7606
-
7607
- // The first operand of the ADDIToFold should be the thread pointer.
7608
- // This transformation is only performed if the first operand of the
7609
- // addi is the thread pointer.
7610
- SDValue TPRegNode = ADDIToFold.getOperand (0 );
7611
- RegisterSDNode *TPReg = dyn_cast<RegisterSDNode>(TPRegNode.getNode ());
7612
- if (!TPReg || (TPReg->getReg () != Subtarget.getThreadPointerRegister ()))
7605
+ if (!(Subtarget.hasAIXSmallLocalDynamicTLS () ||
7606
+ Subtarget.hasAIXSmallLocalExecTLS () || hasAIXSmallTLSAttr (TLSVarNode)))
7613
7607
return false ;
7614
7608
7615
7609
// The second operand of the ADDIToFold should be the global TLS address
@@ -7619,52 +7613,54 @@ static bool isEligibleToFoldADDIForLocalExecAccesses(SelectionDAG *DAG,
7619
7613
if (!GA)
7620
7614
return false ;
7621
7615
7622
- // The local-exec TLS variable should only have the MO_TPREL_FLAG target flag,
7623
- // so this optimization is not performed otherwise if the flag is not set.
7616
+ if (DAG->getTarget ().getTLSModel (GA->getGlobal ()) == TLSModel::LocalExec) {
7617
+ // The first operand of the ADDIToFold should be the thread pointer.
7618
+ // This transformation is only performed if the first operand of the
7619
+ // addi is the thread pointer.
7620
+ SDValue TPRegNode = ADDIToFold.getOperand (0 );
7621
+ RegisterSDNode *TPReg = dyn_cast<RegisterSDNode>(TPRegNode.getNode ());
7622
+ if (!TPReg || (TPReg->getReg () != Subtarget.getThreadPointerRegister ()))
7623
+ return false ;
7624
+ }
7625
+
7626
+ // The local-[exec|dynamic] TLS variable should only have the
7627
+ // [MO_TPREL_FLAG|MO_TLSLD_FLAG] target flags, so this optimization is not
7628
+ // performed otherwise if the flag is not set.
7624
7629
unsigned TargetFlags = GA->getTargetFlags ();
7625
- if (TargetFlags != PPCII::MO_TPREL_FLAG)
7630
+ if (!(TargetFlags == PPCII::MO_TPREL_FLAG ||
7631
+ TargetFlags == PPCII::MO_TLSLD_FLAG))
7626
7632
return false ;
7627
7633
7628
7634
// If all conditions are satisfied, the ADDI is valid for folding.
7629
7635
return true ;
7630
7636
}
7631
7637
7632
- // For non-TOC-based local-exec access where an addi is feeding into another
7633
- // addi, fold this sequence into a single addi if possible.
7634
- // Before this optimization, the sequence appears as:
7635
- // addi rN, r13, sym@le
7638
+ // For non-TOC-based local-[ exec|dynamic] access where an addi is feeding into
7639
+ // another addi, fold this sequence into a single addi if possible. Before this
7640
+ // optimization, the sequence appears as:
7641
+ // addi rN, r13, sym@[le|ld]
7636
7642
// addi rM, rN, imm
7637
7643
// After this optimization, we can fold the two addi into a single one:
7638
- // addi rM, r13, sym@le + imm
7639
- static void foldADDIForLocalExecAccesses (SDNode *N, SelectionDAG *DAG) {
7644
+ // addi rM, r13, sym@[le|ld] + imm
7645
+ static void foldADDIForFasterLocalAccesses (SDNode *N, SelectionDAG *DAG) {
7640
7646
if (N->getMachineOpcode () != PPC::ADDI8)
7641
7647
return ;
7642
7648
7643
7649
// InitialADDI is the addi feeding into N (also an addi), and the addi that
7644
7650
// we want optimized out.
7645
7651
SDValue InitialADDI = N->getOperand (0 );
7646
7652
7647
- if (!isEligibleToFoldADDIForLocalExecAccesses (DAG, InitialADDI))
7653
+ if (!isEligibleToFoldADDIForFasterLocalAccesses (DAG, InitialADDI))
7648
7654
return ;
7649
7655
7650
- // At this point, InitialADDI can be folded into a non-TOC-based local-exec
7651
- // access. The first operand of InitialADDI should be the thread pointer,
7652
- // which has been checked in isEligibleToFoldADDIForLocalExecAccesses().
7653
- SDValue TPRegNode = InitialADDI.getOperand (0 );
7654
- [[maybe_unused]] RegisterSDNode *TPReg = dyn_cast<RegisterSDNode>(TPRegNode.getNode ());
7655
- [[maybe_unused]] const PPCSubtarget &Subtarget =
7656
- DAG->getMachineFunction ().getSubtarget <PPCSubtarget>();
7657
- assert ((TPReg && (TPReg->getReg () == Subtarget.getThreadPointerRegister ())) &&
7658
- " Expecting the first operand to be a thread pointer for folding addi "
7659
- " in local-exec accesses!" );
7660
-
7661
7656
// The second operand of the InitialADDI should be the global TLS address
7662
- // (the local-exec TLS variable), with the MO_TPREL_FLAG target flag.
7663
- // This has been checked in isEligibleToFoldADDIForLocalExecAccesses().
7657
+ // (the local-[exec|dynamic] TLS variable), with the
7658
+ // [MO_TPREL_FLAG|MO_TLSLD_FLAG] target flag. This has been checked in
7659
+ // isEligibleToFoldADDIForFasterLocalAccesses().
7664
7660
SDValue TLSVarNode = InitialADDI.getOperand (1 );
7665
7661
GlobalAddressSDNode *GA = dyn_cast<GlobalAddressSDNode>(TLSVarNode);
7666
7662
assert (GA && " Expecting a valid GlobalAddressSDNode when folding addi into "
7667
- " local-exec accesses!" );
7663
+ " local-[ exec|dynamic] accesses!" );
7668
7664
unsigned TargetFlags = GA->getTargetFlags ();
7669
7665
7670
7666
// The second operand of the addi that we want to preserve will be an
@@ -7676,7 +7672,7 @@ static void foldADDIForLocalExecAccesses(SDNode *N, SelectionDAG *DAG) {
7676
7672
TLSVarNode = DAG->getTargetGlobalAddress (GA->getGlobal (), SDLoc (GA), MVT::i64 ,
7677
7673
Offset, TargetFlags);
7678
7674
7679
- (void )DAG->UpdateNodeOperands (N, TPRegNode , TLSVarNode);
7675
+ (void )DAG->UpdateNodeOperands (N, InitialADDI. getOperand ( 0 ) , TLSVarNode);
7680
7676
if (InitialADDI.getNode ()->use_empty ())
7681
7677
DAG->RemoveDeadNode (InitialADDI.getNode ());
7682
7678
}
@@ -7693,8 +7689,9 @@ void PPCDAGToDAGISel::PeepholePPC64() {
7693
7689
if (isVSXSwap (SDValue (N, 0 )))
7694
7690
reduceVSXSwap (N, CurDAG);
7695
7691
7696
- // This optimization is performed for non-TOC-based local-exec accesses.
7697
- foldADDIForLocalExecAccesses (N, CurDAG);
7692
+ // This optimization is performed for non-TOC-based local-[exec|dynamic]
7693
+ // accesses.
7694
+ foldADDIForFasterLocalAccesses (N, CurDAG);
7698
7695
7699
7696
unsigned FirstOp;
7700
7697
unsigned StorageOpcode = N->getMachineOpcode ();
@@ -7852,13 +7849,15 @@ void PPCDAGToDAGISel::PeepholePPC64() {
7852
7849
ImmOpnd = CurDAG->getTargetConstant (Offset, SDLoc (ImmOpnd),
7853
7850
ImmOpnd.getValueType ());
7854
7851
} else if (Offset != 0 ) {
7855
- // This optimization is performed for non-TOC-based local-exec accesses.
7856
- if (isEligibleToFoldADDIForLocalExecAccesses (CurDAG, Base)) {
7852
+ // This optimization is performed for non-TOC-based local-[exec|dynamic]
7853
+ // accesses.
7854
+ if (isEligibleToFoldADDIForFasterLocalAccesses (CurDAG, Base)) {
7857
7855
// Add the non-zero offset information into the load or store
7858
- // instruction to be used for non-TOC-based local-exec accesses.
7856
+ // instruction to be used for non-TOC-based local-[exec|dynamic]
7857
+ // accesses.
7859
7858
GlobalAddressSDNode *GA = dyn_cast<GlobalAddressSDNode>(ImmOpnd);
7860
7859
assert (GA && " Expecting a valid GlobalAddressSDNode when folding "
7861
- " addi into local-exec accesses!" );
7860
+ " addi into local-[ exec|dynamic] accesses!" );
7862
7861
ImmOpnd = CurDAG->getTargetGlobalAddress (GA->getGlobal (), SDLoc (GA),
7863
7862
MVT::i64 , Offset,
7864
7863
GA->getTargetFlags ());
0 commit comments