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

            Bug ID: 43823
           Summary: Missed opportunity to use cmp with exx instead od rxx
                    (code size optimization)
           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

bool test1(U64 val)
{
    return ((U32)(val & 0x120)) == 0x20;
}

define dso_local zeroext i1 @test1(i64 %0) local_unnamed_addr #0 {
  %2 = and i64 %0, 288
  %3 = icmp eq i64 %2, 32
  ret i1 %3
}

test1:  
        and     edi, 288
        cmp     rdi, 32
        sete    al
        ret

(-O0's trunc LLVM IR instruction is eliminated)

but codegen could use "cmp edi" instead of "cmp rdi":

test1:
        and     edi, 288
        cmp     edi, 32
        sete    al
        ret

GCC does this code size optimization (eliminate REX prefix), Clang does not.

Another opportunity for "cmp edi":
bool test2(U64 val)
{
    return (val & 0x120) == 0x20;
}

test2:                     
        and     edi, 288
        cmp     rdi, 32
        sete    al
        ret

Both GCC and Clang fails to use rdi for "test2" case.

https://godbolt.org/z/A0hjTg


Another case:

bool test3(U64 val)
{
    return ((short)(val & 0x120)) == 0x20;
}

Clang
test3:                                  # @test3
        and     edi, 288
        cmp     rdi, 32
        sete    al
        ret

GCC
test3:
        and     di, 288
        cmp     di, 32
        sete    al
        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