From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D99253858432; Fri, 12 Apr 2024 07:14:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D99253858432 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1712906054; bh=ZW80CVnXERg3BeYGerLdhpMWPEQ9kBYuptzV5MCZTUA=; h=From:To:Subject:Date:From; b=kwRomdTxRkgjlTsp+Pj4j/1NH+zpk1GYje0prWuHNGnM+ieMz4M4EpzOYji7aYNsl OeGJ7Se9UWY4xq8ige8Eqph/kTv7H2uAwRPWmSeaFs+yJU4vi/jFj4q8ysyP7V3SDr libh/SuRC/8fzhc8n5PezPhx4bWQ12aK0a7WmKpk= From: "652023330028 at smail dot nju.edu.cn" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/114701] New: Missed optimization of loop invariant Date: Fri, 12 Apr 2024 07:14:14 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: 652023330028 at smail dot nju.edu.cn 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=3D114701 Bug ID: 114701 Summary: Missed optimization of loop invariant Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: 652023330028 at smail dot nju.edu.cn Target Milestone: --- Hello, we noticed that maybe there is a missed optimization of loop invaria= nt. Loop invariant: 100/(b+d). https://godbolt.org/z/jKs5qohMs int a, b; void func() { int d =3D 0; for (int i =3D 0; i < 1000; i++) { b +=3D 1; d +=3D -1; a +=3D 100 / (b + d); } } GCC -O3 -fwrapv: func(): mov r9d, DWORD PTR b[rip] mov edi, DWORD PTR a[rip] xor ecx, ecx lea r8d, [r9+1] .L2: mov esi, r8d mov eax, 100 xor edx, edx sub esi, ecx sub ecx, 1 add esi, ecx idiv esi add edi, eax cmp ecx, -1000 jne .L2 add r9d, 1000 mov DWORD PTR a[rip], edi mov DWORD PTR b[rip], r9d ret Expected code (Clang -O3 -fwrapv -fno-tree-vectorize): func(): # @func() mov ecx, dword ptr [rip + b] mov esi, dword ptr [rip + a] mov eax, 100 xor edx, edx idiv ecx add eax, eax mov edx, 1000 lea edi, [rax + rax] .LBB0_1: # =3D>This Inner Loop Header: Depth= =3D1 add esi, eax add esi, edi add esi, edi add edx, -10 jne .LBB0_1 add ecx, 1000 mov dword ptr [rip + b], ecx mov dword ptr [rip + a], esi ret Thank you very much for your time and effort! We look forward to hearing fr= om you.=