From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A826C3858407; Thu, 31 Aug 2023 01:03:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A826C3858407 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1693443797; bh=Wx7WSfw3R71fhKCntZoHyGiHN+ikGHz4ULMx+EFa0DI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=NSK45A3fE34YZIJUC+sCi5ixHcPIgcfbDSJrd1FZXoH/JIz28NEsXzIte8Ax/NHOU 1FQpTMQ2iC+WqVWg5C6CAd84YOXSaj/uMMAeJ5jR05ng4jWa5q/kVwgTDquNzNv0Eo hRaXxuJJPV6xJyAiZIPAdt5fag8FmPkpiXsVqNNE= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/19832] don't remove an if when we know the value is the same as with the if (subtraction) Date: Thu, 31 Aug 2023 01:03:16 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 4.0.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: pinskia 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=3D19832 --- Comment #8 from Andrew Pinski --- Xor should be handled too: ``` int f_xor(int i, int j) { if (i!=3Dj) return i ^ j; return 0; } `` ior and and should be handled ``` int f_or(int i, int j) { if (i!=3Dj) return i | j; return i; // could be j not just i } int f_and(int i, int j) { if (i!=3Dj) return i & j; return i; // could be j not just i } ``` So can plus and multiply: ``` int f_add(int i, int j) { if (i!=3Dj) return i + j; return i+i; } int f_mult(int i, int j) { if (i!=3Dj) return i * j; return i*i; } ``` Note clang handles all of these except for f_add. f_mult might be handled v= ia the pull `i*` out of the conditional and then you have `i!=3Dj?j:i` which t= hen will be reduced to j (that is they don't pattern match f_mult). They don't = have pattern matching for f_add either and `i+i` will change to `i*2` and not pu= lled out of the condition.=