The use operand may be undefined. In that case we can just continue to
check the next operand since it won't increase register pressure.
Details
- Reviewers
shchenz MatzeB - Commits
- rG16547f9fbbd5: [CodeGen] Fix the bug of machine sink
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
LGTM with one nit. Thanks for fixing this.
llvm/lib/CodeGen/MachineSink.cpp | ||
---|---|---|
802 | Maybe better to exclude the undef case at the very beginning? |
llvm/lib/CodeGen/MachineSink.cpp | ||
---|---|---|
802 | So do we also ingore undef value for physical register? |
Thanks @shchenz for review. Let me land this patch first and we can improve the code later.
I'm also not sure right now if vregs without definitions are even legal MIR while we are still in MachineSSA... Checking that now
llvm/lib/CodeGen/MachineSink.cpp | ||
---|---|---|
802 | Do we have undef physical register? I don't see such usage and sounds weird to me, it is a physical register but it is undef.... |
Sorry, I merged it in a rush. We can revert it and add assert for nullptr if undef value is illegal in MIR.
llvm/lib/CodeGen/MachineSink.cpp | ||
---|---|---|
802 | Yes the definition of a physical register may not be visible in the MIR (could be a parameter, a side effect of a call or exception unwinding etc...) And physreg uses can be undef just like VRegs. |
I see this code in the MachineVerifier:
} else if (MRI->def_empty(Reg)) { report("Reading virtual register without a def", MO, MONum);
Which reads to me that we do not allow virtual registers without a definition if there is at least 1 read of the register. But I guess that means you can indeed have a vreg without a def if all the uses are marked undef or are debug operands or similar situations where MO.readsReg() is false.
We can add undef flag to tell verifier it is undef register, e.g., %2:gr32 = MOV32rr undef %3:gr32.
Yes that's what I wrote. It seems there is an exception that if for all operands you get readReg() == false (that includes undef) then it is indeed allowed to have a VReg without a definition.
Maybe better to exclude the undef case at the very beginning?