Transform (add (shl x, c0), c1) -> (add (shl (add x, c1>>c0), c0), c1-(c1>>c0<<c0)), if c1>>c0 and c1-(c1>>c0<<c0) are simm12, while c1 is not. Or transform (add (shl x, c0), c1) -> (shl (add x, c1>>c0), c0), if c1-(c1>>c0<<c0) is zero, and c1>>c0 is simm12 while c1 is not.
Details
- Reviewers
craig.topper luismarques asb jrtc27
Diff Detail
Event Timeline
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | ||
---|---|---|
6474 ↗ | (On Diff #377088) | I think you can drop this if, getNode will see the constant is 0 and not produce an ADD node. |
6482 ↗ | (On Diff #377088) | This comment is already above transformAddImmShlImm, we don't need to repeat it. |
6491 ↗ | (On Diff #377088) | Just drop this comment. It's already above transformAddImmMulImm. |
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | ||
---|---|---|
6454 ↗ | (On Diff #379574) | This comment also repeated before the definition of transformAddShlImm, and should also be dropped. |
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | ||
---|---|---|
6468 ↗ | (On Diff #379586) | I think you need to abort if C0 is greater than VT.getSizeInBits() - 1. |
I'm getting a warning when building this (with clang 12.0.1):
/home/asb/llvm-project/llvm/lib/Target/RISCV/RISCVISelLowering.cpp:6490:20: warning: comparison of integers of different signs: 'int64_t' (aka 'long') and 'unsigned long' [-Wsign-compare] if (C0 < 1 || C0 > VT.getSizeInBits() - 1 || isInt<12>(C1) ||
I'm seeing some code size regressions on this patch - specifically, cases where a reg-reg add is replaced with an addi -256 (which isn't compressible). e.g. 20050121-1.c from the GCC torture suite (-O1, rv32imafdc).
Thanks for your patient and careful test, I will made a new patch for SHL related optimization after a careful check.