@@ -622,9 +622,18 @@ MachineInstr *SystemZInstrInfo::optimizeLoadInstr(MachineInstr &MI,
622
622
!MRI->hasOneNonDBGUse (FoldAsLoadDefReg))
623
623
return nullptr ;
624
624
625
- int UseOpIdx = MI.findRegisterUseOperandIdx (FoldAsLoadDefReg);
625
+ int UseOpIdx =
626
+ MI.findRegisterUseOperandIdx (FoldAsLoadDefReg, /* TRI=*/ nullptr );
626
627
assert (UseOpIdx != -1 && " Expected FoldAsLoadDefReg to be used by MI." );
627
- return foldMemoryOperand (MI, {((unsigned ) UseOpIdx)}, *DefMI);
628
+
629
+ // Check whether we can fold the load.
630
+ if (MachineInstr *FoldMI =
631
+ foldMemoryOperand (MI, {((unsigned )UseOpIdx)}, *DefMI)) {
632
+ FoldAsLoadDefReg = 0 ;
633
+ return FoldMI;
634
+ }
635
+
636
+ return nullptr ;
628
637
}
629
638
630
639
bool SystemZInstrInfo::foldImmediate (MachineInstr &UseMI, MachineInstr &DefMI,
@@ -955,8 +964,9 @@ static LogicOp interpretAndImmediate(unsigned Opcode) {
955
964
}
956
965
957
966
static void transferDeadCC (MachineInstr *OldMI, MachineInstr *NewMI) {
958
- if (OldMI->registerDefIsDead (SystemZ::CC)) {
959
- MachineOperand *CCDef = NewMI->findRegisterDefOperand (SystemZ::CC);
967
+ if (OldMI->registerDefIsDead (SystemZ::CC, /* TRI=*/ nullptr )) {
968
+ MachineOperand *CCDef =
969
+ NewMI->findRegisterDefOperand (SystemZ::CC, /* TRI=*/ nullptr );
960
970
if (CCDef != nullptr )
961
971
CCDef->setIsDead (true );
962
972
}
@@ -1453,8 +1463,8 @@ MachineInstr *SystemZInstrInfo::foldMemoryOperandImpl(
1453
1463
assert (LoadMI != InsertPt && " Assuming InsertPt not to be first in MBB." );
1454
1464
for (MachineBasicBlock::iterator MII = std::prev (InsertPt);;
1455
1465
--MII) {
1456
- if (MII->definesRegister (SystemZ::CC)) {
1457
- if (!MII->registerDefIsDead (SystemZ::CC))
1466
+ if (MII->definesRegister (SystemZ::CC, /* TRI= */ nullptr )) {
1467
+ if (!MII->registerDefIsDead (SystemZ::CC, /* TRI= */ nullptr ))
1458
1468
return nullptr ;
1459
1469
break ;
1460
1470
}
@@ -1467,9 +1477,8 @@ MachineInstr *SystemZInstrInfo::foldMemoryOperandImpl(
1467
1477
}
1468
1478
1469
1479
Register FoldAsLoadDefReg = LoadMI.getOperand (0 ).getReg ();
1470
- // We don't really need Ops, but do a sanity check:
1471
- assert (Ops.size () == 1 && FoldAsLoadDefReg == MI.getOperand (Ops[0 ]).getReg () &&
1472
- " Expected MI to have the only use of the load." );
1480
+ if (Ops.size () != 1 || FoldAsLoadDefReg != MI.getOperand (Ops[0 ]).getReg ())
1481
+ return nullptr ;
1473
1482
Register DstReg = MI.getOperand (0 ).getReg ();
1474
1483
MachineOperand LHS = MI.getOperand (1 );
1475
1484
MachineOperand RHS = MI.getOperand (2 );
0 commit comments