From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4F21738582B3; Mon, 8 Aug 2022 10:00:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4F21738582B3 From: "malat at debian dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/106322] tree-vectorize: Wrong code at O2 level (-fno-tree-vectorize is working) Date: Mon, 08 Aug 2022 10:00:13 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 12.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: malat at debian dot org X-Bugzilla-Status: WAITING X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Aug 2022 10:00:13 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106322 --- Comment #18 from Mathieu Malaterre --- Brushed-up example (with Makefile): % more Makefile bytes.cc demo.cc :::::::::::::: Makefile :::::::::::::: CXXFLAGS :=3D -O2 demo: demo.o bytes.o $(CXX) $(CXXFLAGS) -o $@ $^ -lhwy clean: rm -f bytes.o demo.o :::::::::::::: bytes.cc :::::::::::::: #include bool BytesEqual2(const void *bytes1, const void *bytes2, const size_t size)= { return memcmp(bytes1, bytes2, size) =3D=3D 0; } :::::::::::::: demo.cc :::::::::::::: #include "hwy/aligned_allocator.h" #include "hwy/highway.h" #include bool BytesEqual2(const void *p1, const void *p2, const size_t size); template void AssertVecEqual2(D d, const uint16_t *expected, const V &actual) { const size_t N =3D 2; auto actual_lanes =3D hwy::AllocateAligned(N); Store(actual, d, actual_lanes.get()); const uint8_t *expected_array =3D reinterpret_cast(expec= ted); const uint8_t *actual_array =3D reinterpret_cast(actual_lanes.get()); for (size_t i =3D 0; i < N; ++i) { const uint8_t *expected_ptr =3D expected_array + i * 2; const uint8_t *actual_ptr =3D actual_array + i * 2; #if 1 // trigger bug if (!BytesEqual2(expected_ptr, actual_ptr, 2)) { #else // no bug if (std::memcmp(expected_ptr, actual_ptr, 2) !=3D 0) { #endif abort(); } } } int main() { hwy::N_EMU128::FixedTag d; const size_t N =3D 2; hwy::AlignedFreeUniquePtr in_lanes =3D hwy::AllocateAligned(N); uint16_t expected_lanes[2]; in_lanes[0] =3D 65535; in_lanes[1] =3D 32767; expected_lanes[0] =3D 65534; expected_lanes[1] =3D 16383; hwy::N_EMU128::Vec128 v =3D Load(d, in_lanes.get()); hwy::N_EMU128::Vec128 actual =3D MulHigh(v, v); AssertVecEqual2(d, expected_lanes, actual); }=