Skip to content

Commit e3cfd9d

Browse files
committed
[AIEX] Add AA support for stack fixed objects
1 parent 93b787a commit e3cfd9d

File tree

3 files changed

+65
-3
lines changed

3 files changed

+65
-3
lines changed

llvm/lib/Target/AIE/AIEBaseInstrInfo.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
const int64_t MMOOffsetA = MMOa->getOffset();
1472+
const 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 ExistBothPseudoSources = PSVa && PSVb;
1484+
if (!ExistBothPseudoSources)
1485+
return false;
1486+
1487+
const bool SamePseudoSource = PSVa == PSVb;
1488+
if (SamePseudoSource)
1489+
return CheckOverlapping(MMOOffsetA, 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 ExistsBothFixedStackObjs = FixedStackA && FixedStackB;
1500+
if (!ExistsBothFixedStackObjs)
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+
}

llvm/lib/Target/AIE/AIEBaseInstrInfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,9 @@ struct AIEBaseInstrInfo : public TargetInstrInfo {
869869
const DebugLoc &dl, Register DestReg,
870870
ArrayRef<MachineOperand> Cond, Register TrueReg,
871871
Register FalseReg) const override;
872+
873+
bool areMemAccessesTriviallyDisjoint(const MachineInstr &MIa,
874+
const MachineInstr &MIb) const override;
872875
};
873876

874877
template <unsigned NumEncodingBits, unsigned Step>

llvm/test/CodeGen/AIE/aie2p/schedule/pre_ra/stackAA-presched.mir

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
# In this case, we have five fixed stack objects: 0, that is aliasing (same offset)
2929
# with 2 and 1 that is aliasing with 3. We also have an object 4 that partially alias
3030
# with 0 and 2.
31+
# Note: this tests AIEBaseInstrInfo::areMemAccessesTriviallyDisjoint()
3132

3233
---
3334
name: load_and_store_chain
@@ -72,8 +73,8 @@ body: |
7273
; CHECK: SU(1): %1:er = LDA_dms_lda_idx_imm %0:ep, 0 :: (invariant load (s32) from %fixed-stack.1)
7374
; CHECK: Successors:
7475
; CHECK: SU(6): Data Latency=7 Reg=%1
75-
; CHECK: SU(10): Ord Latency=0 Memory
76-
; CHECK: SU(8): Ord Latency=0 Memory
76+
; CHECK-NOT: SU(10): Ord Latency=0 Memory
77+
; CHECK-NOT: SU(8): Ord Latency=0 Memory
7778
; CHECK: SU(6): Ord Latency=0 Memory
7879
7980
; CHECK: SU(3): %3:er = LDA_dms_lda_idx_imm %2:ep, 0 :: (invariant load (s32) from %fixed-stack.2, align 8)
@@ -82,7 +83,7 @@ body: |
8283
; CHECK: SU(8): Data Latency=7 Reg=%3
8384
; CHECK: SU(10): Ord Latency=0 Memory
8485
; CHECK: SU(8): Ord Latency=0 Memory
85-
; CHECK: SU(6): Ord Latency=0 Memory
86+
; CHECK-NOT: SU(6): Ord Latency=0 Memory
8687
8788
; CHECK: SU(6): ST_dms_sts_idx_imm %1:er, %4:ep, 0 :: (store (s32) into %fixed-stack.3, align 32)
8889
; CHECK: SU(8): ST_dms_sts_idx_imm %3:er, %5:ep, 0 :: (store (s32) into %fixed-stack.4)

0 commit comments

Comments
 (0)