public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/47673] New: Redundant NULL check
@ 2011-02-10  0:06 ian at airs dot com
  2011-02-10  0:09 ` [Bug middle-end/47673] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: ian at airs dot com @ 2011-02-10  0:06 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47673

           Summary: Redundant NULL check
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: ian@airs.com


Consider this C code:

struct s1 { int x; };
struct s2 { struct s1 *p1; };
extern void f1(struct s1 *);
static inline void inline_func(struct s1 *p1) { if (p1) f1 (p1); }
void global_function(struct s2 *p2) {
  if (p2->p1 != 0 && p2->p1 != (struct s1 *) -1)
    inline_func(p2->p1);
}

When I compile this with -O2 with current mainline on x86_64, I get this:

    movq    (%rdi), %rdi
    leaq    -1(%rdi), %rax
    cmpq    $-3, %rax
    ja    .L1
    testq    %rdi, %rdi
    je    .L1
    jmp    f1

If %rdi is 0, %rax will be -1, and the ja branch will be taken.  Therefore, the
je following the testq %rdi,%rdi will never be taken.  The test and branch
should be eliminated.


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

* [Bug middle-end/47673] Redundant NULL check
  2011-02-10  0:06 [Bug tree-optimization/47673] New: Redundant NULL check ian at airs dot com
@ 2011-02-10  0:09 ` pinskia at gcc dot gnu.org
  2011-02-10  2:14 ` rguenth at gcc dot gnu.org
  2021-07-26  9:49 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-02-10  0:09 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47673

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011.02.10 00:06:01
          Component|tree-optimization           |middle-end
     Ever Confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-02-10 00:06:01 UTC ---
  if (p2->p1 + -1 <= -3B)

We should disable the optimization which converts 
p2->p1 != 0 && p2->p1 != (struct s1 *) -1 into p2->p1 + -1 <= -3B for pointer
types.


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

* [Bug middle-end/47673] Redundant NULL check
  2011-02-10  0:06 [Bug tree-optimization/47673] New: Redundant NULL check ian at airs dot com
  2011-02-10  0:09 ` [Bug middle-end/47673] " pinskia at gcc dot gnu.org
@ 2011-02-10  2:14 ` rguenth at gcc dot gnu.org
  2021-07-26  9:49 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-02-10  2:14 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47673

--- Comment #2 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-02-10 00:22:05 UTC ---
(In reply to comment #1)
>   if (p2->p1 + -1 <= -3B)
> 
> We should disable the optimization which converts 
> p2->p1 != 0 && p2->p1 != (struct s1 *) -1 into p2->p1 + -1 <= -3B for pointer
> types.

No, VRP should simply work on pointers more properly.


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

* [Bug middle-end/47673] Redundant NULL check
  2011-02-10  0:06 [Bug tree-optimization/47673] New: Redundant NULL check ian at airs dot com
  2011-02-10  0:09 ` [Bug middle-end/47673] " pinskia at gcc dot gnu.org
  2011-02-10  2:14 ` rguenth at gcc dot gnu.org
@ 2021-07-26  9:49 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-26  9:49 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |11.0
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed in GCC 11.
I suspect r11-3685 but I am not 100%.  It is definitely related to ranger
improvements to VRP.

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

end of thread, other threads:[~2021-07-26  9:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-10  0:06 [Bug tree-optimization/47673] New: Redundant NULL check ian at airs dot com
2011-02-10  0:09 ` [Bug middle-end/47673] " pinskia at gcc dot gnu.org
2011-02-10  2:14 ` rguenth at gcc dot gnu.org
2021-07-26  9:49 ` 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).