From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B27653858D32; Mon, 24 Jul 2023 10:51:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B27653858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690195872; bh=1B4i1wgxpNSRPmtSXfYxNzXeo9ZH8H7hs/NQ6nk5xn4=; h=From:To:Subject:Date:From; b=PVuLCKM6Pf14J+hDlVh4wBe4Y4+r/uyHG/nbTl3fka/L7wYqnQShfxNlSJcDqGL3U 9z4vIHZY0QLGesOKIS1+o7IOiP1qQZRwr6oKQtjv4HozS7td0vV/VCeFSqMbaTG73S Oqoj+Sct3FgY/j9HSwZt1Qn2gDa6SB6pklz370xU= From: "acoplan at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/110791] New: [12/13/14 Regression] arm: Wrong code with -Os -march=armv8.1-m.main Date: Mon, 24 Jul 2023 10:51:12 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: acoplan at gcc dot gnu.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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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=3D110791 Bug ID: 110791 Summary: [12/13/14 Regression] arm: Wrong code with -Os -march=3Darmv8.1-m.main Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: acoplan at gcc dot gnu.org Target Milestone: --- The following testcase is miscompiled since at least GCC 12 with -Os -march=3Darmv8.1-m.main: void __attribute__ ((noinline)) foo (char *path, int *result) { char *p =3D path; while (p >=3D path && *p !=3D '/') p--; while (p > path && p[-1] =3D=3D '/') p--; if (p < path) *result =3D 1; } int main(void) { char path[4] =3D "usr"; int x =3D 0; foo (path + 2, &x); if (!x) __builtin_abort (); } Below is the assembly we currently generate together with comments showing = how this goes wrong at runtime: foo: mov r3, r0 @ r3 <- (p =3D path) ldrb r2, [r3], #-1 @ r2 <- *p; p--; cmp r2, #47 it eq moveq r3, r0 @ if (r2 =3D=3D 47) p <- path subs r2, r3, r0 cmp r0, r3 add r2, r2, #1 bhi .L9 @ if (path > p) goto .L9 [taken] adds r0, r0, #1 bne .L6 .L9: movs r2, #1 .L6: subs r2, r2, #1 @ r2 <- 0 [fall through from above] bne .L3 @ [not taken, r2 was #1] bcc .L4 @ [not taken] bx lr @ [return without setting *result =3D 1] .L3: ldrb r0, [r3, #-1]! cmp r0, #47 beq .L6 bx lr .L4: movs r3, #1 str r3, [r1] bx lr At -O2 the code is both correct and much better quality: foo: ldrb r3, [r0] @ zero_extendqisi2 cmp r3, #47 itt ne movne r3, #1 strne r3, [r1] bx lr=