From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A0ADE3851ABF; Mon, 20 Mar 2023 16:15:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A0ADE3851ABF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679328928; bh=5a9si0ii9D1IJ6jZGdyBgpO9mHZjWhAdEx8qdcWTvgw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=KV3DQAC01UxGJvRTKAZ7NotTBQB/x1nVa/kGc2NjY+Fc/ipVH17+tPHQ9kWm+bUi+ y7khrBZbyNQSOx6ZpRafqiInEJA6pDxMB2Th/YtYZvW82DjI0hhSFSbTM2xFtWnfNL hB+yneo0A9bwJxSPXyKiTDGdMNaa+n47oRqi+D+s= From: "amonakov at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/109187] [13 Regression] ICE: qsort checking failed: qsort comparator non-negative on sorted output: 1736258160 at -O2 since r13-5154-g733a1b777f16cd Date: Mon, 20 Mar 2023 16:15:28 +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: ice-checking, ice-on-valid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: amonakov at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 13.0 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=3D109187 --- Comment #2 from Alexander Monakov --- This is caused by overflowing subtraction in autopref_rank_for_schedule: if (!irrel1 && !irrel2) /* Sort memory references from lowest offset to the largest. */ r =3D data1->offset - data2->offset; When offsets are arbitrary this pattern (anti-pattern?) is inappropriate for producing a less/equal/greater comparison result. The following (or variant= s) is safe: diff --git a/gcc/haifa-sched.cc b/gcc/haifa-sched.cc index 4efaa9445..11bf10645 100644 --- a/gcc/haifa-sched.cc +++ b/gcc/haifa-sched.cc @@ -5686,7 +5686,7 @@ autopref_rank_for_schedule (const rtx_insn *insn1, co= nst rtx_insn *insn2) if (!irrel1 && !irrel2) /* Sort memory references from lowest offset to the largest. */ - r =3D data1->offset - data2->offset; + r =3D (data1->offset > data2->offset) - (data1->offset < data2->off= set); else if (write) /* Schedule "irrelevant" insns before memory stores to resolve as many producer dependencies of stores as possible. */=