From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C8319384D163; Thu, 6 Oct 2022 06:00:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C8319384D163 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665036040; bh=I9EgJeqPMvV0pwapWVYqY6l78GjEV8tQ1pOBXkIQXQs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=CSdR4wh4fYNlG6/lnvTE4T5kyp5drZ2dztSm8s/+nxbGif/OFAFZxaxcAfKHwTRvO JDO6g/tfU3Vu0HusMugU5zR/VNIaF7m8i4V35ca98X0rOKDAq8/EEUVJhFsHLiwsn2 A3wncC86ewo4CvAH5A3kPDf10VOGeAAvAbJINhTg= From: "unlvsur at live dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/107167] It looks like GCC wastes registers on trivial computations when result can be cached Date: Thu, 06 Oct 2022 06:00:40 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: unlvsur at live 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=3D107167 --- Comment #2 from cqwrteur --- (In reply to Andrew Pinski from comment #1) > This is a reassociation, scheduling issue and register allocation issue. >=20 > Plus your example might be slower due to dependencies. >=20 > Without a full example of where gcc ra goes wrong, gcc actually produces > much better code for this example due to register renaming in hw. > Note many x86_64 also does register renaming for the stack too The problem I do things like sha512_round: =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 sha512_round(x[0]=3Dbig_endian(W[0]),a,b,d,e,f,g,h,bpc,0x428a2f98d728ae22); sha512_round(x[1]=3Dbig_endian(W[1]),h,a,c,d,e,f,g,bpc,0x7137449123ef65cd); sha512_round(x[2]=3Dbig_endian(W[2]),g,h,b,c,d,e,f,bpc,0xb5c0fbcfec4d3b2f); sha512_round(x[3]=3Dbig_endian(W[3]),f,g,a,b,c,d,e,bpc,0xe9b5dba58189dbbc); sha512_round(x[4]=3Dbig_endian(W[4]),e,f,h,a,b,c,d,bpc,0x3956c25bf348b538); They use tons of registers. If GCC wastes registers, tons of time would was= te on stack push/load. My implementation by GCC on x86_64 is slower than openssl's asm version particularly due to this reason. GCC just pushes/stores too many values on = the stack. https://github.com/openssl/openssl/blob/master/crypto/sha/asm/sha512-x86_64= .pl#L192 OpenSSL does exactly what I do here.=