When Zbt is enabled, we can generate SELECT for division by power
of 2, so that there is no data dependency.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | ||
---|---|---|
10095 | Capitalize 'only' | |
10105 | Is i64 correct here for RV32? I don't see a test case. | |
10106 | Use APInt::isNegatedPowerOf2 | |
llvm/test/CodeGen/RISCV/rv32zbt-div-pow2.ll | ||
1 | Can you add test cases for dividing by 2 and -2 as well? X86 does not use BuildSDIVPow2 for those cases so we should check those. |
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | ||
---|---|---|
10096 | Should say *why*, ie need conditional move | |
10100 | X86 prioritises isIntDivCheap over a lack of conditional move; what's the justification for doing it the other way round? | |
10106 | X86 asserts it's one of the two, so this check seems bogus given the function name... | |
llvm/test/CodeGen/RISCV/rv32zbt-div-pow2.ll | ||
7 | No positive power of 2 tests, and no tests for isIntDivCheap being true? | |
llvm/test/CodeGen/RISCV/rv64zbt-div-pow2.ll | ||
8 | Don't duplicate tests, just add rv64 check lines to your existing rv32-only test | |
31 | And we should test we don't do stupid things for i64 on RV32 |
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | ||
---|---|---|
10100 | I agree with @jrtc27. The isIntDivCheap check should be at the top. | |
10106 | I think AArch64 explicitly checks it. I wrote X86 later and used an assert. | |
llvm/test/CodeGen/RISCV/rv32zbt-div-pow2.ll | ||
7 | isIntDivCheap is never true for RISCV today. We should also add a test for dividing by 4096 or larger for RV32 and RV64. And probably something larger than 2^32 for RV64. The constant materialization will add additional instructions not seen in the 1024 case. |
That's what several targets use isIntDivCheap for. I don't think RISCV does. The patch here doesn't make that situation worse.
Some of the i32 ones look like they might not be profitable on RV64 unless you have a wide out-of-order processor; 50% more instructions in some cases
For i32 on RV64, sign extension is needed, so there are sext.w. And the only case with 50% more instructions is when divisor is 2.
Maybe we should skip these divisors, any ideas?
llvm/test/CodeGen/RISCV/rv32zbt-div-pow2.ll | ||
---|---|---|
7 |
| |
7 | Thanks. I added tests divided by n (|n| ≥ 2^12) and two materialization instructions were generated. So it may be non-profitable when absolute values of divisors are larger than 2^12. |
llvm/test/CodeGen/RISCV/div-pow2.ll | ||
---|---|---|
14 ↗ | (On Diff #393864) | I think it makes sense to keep the old codegen when dividing by 2. |
58 ↗ | (On Diff #393864) | Original code is less instructions and has the same critical path instruction count. |
355 ↗ | (On Diff #393864) | Original code looks better. |
406 ↗ | (On Diff #393864) | Original code looks better |
From the LLVM Code-Review Policy and Practices (https://llvm.org/docs/CodeReview.html):
If it is urgent, provide reasons why it is important to you to get this patch landed and ping it every couple of days. If it is not urgent, the common courtesy ping rate is one week. Remember that you’re asking for valuable time from other professional developers.
It's only been 3 days for this and other patches you've just pinged
Capitalize 'only'