[gcc r17-2425] [PATCH] RISC-V: Fix GE/GEU zicond splitter emitting the wrong comparison

Jeff Law via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:ec4f03aae5e81c67e0cb5afd7f5c7cbf199fa411

commit r17-2425-gec4f03aae5e81c67e0cb5afd7f5c7cbf199fa411
Author: Jim Lin <[email protected]>
Date:   Wed Jul 15 13:55:57 2026 -0600

    [PATCH] RISC-V: Fix GE/GEU zicond splitter emitting the wrong comparison
    
    The splitter matching (x >= 1 ? 2^n : 0) lowered it to
    tmp = (x > 1); result = tmp << n, emitting any_gt instead of any_ge.
    At x == 1 the original yields 2^n but the split yields 0, a
    miscompile.  Emit any_ge to reproduce the matched comparison, as the
    sibling GE/GEU splitters already do.
    
    gcc/ChangeLog:
    
            * config/riscv/zicond.md: Emit any_ge instead of any_gt in the
            GE/GEU if-then-else splitter.
    
    Signed-off-by: Jim Lin <[email protected]>

Diff:
---
 gcc/config/riscv/zicond.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/riscv/zicond.md b/gcc/config/riscv/zicond.md
index a890322a5189..b0152cb773f4 100644
--- a/gcc/config/riscv/zicond.md
+++ b/gcc/config/riscv/zicond.md
@@ -458,7 +458,7 @@
 	 (const_int 0)))
    (clobber (match_operand:X 3 "register_operand"))]
   "exact_log2 (INTVAL (operands[2])) >= 0"
-  [(set (match_dup 3) (any_gt:X (match_dup 1) (const_int 1)))
+  [(set (match_dup 3) (any_ge:X (match_dup 1) (const_int 1)))
    (set (match_dup 0) (ashift:X (match_dup 3) (match_dup 4)))]
   { operands[4] = GEN_INT (exact_log2 (INTVAL (operands[2]))); })
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.