From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 41B78382CC03; Tue, 27 Jul 2021 02:41:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 41B78382CC03 From: "tobi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/24568] [meta-bug] Missed optimization: trivialization of silly code Date: Tue, 27 Jul 2021 02:41:39 +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: 4.1.0 X-Bugzilla-Keywords: meta-bug, missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: tobi at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: FIXED X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_status resolution 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 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: Tue, 27 Jul 2021 02:41:40 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D24568 Tobias Schl=C3=BCter changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |FIXED --- Comment #11 from Tobias Schl=C3=BCter --- Take milliDiff =3D INT_MIN (<0). milliDiff_6 =3D -milliDiff_5(D); // milliDiff_6 =3D INT_MIN (still <= 0) minutesDiff_13 =3D milliDiff_6 / 60000;// minutesDiff_13 =3D INT_MIN/60000= =3D -35791; minutesDiff_8 =3D -minutesDiff_13; // minutesDiff_8 =3D 35791 (>0!) So negation and division don't commute over the two's complement integers, = and I don't think there is any bug left. I'm taking the liberty to close this.= =20 Link to a demonstration on the Compiler Explorer: https://godbolt.org/z/hnjcMdjnq Why the person who wrote that original bit of code wanted to deal with INT_= MIN (LONG_MIN in the original, but the testcase would overflow if sizeof(int) < sizeof(long)) in this way is another question.=