From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 124953858024; Fri, 16 Jun 2023 11:32:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 124953858024 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686915174; bh=a1ga8paKagW+xkYrkFD8LZFx+oG2yt8shvovJMSKeqY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=RHW1letdMVHt5CAw1RePU75fXeQmeDCOBtQNwzEjB1Mv6P4MlkU2V9lJp/kuBhrSb iltq/a1fk3IyqZN6CCvj5YhsVLrPDez+oVfoC+xuumM1bXZFobYBlwXtOuTQ2es+iJ TE1PEGTNyUBCanaU48iFjIE4J9xbts9zZk0kvep8= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/110243] [13/14 Regression] Wrong code at -O3 on x86_64-linux-gnu Date: Fri, 16 Jun 2023 11:32:53 +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: 14.0 X-Bugzilla-Keywords: needs-bisection, 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: 13.2 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=3D110243 --- Comment #2 from Richard Biener --- [local count: 5636687]: + _141 =3D (int) _5; + _144 =3D _141 * 2; + ivtmp.22_136 =3D (unsigned int) _144; ... [local count: 51242611]: - # d.7_1 =3D PHI <0(26), _48(23)> + # ivtmp.22_17 =3D PHI ... - _45 =3D d.7_1 + 3194967297; - _46 =3D _44 + _45; + _46 =3D ivtmp.22_17 + 2094967296; that signed multiplication by two smells like it could be an issue. Keeping IVOPTs enabled works when disabling the followup DOM and VRP passes who eventually produce range info. IV struct: SSA_NAME: _46 Type: unsigned int Base: (unsigned int) (((int) _5 + -1) + ((int) _5 + -1100000000)) + 3194967297 Step: 1 Biv: N Candidate 5: Var befor: ivtmp.22 Var after: ivtmp.22 Incr POS: before exit test IV struct: Type: unsigned int Base: (unsigned int) ((int) _5 * 2)=20 Step: 1 Biv: N Overflowness wrto loop niter: Overflow and indeed (int) _5 * 2 will overflow as _5 is 'X'. This multiplication is built via #0 0x00000000010eaa2a in fold_build2_loc (loc=3D0, code=3DMULT_EXPR,=20 type=3D, op0=3D,=20 op1=3D) at /home/rguenther/src/trunk/gcc/fold-const.cc:13781 #1 0x0000000002e41e72 in generic_simplify_PLUS_EXPR (loc=3D0, code=3DPLUS_= EXPR,=20 type=3D, _p0=3D,=20 _p1=3D) at generic-match-2.cc:4924 #2 0x0000000001edc488 in generic_simplify (loc=3D0, code=3DPLUS_EXPR,=20 type=3D, _p0=3D,=20 _p1=3D) at generic-match-5.cc:8173 #3 0x00000000010dbf1a in fold_binary_loc (loc=3D0, code=3DPLUS_EXPR,=20 type=3D, op0=3D,=20 op1=3D) at /home/rguenther/src/trunk/gcc/fold-const.cc:10889 #4 0x00000000010eaa03 in fold_build2_loc (loc=3D0, code=3DPLUS_EXPR,=20 type=3D, op0=3D,=20 op1=3D) at /home/rguenther/src/trunk/gcc/fold-const.cc:13779 #5 0x000000000180266d in strip_offset_1 (expr=3D= ,=20 inside_addr=3Dfalse, top_compref=3Dfalse, offset=3D0x7fffffffd628) at /home/rguenther/src/trunk/gcc/tree-ssa-loop-ivopts.cc:2822 #6 0x00000000018024f7 in strip_offset_1 (expr=3D= ,=20 inside_addr=3Dfalse, top_compref=3Dfalse, offset=3D0x7fffffffd6d0) at /home/rguenther/src/trunk/gcc/tree-ssa-loop-ivopts.cc:2804 #7 0x0000000001802e70 in strip_offset (expr=3D,= =20 offset=3D0x7fffffffd728) at /home/rguenther/src/trunk/gcc/tree-ssa-loop-ivopts.cc:2949 #8 0x0000000001804d7e in add_iv_candidate_for_use (data=3D0x7fffffffd990,= =20 use=3D0x4207f60) at /home/rguenther/src/trunk/gcc/tree-ssa-loop-ivopts.cc:3566 where strip_offset simplifies (unsigned int) (((int) _5 + -1) + ((int) _5 + -1100000000)) + 3194967297 to this expression and an offset. I think IVOPTs strip_offset suffers from the same issues as tree-data-ref.cc split_constant_offset did. Using split_constant_offset instead does not produce this candidate. Instead we have Candidate 4: Var befor: ivtmp.21 Var after: ivtmp.21 Incr POS: before exit test IV struct: Type: unsigned int Base: (unsigned int) (((int) _5 + -1) + ((int) _5 + -1100000000))= + 3194967297 Step: 1 Biv: N Overflowness wrto loop niter: Overflow Candidate 5: Var befor: ivtmp.22 Var after: ivtmp.22 Incr POS: before exit test IV struct: Type: unsigned int Base: (unsigned int) _5 + 3194967298 Step: 1 Biv: N Overflowness wrto loop niter: Overflow and Selected IV set for loop 3 at t.c:16, 9 avg niters, 1 IVs: Candidate 5: Var befor: ivtmp.22_17 Var after: ivtmp.22_16 Incr POS: before exit test IV struct: Type: unsigned int Base: (unsigned int) _5 + 3194967298 Step: 1 Biv: N Overflowness wrto loop niter: Overflow=