public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/114009] [11/12/13/14 Regression] Missed optimization: (!a) * a => 0 when a=(a/2)*2
Date: Thu, 07 Mar 2024 07:47:04 +0000	[thread overview]
Message-ID: <bug-114009-4-JLRXRlrjde@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-114009-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114009

--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:95b6ee96348041eaee9133f082b57f3e57ef0b11

commit r14-9350-g95b6ee96348041eaee9133f082b57f3e57ef0b11
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Mar 7 08:43:16 2024 +0100

    match.pd: Optimize a * !a to 0 [PR114009]

    The following patch attempts to fix an optimization regression through
    adding a simple simplification.  We already have the
    /* (m1 CMP m2) * d -> (m1 CMP m2) ? d : 0  */
    (if (!canonicalize_math_p ())
     (for cmp (tcc_comparison)
      (simplify
       (mult:c (convert (cmp@0 @1 @2)) @3)
       (if (INTEGRAL_TYPE_P (type)
            && INTEGRAL_TYPE_P (TREE_TYPE (@0)))
         (cond @0 @3 { build_zero_cst (type); })))
    optimization which otherwise triggers during the a * !a multiplication,
    but that is done only late and we aren't able through range assumptions
    optimize it yet anyway.

    The patch adds a specific simplification for it.
    If a is zero, then a * !a will be 0 * 1 (or for signed 1-bit 0 * -1)
    and so 0.
    If a is non-zero, then a * !a will be a * 0 and so again 0.
    THe pattern is valid for scalar integers, complex integers and vector
types,
    but I think will actually trigger only for the scalar integers.  For
    vector types I've added other two with VEC_COND_EXPR in it, for complex
    there are different GENERIC trees to match and it is something that likely
    would be never matched in GIMPLE, so I didn't handle that.

    2024-03-07  Jakub Jelinek  <jakub@redhat.com>

            PR tree-optimization/114009
            * genmatch.cc (decision_tree::gen): Emit ARG_UNUSED for captures
            argument even for GENERIC, not just for GIMPLE.
            * match.pd (a * !a -> 0): New simplifications.

            * gcc.dg/tree-ssa/pr114009.c: New test.

  parent reply	other threads:[~2024-03-07  7:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-20 10:16 [Bug tree-optimization/114009] New: " 652023330028 at smail dot nju.edu.cn
2024-02-20 23:50 ` [Bug tree-optimization/114009] " pinskia at gcc dot gnu.org
2024-02-20 23:56 ` [Bug tree-optimization/114009] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
2024-02-21  0:03 ` pinskia at gcc dot gnu.org
2024-02-22 10:21 ` rguenth at gcc dot gnu.org
2024-03-05 13:02 ` jakub at gcc dot gnu.org
2024-03-05 14:14 ` jakub at gcc dot gnu.org
2024-03-05 14:24 ` jakub at gcc dot gnu.org
2024-03-07  7:47 ` cvs-commit at gcc dot gnu.org [this message]
2024-03-15  9:45 ` jakub at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-114009-4-JLRXRlrjde@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).