]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
i386: Use CMOV in .SAT_{ADD|SUB} expansion for TARGET_CMOV [PR112600]
authorUros Bizjak <ubizjak@gmail.com>
Tue, 11 Jun 2024 14:00:31 +0000 (16:00 +0200)
committerUros Bizjak <ubizjak@gmail.com>
Tue, 11 Jun 2024 16:59:20 +0000 (18:59 +0200)
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 (usadd<mode>3): Emit insn sequence
involving conditional move for TARGET_CMOVE targets.
(ussub<mode>3): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr112600-a.c: Also scan for cmov.
* gcc.target/i386/pr112600-b.c: Ditto.

gcc/config/i386/i386.md
gcc/testsuite/gcc.target/i386/pr112600-a.c
gcc/testsuite/gcc.target/i386/pr112600-b.c

index d69bc8d6e48202fdb72917fa74fb122e2f2dec9b..a64f2ad4f5f005fdb363241dfdea6a2d9137f441 100644 (file)
   ""
 {
   rtx res = gen_reg_rtx (<MODE>mode);
-  rtx msk = gen_reg_rtx (<MODE>mode);
   rtx dst;
 
   emit_insn (gen_add<mode>3_cc_overflow_1 (res, operands[1], operands[2]));
-  emit_insn (gen_x86_mov<mode>cc_0_m1_neg (msk));
-  dst = expand_simple_binop (<MODE>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 (<MODE_SIZE> < GET_MODE_SIZE (SImode))
+       {
+         dst = force_reg (<MODE>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_mov<mode>cc (dst, cmp, res, constm1_rtx));
+       }
+    }
+  else
+    {
+      rtx msk = gen_reg_rtx (<MODE>mode);
+
+      emit_insn (gen_x86_mov<mode>cc_0_m1_neg (msk));
+      dst = expand_simple_binop (<MODE>mode, IOR, res, msk,
+                                operands[0], 1, OPTAB_WIDEN);
+    }
 
   if (!rtx_equal_p (dst, operands[0]))
     emit_move_insn (operands[0], dst);
   ""
 {
   rtx res = gen_reg_rtx (<MODE>mode);
-  rtx msk = gen_reg_rtx (<MODE>mode);
   rtx dst;
 
   emit_insn (gen_sub<mode>_3 (res, operands[1], operands[2]));
-  emit_insn (gen_x86_mov<mode>cc_0_m1_neg (msk));
-  msk = expand_simple_unop (<MODE>mode, NOT, msk, NULL, 1);
-  dst = expand_simple_binop (<MODE>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 (<MODE_SIZE> < GET_MODE_SIZE (SImode))
+       {
+         dst = force_reg (<MODE>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_mov<mode>cc (dst, cmp, res, const0_rtx));
+       }
+    }
+  else
+    {
+      rtx msk = gen_reg_rtx (<MODE>mode);
+
+      emit_insn (gen_x86_mov<mode>cc_0_m1_neg (msk));
+      msk = expand_simple_unop (<MODE>mode, NOT, msk, NULL, 1);
+      dst = expand_simple_binop (<MODE>mode, AND, res, msk,
+                                operands[0], 1, OPTAB_WIDEN);
+    }
 
   if (!rtx_equal_p (dst, operands[0]))
     emit_move_insn (operands[0], dst);
index fa122bc7a3fd4e7302c1dff9bd6f18d976694918..2b0848604512e72af81a12c6460eac3b45bbf932 100644 (file)
@@ -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)
index ea14bb9738b72745175d4a9de24789412412be34..ac4e26423b6fbfb5e99b0e22f8c8f0e964cbc902 100644 (file)
@@ -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)