@@ -274,11 +274,11 @@ static bool HasOneUse(unsigned Reg, MachineInstr *Def,
274
274
// TODO: Compute memory dependencies in a way that uses AliasAnalysis to be
275
275
// more precise.
276
276
static bool IsSafeToMove (const MachineInstr *Def, const MachineInstr *Insert,
277
- AliasAnalysis &AA, const LiveIntervals &LIS,
278
- const MachineRegisterInfo &MRI) {
277
+ AliasAnalysis &AA, const MachineRegisterInfo &MRI) {
279
278
assert (Def->getParent () == Insert->getParent ());
280
279
281
280
// Check for register dependencies.
281
+ SmallVector<unsigned , 4 > MutableRegisters;
282
282
for (const MachineOperand &MO : Def->operands ()) {
283
283
if (!MO.isReg () || MO.isUndef ())
284
284
continue ;
@@ -301,29 +301,20 @@ static bool IsSafeToMove(const MachineInstr *Def, const MachineInstr *Insert,
301
301
return false ;
302
302
}
303
303
304
- // Ask LiveIntervals whether moving this virtual register use or def to
305
- // Insert will change which value numbers are seen.
306
- //
307
- // If the operand is a use of a register that is also defined in the same
308
- // instruction, test that the newly defined value reaches the insert point,
309
- // since the operand will be moving along with the def.
310
- const LiveInterval &LI = LIS.getInterval (Reg);
311
- VNInfo *DefVNI =
312
- (MO.isDef () || Def->definesRegister (Reg)) ?
313
- LI.getVNInfoAt (LIS.getInstructionIndex (*Def).getRegSlot ()) :
314
- LI.getVNInfoBefore (LIS.getInstructionIndex (*Def));
315
- assert (DefVNI && " Instruction input missing value number" );
316
- VNInfo *InsVNI = LI.getVNInfoBefore (LIS.getInstructionIndex (*Insert));
317
- if (InsVNI && DefVNI != InsVNI)
318
- return false ;
304
+ // If one of the operands isn't in SSA form, it has different values at
305
+ // different times, and we need to make sure we don't move our use across
306
+ // a different def.
307
+ if (!MO.isDef () && !MRI.hasOneDef (Reg))
308
+ MutableRegisters.push_back (Reg);
319
309
}
320
310
321
311
bool Read = false , Write = false , Effects = false , StackPointer = false ;
322
312
Query (*Def, AA, Read, Write, Effects, StackPointer);
323
313
324
314
// If the instruction does not access memory and has no side effects, it has
325
315
// no additional dependencies.
326
- if (!Read && !Write && !Effects && !StackPointer)
316
+ bool HasMutableRegisters = !MutableRegisters.empty ();
317
+ if (!Read && !Write && !Effects && !StackPointer && !HasMutableRegisters)
327
318
return true ;
328
319
329
320
// Scan through the intervening instructions between Def and Insert.
@@ -343,6 +334,11 @@ static bool IsSafeToMove(const MachineInstr *Def, const MachineInstr *Insert,
343
334
return false ;
344
335
if (StackPointer && InterveningStackPointer)
345
336
return false ;
337
+
338
+ for (unsigned Reg : MutableRegisters)
339
+ for (const MachineOperand &MO : I->operands ())
340
+ if (MO.isReg () && MO.isDef () && MO.getReg () == Reg)
341
+ return false ;
346
342
}
347
343
348
344
return true ;
@@ -781,7 +777,7 @@ bool WebAssemblyRegStackify::runOnMachineFunction(MachineFunction &MF) {
781
777
// supports intra-block moves) and it's MachineSink's job to catch all
782
778
// the sinking opportunities anyway.
783
779
bool SameBlock = Def->getParent () == &MBB;
784
- bool CanMove = SameBlock && IsSafeToMove (Def, Insert, AA, LIS, MRI) &&
780
+ bool CanMove = SameBlock && IsSafeToMove (Def, Insert, AA, MRI) &&
785
781
!TreeWalker.IsOnStack (Reg);
786
782
if (CanMove && HasOneUse (Reg, Def, MRI, MDT, LIS)) {
787
783
Insert = MoveForSingleUse (Reg, Op, Def, MBB, Insert, LIS, MFI, MRI);
0 commit comments