From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 116984 invoked by alias); 17 Oct 2015 08:34:19 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 116948 invoked by uid 48); 17 Oct 2015 08:34:15 -0000 From: "glisse at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/68000] Suboptimal ternary operator codegen Date: Sat, 17 Oct 2015 08:34:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 5.1.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: glisse 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: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-10/txt/msg01366.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68000 --- Comment #2 from Marc Glisse --- Independently of hoisting, mov eax, edx add edx, 1 add eax, 1 apparently we fail to CSE this because at the time of CSE, one addition is done in mode QI and the other in SI, and it is only in split2 that the QI one is promoted to SI, which is too late for CSE. Actually, it is quite hard to notice that foo is equivalent to the other versions. If you wrote: return (uint8_t)(p->x + 1) == p->y ? 0 : p->x + 1; it would be much easier, and indeed I get better code. For the equivalence, the compiler has to notice that the only case where the cast matters is when x is 255 and y is 0, and in that case both branches (after sinking the cast to uint8_t from the return type) are equivalent.