From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7A76E385770F; Wed, 17 May 2023 23:42:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A76E385770F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684366931; bh=9htaJb2IIeW86590tV6rU7yrzkjShdUPWKCT3lTzMyo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=gZCtVy5abzJ7Q2eBaZHwiiaZB9qe8+DBs6/y26J1PGSjQqcknWNSbjN25ZFPBHI1g v9RNGWDS25vCrUSA68sgiTAUITv2Drs726zN0lGHBpGYUlKgtmI8WPzBOHTG3kVgRn pYMRgbzEyelbWr1qhXLvEvf6KEbJT377AeFOxJvs= From: "thiago at kde dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/109896] Missed optimisation: overflow detection in multiplication instructions for operator new Date: Wed, 17 May 2023 23:42:11 +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: 13.1.1 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: thiago at kde 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109896 --- Comment #3 from Thiago Macieira --- (In reply to H.J. Lu from comment #2) > (In reply to Andrew Pinski from comment #1) > > I suspect the overflow code was added before __builtin_*_overflow were = added > > which is why the generated code is this way. >=20 > Should the C++ front-end use __builtin_mul_overflow? That's what that code is doing, yes. But mind you that not all examples are doing actual multiplications. That's= why I had the weird size of 47. A size that is a power of 2 is just doing bit checks. For example, 16: movq %rdi, %rax shrq $59, %rax jne .L2 Other sizes do the compare, but there's no multiplication involved. For 24: movabsq $384307168202282325, %rax cmpq %rdi, %rax jb .L2 leaq (%rdi,%rdi,2), %rdi salq $3, %rdi 5 instructions, 4 cycles (not including front-end decode), so roughly the s= ame as the imulq example above (4 cycles), but with far more ports to dispatch = to.=