public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "guojiufu at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/102131] [12 Regression] wrong code at -O1 and above on x86_64-linux-gnu
Date: Thu, 02 Sep 2021 07:14:56 +0000	[thread overview]
Message-ID: <bug-102131-4-oqnbFDwYpT@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-102131-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #6 from Jiu Fu Guo <guojiufu at gcc dot gnu.org> ---
Drafted a patch as below.  With this patch, those cases can pass.

diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c
index 7af92d1c893..a400c42919b 100644
--- a/gcc/tree-ssa-loop-niter.c
+++ b/gcc/tree-ssa-loop-niter.c
@@ -1866,6 +1866,24 @@ number_of_iterations_cond (class loop *loop,
              || !iv0->no_overflow || !iv1->no_overflow))
        return false;

+      /* GT/GE has been transformed to LT/LE already.
+       cmp_code could be LT, LE or NE
+
+       For LE/LT transform
+       {iv0.base, iv0.step} LT/LE {iv1.base, iv1.step}
+       to
+       {iv0.base, iv0.step - iv1.step} LT/LE {iv1.base, 0}
+       Negative iv0.step - iv1.step means decreasing until wrap,
+       then the transform is not accurate.
+
+       For example:
+       {1, +, 1} <= {4, +, 3}
+       is not same with
+       {1, +, -2} <= {4, +, 0}
+       */
+      if ((code == LE_EXPR || code == LT_EXPR) && tree_int_cst_sign_bit
(step))
+       return false;
+
       iv0->step = step;
       if (!POINTER_TYPE_P (type))
        iv0->no_overflow = false;

  parent reply	other threads:[~2021-09-02  7:14 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-30 17:12 [Bug tree-optimization/102131] New: " zhendong.su at inf dot ethz.ch
2021-08-30 18:13 ` [Bug tree-optimization/102131] [12 Regression] " jakub at gcc dot gnu.org
2021-08-31  6:34 ` guojiufu at gcc dot gnu.org
2021-08-31  9:51 ` guojiufu at gcc dot gnu.org
2021-08-31 10:34 ` amker at gcc dot gnu.org
2021-09-01  9:23 ` guojiufu at gcc dot gnu.org
2021-09-02  7:14 ` guojiufu at gcc dot gnu.org [this message]
2021-11-15 17:04 ` [Bug tree-optimization/102131] [12 Regression] wrong code at -O1 and above on x86_64-linux-gnu since r12-3136 jakub at gcc dot gnu.org
2021-11-16  2:01 ` guojiufu at gcc dot gnu.org
2021-12-15 10:18 ` zhendong.su at inf dot ethz.ch
2022-01-24 10:43 ` rguenth at gcc dot gnu.org
2022-01-24 12:15 ` cvs-commit at gcc dot gnu.org
2022-01-24 12:48 ` rguenth at gcc dot gnu.org
2022-01-25  1:28 ` crazylht at gmail dot com

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-102131-4-oqnbFDwYpT@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).