public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "652023330028 at smail dot nju.edu.cn" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/111724] New: [Regression] Missed optimizations probably because of too early arithmetic optimization
Date: Sun, 08 Oct 2023 07:55:46 +0000	[thread overview]
Message-ID: <bug-111724-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 111724
           Summary: [Regression] Missed optimizations probably because of
                    too early arithmetic optimization
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 652023330028 at smail dot nju.edu.cn
  Target Milestone: ---

Hello, we found some optimizations (probably because of too early arithmetic
optimization) that GCC may have missed. We would greatly appreicate if you can
take a look and let us know what you think.

Given the following code:
https://godbolt.org/z/8EW8fx78K
int n;
void func(int w, int a, int b){
    for(int i=0;i<w;i++){
        n += (a+a)+(b+b);
        b += b;
    }
}

`a+a` is a loop invariant. But gcc-trunk -O3:
func(int, int, int):
        push    {r4, lr}
        subs    lr, r0, #0
        ble     .L1
        movw    r4, #:lower16:.LANCHOR0
        movt    r4, #:upper16:.LANCHOR0
        mov     ip, #0
        ldr     r0, [r4]
.L3:
        adds    r3, r1, r2
        add     ip, ip, #1
        lsls    r2, r2, #1
        cmp     lr, ip
        add     r0, r0, r3, lsl #1
        bne     .L3
        str     r0, [r4]

From original(tree):
   (void) (n = (a + b) * 2 + n) >>>>>;

This leads to:
  _1 = a_11(D) + b_18;
  _2 = _1 * 2;
  _4 = _2 + n_lsm.4_7;

So, it looks like the missed LICM is due to too early arithmetic optimization.

On gcc-6.4, it works as expected.

We found that this also affects other optimizations, such as common
subexpression elimination. We can provide examples if required.

Thank you very much for your time and effort! We look forward to hearing from
you.

             reply	other threads:[~2023-10-08  7:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-08  7:55 652023330028 at smail dot nju.edu.cn [this message]
2023-10-09  9:53 ` [Bug tree-optimization/111724] " rguenth at gcc dot gnu.org
2023-10-09 10:34 ` 652023330028 at smail dot nju.edu.cn

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