Using AArch64's original implementation for reference, this patch
implements a pass to remove unneeded copies of X0. This pass runs
after register allocation and looks to see if a register is implied
to be 0 by a branch in the predecessor basic block.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
LGTM. It feels like this could perhaps be made target-independent with some additional hooks - a companion to or modification to isConstantPhysReg that indicates what the constant value is, and using analyzeBranchPredicate. Though extending it in some of the ways suggested in the TODOs would be more difficult, and as the pass itself as quite simple, the code added in terms of target hooks / interface modifications could quickly become larger than the pass itself.
I might look at this in the future. I started with the simpler version AArch64 started with so I didn't look as much at its current version which handles multiple branches, and constants. As noted in the TODOs, constants for RISCV will be harder. If the constant doesn't fit in an ADDI we might get luck and they'll be CSEd together. Then we would just need to check for register equality/inequality.
clang-format not found in user’s local PATH; not linting file.