@@ -7635,7 +7635,6 @@ void PPCDAGToDAGISel::PeepholePPC64() {
7635
7635
break ;
7636
7636
case PPC::ADDItoc:
7637
7637
case PPC::ADDItoc8:
7638
- ReplaceFlags = false ;
7639
7638
if (RequiresMod4Offset) {
7640
7639
if (GlobalAddressSDNode *GA =
7641
7640
dyn_cast<GlobalAddressSDNode>(Base.getOperand (0 ))) {
@@ -7650,58 +7649,42 @@ void PPCDAGToDAGISel::PeepholePPC64() {
7650
7649
break ;
7651
7650
}
7652
7651
7653
- const unsigned BaseOpcode = Base.getMachineOpcode ();
7654
- // ADDItoc and ADDItoc8 are pseudos used exclusively by AIX small code
7655
- // model when a global is defined in the TOC.
7656
- const bool OpcodeIsAIXSmallTocData =
7657
- BaseOpcode == PPC::ADDItoc || BaseOpcode == PPC::ADDItoc8;
7652
+ SDValue ImmOpnd = Base.getOperand (1 );
7658
7653
7659
- SDValue RegOperand;
7660
- SDValue ImmOpnd;
7661
- // The AIX small code model nodes have the operands reversed.
7662
- if (OpcodeIsAIXSmallTocData) {
7663
- RegOperand = Base. getOperand ( 1 ) ;
7664
- ImmOpnd = Base. getOperand ( 0 );
7665
- } else {
7666
- RegOperand = Base. getOperand ( 0 );
7667
- ImmOpnd = Base. getOperand ( 1 );
7654
+ // On PPC64, the TOC base pointer is guaranteed by the ABI only to have
7655
+ // 8-byte alignment, and so we can only use offsets less than 8 (otherwise,
7656
+ // we might have needed different @ha relocation values for the offset
7657
+ // pointers).
7658
+ int MaxDisplacement = 7 ;
7659
+ if (GlobalAddressSDNode *GA = dyn_cast<GlobalAddressSDNode>(ImmOpnd)) {
7660
+ const GlobalValue *GV = GA-> getGlobal ();
7661
+ Align Alignment = GV-> getPointerAlignment (CurDAG-> getDataLayout () );
7662
+ MaxDisplacement = std::min (( int )Alignment. value () - 1 , MaxDisplacement );
7668
7663
}
7669
7664
7670
- int Offset = N->getConstantOperandVal (FirstOp);
7671
-
7672
- SDValue HBase;
7673
7665
bool UpdateHBase = false ;
7674
- if (ReplaceFlags) {
7675
- // On PPC64, the TOC base pointer is guaranteed by the ABI only to have
7676
- // 8-byte alignment, and so we can only use offsets less than 8
7677
- // (otherwise, we might have needed different @ha relocation values for
7678
- // the offset pointers).
7679
- int MaxDisplacement = 7 ;
7680
- if (GlobalAddressSDNode *GA = dyn_cast<GlobalAddressSDNode>(ImmOpnd)) {
7681
- const GlobalValue *GV = GA->getGlobal ();
7682
- Align Alignment = GV->getPointerAlignment (CurDAG->getDataLayout ());
7683
- MaxDisplacement = std::min ((int )Alignment.value () - 1 , MaxDisplacement);
7684
- }
7666
+ SDValue HBase = Base.getOperand (0 );
7685
7667
7668
+ int Offset = N->getConstantOperandVal (FirstOp);
7669
+ if (ReplaceFlags) {
7686
7670
if (Offset < 0 || Offset > MaxDisplacement) {
7687
7671
// If we have a addi(toc@l)/addis(toc@ha) pair, and the addis has only
7688
7672
// one use, then we can do this for any offset, we just need to also
7689
7673
// update the offset (i.e. the symbol addend) on the addis also.
7690
- if (BaseOpcode != PPC::ADDItocL)
7674
+ if (Base. getMachineOpcode () != PPC::ADDItocL)
7691
7675
continue ;
7692
7676
7693
- if (!RegOperand .isMachineOpcode () ||
7694
- RegOperand .getMachineOpcode () != PPC::ADDIStocHA8)
7677
+ if (!HBase .isMachineOpcode () ||
7678
+ HBase .getMachineOpcode () != PPC::ADDIStocHA8)
7695
7679
continue ;
7696
7680
7697
- if (!Base.hasOneUse () || !RegOperand .hasOneUse ())
7681
+ if (!Base.hasOneUse () || !HBase .hasOneUse ())
7698
7682
continue ;
7699
7683
7700
- SDValue HImmOpnd = RegOperand .getOperand (1 );
7684
+ SDValue HImmOpnd = HBase .getOperand (1 );
7701
7685
if (HImmOpnd != ImmOpnd)
7702
7686
continue ;
7703
7687
7704
- HBase = RegOperand;
7705
7688
UpdateHBase = true ;
7706
7689
}
7707
7690
} else {
@@ -7726,10 +7709,10 @@ void PPCDAGToDAGISel::PeepholePPC64() {
7726
7709
}
7727
7710
}
7728
7711
7729
- // We found an opportunity. Forward the operands from the add
7730
- // immediate to the load or store. If needed, update the target
7731
- // flags for the immediate operand to reflect the necessary
7732
- // relocation information.
7712
+ // We found an opportunity. Reverse the operands from the add
7713
+ // immediate and substitute them into the load or store. If
7714
+ // needed, update the target flags for the immediate operand to
7715
+ // reflect the necessary relocation information.
7733
7716
LLVM_DEBUG (dbgs () << " Folding add-immediate into mem-op:\n Base: " );
7734
7717
LLVM_DEBUG (Base->dump (CurDAG));
7735
7718
LLVM_DEBUG (dbgs () << " \n N: " );
@@ -7745,10 +7728,6 @@ void PPCDAGToDAGISel::PeepholePPC64() {
7745
7728
Align Alignment = GV->getPointerAlignment (CurDAG->getDataLayout ());
7746
7729
// We can't perform this optimization for data whose alignment
7747
7730
// is insufficient for the instruction encoding.
7748
- // TODO FIXME Verify and document why the offset must be a multiple of
7749
- // 4 when the aligment is less than 4. It is not about the encoding of
7750
- // the instruction: the value of Offset comes directly from the original
7751
- // load/store instruction on the path that reaches this check.
7752
7731
if (Alignment < 4 && (RequiresMod4Offset || (Offset % 4 ) != 0 )) {
7753
7732
LLVM_DEBUG (dbgs () << " Rejected this candidate for alignment.\n\n " );
7754
7733
continue ;
@@ -7762,12 +7741,27 @@ void PPCDAGToDAGISel::PeepholePPC64() {
7762
7741
}
7763
7742
}
7764
7743
7744
+ const unsigned BaseOpcode = Base.getMachineOpcode ();
7745
+ // ADDItoc and ADDItoc8 are pseudos used exclusively by AIX small code
7746
+ // model when a global is defined in the TOC.
7747
+ const bool OpcodeIsAIXTocData =
7748
+ BaseOpcode == PPC::ADDItoc || BaseOpcode == PPC::ADDItoc8;
7749
+
7765
7750
if (FirstOp == 1 ) // Store
7766
- (void )CurDAG->UpdateNodeOperands (N, N->getOperand (0 ), ImmOpnd, RegOperand,
7767
- N->getOperand (3 ));
7751
+ if (OpcodeIsAIXTocData)
7752
+ (void )CurDAG->UpdateNodeOperands (N, N->getOperand (0 ),
7753
+ Base.getOperand (0 ), Base.getOperand (1 ),
7754
+ N->getOperand (3 ));
7755
+ else
7756
+ (void )CurDAG->UpdateNodeOperands (N, N->getOperand (0 ), ImmOpnd,
7757
+ Base.getOperand (0 ), N->getOperand (3 ));
7768
7758
else // Load
7769
- (void )CurDAG->UpdateNodeOperands (N, ImmOpnd, RegOperand,
7770
- N->getOperand (2 ));
7759
+ if (OpcodeIsAIXTocData)
7760
+ (void )CurDAG->UpdateNodeOperands (N, Base.getOperand (0 ),
7761
+ Base.getOperand (1 ), N->getOperand (2 ));
7762
+ else
7763
+ (void )CurDAG->UpdateNodeOperands (N, ImmOpnd, Base.getOperand (0 ),
7764
+ N->getOperand (2 ));
7771
7765
7772
7766
if (UpdateHBase)
7773
7767
(void )CurDAG->UpdateNodeOperands (HBase.getNode (), HBase.getOperand (0 ),
0 commit comments