public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/95393] New: Failure to optimize loop condition arithmetic for mismatched types
@ 2020-05-28 17:01 gabravier at gmail dot com
  2020-05-28 17:45 ` [Bug tree-optimization/95393] " glisse at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: gabravier at gmail dot com @ 2020-05-28 17:01 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95393
           Summary: Failure to optimize loop condition arithmetic for
                    mismatched types
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gabravier at gmail dot com
  Target Milestone: ---

int f(unsigned s)
{
    int i;
    for (i = 0; i < s; ++i)
        ;

    return i;
}

This can be optimized to `return s;`. LLVM does this transformation, but GCC
does not.

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

* [Bug tree-optimization/95393] Failure to optimize loop condition arithmetic for mismatched types
  2020-05-28 17:01 [Bug tree-optimization/95393] New: Failure to optimize loop condition arithmetic for mismatched types gabravier at gmail dot com
@ 2020-05-28 17:45 ` glisse at gcc dot gnu.org
  2020-05-28 20:24 ` gabravier at gmail dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: glisse at gcc dot gnu.org @ 2020-05-28 17:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Marc Glisse <glisse at gcc dot gnu.org> ---
It does optimize for me with -O2 or -O3. It could optimize earlier though, by
the end of gimple, we are still trying to return max(s,0).

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

* [Bug tree-optimization/95393] Failure to optimize loop condition arithmetic for mismatched types
  2020-05-28 17:01 [Bug tree-optimization/95393] New: Failure to optimize loop condition arithmetic for mismatched types gabravier at gmail dot com
  2020-05-28 17:45 ` [Bug tree-optimization/95393] " glisse at gcc dot gnu.org
@ 2020-05-28 20:24 ` gabravier at gmail dot com
  2020-05-29  6:30 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: gabravier at gmail dot com @ 2020-05-28 20:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Gabriel Ravier <gabravier at gmail dot com> ---
Hm, I've just done some further testing and it appears that it only occurs for
me on x86 when I have `-msse4.1` on the command line, in which case it doesn't
optimize it to `return s;`, but instead does a compare beforehand.

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

* [Bug tree-optimization/95393] Failure to optimize loop condition arithmetic for mismatched types
  2020-05-28 17:01 [Bug tree-optimization/95393] New: Failure to optimize loop condition arithmetic for mismatched types gabravier at gmail dot com
  2020-05-28 17:45 ` [Bug tree-optimization/95393] " glisse at gcc dot gnu.org
  2020-05-28 20:24 ` gabravier at gmail dot com
@ 2020-05-29  6:30 ` rguenth at gcc dot gnu.org
  2020-05-29  8:16 ` cvs-commit at gcc dot gnu.org
  2020-05-29  8:16 ` rguenth at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-05-29  6:30 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-05-29
             Status|UNCONFIRMED                 |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Looks like phiopt fails to fold the generated MAX_EXPR.

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

* [Bug tree-optimization/95393] Failure to optimize loop condition arithmetic for mismatched types
  2020-05-28 17:01 [Bug tree-optimization/95393] New: Failure to optimize loop condition arithmetic for mismatched types gabravier at gmail dot com
                   ` (2 preceding siblings ...)
  2020-05-29  6:30 ` rguenth at gcc dot gnu.org
@ 2020-05-29  8:16 ` cvs-commit at gcc dot gnu.org
  2020-05-29  8:16 ` rguenth at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-05-29  8:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:07852a81f58532c63a57631d7c3757fc6bcea17d

commit r11-710-g07852a81f58532c63a57631d7c3757fc6bcea17d
Author: Richard Biener <rguenther@suse.de>
Date:   Fri May 29 09:25:53 2020 +0200

    tree-optimization/95393 - fold MIN/MAX_EXPR generated by phiopt

    This makes sure to fold generated stmts so they do not survive
    until RTL expansion and cause awkward code generation.

    2020-05-29  Richard Biener <rguenther@suse.de>

            PR tree-optimization/95393
            * tree-ssa-phiopt.c (minmax_replacement): Use gimple_build
            to build the min/max expression so we simplify cases like
            MAX(0, s) immediately.

            * gcc.dg/tree-ssa/phi-opt-21.c: New testcase.
            * g++.dg/vect/slp-pr87105.cc: Adjust.

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

* [Bug tree-optimization/95393] Failure to optimize loop condition arithmetic for mismatched types
  2020-05-28 17:01 [Bug tree-optimization/95393] New: Failure to optimize loop condition arithmetic for mismatched types gabravier at gmail dot com
                   ` (3 preceding siblings ...)
  2020-05-29  8:16 ` cvs-commit at gcc dot gnu.org
@ 2020-05-29  8:16 ` rguenth at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-05-29  8:16 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed.

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

end of thread, other threads:[~2020-05-29  8:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-28 17:01 [Bug tree-optimization/95393] New: Failure to optimize loop condition arithmetic for mismatched types gabravier at gmail dot com
2020-05-28 17:45 ` [Bug tree-optimization/95393] " glisse at gcc dot gnu.org
2020-05-28 20:24 ` gabravier at gmail dot com
2020-05-29  6:30 ` rguenth at gcc dot gnu.org
2020-05-29  8:16 ` cvs-commit at gcc dot gnu.org
2020-05-29  8:16 ` 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).