https://bugs.llvm.org/show_bug.cgi?id=43597

            Bug ID: 43597
           Summary: Reuse flags from shift instruction -> avoid test
                    instruction
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: unassignedb...@nondot.org
          Reporter: david.bolvan...@gmail.com
                CC: craig.top...@gmail.com, llvm-bugs@lists.llvm.org,
                    llvm-...@redking.me.uk, spatel+l...@rotateright.com

int foo (int a)
{
  int b = 0;
  while (a >>= 1)
    b++;

  return b;
}

foo:                                  
        mov     eax, -1
.LBB0_1:                               
        sar     edi
        add     eax, 1
        test    edi, edi
        jne     .LBB0_1
        ret

https://c9x.me/x86/html/file_module_x86_id_285.html

"The SF, ZF, and PF flags are set according to the result. If the count is 0,
the flags are not affected. For a non-zero count, the AF flag is undefined."

So 'test' could be eliminated here.

foo:                                  
        mov     eax, -1
.LBB0_1:                               
        add     eax, 1
        sar     edi
        jne     .LBB0_1
        ret

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to