From: Uros Bizjak Date: Tue, 11 Jun 2024 14:00:31 +0000 (+0200) Subject: i386: Use CMOV in .SAT_{ADD|SUB} expansion for TARGET_CMOV [PR112600] X-Git-Tag: basepoints/gcc-16~8370 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=05b95238be648c9cf8af2516930af6a7b637a2b8;p=thirdparty%2Fgcc.git i386: Use CMOV in .SAT_{ADD|SUB} expansion for TARGET_CMOV [PR112600] For TARGET_CMOV targets emit insn sequence involving conditonal move. .SAT_ADD: addl %esi, %edi movl $-1, %eax cmovnc %edi, %eax ret .SAT_SUB: subl %esi, %edi movl $0, %eax cmovnc %edi, %eax ret PR target/112600 gcc/ChangeLog: * config/i386/i386.md (usadd3): Emit insn sequence involving conditional move for TARGET_CMOVE targets. (ussub3): Ditto. gcc/testsuite/ChangeLog: * gcc.target/i386/pr112600-a.c: Also scan for cmov. * gcc.target/i386/pr112600-b.c: Ditto. --- diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index d69bc8d6e48..a64f2ad4f5f 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -9885,13 +9885,35 @@ "" { rtx res = gen_reg_rtx (mode); - rtx msk = gen_reg_rtx (mode); rtx dst; emit_insn (gen_add3_cc_overflow_1 (res, operands[1], operands[2])); - emit_insn (gen_x86_movcc_0_m1_neg (msk)); - dst = expand_simple_binop (mode, IOR, res, msk, - operands[0], 1, OPTAB_WIDEN); + + if (TARGET_CMOVE) + { + rtx cmp = gen_rtx_GEU (VOIDmode, gen_rtx_REG (CCCmode, FLAGS_REG), + const0_rtx); + + if ( < GET_MODE_SIZE (SImode)) + { + dst = force_reg (mode, operands[0]); + emit_insn (gen_movsicc (gen_lowpart (SImode, dst), cmp, + gen_lowpart (SImode, res), constm1_rtx)); + } + else + { + dst = operands[0]; + emit_insn (gen_movcc (dst, cmp, res, constm1_rtx)); + } + } + else + { + rtx msk = gen_reg_rtx (mode); + + emit_insn (gen_x86_movcc_0_m1_neg (msk)); + dst = expand_simple_binop (mode, IOR, res, msk, + operands[0], 1, OPTAB_WIDEN); + } if (!rtx_equal_p (dst, operands[0])) emit_move_insn (operands[0], dst); @@ -9905,14 +9927,36 @@ "" { rtx res = gen_reg_rtx (mode); - rtx msk = gen_reg_rtx (mode); rtx dst; emit_insn (gen_sub_3 (res, operands[1], operands[2])); - emit_insn (gen_x86_movcc_0_m1_neg (msk)); - msk = expand_simple_unop (mode, NOT, msk, NULL, 1); - dst = expand_simple_binop (mode, AND, res, msk, - operands[0], 1, OPTAB_WIDEN); + + if (TARGET_CMOVE) + { + rtx cmp = gen_rtx_GEU (VOIDmode, gen_rtx_REG (CCCmode, FLAGS_REG), + const0_rtx); + + if ( < GET_MODE_SIZE (SImode)) + { + dst = force_reg (mode, operands[0]); + emit_insn (gen_movsicc (gen_lowpart (SImode, dst), cmp, + gen_lowpart (SImode, res), const0_rtx)); + } + else + { + dst = operands[0]; + emit_insn (gen_movcc (dst, cmp, res, const0_rtx)); + } + } + else + { + rtx msk = gen_reg_rtx (mode); + + emit_insn (gen_x86_movcc_0_m1_neg (msk)); + msk = expand_simple_unop (mode, NOT, msk, NULL, 1); + dst = expand_simple_binop (mode, AND, res, msk, + operands[0], 1, OPTAB_WIDEN); + } if (!rtx_equal_p (dst, operands[0])) emit_move_insn (operands[0], dst); diff --git a/gcc/testsuite/gcc.target/i386/pr112600-a.c b/gcc/testsuite/gcc.target/i386/pr112600-a.c index fa122bc7a3f..2b084860451 100644 --- a/gcc/testsuite/gcc.target/i386/pr112600-a.c +++ b/gcc/testsuite/gcc.target/i386/pr112600-a.c @@ -1,7 +1,7 @@ /* PR target/112600 */ /* { dg-do compile } */ /* { dg-options "-O2" } */ -/* { dg-final { scan-assembler-times "sbb" 4 } } */ +/* { dg-final { scan-assembler-times "sbb|cmov" 4 } } */ unsigned char add_sat_char (unsigned char x, unsigned char y) diff --git a/gcc/testsuite/gcc.target/i386/pr112600-b.c b/gcc/testsuite/gcc.target/i386/pr112600-b.c index ea14bb9738b..ac4e26423b6 100644 --- a/gcc/testsuite/gcc.target/i386/pr112600-b.c +++ b/gcc/testsuite/gcc.target/i386/pr112600-b.c @@ -1,7 +1,7 @@ /* PR target/112600 */ /* { dg-do compile } */ /* { dg-options "-O2" } */ -/* { dg-final { scan-assembler-times "sbb" 4 } } */ +/* { dg-final { scan-assembler-times "sbb|cmov" 4 } } */ unsigned char sub_sat_char (unsigned char x, unsigned char y)