Skip to content

Commit 21866f2

Browse files
committed
strlen: Fixup load alignment for memcmp
Like the previous commit but for strlen copy so we can backport this commit. The loads should have the correct alignment on them so we need to create newly aligned types when the alignment of the pointer is less than the alignment of the current type. Pushed as pre-approved by https://gcc.gnu.org/pipermail/gcc-patches/2025-September/694016.html after a bootstrap/test on x86_64-linux-gnu. PR tree-optimization/121776 gcc/ChangeLog: * tree-ssa-strlen.cc (strlen_pass::handle_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 <[email protected]> (cherry picked from commit caa1c2f)
1 parent f30c88d commit 21866f2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

gcc/tree-ssa-strlen.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4009,8 +4009,16 @@ strlen_pass::handle_builtin_memcmp ()
40094009
tree ptrtype = build_pointer_type_for_mode (char_type_node,
40104010
ptr_mode, true);
40114011
off = build_int_cst (ptrtype, 0);
4012-
arg1 = build2_loc (loc, MEM_REF, type, arg1, off);
4013-
arg2 = build2_loc (loc, MEM_REF, type, arg2, off);
4012+
4013+
/* Create unaligned types if needed. */
4014+
tree type1 = type, type2 = type;
4015+
if (TYPE_ALIGN (type1) > align1)
4016+
type1 = build_aligned_type (type1, align1);
4017+
if (TYPE_ALIGN (type2) > align2)
4018+
type2 = build_aligned_type (type2, align2);
4019+
4020+
arg1 = build2_loc (loc, MEM_REF, type1, arg1, off);
4021+
arg2 = build2_loc (loc, MEM_REF, type2, arg2, off);
40144022
tree tem1 = fold_const_aggregate_ref (arg1);
40154023
if (tem1)
40164024
arg1 = tem1;

0 commit comments

Comments
 (0)