[Bug tree-optimization/119509] Missed optimization for comparison of division equivalent to right shift

skrll at netbsd dot org gcc-bugzilla@gcc.gnu.org
Mon Dec 8 08:51:57 GMT 2025


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119509

--- Comment #10 from Nick Hudson <skrll at netbsd dot org> ---
(In reply to Jeffrey A. Law from comment #9)
> So I was looking at this for riscv.  While I think the code can clearly be
> improved, the path for doing so is far from obvious.

Thanks for looking.

Is my candidate fix not usable? It changes the output of the test program for
riscv as follows

-- riscv64.foo.s       2025-12-08 08:25:17.259616639 +0000
+++ riscv64.foo.s.new   2025-12-08 08:47:53.751282204 +0000
@@ -10,11 +10,9 @@
 foo:
 .LFB0:
        .cfi_startproc
-       li      a5,16777216
-       addi    a5,a5,-256
-       and     a0,a0,a5
-       li      a5,255
-       sgtu    a0,a0,a5
+       slli    a0,a0,40
+       srli    a0,a0,48
+       snez    a0,a0
        ret
        .cfi_endproc
 .LFE0:


More information about the Gcc-bugs mailing list