public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "amacleod at redhat dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/108360] [13 Regression] Dead Code Elimination Regression at -Os since r13-2048-g418b71c0d535bf
Date: Tue, 10 Jan 2023 19:18:29 +0000	[thread overview]
Message-ID: <bug-108360-4-QgVS0OQMJn@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-108360-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #4 from Andrew Macleod <amacleod at redhat dot com> ---
The IL is different in VRP2 between GCC12 and GCC13.  IN GCC 12 I see:

  <bb 2> [local count: 1073741824]:
  b.2_1 = b;
  _2 = b.2_1 <= 0;
  h.0_20 = (unsigned short) _2;
  _21 = h.0_20 + 65535;
  _22 = (short int) _21;
  _3 = _22 >= 0;
  _4 = (char) _3;
  f = _4;
  f.5_5 = (unsigned char) _3;
  _6 = f.5_5 << 4;
  e = _6;
  h_23 = (short int) _6;
  if (_6 == 0)
    goto <bb 5>; [50.00%]
  else
    goto <bb 3>; [50.00%]

  <bb 3> [local count: 805306368]:
  _8 = b.2_1 == h_23;

Global ranges for bb2 are:
_4 : char [0, 1]
f.5_5 : unsigned char [0, 1]
_6 : unsigned char [0, 0][16, 16]
h.0_20 : unsigned short [0, 1]
_21 : unsigned short [0, 0][+INF, +INF]
_22 : short int [-1, 0]

Looking at what ranger calculates for the edge 2->3 based on _6 having to be 0:

2->3  (F) b.2_1 :       short int [-INF, 0]
2->3  (F) _2 :  _Bool [1, 1]
2->3  (F) _3 :  _Bool [1, 1]
2->3  (F) _4 :  char [1, 1]
2->3  (F) f.5_5 :       unsigned char [1, 1]
2->3  (F) _6 :  unsigned char [16, 16]
2->3  (F) h.0_20 :      unsigned short [1, 1]
2->3  (F) _21 :         unsigned short [0, 0]
2->3  (F) _22 :         short int [0, 0]
2->3  (F) h_23 :        short int [16, 16]

It can determine that h_23 is [16,16] and therefore _8 is always false.  and
when you use _8 = [0, 0]  the condition leading to the call can never be true
so it's eliminated.

The code sequence at -Os is quite different coming into VRP2 in GCC13.  It
involves a PHI node and the condition uses _21 == -1  instead of _6 == 0.  
This cahnges what we can evaluate going out, and when we get to valuation of
_8, it sees:

_8 = b.2_1 == iftmp.8_28;

and iftmp.8_28 is evaluated as [0, 0][16, 16][512, 512]

Because 0 hasnt been eliminated, we cant fold the condition.

We do still get this at -O2... just not at -Os.

  parent reply	other threads:[~2023-01-10 19:18 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-10 13:10 [Bug tree-optimization/108360] New: Dead Code Elimination Regression at -Os (trunk vs. 12.2.0) yann at ywg dot ch
2023-01-10 14:48 ` [Bug tree-optimization/108360] [13 Regression] Dead Code Elimination Regression at -Os since r13-2048-g418b71c0d535bf marxin at gcc dot gnu.org
2023-01-10 17:00 ` jakub at gcc dot gnu.org
2023-01-10 17:32 ` jakub at gcc dot gnu.org
2023-01-10 17:45 ` jakub at gcc dot gnu.org
2023-01-10 19:18 ` amacleod at redhat dot com [this message]
2023-01-10 19:26 ` amacleod at redhat dot com
2023-01-10 19:28 ` amacleod at redhat dot com
2023-03-27 11:37 ` rguenth at gcc dot gnu.org
2023-04-08 14:37 ` law at gcc dot gnu.org
2023-04-26  6:57 ` [Bug tree-optimization/108360] [13/14 " rguenth at gcc dot gnu.org
2023-07-27  9:25 ` rguenth at gcc dot gnu.org
2023-08-07  8:53 ` pinskia at gcc dot gnu.org
2023-08-09  1:25 ` pinskia at gcc dot gnu.org
2024-05-21  9:13 ` [Bug tree-optimization/108360] [13/14/15 " 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-108360-4-QgVS0OQMJn@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).