Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC][AIE2] Add an IR Phi reordering pass #128

Open
wants to merge 1 commit into
base: aie-public
Choose a base branch
from

Conversation

andcarminati
Copy link
Collaborator

This pass helps Greedy to avoid spills.

This pass is indented to solve spill problems related to -fno-unroll-loops. No specific tests yet, just for evaluation and comments.

This pass helps Greedy to avoid spills.
//
//===----------------------------------------------------------------------===//

#include "AIE2.h"
Copy link
Collaborator

@martien-de-jong martien-de-jong Jul 19, 2024

Choose a reason for hiding this comment

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

If it is AIE2 specific, consider renaming to AIE2PHISorterPass. Otherwise, try to avoid including AIE2.h

}

if (WorkList.empty())
continue;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess InstrOrder could be declared after this continue.

for (BasicBlock *BB : PHI.blocks()) {
// Check basically if this loop block
// is part of the body.
if (BB == &B)
Copy link
Collaborator

@martien-de-jong martien-de-jong Jul 19, 2024

Choose a reason for hiding this comment

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

I'm wondering why you use LoopInfo. If this condition holds, you have a single block loop. If getLoopFor holds, it's a block somewhere in a multi-block loop. Therefore, this inner condition is stronger than the outer one.
If you only want to process 'relevant' blocks, consider traversing the loop tree rather than the basic block list. In particular, you could limit yourself to the header blocks of the leaf loops, ie. the ones without children.

unsigned PositionCounter = 0;

// Collect instruction ordering.
for (auto &I : B)
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about making PositionCounter local-scoped by declaring it here as const unsigned PositionCounter = InstrOrder.size();

#include "llvm/IR/LLVMContext.h"
#include "llvm/InitializePasses.h"
#include "llvm/Support/Debug.h"
#include "llvm/Transforms/Utils/Cloning.h"
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 only need a fraction of these includes. And as remarked, I think it could be independent on LoopInfo. If you want to generalize later, I would already make the 'is part of the body' test based on comparing getLoopFor of both blocks for equality.

@qcolombet
Copy link

I feel that this patch is about pushing the coalescing (or reg alloc) towards a particular direction.
But this is done indirectly.
What is missing to be able to drive the related passes directly?

@andcarminati
Copy link
Collaborator Author

I feel that this patch is about pushing the coalescing (or reg alloc) towards a particular direction. But this is done indirectly. What is missing to be able to drive the related passes directly?

Hi @qcolombet, indeed it is. This PR was more for discussions, because the effect is very hard to identify. We had one benchmark where the fno-unroll-loops induced a different ordering in the phi nodes. The result after GSelect was also the same (except phi ordering) and this ended in side-effects after Machine Pipeliner. In Both cases we had sw-pipeline, but with fno-unroll-loops we had also spills.

@qcolombet
Copy link

Thanks @andcarminati for the confirmation!
Could you file an issue, capture and upload the outputs of -debug-only regalloc with and without the phi ordering change that results in spill/non-spill?
I can take a look and maybe identify what heuristics could be improvement.

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.

3 participants