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

commit r16-3530-ga6e0a610e6546dc3e6f26deb7b925cc1b2a681a5
Author: Andrew Pinski <andrew.pin...@oss.qualcomm.com>
Date:   Mon Sep 1 17:47:55 2025 -0700

    forwprop: Fix alignment of types in expansion of memcmp
    
    I noticed that when looking into g++.dg/tree-ssa/vector-compare-1.C
    failure on arm, the wrong alignment was being used for the load.
    There needs to be an unaligned type here to get the correct alignment.
    
    NOTE this means the code in strlen is also wrong but that is on its way
    out so I am not sure if we should update it or not to backport to the
    release branches; there could be wrong code happening too.
    
    Bootstrapped and tested on x86_64-linux-gnu.
    
    gcc/ChangeLog:
    
            * tree-ssa-forwprop.cc (simplify_builtin_memcmp): Create
            unaligned types if the alignment of the pointers is less
            than the alignment of the new type.
    
    Signed-off-by: Andrew Pinski <andrew.pin...@oss.qualcomm.com>

Diff:
---
 gcc/tree-ssa-forwprop.cc | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index 32ce75099342..df876f7db0a0 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -1618,8 +1618,16 @@ simplify_builtin_memcmp (gimple_stmt_iterator *gsi_p, 
gcall *stmt)
          tree ptrtype = build_pointer_type_for_mode (char_type_node,
                                                      ptr_mode, true);
          off = build_int_cst (ptrtype, 0);
-         arg1 = build2_loc (loc, MEM_REF, type, arg1, off);
-         arg2 = build2_loc (loc, MEM_REF, type, arg2, off);
+
+         /* Create unaligned types if needed. */
+         tree type1 = type, type2 = type;
+         if (TYPE_ALIGN (type1) > align1)
+           type1 = build_aligned_type (type1, align1);
+         if (TYPE_ALIGN (type2) > align2)
+           type2 = build_aligned_type (type2, align2);
+
+         arg1 = build2_loc (loc, MEM_REF, type1, arg1, off);
+         arg2 = build2_loc (loc, MEM_REF, type2, arg2, off);
          tree tem1 = fold_const_aggregate_ref (arg1);
          if (tem1)
            arg1 = tem1;

Reply via email to