From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CAC73396EC82; Tue, 2 Feb 2021 09:35:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CAC73396EC82 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/97960] [8/9/10 Regression] Wrong code at -O3 since r8-6511-g3ae129323d Date: Tue, 02 Feb 2021 09:35:23 +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: 11.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: rsandifo at gcc dot gnu.org X-Bugzilla-Target-Milestone: 8.5 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: short_desc 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, 02 Feb 2021 09:35:23 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97960 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|[8/9/10/11 Regression] |[8/9/10 Regression] Wrong |Wrong code at -O3 since |code at -O3 since |r8-6511-g3ae129323d |r8-6511-g3ae129323d --- Comment #10 from Jakub Jelinek --- Fixed on the trunk by https://gcc.gnu.org/g:4cf70c20cb10acd6fb1016611d05540728176b60=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20 commit r11-5904-g4cf70c20cb10acd6fb1016611d05540728176b60=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 Author: Richard Sandiford =20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 Date: Thu Dec 10 12:10:00 2020 +0000=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20 data-ref: Rework integer handling in split_constant_offset [PR98069]=20= =20=20=20=20=20=20=20 PR98069 is about a case in which split_constant_offset miscategorises= =20=20=20=20=20=20=20 an expression of the form:=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20 int foo;=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 =E2=80=A6=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20 POINTER_PLUS_EXPR=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20 as:=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20 base: base=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 offset: (sizetype) (-foo) * size=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20 init: INT_MIN * size=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20 =E2=80=9C-foo=E2=80=9D overflows when =E2=80=9Cfoo=E2=80=9D is INT_MIN,= whereas the original expression=20=20=20=20=20 didn't overflow in that case.=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20 As discussed in the PR trail, we could simply ignore the fact that=20= =20=20=20=20=20=20=20=20=20 int overflow is undefined and treat it as a wrapping type, but that=20= =20=20=20=20=20=20=20=20 is likely to pessimise quite a few cases.=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 This patch instead reworks split_constant_offset so that:=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 - it treats integer operations as having an implicit cast to sizetype= =20=20=20=20=20=20=20 - for integer operations, the returned VAR has type sizetype=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20 In other words, the problem becomes to express:=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 (sizetype) (OP0 CODE OP1)=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20 as:=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20 VAR:sizetype + (sizetype) OFF:ssizetype=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 The top-level integer split_constant_offset will (usually) be a sizetyp= e=20=20=20=20 POINTER_PLUS operand, so the extra cast to sizetype disappears. But ad= ding=20 the cast allows the conversion handling to defer a lot of the difficult= =20=20=20=20=20 cases to the recursive split_constant_offset call, which can detect=20= =20=20=20=20=20=20=20=20 overflow on individual operations.=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20 The net effect is to analyse the access above as:=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 base: base=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 offset: -(sizetype) foo * size=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20 init: INT_MIN * size=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20 See the comments in the patch for more details.=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 gcc/=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 PR tree-optimization/98069=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20 * tree-data-ref.c (compute_distributive_range): New function.= =20=20=20=20=20=20=20 (nop_conversion_for_offset_p): Likewise.=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 (split_constant_offset): In the internal overload, treat intege= r=20=20=20=20 expressions as having an implicit cast to sizetype and express= =20=20=20=20=20=20 them accordingly. Pass back the range of the original (uncast)= =20=20=20=20=20 expression in a new range parameter.=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 (split_constant_offset_1): Likewise. Rework the handling of=20= =20=20=20=20=20=20=20 conversions to account for the implicit sizetype casts.=