]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Apply pattern initialization only when have_insn_for return true.
authorQing Zhao <qing.zhao@oracle.com>
Wed, 10 Nov 2021 17:59:31 +0000 (17:59 +0000)
committerQing Zhao <qing.zhao@oracle.com>
Wed, 10 Nov 2021 17:59:31 +0000 (17:59 +0000)
For -ftrivial-auto-var-init=pattern, initialize the variable with patterns only
when have_insn_for (SET, mode) return true.  Otherwise initialize it with zeros.
with this change, _Complex long double on X86 is initialized to zero for
pattern initialization.

gcc/ChangeLog:

2021-11-10  qing zhao  <qing.zhao@oracle.com>

* internal-fn.c (expand_DEFERRED_INIT): Apply pattern initialization
only when have_insn_for return true for the mode. Fix a memory leak.

gcc/testsuite/ChangeLog:

2021-11-10  qing zhao  <qing.zhao@oracle.com>

* gcc.target/i386/auto-init-6.c: _Complex long double is initialized
to zero now with -ftrivial-auto-var-init=pattern.

gcc/internal-fn.c
gcc/testsuite/gcc.target/i386/auto-init-6.c

index 0cba95411a63423484dda5b1251f47de24e926ba..e8fd16b9c21f76d18075060a4547dac1059a1eef 100644 (file)
@@ -3059,10 +3059,10 @@ expand_DEFERRED_INIT (internal_fn, gcall *stmt)
       mark_addressable (lhs);
       tree var_addr = build_fold_addr_expr (lhs);
 
-      tree value = (init_type == AUTO_INIT_PATTERN) ?
-                   build_int_cst (integer_type_node,
-                                  INIT_PATTERN_VALUE) :
-                   integer_zero_node;
+      tree value = (init_type == AUTO_INIT_PATTERN)
+                   build_int_cst (integer_type_node,
+                                    INIT_PATTERN_VALUE)
+                   integer_zero_node;
       tree m_call = build_call_expr (builtin_decl_implicit (BUILT_IN_MEMSET),
                                     3, var_addr, value, var_size);
       /* Expand this memset call.  */
@@ -3073,15 +3073,17 @@ expand_DEFERRED_INIT (internal_fn, gcall *stmt)
       /* If this variable is in a register use expand_assignment.
         For boolean scalars force zero-init.  */
       tree init;
+      scalar_int_mode var_mode;
       if (TREE_CODE (TREE_TYPE (lhs)) != BOOLEAN_TYPE
          && tree_fits_uhwi_p (var_size)
          && (init_type == AUTO_INIT_PATTERN
              || !is_gimple_reg_type (var_type))
          && int_mode_for_size (tree_to_uhwi (var_size) * BITS_PER_UNIT,
-                               0).exists ())
+                               0).exists (&var_mode)
+         && have_insn_for (SET, var_mode))
        {
          unsigned HOST_WIDE_INT total_bytes = tree_to_uhwi (var_size);
-         unsigned char *buf = (unsigned char *) xmalloc (total_bytes);
+         unsigned char *buf = XALLOCAVEC (unsigned char, total_bytes);
          memset (buf, (init_type == AUTO_INIT_PATTERN
                        ? INIT_PATTERN_VALUE : 0), total_bytes);
          tree itype = build_nonstandard_integer_type
index 339f8bc29660e1282fe82237bc7c2f04c6c2816a..e53385f0eb74543beea46b515d4b658af68668fa 100644 (file)
@@ -1,4 +1,6 @@
 /* Verify pattern initialization for complex type automatic variables.  */
+/* Note, _Complex long double is initialized to zeroes due to the current
+   implemenation limitation.  */
 /* { dg-do compile } */
 /* { dg-options "-ftrivial-auto-var-init=pattern -march=x86-64 -mtune=generic -msse" } */
 
@@ -15,6 +17,6 @@ _Complex long double foo()
   return result;
 }
 
-/* { dg-final { scan-assembler-times "long\t-16843010" 10  { target { ! ia32 } } } } */
-/* { dg-final { scan-assembler-times "long\t-16843010" 6  { target { ia32 } } } } */
+/* { dg-final { scan-assembler-times "long\t0" 8  { target { ! ia32 } } } } */
+/* { dg-final { scan-assembler-times "long\t-16843010" 6  } } */