From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C1BB53858C2C; Fri, 26 May 2023 16:08:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C1BB53858C2C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685117322; bh=k9MeH/CtR6Gu5P4edczCWKxE79vKRZM2+ksNeUb8cIM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Q5YPVgxDmps+dXXt6W/cJCKbeyPNwXykafCKTJVIv2+NQi84imQ53Kdnafk3GIntV JnV6/KIQM8+VvwwJc8IyNfziOCNSPvjje1h0B4xFMctqOmNwF72sfZcwRWPLZnTnk5 XUiSITXfFJ17o8mWN9IFz8SfmqD9vL0NhMo50qQM= From: "gjl at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/109907] Missed optimization for bit extraction (uses shift instead of single bit-test) Date: Fri, 26 May 2023 16:08:42 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: gjl at gcc dot gnu.org X-Bugzilla-Status: NEW 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=3D109907 --- Comment #23 from Georg-Johann Lay --- Thank you so much for looking into this. For the test case from comment #21 though, the problem is somewhere in tree optimizations. > unsigned char lfsr32_mpp_ge0 (unsigned long number) > { > unsigned char b =3D 0; > if (number >=3D 0) b--; > if (number & (1UL << 29)) b++; > if (number & (1UL << 13)) b++; >=20 > return b; > } The -fdump-tree-optimized dump reads: ;; Function lfsr32_mpp_ge0 (lfsr32_mpp_ge0, funcdef_no=3D0, decl_uid=3D1880, cgraph_uid=3D1, symbol_order=3D0) unsigned char lfsr32_mpp_ge0 (long unsigned int number) { unsigned char b; long unsigned int _1; long unsigned int _2; _Bool _3; unsigned char _8; _Bool _9; unsigned char _10; unsigned char _11; [local count: 1073741824]: _1 =3D number_5(D) & 536870912; _2 =3D number_5(D) & 8192; if (_2 !=3D 0) goto ; [50.00%] else goto ; [50.00%] [local count: 536870912]: _9 =3D _1 =3D=3D 0; _10 =3D (unsigned char) _9; _11 =3D -_10; goto ; [100.00%] [local count: 536870913]: _3 =3D _1 !=3D 0; _8 =3D (unsigned char) _3; [local count: 1073741824]: # b_4 =3D PHI <_11(3), _8(4)> return b_4; } The ANDs are expanded by expand_binop() and later passes have to deal with = the 32-bit arithmnetic. combine finds one combination of andsi3 into "*sbrx_and_branch_split" with mode=3Dsi, but apart from that the mess= still lives in asm.=