https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120817
Bug ID: 120817 Summary: [13/14/15 regression] Wrong code when compiled with -O1 -ftree-loop-vectorize for AArch64 target Product: gcc Version: 14.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: blankspruce at protonmail dot com Target Milestone: --- Host: x86_64-linux-gnu Target: aarch64-linux-gnu Build: x86_64-linux-gnu The following code: #include <array> #include <cstdint> #include <iostream> #include <string> auto getSafeSize(const auto inSize, const auto outSize) { if (inSize > outSize) { // Beetlejuice-like string construction throw std::length_error("" + std::string("") + "" + std::string("") + "" + std::string("")); } return std::min(inSize, outSize); } auto copySourceIntoTarget(const std::string& source) { std::array<std::uint8_t, 5> target{}; const auto loop_end = source.begin() + getSafeSize(source.size(), target.size()); auto source_it = source.begin(); auto target_it = target.begin(); for (; source_it != loop_end; source_it++, target_it++) { *target_it = *source_it; } return target; } void describe(const char* name, const auto& collection) { std::cout << name << ": ["; for (const auto& character : collection) { std::cout << int(character) << ", "; } std::cout << "]\n"; } int main() { std::string source{{'h', 'e', 'l', 'l', 'o'}}; describe("Source", source); const auto target = copySourceIntoTarget(source); describe("Target", target); } when compiled with these flags: -mcpu=neoverse-n2+crypto -O1 -ftree-loop-vectorize -std=c++20 produces different outputs with GCC 12.2.0 and with GCC 14.2.0 GCC 12.2.0: Source: [104, 101, 108, 108, 111, ] Target: [104, 101, 108, 108, 111, ] GCC 14.2.0 Source: [104, 101, 108, 108, 111, ] Target: [0, 0, 0, 0, 0, ] Demonstration on Godbolt: https://godbolt.org/z/75xqrW8K8 Known versions on Ubuntu affected by this problem: Ubuntu 24.04/24.10 13.3.0-6ubuntu2 14.2.0-4ubuntu2 Ubuntu 25.04: 13.3.0-13ubuntu1 14.2.0-19ubuntu2 Based on some internal testing removal of `case IFN_MASK_STORE` seems to fix the issue: https://gcc.gnu.org/cgit/gcc/tree/gcc/tree-ssa-dse.cc?h=releases/gcc-14.2.0#n162