public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114719] New: Missed optimization: conditional in loop is an invariant (a%2)
@ 2024-04-15  8:46 652023330028 at smail dot nju.edu.cn
  2024-04-15 11:46 ` [Bug tree-optimization/114719] " rguenth at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: 652023330028 at smail dot nju.edu.cn @ 2024-04-15  8:46 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114719
           Summary: Missed optimization: conditional in loop is an
                    invariant (a%2)
           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 noticed that maybe there is a missed optimization for Loop Unswitch.

In the following reduced code, the value of 'a%2' is the same each time through
the loop.

https://godbolt.org/z/49cGaanr8

unsigned a, b;
int m,n;
void func() {
  for (unsigned i=0; i < 1000; i++) {
    if(a%2)
        b++;
    a += 2;
  }
}

But GCC -O3 -fwrapv:
  <bb 3> [local count: 1063004408]:
  # b_lsm.7_10 = PHI <b_lsm.7_20(2), b_lsm.7_34(5)>
  # b_lsm_flag.8_11 = PHI <0(2), b_lsm_flag.8_35(5)>
  # ivtmp.13_24 = PHI <a_lsm.6_19(2), ivtmp.13_28(5)>
  # DEBUG i => NULL
  # DEBUG BEGIN_STMT
  _32 = ivtmp.13_24 & 1;
  if (_32 != 0)
    goto <bb 4>; [50.00%]
  else
    goto <bb 5>; [50.00%]

  <bb 4> [local count: 531502204]:
  # DEBUG BEGIN_STMT
  _33 = b_lsm.7_10 + 1;

  <bb 5> [local count: 1063004408]:
  # b_lsm.7_34 = PHI <b_lsm.7_10(3), _33(4)>
  # b_lsm_flag.8_35 = PHI <b_lsm_flag.8_11(3), 1(4)>
  # DEBUG BEGIN_STMT
  # DEBUG BEGIN_STMT
  # DEBUG i => NULL
  # DEBUG BEGIN_STMT
  ivtmp.13_28 = ivtmp.13_24 + 2;
  if (ivtmp.13_28 != _37)
    goto <bb 3>; [98.99%]
  else
    goto <bb 6>; [1.01%]

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug tree-optimization/114719] Missed optimization: conditional in loop is an invariant (a%2)
  2024-04-15  8:46 [Bug tree-optimization/114719] New: Missed optimization: conditional in loop is an invariant (a%2) 652023330028 at smail dot nju.edu.cn
@ 2024-04-15 11:46 ` rguenth at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-04-15 11:46 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |missed-optimization
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-04-15
             Blocks|                            |85316

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85316
[Bug 85316] [meta-bug] VRP range propagation missed cases

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-04-15 11:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-15  8:46 [Bug tree-optimization/114719] New: Missed optimization: conditional in loop is an invariant (a%2) 652023330028 at smail dot nju.edu.cn
2024-04-15 11:46 ` [Bug tree-optimization/114719] " rguenth at gcc dot gnu.org

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).