https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118669
Bug ID: 118669 Summary: Misaligned store after after vectorization Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: kristerw at gcc dot gnu.org Target Milestone: --- Vectorization creates misaligned stores for the function below when compiled for AArch64 with "-O3 -march=armv9.4": void foo (int i, int *a) { for (int j = 0; j < i; j++) a[j] = j; } The vectorized code start by writing 2*vector_length elements at a time, as long as there are more than 2*vector_length elements remaining: <bb 3> [local count: 860067200]: # vect_vec_iv_.6_37 = PHI <_38(6), { 0, 1, 2, ... }(14)> # vectp_a.7_40 = PHI <vectp_a.7_41(6), a_8(D)(14)> # ivtmp_46 = PHI <ivtmp_47(6), 0(14)> _38 = vect_vec_iv_.6_37 + { POLY_INT_CST [8, 8], ... }; _39 = vect_vec_iv_.6_37 + { POLY_INT_CST [4, 4], ... }; MEM <vector([4,4]) int> [(int *)vectp_a.7_40] = vect_vec_iv_.6_37; vectp_a.7_43 = vectp_a.7_40 + POLY_INT_CST [16, 16]; MEM <vector([4,4]) int> [(int *)vectp_a.7_43] = _39; vectp_a.7_41 = vectp_a.7_43 + POLY_INT_CST [16, 16]; ivtmp_47 = ivtmp_46 + POLY_INT_CST [8, 8]; if (ivtmp_47 <= _45) goto <bb 6>; [89.00%] else goto <bb 10>; [11.00%] <bb 6> [local count: 765459809]: goto <bb 3>; [100.00%] The store MEM <vector([4,4]) int> [(int *)vectp_a.7_40] = vect_vec_iv_.6_37; may be misaligned as TYPE_ALIGN for "vector([4,4])" is 128 bits, while the pointer in the first iteration is the "int *a" function argument which which only guarantees 32-bit alignment.