From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B42AA3858C60; Tue, 26 Oct 2021 16:49:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B42AA3858C60 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/102951] failure to optimize MIN_EXPR of subobject addresses of the same object Date: Tue, 26 Oct 2021 16:49:51 +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: 12.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub 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: cc 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, 26 Oct 2021 16:49:51 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102951 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #1 from Jakub Jelinek --- extern int a[]; int * foo (void) { int *p1 =3D &a[1]; int *p2 =3D &a[2]; return p1 < p2 ? p1 : p2; } int bar (void) { int *p1 =3D &a[1]; int *p2 =3D &a[2]; return p1 < p2; } For the latter function, we optimize it in match.pd: /* When the addresses are not directly of decls compare base and offset. This implements some remaining parts of fold_comparison address comparisons but still no complete part of it. Still it is good enough to make fold_stmt not regress when not dispatching to fold_binary= .=20 */ (for cmp (simple_comparison) (simplify (cmp (convert1?@2 addr@0) (convert2? addr@1)) (with { poly_int64 off0, off1; ... So, I guess for MIN_EXPR/MAX_EXPR with ADDR_EXPR operands, we can optimize = it similarly, the question is if we should try to do that through repeating that huge code from there, or try to outline big parts of that in= to a helper function, or perhaps could we e.g. do (with { #if GENERIC tree l =3D generic_simplify (..., LT_EXPR, ...); #else tree l =3D gimple_simplify (..., LT_EXPR, ...); #endif } (if (l && integer_zerop (l)) @0) (if (l && integer_nonzerop (l)) @1))) or so? and therefore try to fold LT_EXPR instead of MIN_EXPR or MAX_EXPR and if th= at folds into integer_zerop or integer_nonzerop=