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

commit r12-11024-gbfb1b0f8bb9fe76071fb02840002a17ed00a8999
Author: Richard Biener <rguent...@suse.de>
Date:   Wed Mar 6 09:02:31 2024 +0100

    tree-optimization/114246 - invalid call argument from DSE
    
    The following makes sure to strip type conversions added by
    build_fold_addr_expr before placing the result in a call argument.
    
            PR tree-optimization/114246
            * tree-ssa-dse.cc (increment_start_addr): Strip useless
            type conversions from the adjusted address.
    
            * gcc.dg/torture/pr114246.c: New testcase.
    
    (cherry picked from commit 0249744a9fe0775c2c895727aeebec4c59fd5f95)

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr114246.c | 11 +++++++++++
 gcc/tree-ssa-dse.cc                     |  2 ++
 2 files changed, 13 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/torture/pr114246.c 
b/gcc/testsuite/gcc.dg/torture/pr114246.c
new file mode 100644
index 000000000000..eb20db594cd0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr114246.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-w" } */
+
+int a, b;
+
+void
+foo (void)
+{
+  __builtin_memcpy (&a, (char *)&b - 1, 2);
+  __builtin_memcpy (&a, &b, 1);
+}
diff --git a/gcc/tree-ssa-dse.cc b/gcc/tree-ssa-dse.cc
index c373dacd806d..749756d8197b 100644
--- a/gcc/tree-ssa-dse.cc
+++ b/gcc/tree-ssa-dse.cc
@@ -45,6 +45,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "ipa-modref.h"
 #include "target.h"
 #include "tree-ssa-loop-niter.h"
+#include "tree-ssa.h"
 
 /* This file implements dead store elimination.
 
@@ -614,6 +615,7 @@ increment_start_addr (gimple *stmt, tree *where, int 
increment)
                                              *where,
                                              build_int_cst (ptr_type_node,
                                                             increment)));
+  STRIP_USELESS_TYPE_CONVERSION (*where);
 }
 
 /* STMT is builtin call that writes bytes in bitmap ORIG, some bytes are dead

Reply via email to