@@ -1448,3 +1448,61 @@ void AIEBaseInstrInfo::insertSelect(MachineBasicBlock &MBB,
14481448      .addReg (Support->getSelectSrcOperand (InputOperands, 1 ))
14491449      .addReg (Support->getSelectSrcOperand (InputOperands, 2 ));
14501450}
1451+ 
1452+ bool  AIEBaseInstrInfo::areMemAccessesTriviallyDisjoint (
1453+     const  MachineInstr &MIa, const  MachineInstr &MIb) const  {
1454+   if  (!MIa.hasOneMemOperand () || !MIb.hasOneMemOperand ())
1455+     return  false ;
1456+ 
1457+   //  If mem-operands show that the same address Value is used by both
1458+   //  instructions, check for non-overlapping offsets and widths.
1459+   const  MachineMemOperand *MMOa = *MIa.memoperands_begin ();
1460+   const  MachineMemOperand *MMOb = *MIb.memoperands_begin ();
1461+ 
1462+   auto  CheckOverlapping = [=](int64_t  OffsetA, int64_t  OffsetB) {
1463+     const  LocationSize WidthA = MMOa->getSize (), WidthB = MMOb->getSize ();
1464+     const  int64_t  LowOffset = OffsetA < OffsetB ? OffsetA : OffsetB;
1465+     const  int64_t  HighOffset = OffsetA < OffsetB ? OffsetB : OffsetA;
1466+     const  LocationSize LowWidth = (LowOffset == OffsetA) ? WidthA : WidthB;
1467+     return  (LowWidth.hasValue () &&
1468+             LowOffset + (int64_t )LowWidth.getValue () <= HighOffset);
1469+   };
1470+ 
1471+   int64_t  MMOOffsetA = MMOa->getOffset ();
1472+   int64_t  MMOOffsetB = MMOb->getOffset ();
1473+ 
1474+   const  Value *VALa = MMOa->getValue ();
1475+   const  Value *VALb = MMOb->getValue ();
1476+   const  bool  SameValue = (VALa && VALb && (VALa == VALb));
1477+   if  (SameValue)
1478+     return  CheckOverlapping (MMOOffsetA, MMOOffsetB);
1479+ 
1480+   const  PseudoSourceValue *PSVa = MMOa->getPseudoValue ();
1481+   const  PseudoSourceValue *PSVb = MMOb->getPseudoValue ();
1482+ 
1483+   const  bool  WithBothPseudoSources = PSVa && PSVb;
1484+   if  (!WithBothPseudoSources)
1485+     return  false ;
1486+ 
1487+   const  bool  SamePseudoSource = PSVa == PSVb;
1488+   if  (SamePseudoSource)
1489+     return  CheckOverlapping (MMOOffsetB, MMOOffsetB);
1490+ 
1491+   const  FixedStackPseudoSourceValue *FixedStackA =
1492+       dyn_cast<FixedStackPseudoSourceValue>(PSVa);
1493+   const  FixedStackPseudoSourceValue *FixedStackB =
1494+       dyn_cast<FixedStackPseudoSourceValue>(PSVb);
1495+ 
1496+   //  If we have different fixed stack objects, we have disjoint access
1497+   //  when offsets are different and we don't have any partial overlap
1498+   //  (SameVal check).
1499+   const  bool  WithBothFixedStackObj = FixedStackA && FixedStackB;
1500+   if  (!WithBothFixedStackObj)
1501+     return  false ;
1502+ 
1503+   const  MachineFrameInfo &MFI = MIa.getMF ()->getFrameInfo ();
1504+   const  int64_t  ObjOffsetA = MFI.getObjectOffset (FixedStackA->getFrameIndex ());
1505+   const  int64_t  ObjOffsetB = MFI.getObjectOffset (FixedStackB->getFrameIndex ());
1506+ 
1507+   return  CheckOverlapping (ObjOffsetA, ObjOffsetB);
1508+ }
0 commit comments