@@ -202,8 +202,7 @@ namespace {
202
202
bool isMoveImmediate (MachineInstr &MI, SmallSet<Register, 4 > &ImmDefRegs,
203
203
DenseMap<Register, MachineInstr *> &ImmDefMIs);
204
204
bool foldImmediate (MachineInstr &MI, SmallSet<Register, 4 > &ImmDefRegs,
205
- DenseMap<Register, MachineInstr *> &ImmDefMIs,
206
- bool &Deleted);
205
+ DenseMap<Register, MachineInstr *> &ImmDefMIs);
207
206
208
207
// / Finds recurrence cycles, but only ones that formulated around
209
208
// / a def operand and a use operand that are tied. If there is a use
@@ -218,11 +217,8 @@ namespace {
218
217
// / set \p CopyMIs. If this virtual register was previously seen as a
219
218
// / copy, replace the uses of this copy with the previously seen copy's
220
219
// / destination register.
221
- // / \p LocalMIs contains all previous seen instructions. An optimized away
222
- // / instruction should be deleted from LocalMIs.
223
220
bool foldRedundantCopy (MachineInstr &MI,
224
- DenseMap<RegSubRegPair, MachineInstr *> &CopyMIs,
225
- SmallPtrSetImpl<MachineInstr *> &LocalMIs);
221
+ DenseMap<RegSubRegPair, MachineInstr *> &CopyMIs);
226
222
227
223
// / Is the register \p Reg a non-allocatable physical register?
228
224
bool isNAPhysCopy (Register Reg);
@@ -1355,28 +1351,26 @@ bool PeepholeOptimizer::isMoveImmediate(
1355
1351
MachineInstr &MI, SmallSet<Register, 4 > &ImmDefRegs,
1356
1352
DenseMap<Register, MachineInstr *> &ImmDefMIs) {
1357
1353
const MCInstrDesc &MCID = MI.getDesc ();
1358
- if (MCID. getNumDefs () != 1 || ! MI.getOperand ( 0 ). isReg ())
1354
+ if (! MI.isMoveImmediate ())
1359
1355
return false ;
1360
- Register Reg = MI.getOperand (0 ).getReg ();
1361
- if (!Reg.isVirtual ())
1362
- return false ;
1363
-
1364
- int64_t ImmVal;
1365
- if (!MI.isMoveImmediate () && !TII->getConstValDefinedInReg (MI, Reg, ImmVal))
1356
+ if (MCID.getNumDefs () != 1 )
1366
1357
return false ;
1358
+ Register Reg = MI.getOperand (0 ).getReg ();
1359
+ if (Reg.isVirtual ()) {
1360
+ ImmDefMIs.insert (std::make_pair (Reg, &MI));
1361
+ ImmDefRegs.insert (Reg);
1362
+ return true ;
1363
+ }
1367
1364
1368
- ImmDefMIs.insert (std::make_pair (Reg, &MI));
1369
- ImmDefRegs.insert (Reg);
1370
- return true ;
1365
+ return false ;
1371
1366
}
1372
1367
1373
1368
// / Try folding register operands that are defined by move immediate
1374
1369
// / instructions, i.e. a trivial constant folding optimization, if
1375
1370
// / and only if the def and use are in the same BB.
1376
1371
bool PeepholeOptimizer::foldImmediate (
1377
1372
MachineInstr &MI, SmallSet<Register, 4 > &ImmDefRegs,
1378
- DenseMap<Register, MachineInstr *> &ImmDefMIs, bool &Deleted) {
1379
- Deleted = false ;
1373
+ DenseMap<Register, MachineInstr *> &ImmDefMIs) {
1380
1374
for (unsigned i = 0 , e = MI.getDesc ().getNumOperands (); i != e; ++i) {
1381
1375
MachineOperand &MO = MI.getOperand (i);
1382
1376
if (!MO.isReg () || MO.isDef ())
@@ -1390,19 +1384,6 @@ bool PeepholeOptimizer::foldImmediate(
1390
1384
assert (II != ImmDefMIs.end () && " couldn't find immediate definition" );
1391
1385
if (TII->FoldImmediate (MI, *II->second , Reg, MRI)) {
1392
1386
++NumImmFold;
1393
- // FoldImmediate can delete ImmDefMI if MI was its only user. If ImmDefMI
1394
- // is not deleted, and we happened to get a same MI, we can delete MI and
1395
- // replace its users.
1396
- if (MRI->getVRegDef (Reg) &&
1397
- MI.isIdenticalTo (*II->second , MachineInstr::IgnoreVRegDefs)) {
1398
- Register DstReg = MI.getOperand (0 ).getReg ();
1399
- if (DstReg.isVirtual () &&
1400
- MRI->getRegClass (DstReg) == MRI->getRegClass (Reg)) {
1401
- MRI->replaceRegWith (DstReg, Reg);
1402
- MI.eraseFromParent ();
1403
- Deleted = true ;
1404
- }
1405
- }
1406
1387
return true ;
1407
1388
}
1408
1389
}
@@ -1424,8 +1405,7 @@ bool PeepholeOptimizer::foldImmediate(
1424
1405
//
1425
1406
// Should replace %2 uses with %1:sub1
1426
1407
bool PeepholeOptimizer::foldRedundantCopy (
1427
- MachineInstr &MI, DenseMap<RegSubRegPair, MachineInstr *> &CopyMIs,
1428
- SmallPtrSetImpl<MachineInstr *> &LocalMIs) {
1408
+ MachineInstr &MI, DenseMap<RegSubRegPair, MachineInstr *> &CopyMIs) {
1429
1409
assert (MI.isCopy () && " expected a COPY machine instruction" );
1430
1410
1431
1411
Register SrcReg = MI.getOperand (1 ).getReg ();
@@ -1445,10 +1425,6 @@ bool PeepholeOptimizer::foldRedundantCopy(
1445
1425
}
1446
1426
1447
1427
MachineInstr *PrevCopy = CopyMIs.find (SrcPair)->second ;
1448
- // A COPY instruction can be deleted or changed by other optimizations.
1449
- // Check if the previous COPY instruction is existing and still a COPY.
1450
- if (!LocalMIs.count (PrevCopy) || !PrevCopy->isCopy ())
1451
- return false ;
1452
1428
1453
1429
assert (SrcSubReg == PrevCopy->getOperand (1 ).getSubReg () &&
1454
1430
" Unexpected mismatching subreg!" );
@@ -1756,7 +1732,7 @@ bool PeepholeOptimizer::runOnMachineFunction(MachineFunction &MF) {
1756
1732
continue ;
1757
1733
}
1758
1734
1759
- if (MI->isCopy () && (foldRedundantCopy (*MI, CopySrcMIs, LocalMIs ) ||
1735
+ if (MI->isCopy () && (foldRedundantCopy (*MI, CopySrcMIs) ||
1760
1736
foldRedundantNAPhysCopy (*MI, NAPhysToVirtMIs))) {
1761
1737
LocalMIs.erase (MI);
1762
1738
LLVM_DEBUG (dbgs () << " Deleting redundant copy: " << *MI << " \n " );
@@ -1774,14 +1750,8 @@ bool PeepholeOptimizer::runOnMachineFunction(MachineFunction &MF) {
1774
1750
// next iteration sees the new instructions.
1775
1751
MII = MI;
1776
1752
++MII;
1777
- if (SeenMoveImm) {
1778
- bool Deleted;
1779
- Changed |= foldImmediate (*MI, ImmDefRegs, ImmDefMIs, Deleted);
1780
- if (Deleted) {
1781
- LocalMIs.erase (MI);
1782
- continue ;
1783
- }
1784
- }
1753
+ if (SeenMoveImm)
1754
+ Changed |= foldImmediate (*MI, ImmDefRegs, ImmDefMIs);
1785
1755
}
1786
1756
1787
1757
// Check whether MI is a load candidate for folding into a later
0 commit comments