Bug ID: 77647
           Summary: Missed opportunity to use register value causes
                    additional load
           Product: gcc
           Version: 6.2.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot
          Reporter: npiggin at gmail dot com
  Target Milestone: ---

static inline long load(long *p)
        long ret;
        asm ("movq      %1,%0\n\t" : "=r" (ret) : "m" (*p));
        if (ret != *p)
        return ret;

long foo(long *mem)
        long ret;
        ret = load(mem);
        return ret - *mem;

foo() compiles down to 'xorl %eax,%eax ; ret' which is great. Changing the
minus to plus gives

        movq    (%rdi),%rax
        addq    (%rdi),%rax

Reply via email to