@@ -4056,7 +4056,10 @@ SDValue SystemZTargetLowering::lowerATOMIC_CMP_SWAP(SDValue Op,
4056
4056
SDValue Success = emitSETCC (DAG, DL, AtomicOp.getValue (1 ),
4057
4057
SystemZ::CCMASK_ICMP, SystemZ::CCMASK_CMP_EQ);
4058
4058
4059
- DAG.ReplaceAllUsesOfValueWith (Op.getValue (0 ), AtomicOp.getValue (0 ));
4059
+ // emitAtomicCmpSwapW() will zero extend the result (original value).
4060
+ SDValue OrigVal = DAG.getNode (ISD::AssertZext, DL, WideVT, AtomicOp.getValue (0 ),
4061
+ DAG.getValueType (NarrowVT));
4062
+ DAG.ReplaceAllUsesOfValueWith (Op.getValue (0 ), OrigVal);
4060
4063
DAG.ReplaceAllUsesOfValueWith (Op.getValue (1 ), Success);
4061
4064
DAG.ReplaceAllUsesOfValueWith (Op.getValue (2 ), AtomicOp.getValue (2 ));
4062
4065
return SDValue ();
@@ -7578,7 +7581,6 @@ MachineBasicBlock *SystemZTargetLowering::emitAtomicLoadMinMax(
7578
7581
MachineBasicBlock *
7579
7582
SystemZTargetLowering::emitAtomicCmpSwapW (MachineInstr &MI,
7580
7583
MachineBasicBlock *MBB) const {
7581
-
7582
7584
MachineFunction &MF = *MBB->getParent ();
7583
7585
const SystemZInstrInfo *TII =
7584
7586
static_cast <const SystemZInstrInfo *>(Subtarget.getInstrInfo ());
@@ -7588,7 +7590,7 @@ SystemZTargetLowering::emitAtomicCmpSwapW(MachineInstr &MI,
7588
7590
Register Dest = MI.getOperand (0 ).getReg ();
7589
7591
MachineOperand Base = earlyUseOperand (MI.getOperand (1 ));
7590
7592
int64_t Disp = MI.getOperand (2 ).getImm ();
7591
- Register OrigCmpVal = MI.getOperand (3 ).getReg ();
7593
+ Register CmpVal = MI.getOperand (3 ).getReg ();
7592
7594
Register OrigSwapVal = MI.getOperand (4 ).getReg ();
7593
7595
Register BitShift = MI.getOperand (5 ).getReg ();
7594
7596
Register NegBitShift = MI.getOperand (6 ).getReg ();
@@ -7597,19 +7599,19 @@ SystemZTargetLowering::emitAtomicCmpSwapW(MachineInstr &MI,
7597
7599
7598
7600
const TargetRegisterClass *RC = &SystemZ::GR32BitRegClass;
7599
7601
7600
- // Get the right opcodes for the displacement.
7602
+ // Get the right opcodes for the displacement and zero-extension .
7601
7603
unsigned LOpcode = TII->getOpcodeForOffset (SystemZ::L, Disp);
7602
7604
unsigned CSOpcode = TII->getOpcodeForOffset (SystemZ::CS, Disp);
7605
+ unsigned ZExtOpcode = BitSize == 8 ? SystemZ::LLCR : SystemZ::LLHR;
7603
7606
assert (LOpcode && CSOpcode && " Displacement out of range" );
7604
7607
7605
7608
// Create virtual registers for temporary results.
7606
7609
Register OrigOldVal = MRI.createVirtualRegister (RC);
7607
7610
Register OldVal = MRI.createVirtualRegister (RC);
7608
- Register CmpVal = MRI.createVirtualRegister (RC);
7609
7611
Register SwapVal = MRI.createVirtualRegister (RC);
7610
7612
Register StoreVal = MRI.createVirtualRegister (RC);
7613
+ Register OldValRot = MRI.createVirtualRegister (RC);
7611
7614
Register RetryOldVal = MRI.createVirtualRegister (RC);
7612
- Register RetryCmpVal = MRI.createVirtualRegister (RC);
7613
7615
Register RetrySwapVal = MRI.createVirtualRegister (RC);
7614
7616
7615
7617
// Insert 2 basic blocks for the loop.
@@ -7631,52 +7633,45 @@ SystemZTargetLowering::emitAtomicCmpSwapW(MachineInstr &MI,
7631
7633
7632
7634
// LoopMBB:
7633
7635
// %OldVal = phi [ %OrigOldVal, EntryBB ], [ %RetryOldVal, SetMBB ]
7634
- // %CmpVal = phi [ %OrigCmpVal, EntryBB ], [ %RetryCmpVal, SetMBB ]
7635
7636
// %SwapVal = phi [ %OrigSwapVal, EntryBB ], [ %RetrySwapVal, SetMBB ]
7636
- // %Dest = RLL %OldVal, BitSize(%BitShift)
7637
+ // %OldValRot = RLL %OldVal, BitSize(%BitShift)
7637
7638
// ^^ The low BitSize bits contain the field
7638
7639
// of interest.
7639
- // %RetryCmpVal = RISBG32 %CmpVal , %Dest , 32, 63-BitSize, 0
7640
+ // %RetrySwapVal = RISBG32 %SwapVal , %OldValRot , 32, 63-BitSize, 0
7640
7641
// ^^ Replace the upper 32-BitSize bits of the
7641
- // comparison value with those that we loaded,
7642
- // so that we can use a full word comparison.
7643
- // CR %Dest, %RetryCmpVal
7642
+ // swap value with those that we loaded and rotated.
7643
+ // %Dest = LL[CH] %OldValRot
7644
+ // CR %Dest, %CmpVal
7644
7645
// JNE DoneMBB
7645
7646
// # Fall through to SetMBB
7646
7647
MBB = LoopMBB;
7647
7648
BuildMI (MBB, DL, TII->get (SystemZ::PHI), OldVal)
7648
7649
.addReg (OrigOldVal).addMBB (StartMBB)
7649
7650
.addReg (RetryOldVal).addMBB (SetMBB);
7650
- BuildMI (MBB, DL, TII->get (SystemZ::PHI), CmpVal)
7651
- .addReg (OrigCmpVal).addMBB (StartMBB)
7652
- .addReg (RetryCmpVal).addMBB (SetMBB);
7653
7651
BuildMI (MBB, DL, TII->get (SystemZ::PHI), SwapVal)
7654
7652
.addReg (OrigSwapVal).addMBB (StartMBB)
7655
7653
.addReg (RetrySwapVal).addMBB (SetMBB);
7656
- BuildMI (MBB, DL, TII->get (SystemZ::RLL), Dest )
7654
+ BuildMI (MBB, DL, TII->get (SystemZ::RLL), OldValRot )
7657
7655
.addReg (OldVal).addReg (BitShift).addImm (BitSize);
7658
- BuildMI (MBB, DL, TII->get (SystemZ::RISBG32), RetryCmpVal)
7659
- .addReg (CmpVal).addReg (Dest).addImm (32 ).addImm (63 - BitSize).addImm (0 );
7656
+ BuildMI (MBB, DL, TII->get (SystemZ::RISBG32), RetrySwapVal)
7657
+ .addReg (SwapVal).addReg (OldValRot).addImm (32 ).addImm (63 - BitSize).addImm (0 );
7658
+ BuildMI (MBB, DL, TII->get (ZExtOpcode), Dest)
7659
+ .addReg (OldValRot);
7660
7660
BuildMI (MBB, DL, TII->get (SystemZ::CR))
7661
- .addReg (Dest).addReg (RetryCmpVal );
7661
+ .addReg (Dest).addReg (CmpVal );
7662
7662
BuildMI (MBB, DL, TII->get (SystemZ::BRC))
7663
7663
.addImm (SystemZ::CCMASK_ICMP)
7664
7664
.addImm (SystemZ::CCMASK_CMP_NE).addMBB (DoneMBB);
7665
7665
MBB->addSuccessor (DoneMBB);
7666
7666
MBB->addSuccessor (SetMBB);
7667
7667
7668
7668
// SetMBB:
7669
- // %RetrySwapVal = RISBG32 %SwapVal, %Dest, 32, 63-BitSize, 0
7670
- // ^^ Replace the upper 32-BitSize bits of the new
7671
- // value with those that we loaded.
7672
- // %StoreVal = RLL %RetrySwapVal, -BitSize(%NegBitShift)
7669
+ // %StoreVal = RLL %RetrySwapVal, -BitSize(%NegBitShift)
7673
7670
// ^^ Rotate the new field to its proper position.
7674
- // %RetryOldVal = CS %Dest , %StoreVal, Disp(%Base)
7671
+ // %RetryOldVal = CS %OldVal , %StoreVal, Disp(%Base)
7675
7672
// JNE LoopMBB
7676
7673
// # fall through to ExitMMB
7677
7674
MBB = SetMBB;
7678
- BuildMI (MBB, DL, TII->get (SystemZ::RISBG32), RetrySwapVal)
7679
- .addReg (SwapVal).addReg (Dest).addImm (32 ).addImm (63 - BitSize).addImm (0 );
7680
7675
BuildMI (MBB, DL, TII->get (SystemZ::RLL), StoreVal)
7681
7676
.addReg (RetrySwapVal).addReg (NegBitShift).addImm (-BitSize);
7682
7677
BuildMI (MBB, DL, TII->get (CSOpcode), RetryOldVal)
0 commit comments