From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 511313861962; Thu, 9 Jul 2020 14:01:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 511313861962 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1594303267; bh=yGqbqPq+Qx19b6HCaz2rgFrT9pDECDGKQb4K4JdOHa4=; h=From:To:Subject:Date:From; b=k1nTwDsFX43sCRtecs/vq7ljL+uqY1V6RzZ6CxjR033hfGin7ERdxCdYOv1I6Lcp2 JHABHOqbvXVY1bxG6MaCr2bdva6PhjViqA7ofydiE/Qml/8oppxpmMoZUVbeaVJYRW rQ+fuW/m48Y4obsNG7mwVfyMNazSYIuVPrf+umuc= From: "tobi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/96135] New: [9/10/11 regression] bswap not detected by bswap pass, unexpected results between optimization levels Date: Thu, 09 Jul 2020 14:01:07 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: tobi 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Jul 2020 14:01:07 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96135 Bug ID: 96135 Summary: [9/10/11 regression] bswap not detected by bswap pass, unexpected results between optimization levels Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: tobi at gcc dot gnu.org Target Milestone: --- This is an odd one, and it seems different from the other bswap bugs that I could find in bugzilla. This is on x64. Compiler Explorer link is here: https://godbolt.org/z/arTf5T Full source code: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D constexpr long long bswap64(long long in) // unsigned long long behaves the same { union { long long v; char c[8]; } u{in}; union { char c[8]; long long v; } v{ u.c[7], u.c[6], u.c[5], u.c[4], u.c[3], u.c[2], u.c[1], u.c[0]}; return v.v; } long long f(long long i) { return bswap64(i); } constexpr long long bswapD(double x) { return bswap64(*(long long*)&x); } long long g(double x) { return bswapD(x); } =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D There are three observations / bugs: 1) bswapD is never recognized as byte-swapping 2) bswap64 is optimized to bswap at -O2 but not at -O3 3) 131t.bswap never shows bswap, apparently the pass doesn't detect this wa= y of writing bswap, leaving it to the RTL optimizers. Hence I classified this as tree-optimization bug. Verified at -O2 with 9.3, 10.1 and trunk on the compiler explorer. I'm flagging this as a regression because at -O2 gcc 8.3 detects bswap in b= oth cases, but I'm guessing that this is by some accident. In 7.5 neither func= tion is compiled as bswap.=