public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/112982] New: Missing optimization: fold max(b, a + 1) to b when a < b
@ 2023-12-12 10:24 xxs_chy at outlook dot com
  2023-12-12 17:35 ` [Bug tree-optimization/112982] " pinskia at gcc dot gnu.org
  2023-12-12 19:05 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: xxs_chy at outlook dot com @ 2023-12-12 10:24 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112982
           Summary: Missing optimization: fold max(b, a + 1) to b when a <
                    b
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xxs_chy at outlook dot com
  Target Milestone: ---

Godbolt example: https://godbolt.org/z/nn8hT16Ka

long src(long a, long b) {
    if(a < b){
        return max(b, a + 1);
    }else{
        return 0;
    }
}

can be folded to:

long tgt(long a, long b) {
    if(a < b){
        return b;
    }else{
        return 0;
    }
}

Similarly, such pattern can be generalized to `a > b`, `min(b, a + 1)`.
Both GCC and LLVM missed such optimization opportunity.

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

* [Bug tree-optimization/112982] Missing optimization: fold max(b, a + 1) to b when a < b
  2023-12-12 10:24 [Bug tree-optimization/112982] New: Missing optimization: fold max(b, a + 1) to b when a < b xxs_chy at outlook dot com
@ 2023-12-12 17:35 ` pinskia at gcc dot gnu.org
  2023-12-12 19:05 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-12 17:35 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement

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

* [Bug tree-optimization/112982] Missing optimization: fold max(b, a + 1) to b when a < b
  2023-12-12 10:24 [Bug tree-optimization/112982] New: Missing optimization: fold max(b, a + 1) to b when a < b xxs_chy at outlook dot com
  2023-12-12 17:35 ` [Bug tree-optimization/112982] " pinskia at gcc dot gnu.org
@ 2023-12-12 19:05 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-12 19:05 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-12-12
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed. Very much related to PR 110199 .

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

end of thread, other threads:[~2023-12-12 19:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-12 10:24 [Bug tree-optimization/112982] New: Missing optimization: fold max(b, a + 1) to b when a < b xxs_chy at outlook dot com
2023-12-12 17:35 ` [Bug tree-optimization/112982] " pinskia at gcc dot gnu.org
2023-12-12 19:05 ` pinskia 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).