[PATCH] RISC-V: Optimize branches with shifted immediate operands

2024-09-02 Thread Jovan Vukic
.L21   ret Tested on both RV32 and RV64 with no regressions. 2024-09-02 Jovan Vukic gcc/ChangeLog:   PR target/113248   * config/riscv/riscv.md (*branch_shiftedarith_equals_shifted): New pattern. gcc/testsuite/ChangeLog:   PR target/113248   * gcc.target/riscv/branch

Re: [PATCH] RISC-V: Optimize branches with shifted immediate operands

2024-09-05 Thread Jovan Vukic
> It's worth noting there is a newer way which is usually slightly simpler > than a match_operator. Specifically code iterators. Thank you for the very detailed feedback. It is not a problem to add code iterators. I would add iterators for "eq" and "ne" in riscv/iterators.md since they don't cur

[PATCH] RISC-V: Improve code generation for select of consecutive constants

2024-09-17 Thread Jovan Vukic
placed by the inverse operation x > y (y < x), which requires replacing the following addi instruction with an xori instruction as well, as proposed by the patch. Tested on both RV32 and RV64 with no regressions. 2024-09-17 Jovan Vukic PR target/108038 gcc/ChangeLog: *

[PATCH v3] RISC-V: Optimize branches with shifted immediate operands

2024-10-09 Thread Jovan Vukic
a5,a0,11 andia5,a5,1023 li a4,569 beq a5,a4,.L5 f6: srlia5,a0,11 andia5,a5,1663 li a4,544 beq a5,a4,.L9 2024-10-09 Jovan Vukic PR target/115921 gcc/ChangeLog: * config/riscv/iterators.md

[PATCH v2] RISC-V: Optimize branches with shifted immediate operands

2024-09-29 Thread Jovan Vukic
ersion. Regardless, the necessary check has been added, so if a negative case exists, an unrecognized instruction will not be created. 2024-09-30 Jovan Vukic PR target/115921 gcc/ChangeLog: * config/riscv/iterators.md (any_eq): New code iterator. * config/riscv/riscv.h

[PATCH] phi-opt: Add missed optimization for "(cond | (a != b)) ? b : a"

2024-10-22 Thread Jovan Vukic
enerated assembly for RISC-V is: foo: bgt a0, a2, .L4 bne a0, a1, .L4 ret .L4: mv a0, a1 ret After the patch, the generated assembly becomes: foo: mv a0, a1 ret 2024-10-22 Jovan Vukic gcc/ChangeLog: * tree-ssa-

[PATCH v2] phi-opt: Add missed optimization for "(cond | (a != b)) ? b : a"

2024-10-30 Thread Jovan Vukic
function after successfully setting the value of *code within the rhs_is_fed_for_value_replacement function to EQ_EXPR. For BIT_IOR_EXPR, the same check is performed for A NE B, except now *code remains NE_EXPR, and then value_replacement returns the second operand (i.e.

Re: [PATCH v2] phi-opt: Add missed optimization for "(cond | (a != b)) ? b : a"

2024-11-04 Thread Jovan Vukic
On 11/02/24, Jeff Law wrote: >This is well understood. The key in my mind is that for AND we always >select the FALSE arm. For IOR we always select the TRUE arm. Yes, I agree. >> e = (code == NE_EXPR ? true_edge : false_edge); >If I understand everything correctly your assertion is that w

match.pd: Add pattern to simplify `(a - 1) & -a` to `0`

2024-11-13 Thread Jovan Vukic
The patch simplifies expressions (a - 1) & -a, (a - 1) | -a, and (a - 1) ^ -a to the constants 0, -1, and -1, respectively. Currently, GCC does not perform these simplifications. Bootstrapped and tested on x86-linux-gnu with no regressions. gcc/ChangeLog: * match.pd: New pattern. gcc/t

match.pd: Add pattern to simplify `((X - 1) & ~X) < 0` to `X == 0`

2024-11-13 Thread Jovan Vukic
The patch makes the following simplifications: ((X - 1) & ~X) < 0 -> X == 0 ((X - 1) & ~X) >= 0 -> X != 0 On x86, the number of instructions is reduced from 4 to 3, but on platforms like RISC-V, it reduces to a single instruction. Bootstrapped and tested on x86-linux-gnu with no regressions. gcc

[PATCH v2] RISC-V: Improve code generation for select of consecutive constants

2024-09-27 Thread Jovan Vukic
if 2 * (A & B) == 0. In our case, we have A == X ^ C1, B == C2 and X is either 0 or 1. 2024-09-27 Jovan Vukic PR target/108038 gcc/ChangeLog: * simplify-rtx.cc (simplify_context::simplify_binary_operation_1): New simplification. gcc/testsuite/ChangeLog: *

[PATCH v2] match.pd: Add pattern to simplify `(a - 1) & -a` to `0`

2024-11-26 Thread Jovan Vukic
ny issues with match.pd missing any simplifications, but if that happens, the code in simplify-rtx.cc should help. Bootstrapped and tested on x86-linux-gnu with no regressions. 2024-11-26 Jovan Vukic gcc/ChangeLog: * match.pd: New pattern. * simplify-rtx.cc (simplif

[PATCH v3] match.pd: Add pattern to simplify `(a - 1) & -a` to `0`

2024-12-03 Thread Jovan Vukic
patch. 2024-12-03 Jovan Vukic gcc/ChangeLog: * match.pd: New pattern. * simplify-rtx.cc (match_plus_neg_pattern): New helper function. (simplify_context::simplify_binary_operation_1): New code to handle (a - 1) & -a, (a - 1) | -a and (a - 1) ^ -a. gcc/tests