From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id AC694385781F; Fri, 17 Feb 2023 16:46:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AC694385781F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676652389; bh=79NPJSfvzFVyaWWcKfZlMUCayOiEejMNJ3YIu+/CHDc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=KVUXnDbHoH/afAaTR8536DdWA2jz9++P9ak8OOQ9qPGazIyP0foxvwx5G9Y5I6iWn QpsOm2qQmtsZwH1B0Jb8Zk8yt2q3ayEQvgsmnfc1fA2CHye3KRIotOTmbCpKhuuBF2 J7hdSKOFSv1nkghaMqaCAesnMda6EipY7xv32nto= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/108819] [12/13 Regression] ICE on valid code at -O1 with "-fno-tree-ccp -fno-tree-forwprop" on x86_64-linux-gnu: tree check: expected ssa_name, have integer_cst in number_of_iterations_cltz, at tree-ssa-loop-niter.cc:2394 Date: Fri, 17 Feb 2023 16:46:29 +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: 13.0 X-Bugzilla-Keywords: ice-on-valid-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: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.3 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=3D108819 --- Comment #4 from Jakub Jelinek --- (In reply to Richard Biener from comment #3) > --- a/gcc/tree-ssa-reassoc.cc > +++ b/gcc/tree-ssa-reassoc.cc > @@ -2950,6 +2950,9 @@ update_range_test (struct range_entry *range, struct > range_entry *otherrange, > } > if (stmt =3D=3D NULL) > gcc_checking_assert (tem =3D=3D op); > + /* When range->exp is a constant, we can use it as-is. */ > + else if (is_gimple_min_invariant (tem)) > + ; > /* In rare cases range->exp can be equal to lhs of stmt. > In that case we have to insert after the stmt rather then before > it. If stmt is a PHI, insert it at the start of the basic block. = */ That would make things worse, not better (i.e. constants could appear more often and we could trigger these problems more often), no? forwprop/ccp etc. should optimize it later... I wonder if we just can't do: --- gcc/tree-ssa-reassoc.cc.jj 2023-02-16 10:41:11.000000000 +0100 +++ gcc/tree-ssa-reassoc.cc 2023-02-17 17:43:52.169452832 +0100 @@ -4687,6 +4687,8 @@ update_ops (tree var, enum tree_code cod gimple_set_uid (g, gimple_uid (stmt)); gimple_set_visited (g, true); gsi_insert_before (&gsi, g, GSI_SAME_STMT); + gimple_stmt_iterator gsi2 =3D gsi_for_stmt (g); + fold_stmt_inplace (&gsi2); } return var; } or if the in-place folding wouldn't be appropriate, at least fold it by han= d if both arguments are constants. Though, there is also the case of commutative ops and just the first one turned into constant etc.=