From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E3C2E3858C53; Sat, 7 Oct 2023 11:05:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E3C2E3858C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696676710; bh=SqHSYivPITexB+9cEe2exg8BiRmHPSBNed/0U+3B4KE=; h=From:To:Subject:Date:From; b=w+0lxL4x7r5xrWt+MUs9NzuWWxvZgOJLP6uYCm4UBxm5WsA+YkwYbkSRD9s5UDr6p /vggmPOT8LZ2+JepFZMuOapUQCvhTZigNzwNbAmdYl0UQVcXnQeD/Ejb+1zl9WgoCm 7pOARhbqbZ0PVetG6oJJTlqYEQuldvBKxlPGU15s= From: "652023330028 at smail dot nju.edu.cn" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/111718] New: Missed optimization of '(a+a)/a' Date: Sat, 07 Oct 2023 11:05:10 +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=3D111718 Bug ID: 111718 Summary: Missed optimization of '(a+a)/a' 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 found some optimizations (regarding Arithmetic optimization) that= GCC may have missed. We would greatly appreicate if you can take a look and let= us know what you think. Given the following code:=20 https://godbolt.org/z/5de17zvz9 unsigned n1,n2; void func1(unsigned a){ if(a>10&&a<20){ n1=3Da+a; n2=3D(a+a)/a; } } We note that `(a+a)/a` should be optimized to `2`, but gcc-trunk -O3 does n= ot: func1(unsigned int): lea eax, [rdi-11] cmp eax, 8 ja .L1 lea eax, [rdi+rdi] xor edx, edx mov DWORD PTR n1[rip], eax div edi mov DWORD PTR n2[rip], eax .L1: ret Thank you very much for your time and effort! We look forward to hearing fr= om you.=