Skip to content

Conversation

andcarminati
Copy link
Collaborator

This helps the scheduler to generate better code for cases where some parameters are passed by value through the stack.

This has a nice synergy with #669

OffsetA = MFI.getObjectOffset(FixedStackA->getFrameIndex());
OffsetB = MFI.getObjectOffset(FixedStackB->getFrameIndex());
if (OffsetA != OffsetB) {
SameVal = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CHECK: This is a conservative estimate that if the Frameindices are unequal and the offsets are equal they could overlap and to be safe we assign them the same Value?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, if FIs are different and also Offsets are different we use SameVal to check overlapping. We assign SameVal because they are in fact related to the same origin: stack.

const PseudoSourceValue *PSVa = MMOa->getPseudoValue();
const PseudoSourceValue *PSVb = MMOb->getPseudoValue();
if (PSVa && PSVb) {
if (PSVa == PSVb) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a lot of nesting levels here. Could we reduce them and add a couple of early exits?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rewrote the code accordingly.

@andcarminati andcarminati force-pushed the andreu.fixed.stack.aa branch 2 times, most recently from 6196188 to 9ca79fc Compare October 7, 2025 13:57
const PseudoSourceValue *PSVa = MMOa->getPseudoValue();
const PseudoSourceValue *PSVb = MMOb->getPseudoValue();

const bool WithBothPseudoSources = PSVa && PSVb;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ExistBothPseudoSources?


const bool SamePseudoSource = PSVa == PSVb;
if (SamePseudoSource)
return CheckOverlapping(MMOOffsetB, MMOOffsetB);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a bug: return CheckOverlapping(MMOOffsetA, MMOOffsetB);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, happily it is not is not optimistic.


bool AIEBaseInstrInfo::areMemAccessesTriviallyDisjoint(
const MachineInstr &MIa, const MachineInstr &MIb) const {
if (!MIa.hasOneMemOperand() || !MIb.hasOneMemOperand())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could make the first exit check more strict
if (MIa.hasUnmodeledSideEffects() || MIb.hasUnmodeledSideEffects() || MIa.hasOrderedMemoryRef() || MIb.hasOrderedMemoryRef()) return false;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

areMemAccessesTriviallyDisjoint is related to the memory addresses, memory ordering is handled apart of AA.

if (!WithBothPseudoSources)
return false;

const bool SamePseudoSource = PSVa == PSVb;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also be checking PSVa->isAliased()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the sources:

    // If true, an LLVM IR value might point to this object.
    // Normally, spill slots and fixed-offset objects don't alias IR-accessible
    // objects, but there are exceptions (on PowerPC, for example, some byval
    // arguments have ABI-prescribed offsets).

Apart of that, I see that this is not relevant to us because we are not comparing against IR objects.

@F-Stuckmann
Copy link
Collaborator

Overall I like the simpler, logical approach.

@andcarminati andcarminati force-pushed the andreu.fixed.stack.aa branch from 9ca79fc to e3cfd9d Compare October 8, 2025 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants