-
Notifications
You must be signed in to change notification settings - Fork 14
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
[AIEX] Basic LICM pass for control registers #133
Conversation
|
||
using namespace llvm; | ||
|
||
#define DEBUG_TYPE "reserved-reg-licm" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: aie-reserved-reg-licm
because this is also the name of the pass.
static MCRegister getSinglePhysRegDef(const MachineInstr &MI) { | ||
if (MI.getNumDefs() == 1 && MI.getNumExplicitDefs() == 1) { | ||
const MachineOperand &MO = MI.getOperand(0); | ||
return MO.isReg() && MO.getReg().isPhysical() ? MO.getReg().asMCReg() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any possibility that MO is not a register? I think your first If guarantees this condition.
I think it that it can be simpler:
if (MO.getReg().isPhysical())
return MO.getReg().asMCReg();
} | ||
|
||
// Traverse instructions to remove defs | ||
for (const MachineInstr &MI : reverse(Header)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about one case that one register is defined by a block that dominates the Header. I think this case is not captured here, this register will not be in the live in set.
Can we just trust LoopBody->liveins()
? set
Unserstood now: Note we do not need to extend the liveins of the loops BBs with the // newly-hoisted def, because reserved regs are always considered live.
if (MRI->canSimplifyPhysReg(PhysReg)) { | ||
LiveRegs.addReg(PhysReg); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make this function take a block, not a loop, to make it easier to reuse in multi-block loops. And perhaps split off livereg initialization, which would be different for exiting blocks and internal blocks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember in my initial work I extended the pass to support multi-BB loops. Typically outer loops. It was enough to only look in the header, and be conservative if a reserved register was not met there. If I need something more complicated, I'd probably scrap this altogether and extendAIELiveRegs.cpp
be68149
to
c146a11
Compare
Currently this only support sinking into the exit block. Hoisting to the pre-header will come in a future commit. Ultimately, this pass could become generic code, as this uses a generic target hook to determine what is a "safe" reserved register.
c146a11
to
cbcc052
Compare
I think I have addressed all the comments now :) |
cbcc052
to
a66f38d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure whether you check for dedicated exit to hoist into. For the rest it looks fine.
The pass will identify phys regs that are defined once in the loop and are not livein.
a66f38d
to
6b87fa4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Nice work!
This is reviving some older work I made to hoist assignments to CR registers out of loops. This can both hoist to the pre-header, or sink to the exit block. This is needed to clean up our loops so they can later be SW pipelined. QoR shows minor improvements, and one regression: Add2D. What happens is that we now SW-pipeline the inner loop, but spill vector registers. In a future PR, I'll address those spills by teaching the pre-RA scheduler to try even harder to limit register pressure in cases where it is especially high.
E.g.
into:
Limitations: