This patch optimize or/xor with immediate to a pair of BSETI/BINVI
if the immediate has exactly two set bits.
Details
Diff Detail
Event Timeline
We need to optimize integer materialization, both in general and to take advantage of bitmanip. I suppose that the baseline test would be less bad if we had done that, but that this optimization would still be worth it?
llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp | ||
---|---|---|
1293 ↗ | (On Diff #345141) | The code already seems self-explanatory. Remove? |
1299 ↗ | (On Diff #345141) | "The immediate must have exactly two bits set." |
llvm/lib/Target/RISCV/RISCVInstrInfoB.td | ||
90 | "only two set bits" -> "two set bits", otherwise it seems it's "up to two bits" |
Can this be moved into RISCVTargetLowering::targetShrinkDemandedConstant? aarch64 has a great optimizeLogicalImm which may give some inspiration.
Thanks. I have investigated AArch64's targetShrinkDemandedConstant and optimizeLogicalImm, but do not think my optimization is suitable to be there.
AArch64's optimizeLogicalImm does optimize the immediate operand but does not change the operator.
While my optimization changes the operator from or/xor to bseti/binvi.
Thanks for your suggestion. I will check if integer materialization can be optimized by bitmanip. But I still think my optimization is worthy to do. Snice it saves an unnecessary or/xor instr.
llvm/lib/Target/RISCV/RISCVInstrInfoB.td | ||
---|---|---|
91 | Maybe we can't check one use from ImmLeaf? |
llvm/lib/Target/RISCV/RISCVInstrInfoB.td | ||
---|---|---|
91 | But we can use PatLeaf<(imm), [{ }]> I think that's the way to go. I'll post a patch to do the same to AddiPair. |
LGTM. Do you plan to do this for BCLR as well?
Can we use ORI+BSETI if there is one bit set in bits 63:11 and multiple bits in bits 10:0?
Thanks for your suggestion. I will do them in other patches. BTW, could you please also approve https://reviews.llvm.org/D102396 ?
Current patch depends on it.
sorry, I pushed a wrong revision, it seems my description "This patch optimize or/xor with immediate to a pair of BSETI/BINVI
if the immediate has exactly two set bits."
is not included in my commit message.
I will pay attention to that in my future patches/commits.
And the pushed code is the exactly what Craig has approved.
"only two set bits" -> "two set bits", otherwise it seems it's "up to two bits"