From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 20D9E3858D20; Wed, 21 Feb 2024 14:37:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 20D9E3858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708526225; bh=n7oW7T9no+zFocRl1qe04wAF7+bU6o/M8yp/ZPphe1Q=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VIYByYVyFbwYNTpl/3fB7FRdyN53lecXVyagbAhvxhU5LhTzYud7f0iz8BfNGSu39 YRX3gBkKv9+FWnNOEr9HAtGu77de07OOpguuBHM1JweLIS6C7DwVpogM61pXYAiQKU IkpovxYTbCDoGEzLQ2yurh3kPC5K3kH3yLdPuzPQ= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/114032] ifcvt may introduce UB calls to __builtin_clz(0) Date: Wed, 21 Feb 2024 14:37:04 +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: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED 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: cc 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114032 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #1 from Jakub Jelinek --- Indeed, this feels like a bug, though unlikely to actually trigger anything wrong. I wouldn't worry that much about ifcvt IL, but about what makes it out of t= he vectorizer. void foo (unsigned *p) { for (int i =3D 0; i < 1024; ++i) p[i] =3D p[i] ? __builtin_clz (p[i]) : 42; } void bar (unsigned *p) { for (int i =3D 0; i < 1024; ++i) p[i] =3D p[i] ? __builtin_clz (p[i]) : 32; } with -O3 -mavx512{cd,bw,vl,dq} -mlzcnt -mbmi -mbmi2 -fvect-cost-model=3Dunl= imited Before ifcvt we have conditional __builtin_clz in foo and .CLZ (_4, 32); in bar, and out of the vectorizer get the same .CLZ (vect__4.10_37, 32); in both ca= ses, that looks ok. But without the -mlzcnt -mbmi -mbmi2 options, we have conditional __builtin_clz in both cases, and vectorizer results in .CLZ (vect__4.10_37) in both cases. We don't have value ranges on vectors thoug= h, so not really sure what could misbehave during the optimizations later on a= nd I bet all the targets which support vector .CLZ/.CTZ actually have some well defined value for zero. Maybe just the backends even for cases like -mlzcnt -mbmi -mbmi2 should announce C?Z_VALUE_DEFINED_AT_ZERO for vector modes if it supports vector c= ?z optabs? even if it isn't defined for scalar?=