This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/47673] New: Redundant NULL check


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]