public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/94913] New: Failure to optimize not+cmp into overflow check
@ 2020-05-02  2:15 gabravier at gmail dot com
  2020-05-02  2:18 ` [Bug tree-optimization/94913] " gabravier at gmail dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: gabravier at gmail dot com @ 2020-05-02  2:15 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94913
           Summary: Failure to optimize not+cmp into overflow check
           Product: gcc
           Version: 10.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: ---

bool f(unsigned x, unsigned y)
{
    return ~x < y;
}

With -O3, LLVM outputs this :

f(unsigned int, unsigned int):
  add edi, esi
  setb al
  ret

GCC outputs this :

f(unsigned int, unsigned int):
  not edi
  cmp edi, esi
  setb al
  ret

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

* [Bug tree-optimization/94913] Failure to optimize not+cmp into overflow check
  2020-05-02  2:15 [Bug tree-optimization/94913] New: Failure to optimize not+cmp into overflow check gabravier at gmail dot com
@ 2020-05-02  2:18 ` gabravier at gmail dot com
  2020-05-05 20:03 ` ubizjak at gmail dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: gabravier at gmail dot com @ 2020-05-02  2:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Gabriel Ravier <gabravier at gmail dot com> ---
The same thing happens for this code :

bool f(unsigned x, unsigned y)
{
    return (x - y - 1) >= x;
}

LLVM outputs this :

f(unsigned int, unsigned int):
  cmp esi, edi
  setae al
  ret

GCC outputs this :

f(unsigned int, unsigned int):
  mov eax, edi
  sub eax, esi
  sub eax, 1
  cmp eax, edi
  setnb al
  ret

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

* [Bug tree-optimization/94913] Failure to optimize not+cmp into overflow check
  2020-05-02  2:15 [Bug tree-optimization/94913] New: Failure to optimize not+cmp into overflow check gabravier at gmail dot com
  2020-05-02  2:18 ` [Bug tree-optimization/94913] " gabravier at gmail dot com
@ 2020-05-05 20:03 ` ubizjak at gmail dot com
  2020-05-05 20:06 ` ubizjak at gmail dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: ubizjak at gmail dot com @ 2020-05-05 20:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Uroš Bizjak <ubizjak at gmail dot com> ---
Created attachment 48458
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48458&action=edit
Prototype patch

Prototype patch for missed optimization, described in Comment #0.

Following testcase:

--cut here--
int
foo (unsigned int x, unsigned int y)
{
  return ~x < y;
}

void f1 (void);
void f2 (void);

void
bar (unsigned int x, unsigned int y)
{
  if (~x < y)
    f1 ();
  else
    f2 ();
}
--cut here--

compiles (-O2) to:

foo:
        xorl    %eax, %eax
        addl    %esi, %edi
        setc    %al
        ret

bar:
        addl    %esi, %edi
        jnc     .L4
        jmp     f1
.L4:
        jmp     f2

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

* [Bug tree-optimization/94913] Failure to optimize not+cmp into overflow check
  2020-05-02  2:15 [Bug tree-optimization/94913] New: Failure to optimize not+cmp into overflow check gabravier at gmail dot com
  2020-05-02  2:18 ` [Bug tree-optimization/94913] " gabravier at gmail dot com
  2020-05-05 20:03 ` ubizjak at gmail dot com
@ 2020-05-05 20:06 ` ubizjak at gmail dot com
  2020-05-06 13:23 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: ubizjak at gmail dot com @ 2020-05-05 20:06 UTC (permalink / raw)
  To: gcc-bugs

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

Uroš Bizjak <ubizjak at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
                 CC|                            |jakub at gcc dot gnu.org
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-05-05

--- Comment #3 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to Gabriel Ravier from comment #1)
> The same thing happens for this code :
> 
> bool f(unsigned x, unsigned y)
> {
>     return (x - y - 1) >= x;
> }

This transformation is the job for tree combiner.

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

* [Bug tree-optimization/94913] Failure to optimize not+cmp into overflow check
  2020-05-02  2:15 [Bug tree-optimization/94913] New: Failure to optimize not+cmp into overflow check gabravier at gmail dot com
                   ` (2 preceding siblings ...)
  2020-05-05 20:06 ` ubizjak at gmail dot com
@ 2020-05-06 13:23 ` jakub at gcc dot gnu.org
  2020-05-06 15:35 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-05-06 13:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 48467
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48467&action=edit
gcc11-pr94913.patch

Untested fix for that part.

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

* [Bug tree-optimization/94913] Failure to optimize not+cmp into overflow check
  2020-05-02  2:15 [Bug tree-optimization/94913] New: Failure to optimize not+cmp into overflow check gabravier at gmail dot com
                   ` (3 preceding siblings ...)
  2020-05-06 13:23 ` jakub at gcc dot gnu.org
@ 2020-05-06 15:35 ` cvs-commit at gcc dot gnu.org
  2020-05-08  7:33 ` cvs-commit at gcc dot gnu.org
  2020-05-08  7:51 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-05-06 15:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Uros Bizjak <uros@gcc.gnu.org>:

https://gcc.gnu.org/g:7c2879301d3b027a1ba427a5d5c7557decb8a7ab

commit r11-145-g7c2879301d3b027a1ba427a5d5c7557decb8a7ab
Author: Uros Bizjak <ubizjak@gmail.com>
Date:   Wed May 6 17:33:51 2020 +0200

    i386: Use ADD to implement compares with negated operand [PR94913]

    Use carry flag from addition to implement GEU/LTU compares
    with negated operand, so e.g.

            ~x < y

    compiles to:

            addq    %rsi, %rdi
            setc    %al

    instead of:

            notq    %rdi
            cmpq    %rsi, %rdi
            setb    %al

            PR target/94913
            * config/i386/predicates.md (add_comparison_operator): New
predicate.
            * config/i386/i386.md (compare->add splitter): New splitters.

    testsuite/ChangeLog:

            PR target/94913
            * gcc.target/i386/pr94913-1.c: New test.
            * gcc.target/i386/pr94913-2.c: Ditto.

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

* [Bug tree-optimization/94913] Failure to optimize not+cmp into overflow check
  2020-05-02  2:15 [Bug tree-optimization/94913] New: Failure to optimize not+cmp into overflow check gabravier at gmail dot com
                   ` (4 preceding siblings ...)
  2020-05-06 15:35 ` cvs-commit at gcc dot gnu.org
@ 2020-05-08  7:33 ` cvs-commit at gcc dot gnu.org
  2020-05-08  7:51 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-05-08  7:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:ff33680165346cb291667f38dd2e9f25a74cc3c3

commit r11-193-gff33680165346cb291667f38dd2e9f25a74cc3c3
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri May 8 09:32:20 2020 +0200

    match.pd: Simplify unsigned A - B - 1 >= A to B >= A [PR94913]

    Implemented thusly.  The TYPE_OVERFLOW_WRAPS is there just because the
    pattern above it has it too, if you want, I can throw it away from both.

    2020-05-08  Jakub Jelinek  <jakub@redhat.com>

            PR tree-optimization/94913
            * match.pd (A - B + -1 >= A to B >= A): New simplification.
            (A - B > A to A < B): Don't test TYPE_OVERFLOW_WRAPS which is
always
            true for TYPE_UNSIGNED integral types.

            * gcc.dg/tree-ssa/pr94913.c: New test.

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

* [Bug tree-optimization/94913] Failure to optimize not+cmp into overflow check
  2020-05-02  2:15 [Bug tree-optimization/94913] New: Failure to optimize not+cmp into overflow check gabravier at gmail dot com
                   ` (5 preceding siblings ...)
  2020-05-08  7:33 ` cvs-commit at gcc dot gnu.org
@ 2020-05-08  7:51 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-05-08  7:51 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

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

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Should be fixed with both of the commits.

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

end of thread, other threads:[~2020-05-08  7:51 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-02  2:15 [Bug tree-optimization/94913] New: Failure to optimize not+cmp into overflow check gabravier at gmail dot com
2020-05-02  2:18 ` [Bug tree-optimization/94913] " gabravier at gmail dot com
2020-05-05 20:03 ` ubizjak at gmail dot com
2020-05-05 20:06 ` ubizjak at gmail dot com
2020-05-06 13:23 ` jakub at gcc dot gnu.org
2020-05-06 15:35 ` cvs-commit at gcc dot gnu.org
2020-05-08  7:33 ` cvs-commit at gcc dot gnu.org
2020-05-08  7:51 ` jakub 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).