https://gcc.gnu.org/g:1205507f6f358710418e9e9d742b3bbc780b9d61
commit r17-5561-g1205507f6f358710418e9e9d742b3bbc780b9d61 Author: Jeff Law <[email protected]> Date: Sun Oct 25 22:16:25 2026 -0600 [RISC-V] Fix long branch sequences for Andes extensions LLM review of andes.md turned up numerous problems. I'm not going to spend a lot of time on them since I don't know the Andes design but I couldn't just let this one slide by ;-) The Andes extensions have two additional conditional branch instructions. One is a branch-on-bit capability, the other adds the ability to do equality tests against small constants. If you look at the long and short versions, you'll see they use the *same* condition, but the long version really needs the condition inverted since it does a branch around the long unconditional. But the inversion step was never done. As I noted, I'm not spending meaningful time on Andes and that includes burning time to set it up as a testsuite target. So this has only been tested via inspection. Assisted-By: Claude for bug discovery. Pushing to the trunk. * config/riscv/andes.md (branch patterns): Invert condition when branching around long unconditional branch when short direct branch doesn't fit. * config/riscv/iterators.md (sc): New iterator, inverted from "cs". (any_eq_inv): New iterator, eq->ne and ne->eq mapping. Diff: --- gcc/config/riscv/andes.md | 4 ++-- gcc/config/riscv/iterators.md | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/gcc/config/riscv/andes.md b/gcc/config/riscv/andes.md index 4b19fba5aa2f..481ad9baee41 100644 --- a/gcc/config/riscv/andes.md +++ b/gcc/config/riscv/andes.md @@ -42,7 +42,7 @@ "TARGET_XANDESPERF" { if (get_attr_length (insn) == 12) - return "nds.b<optab>c\t%1,%2,1f; jump\t%l0,ra; 1:"; + return "nds.b<any_eq:any_eq_inv>c\t%1,%2,1f; jump\t%l0,ra; 1:"; return "nds.b<optab>c\t%1,%2,%l0"; } @@ -61,7 +61,7 @@ "TARGET_XANDESPERF" { if (get_attr_length (insn) == 12) - return "nds.bb<any_eq:cs>\t%1,%2,1f; jump\t%l0,ra; 1:"; + return "nds.bb<any_eq:sc>\t%1,%2,1f; jump\t%l0,ra; 1:"; return "nds.bb<any_eq:cs>\t%1,%2,%l0"; } diff --git a/gcc/config/riscv/iterators.md b/gcc/config/riscv/iterators.md index c7fc97f6a0f1..2f4fd1d15047 100644 --- a/gcc/config/riscv/iterators.md +++ b/gcc/config/riscv/iterators.md @@ -323,8 +323,9 @@ ;; <su> is like <u>, but the signed form expands to "s" rather than "". (define_code_attr su [(sign_extend "s") (zero_extend "u")]) -;; eq expand to "c" and ne expand to "s". +;; eq expand to "c" and ne expand to "s" and it inversion (define_code_attr cs [(eq "c") (ne "s")]) +(define_code_attr sc [(eq "s") (ne "c")]) ;; <optab> expands to the name of the optab for a particular code. (define_code_attr optab [(ashift "ashl") @@ -365,6 +366,8 @@ (fix "fix_trunc") (unsigned_fix "fixuns_trunc")]) +(define_code_attr any_eq_inv [(eq "ne") (ne "eq")]) + (define_code_attr bit_optab [(ior "bset") (xor "binv")])
