On 6/15/2026 7:35 AM, Milan Tripkovic wrote:
This patch implement new pattern for match.pd that recognize the
sign-extension idiom (x & low_bits) - (x & sign_bit) and tests that covers it.
Pattern is based on conversation from bug report.

TRUNK riscv output:
  sext8_hd:
           andi    a5,a0,127
           andi    a0,a0,128
           sub     a0,a5,a0
           ret

  sext16_hd:
           slli    a5,a0,49
           li      a4,32768
           srli    a5,a5,49
           and     a0,a0,a4
           sub     a0,a5,a0
           ret

NEW riscv output:
sext8_hd:
         slliw   a0,a0,24
         sraiw   a0,a0,24
         ret

sext16_hd:
         slliw   a0,a0,16
         sraiw   a0,a0,16
         ret
And if the "B" extension is available those will collapse even further.


        PR target/125405

gcc/ChangeLog:

      * match.pd: New pattern added

gcc/testsuite/ChangeLog:

      * gcc.dg/pr125405-bitint.c: New test.
      * gcc.dg/tree-ssa/pr125405.c: New test.
      * gcc.target/riscv/pr125405.c: New test.
I've pushed this to the trunk.  FTR this bootstrapped and regression tested on x86_64, riscv, aarch64 and probably a couple other targets in my tester.

Jeff

Reply via email to