From: Qing Zhao Date: Wed, 10 Nov 2021 17:59:31 +0000 (+0000) Subject: Apply pattern initialization only when have_insn_for return true. X-Git-Tag: basepoints/gcc-13~3180 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1c04af34c9c66d8ed9f6c12c97dd064238ddfa20;p=thirdparty%2Fgcc.git Apply pattern initialization only when have_insn_for return true. 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 * 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 * gcc.target/i386/auto-init-6.c: _Complex long double is initialized to zero now with -ftrivial-auto-var-init=pattern. --- diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c index 0cba95411a63..e8fd16b9c21f 100644 --- a/gcc/internal-fn.c +++ b/gcc/internal-fn.c @@ -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 diff --git a/gcc/testsuite/gcc.target/i386/auto-init-6.c b/gcc/testsuite/gcc.target/i386/auto-init-6.c index 339f8bc29660..e53385f0eb74 100644 --- a/gcc/testsuite/gcc.target/i386/auto-init-6.c +++ b/gcc/testsuite/gcc.target/i386/auto-init-6.c @@ -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 } } */