https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108016
--- Comment #10 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jeff Law <l...@gcc.gnu.org>: https://gcc.gnu.org/g:529a43109fcd93f5aafda345da14679f538ada86 commit r16-17-g529a43109fcd93f5aafda345da14679f538ada86 Author: Alexey Merzlyakov <alexey.merzlya...@samsung.com> Date: Fri Apr 18 06:45:10 2025 -0600 [PATCH] [RISC-V] Tune for removal unnecessary sext in builtin overflows [PR108016] It fixes one of the PR108016 mis-optimization. The patch adjusts expanding for __builtin_add/sub_overflow() on RV64 targets to avoid unnecessary sext.w instructions. It replaces expanded for ADD/SUB_OVERFLOW code: r141:SI=r139:DI#0+r140:DI#0 .. r143:DI=sign_extend(r141:SI) to the followong kind of chain -> r143:DI=sign_extend(r139:DI#0+r140:DI#0) .. r141:SI=r143:DI#0 so that sign_extend(a:SI+b:SI) to be emitted as addw (or subw) instruction, while output r141:SI register will be placed at the end of chain without extra dependencies, and thus could be easily optimized-out by further pipeline. PR middle-end/108016 gcc/ChangeLog: * config/riscv/riscv.md (addv<mode>4, uaddv<mode>4, subv<mode>4, usubv<mode>4): Tunes for unnecessary sext.w elimination. PR middle-end/108016 gcc/testsuite/ChangeLog: * gcc.target/riscv/pr108016.c: New test.