From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 90A1D3851C25; Tue, 7 Jul 2020 08:26:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 90A1D3851C25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1594110410; bh=KMfAICfYb+d9hvQvTzdJ06x19YIInijAtENitWYLzsE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=EwjsMM/+w46Jc2eaEbLJqcUfmI1eZv8xYr60as+oodbLvfq2Ba/me0VLMx6b2N15o 82dKYl2HMlqz2YUgcOOeuvrqNnm2s0DTXkQOFygPIxMU5360hNorBS48PrJsZNBS0l d85bQRVHp9c+m7zABNBKS7sSENevwTGjRb/qCVjc= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/95396] [8/9/10/11 Regression] GCC produces incorrect code with -O3 for loops since r8-6511-g3ae129323d150621 Date: Tue, 07 Jul 2020 08:26:50 +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: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 8.5 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 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, 07 Jul 2020 08:26:50 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95396 --- Comment #7 from Richard Biener --- (In reply to Richard Biener from comment #6) > One odd thing is that for unsigned char _3 we get via >=20 > wide_int var_min, var_max; > value_range_kind vr_type =3D get_range_info (tmp_var, &va= r_min, > &var_max); >=20 > [241, 255] >=20 > the add of 15 then overflows for both min and max and thus we happily acc= ept > the result but compute the difference signed (in widest_int): >=20 > /* Calculate (ssizetype) OP0 - (ssizetype) TMP_VAR. */ > widest_int diff =3D (widest_int::from (op0_min, sgn) > - widest_int::from (var_min, sgn)); > var0 =3D tmp_var; > *off =3D wide_int_to_tree (ssizetype, diff); >=20 > which then results in 0-241 =3D=3D -241. >=20 > To me it looks like we should instead do >=20 > /* Calculate (ssizetype) (OP0 - TMP_VAR). */ > widest_int diff =3D widest_int::from (op0_min - var_min, = sgn); >=20 > which fixes this particular testcase. Or alternatively widest_int diff =3D wi::ext (widest_int::from (op0_min, sgn) - widest_int::from (var_min, sgn= ), TYPE_PRECISION (type), TYPE_SIGN (type)); which maybe more highlights the underlying issue (failing zero-extension for the sign-changing conversion)? I don't expect any fallout of either patch possibly due to bad test coverage so extra thoughts welcome.=