[gcc(refs/users/aoliva/heads/testme)] -finline-stringops: avoid too-wide smallest_int_mode_for_size [PR112784]

Alexandre Oliva aoliva@gcc.gnu.org
Fri Dec 8 01:06:18 GMT 2023


https://gcc.gnu.org/g:bf0aa514769cc175d3c3f011ec6a1095b83dec38

commit bf0aa514769cc175d3c3f011ec6a1095b83dec38
Author: Alexandre Oliva <oliva@gnu.org>
Date:   Thu Dec 7 19:33:01 2023 -0300

    -finline-stringops: avoid too-wide smallest_int_mode_for_size [PR112784]

Diff:
---
 gcc/expr.cc                                                | 14 ++++++++------
 .../gcc.target/i386/avx512cd-inline-stringops-pr112784.c   | 12 ++++++++++++
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/gcc/expr.cc b/gcc/expr.cc
index 6da51f2aca2..42db75e2131 100644
--- a/gcc/expr.cc
+++ b/gcc/expr.cc
@@ -2449,9 +2449,10 @@ emit_block_move_via_loop (rtx x, rtx y, rtx size,
     }
   emit_move_insn (iter, iter_init);
 
-  scalar_int_mode int_move_mode
-    = smallest_int_mode_for_size (incr * BITS_PER_UNIT);
-  if (GET_MODE_BITSIZE (int_move_mode) != incr * BITS_PER_UNIT)
+  opt_scalar_int_mode int_move_mode
+    = int_mode_for_size (incr * BITS_PER_UNIT, 1);
+  if (!int_move_mode.exists ()
+      || GET_MODE_BITSIZE (int_move_mode) != incr * BITS_PER_UNIT)
     {
       move_mode = BLKmode;
       gcc_checking_assert (can_move_by_pieces (incr, align));
@@ -2701,9 +2702,10 @@ emit_block_cmp_via_loop (rtx x, rtx y, rtx len, tree len_type, rtx target,
   iter = gen_reg_rtx (iter_mode);
   emit_move_insn (iter, iter_init);
 
-  scalar_int_mode int_cmp_mode
-    = smallest_int_mode_for_size (incr * BITS_PER_UNIT);
-  if (GET_MODE_BITSIZE (int_cmp_mode) != incr * BITS_PER_UNIT
+  opt_scalar_int_mode int_cmp_mode
+    = int_mode_for_size (incr * BITS_PER_UNIT, 1);
+  if (!int_cmp_mode.exists ()
+      || GET_MODE_BITSIZE (int_cmp_mode) != incr * BITS_PER_UNIT
       || !can_compare_p (NE, int_cmp_mode, ccp_jump))
     {
       cmp_mode = BLKmode;
diff --git a/gcc/testsuite/gcc.target/i386/avx512cd-inline-stringops-pr112784.c b/gcc/testsuite/gcc.target/i386/avx512cd-inline-stringops-pr112784.c
new file mode 100644
index 00000000000..c81f99c693c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx512cd-inline-stringops-pr112784.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-mavx512cd -finline-stringops" } */
+
+struct S {
+  int e;
+} __attribute__((aligned(128)));
+
+int main() {
+  struct S s1;
+  struct S s2;
+  int v = __builtin_memcmp(&s1, &s2, sizeof(s1));
+}


More information about the Gcc-cvs mailing list