From d725717165707b49ee2484e462bbb7fbd278b919 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Tue, 28 Nov 2017 11:58:45 +0000 Subject: [PATCH] re PR tree-optimization/83141 (SRA and memcpy folding interact badly generating wrong-code) 2017-11-28 Richard Biener PR middle-end/83141 * gimple-fold.c (gimple_fold_builtin_memory_op): For aggregate copies generated from memcpy use a character array as reference type. From-SVN: r255197 --- gcc/ChangeLog | 7 +++++++ gcc/gimple-fold.c | 18 +++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a86c833d4bb..e83d8d239b6 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2017-11-28 Richard Biener + + PR middle-end/83141 + * gimple-fold.c (gimple_fold_builtin_memory_op): For aggregate + copies generated from memcpy use a character array as reference + type. + 2017-11-28 Julia Koval Sebastian Peryt diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 353a46ed1b7..849b62fa903 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -1039,8 +1039,24 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi, gimple_set_vuse (new_stmt, gimple_vuse (stmt)); gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT); } + new_stmt = gimple_build_assign (destvar, srcvar); + goto set_vop_and_replace; } - new_stmt = gimple_build_assign (destvar, srcvar); + + /* We get an aggregate copy. Use an unsigned char[] type to + perform the copying to preserve padding and to avoid any issues + with TREE_ADDRESSABLE types or float modes behavior on copying. */ + desttype = build_array_type_nelts (unsigned_char_type_node, + tree_to_uhwi (len)); + srctype = desttype; + if (src_align > TYPE_ALIGN (srctype)) + srctype = build_aligned_type (srctype, src_align); + if (dest_align > TYPE_ALIGN (desttype)) + desttype = build_aligned_type (desttype, dest_align); + new_stmt + = gimple_build_assign (fold_build2 (MEM_REF, desttype, dest, off0), + fold_build2 (MEM_REF, srctype, src, off0)); +set_vop_and_replace: gimple_set_vuse (new_stmt, gimple_vuse (stmt)); gimple_set_vdef (new_stmt, gimple_vdef (stmt)); if (gimple_vdef (new_stmt) -- 2.30.2