[llvm-bugs] [Bug 38852] New: clang uses adcx rather then adc when "arch=skylake"

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Sep 6 00:02:46 PDT 2018


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

            Bug ID: 38852
           Summary: clang uses adcx rather then adc when "arch=skylake"
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: ilya.lesokhin at gmail.com
                CC: llvm-bugs at lists.llvm.org

Created attachment 20847
  --> https://bugs.llvm.org/attachment.cgi?id=20847&action=edit
source file

clang uses adcx rather then adc when "arch=skylake"

This seems to be a bad idea for two reasons.
1. adcx is bigger then adc.

2. adcx doesn't update the sign flag which might result in worst code.

Just using -mbmi2, to enable adcx support, doesn't trigger the issue.

See for example:
https://godbolt.org/z/Yt32d9

Source:
#include <stdint.h>

__int128 good(__int128 a, __int128 b) {
    b = a + b;

    return b < 0 ? a : b;
}


__int128 __attribute__ ((__target__ ("arch=skylake"))) bad(__int128 a, __int128
b) {
    b = a + b;

    return b < 0 ? a : b;
}


Output:
good(__int128, __int128): # @good(__int128, __int128)
  add rdx, rdi
  adc rcx, rsi
  cmovs rdx, rdi
  cmovs rcx, rsi
  mov rax, rdx
  mov rdx, rcx
  ret
bad(__int128, __int128): # @bad(__int128, __int128)
  add rdx, rdi
  adcx rcx, rsi
  test rcx, rcx
  cmovs rdx, rdi
  cmovs rcx, rsi
  mov rax, rdx
  mov rdx, rcx
  ret

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180906/c4c32a04/attachment.html>


More information about the llvm-bugs mailing list