From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 30704385841E; Wed, 1 Sep 2021 08:16:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 30704385841E From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/99591] Improving __builtin_add_overflow performance on x86-64 Date: Wed, 01 Sep 2021 08:16:16 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 10.2.1 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW 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: cc 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: Wed, 01 Sep 2021 08:16:17 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99591 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #5 from Jakub Jelinek --- But the user could have written: int signed1_overflow (signed char a, signed char b) { signed char r; return __builtin_add_overflow (a, b, &r); } int signed2_overflow (short a, short b) { short r; return __builtin_add_overflow (a, b, &r); } int signed3_overflow (signed char a, signed char b) { signed char r; return __builtin_add_overflow ((int) a, (int) b, &r); } int signed4_overflow (short a, short b) { short r; return __builtin_add_overflow ((int) a, (int) b, &r); } and then the latter two functions behave the same in C and C++. So, I think it would be better to optimize this at the RTL level (only when we've decided what exact operation we are using), but then I think the prob= lem is that this kind of thing is optimized usually by combine which doesn't trigger as the registers have multiple uses: (insn 9 6 10 2 (set (reg:SI 92) (sign_extend:SI (reg/v:QI 88 [ a ]))) "pr99591.c":16:33 151 {extendqisi2} (nil)) (insn 10 9 11 2 (set (reg:SI 93) (sign_extend:SI (reg/v:QI 90 [ b ]))) "pr99591.c":16:33 151 {extendqisi2} (nil)) (insn 11 10 12 2 (set (reg:QI 86 [ _6+1 ]) (const_int 0 [0])) "pr99591.c":16:33 77 {*movqi_internal} (nil)) (insn 12 11 13 2 (parallel [ (set (reg:CCO 17 flags) (eq:CCO (plus:HI (sign_extend:HI (subreg:QI (reg:SI 92) 0)) (sign_extend:HI (subreg:QI (reg:SI 93) 0))) (sign_extend:HI (plus:QI (subreg:QI (reg:SI 92) 0) (subreg:QI (reg:SI 93) 0))))) (set (reg:QI 94) (plus:QI (subreg:QI (reg:SI 92) 0) (subreg:QI (reg:SI 93) 0))) ]) "pr99591.c":16:33 238 {*addvqi4} (nil)) all in the same insn, but still multiple uses. Another option is some gimple optimization, see the arguments are promoted = and repeat part of the expand_arith_overflow analysis and demote the arguments = if possible. Or maybe just demote always and let expand_arith_overflow promote again if needed?=