From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BE1A4385041E; Sun, 18 Jul 2021 17:04:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BE1A4385041E From: "uwe at netbsd dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/101469] wrong code with "-O2 -fPIE" for SH Date: Sun, 18 Jul 2021 17:04:57 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 10.3.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: uwe at netbsd dot 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: 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: Sun, 18 Jul 2021 17:04:57 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101469 --- Comment #2 from Valeriy E. Ushakov --- I don't have the latest gcc handy, but I see this bug already in an old net= bsd tree from about an year ago with gcc 8.4.0 As hgutch@n.o pointed out, this seems to be a problem with this peephole2: ;; mov r12,r0 ;; add #-48,r0 -> add #-48,r12 ;; mov.l r0,@(4,r10) mov.l r12,@(4,r10) ;; (r12 dead) (define_peephole2 [(set (match_operand:SI 0 "arith_reg_dest") (match_operand:SI 1 "arith_reg_dest")) (set (match_dup 0) (plus:SI (match_dup 0) (match_operand:SI 2 "const_int_operand"))) (set (match_operand:SI 3 "general_movdst_operand") (match_dup 0))] as far as I can tell, it optimizes r0 =3D r2 r0 +=3D 64 *(r0+4) =3D r0 to r2 +=3D 64 *(r0+4) =3D r2 failing to notice that the the destination uses r0 too. Then in the cprop-registers step that r0 is replaced with r12 b/c of r0 =3D= r12 done a bit earlier.=