From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4DB4F3858D3C; Mon, 6 Nov 2023 05:32:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4DB4F3858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1699248771; bh=wef+AWygrgEoFYm7Tw96q/7waHUFNo/ysCtOHCbCgRw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=iwtCT78k7gcwpPFuRafplw80Q6dYNALoyjC0AEDgH2UfR/UsJRfPv44GKGNm554IB LWKKgUJwgyKUR0NOLx9AKuDAw/BFobcZ3FXZE1oVjIy2Q5iCE8A5ZJWBHhsmDSw65n Q6sMD9/VtgppUqKNttY4L1hK8Phr178eEpVX+CLs= From: "lis8215 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/112398] Suboptimal code generation for xor pattern on subword data Date: Mon, 06 Nov 2023 05:32:50 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: lis8215 at gmail dot com 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D112398 --- Comment #3 from Siarhei Volkau --- Well, let's rewrite it in that way: void neg8 (uint8_t *restrict dst, const uint8_t *restrict src) { uint8_t work =3D ~*src; // or *src ^ 0xff; dst[0] =3D (work >> 4) | (work << 4); } Wherever upper bits have to be in zero state it is cheaper to use xor, otherwise we're relying on techniques for eliminating redundant zero_extend= and at least on MIPS (prior to R2) and RISC-V GCC emits the zero_extend instruction. MIPS, neg8: neg8: lbu $2,0($5) nop nor $2,$0,$2 andi $3,$2,0x00ff srl $3,$3,4 sll $2,$2,4 or $2,$2,$3 jr $31 sb $2,0($4) RISC-V, neg8: lbu a5,0(a1) not a5,a5 andi a4,a5,0xff srli a4,a4,4 slli a5,a5,4 or a4,a4,a5 sb a4,0(a0) ret Some other RISCs also emit zero_extend but I'm not sure about having cheaper xor alternative on them (S390, SH, Xtensa).=