From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B11053858D37; Mon, 9 Jan 2023 18:49:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B11053858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673290140; bh=Zs5IzAhourvpeZc1AG8WAvQ0btZiBWES6wJ/pBLhNNE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=GKji8ruqbOSungpMT/85pvjsuuXdKSZ2vm/e91cs/KW5sUqGLBsVeu0b2ufAH9bX5 reJTaAXHIfX26zUNMJP9KQC9tYnrjgys2J3Q2jwzhuJKLnztGHJdgXlzJqQijEaP2w O9CYtH/peJcC8lNd0VaVoPSSts+r9ziOZ/bDnBMI= From: "amacleod at redhat dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/108341] argument to `__builtin_ctz` should be assumed non-zero when CTZ_DEFINED_VALUE_AT_ZERO says it is undefined Date: Mon, 09 Jan 2023 18:49:00 +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.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: amacleod at redhat dot com 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: 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=3D108341 --- Comment #5 from Andrew Macleod --- (In reply to Aldy Hernandez from comment #2) > (In reply to Martin Li=C5=A1ka from comment #1) > > May be an opportunity for Ranger? >=20 > Hmmm... I don't think so: >=20 > : > value.0_1 =3D (unsigned int) value_4(D); > _2 =3D __builtin_ctz (value.0_1); > r =3D _2; > _3 =3D value_4(D) !=3D 0; > _7 =3D (int) _3; > return _7; >=20 > We could add an op1_range operator to class cfn_clz to return nonzero for > op1, but that would only work if we knew _2 to be anything...and have no > info on _2. Seems more like a candidate for gimpe_infer::gimple_infer (gimple *s). THe side effect to register would be to check if 's' is a builtin_ctz and if so, call add_nonzero (operand1) if whatever those other conditions are are matched which make it true. That should register a non-zero inferred range on value.0_1 after the assignment of _2. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D BB 2 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Partial equiv (value.0_1 pe32 value_4(D)) : value.0_1 =3D (unsigned int) value_4(D); _2 =3D __builtin_ctz (value.0_1); r =3D _2; _3 =3D value_4(D) !=3D 0; _7 =3D (int) _3; return _7; I see ranger also registers a 32 bit equivalence between value.0_1 and valu= e_4, so in theory we would then be able to determine that value_4 is also non-ze= ro for the comparison.=