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

            Bug ID: 43310
           Summary: Failed to combine -smax(-x,-y) to smin(x,y)
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected]

Noticed while investigating [Bug #42863] - its a rare case where we do better
on float than integer!

Current codegen: https://gcc.godbolt.org/z/epgWrG

auto min_f32(float x, float y) {
    return std::min(x, y);
}
auto neg_max_f32(float x, float y) {
    return -std::max(-x, -y);
}

auto min_s32(int x, int y) {
    return std::min(x, y);
}
auto neg_max_s32(int x, int y) {
    return -std::max(-x, -y);
}

min_f32(float, float):
        vminss  %xmm0, %xmm1, %xmm0
        retq
neg_max_f32(float, float):
        vminss  %xmm0, %xmm1, %xmm0
        retq
min_s32(int, int):
        movl    %edi, %eax
        cmpl    %edi, %esi
        cmovlel %esi, %eax
        retq
neg_max_s32(int, int):
        movl    %esi, %eax
        negl    %edi
        negl    %eax
        cmpl    %eax, %edi
        cmovgel %edi, %eax
        negl    %eax
        retq

vs gcc:

min_f32(float, float):
        vminss  %xmm0, %xmm1, %xmm0
        ret
neg_max_f32(float, float):
        vminss  %xmm0, %xmm1, %xmm0
        ret
min_s32(int, int):
        cmpl    %edi, %esi
        movl    %edi, %eax
        cmovle  %esi, %eax
        ret
neg_max_s32(int, int):
        cmpl    %esi, %edi
        movl    %esi, %eax
        cmovle  %edi, %eax
        ret

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

Reply via email to