diff options
author | Qing Zhao <qing.zhao@oracle.com> | 2021-11-10 17:59:31 +0000 |
---|---|---|
committer | Qing Zhao <qing.zhao@oracle.com> | 2021-11-10 17:59:31 +0000 |
commit | 1c04af34c9c66d8ed9f6c12c97dd064238ddfa20 (patch) | |
tree | e13afa30218858a13fe76edadab4dab944d9bc31 /gcc | |
parent | 1200e211a823816e47a9312efab61a60e12e33e5 (diff) | |
download | gcc-1c04af34c9c66d8ed9f6c12c97dd064238ddfa20.zip gcc-1c04af34c9c66d8ed9f6c12c97dd064238ddfa20.tar.gz gcc-1c04af34c9c66d8ed9f6c12c97dd064238ddfa20.tar.bz2 |
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 <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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/internal-fn.c | 14 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/i386/auto-init-6.c | 6 |
2 files changed, 12 insertions, 8 deletions
diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c index 0cba954..e8fd16b 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 339f8bc..e53385f 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 } } */ |