Port bitfield optimisations from AArch64 to ARM64
| Bugzilla Link | 19424 |
| Resolution | FIXED |
| Resolved on | Apr 24, 2014 07:13 |
| Version | trunk |
| OS | All |
| Blocks | llvm/llvm-project#19766 |
| CC | @TNorthover |
Extended Description
ARM64 doesn't currently form enough (any?) BFI instructions, which means it cannot pass test/CodeGen/bitfield-insert.ll.
AArch64 gets this via a DAG combine (search for "tryCombineToBFI"). However, there's a wrinkle: transplanting the code directly results in failures in ARM64's rev.ll test because the early formation of ARM64ISD::BFI nodes interferes with the normal DAG combines.
However, the AArch64 code relies on (at least) two passes of DAG combine to reach its optimal form. This is a flaw which means we can't simply disable it during early combines.
So, the options are:
- Rewrite it to be recursive and build the final BFI in just one pass.
- Rewrite it as some C++ ISelDAG code (similarly recursive).
I suspect that the second option will give better results, and not be significantly harder than the first.
In the end I decided the ISelDAGToDAG approach was better, and made it work. Committed as r207102.
There's already quite a bit of C++ in ISelDAGToDAG to handle bitfield operations, but unfortunately it basically only handles the BFX variants (including BFXIL in the slightly misnamed "isBitfieldInsertOpFromOr").
I've tried to implement BFI support there; getting basic functionality isn't too bad, but reaching the corner cases (like where an extra AND, SHL or SHR is needed) looks like it will be a pain in the neck because we can't rely on TableGenerated ISel to pick a sensible variant.
I'll keep it in reserve, but I think I'm going to take another stab at it on the ISelLowering side. Separating them feels untidy, but perhaps there really is something fundamentally different about the cases BFI needs to handle.