[Bug target/112454] csinc (csel is though) is not being used when there is matches twice
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112454 --- Comment #5 from GCC Commits --- The trunk branch has been updated by Andrew Pinski : https://gcc.gnu.org/g:d29d27bde5df89e5357e0a33a71bb49125bd1655 commit r14-5893-gd29d27bde5df89e5357e0a33a71bb49125bd1655 Author: Andrew Pinski Date: Sun Nov 26 23:25:51 2023 + aarch64: Improve cost of `a ? {-,}1 : b` While looking into PR 112454, I found the cost for `(if_then_else (cmp) (const_int 1) (reg))` was being recorded as 8 (or `COSTS_N_INSNS (2)`) but it should have been 4 (or `COSTS_N_INSNS (1)`). This improves the cost by not adding the cost of `(const_int 1)` to the total cost. It does not does not fully fix PR 112454 as that requires other changes to forwprop the `(const_int 1)` earlier than combine. Though we do fix the loop case where the constant was only used once. Bootstrapped and tested on aarch64-linux-gnu with no regressions. gcc/ChangeLog: * config/aarch64/aarch64.cc (aarch64_if_then_else_costs): Handle csinv/csinc case of 1/-1. gcc/testsuite/ChangeLog: * gcc.target/aarch64/csinc-3.c: New test. Signed-off-by: Andrew Pinski
[Bug target/112454] csinc (csel is though) is not being used when there is matches twice
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112454 --- Comment #4 from Andrew Pinski --- So it looks like this is not only a cost issue. I have to look into forwprop to see if it can handle this. Note the cost issue does need to be fixed anyways since it will be needed there; otherwise forwprop might reject it.
[Bug target/112454] csinc (csel is though) is not being used when there is matches twice
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112454 --- Comment #3 from Andrew Pinski --- -1/~0 has the same issue as mentioned: ``` int finv(int a, int b, int c, int d) { return (a == 2 ? -1 : b) + (c == 3 ? -1 : d); } ```
[Bug target/112454] csinc (csel is though) is not being used when there is matches twice
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112454 Andrew Pinski changed: What|Removed |Added Status|UNCONFIRMED |ASSIGNED Last reconfirmed||2023-11-18 Ever confirmed|0 |1 Assignee|unassigned at gcc dot gnu.org |pinskia at gcc dot gnu.org --- Comment #2 from Andrew Pinski --- Mine, looks like a cost issue not recording that 1 (and ~0) are free to create. you can see the cost issue if we look at combine for the case of 1 csel: Trying 37 -> 39: 37: r98:SI=0x1 39: r92:SI={(cc:CC!=0)?r100:SI:r98:SI} REG_DEAD r100:SI REG_DEAD cc:CC REG_DEAD r98:SI Successfully matched this instruction: (set (reg:SI 92 [ ]) (if_then_else:SI (ne (reg:CC 66 cc) (const_int 0 [0])) (reg:SI 100) (const_int 1 [0x1]))) allowing combination of insns 37 and 39 original costs 4 + 4 = 8 replacement cost 8 deferring deletion of insn with uid = 37. modifying insn i339: r92:SI={(cc:CC!=0)?r100:SI:0x1} REG_DEAD cc:CC REG_DEAD r100:SI deferring rescan insn with uid = 39. The replacement cost should be still 4.
[Bug target/112454] csinc (csel is though) is not being used when there is matches twice
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112454 --- Comment #1 from Andrew Pinski --- here is another testcase which shows the issue with pulling the constant one out of the loop when it could have been merged with the csel to use csinc: ``` int f(int *a, int n, int *b, int d) { for(int i = 0; i < n; i++) b[i] = a[i] == 100 ? 1 : d; return 0; } ```