The following code-sequence showed up in a testcase (isolated from SPEC2017) for if-conversion and vectorization when searching for the maximum in an array: addi a2, zero, 1 blt a1, a2, .LBB0_5 which can be expressed as `bge zero,a1,.LBB0_5`/`blez a1,/LBB0_5`. More generally, we want to express (a < 1) as (a <= 0). This adds the required isel-pattern and updates the testcases.
Details
Diff Detail
Event Timeline
llvm/lib/Target/RISCV/RISCVInstrInfo.td | ||
---|---|---|
1001 | We already have this in this exact spot in the file. Is your repo out of date? // Match X > -1, the canonical form of X >= 0, to the bgez pattern. def : Pat<(brcond (XLenVT (setgt GPR:$rs1, -1)), bb:$imm12), (BGE GPR:$rs1, X0, bb:$imm12)>; |
Added a testcase and rebased onto
commit 49942c6d4a0aee740381f754a6a0e6f7e1bfed43 Author: Quentin Colombet <qcolombet@apple.com> Date: Wed Mar 10 13:28:53 2021 -0800
DAG combine and instcombine canonicalize to constants on the RHS and SETGT, SETLT, SETUGT, and SETULT. So X <= 0 will always be rewritten to X< 1.
Ah ok then this looks good to me. Would be good to have the test pre-committed with the worse codegen as usual though.
llvm/lib/Target/RISCV/RISCVInstrInfo.td | ||
---|---|---|
1003 | Indentation looks a little off here. Everything else seems to have aligned the to and from. |
llvm/lib/Target/RISCV/RISCVInstrInfo.td | ||
---|---|---|
1001 | Isn't this the blez pattern? The "into" doesn't read right after the "as" Maybe | |
llvm/test/CodeGen/RISCV/branch.ll | ||
121 ↗ | (On Diff #330217) | This code is pretty trivially unreachable. The block above jumps over it. I'm a little surprised CodeGenPrepare or UnreachableBlockElim didn't notice that. I'd prefer we make it reachable so it can't break in the future. |
FYI, I put up a related patch to fix this same issue for select https://reviews.llvm.org/D98542
llvm/test/CodeGen/RISCV/branch.ll | ||
---|---|---|
121 ↗ | (On Diff #330217) | I applied this patch and this test case fails because the unreachable block does get deleted. |
This updates the test cases and I have rerun 'ninja check' to ensure no further test issues.
The commit message has also been updated to reflect that this is a blez-instruction.
LGTM. Do you need me to commit it? If so can you let me know your email and how you want the Author line to appear in the commit log.
We already have this in this exact spot in the file. Is your repo out of date?