commit c493eaf60c37eb564631a147b70b5b467db3458c
Author: Robert Khasanov <robert.khasanov@intel.com>
Date:   Wed Aug 20 18:51:00 2014 +0400

    [x86] Add _addcarry_u{32|64} and _subborrow_u{32|64}.
    They are added to adxintrin.h but outside __ADX__ block.
    These intrinics generates adc and sbb correspondingly that were available before ADX

diff --git a/include/clang/Basic/BuiltinsX86.def b/include/clang/Basic/BuiltinsX86.def
index 43c7465..6e26d9b 100644
--- a/include/clang/Basic/BuiltinsX86.def
+++ b/include/clang/Basic/BuiltinsX86.def
@@ -611,40 +611,44 @@ BUILTIN(__builtin_ia32_gatherd_d, "V4iV4iV4iC*V4iV4iIc", "")
 BUILTIN(__builtin_ia32_gatherd_d256, "V8iV8iV8iC*V8iV8iIc", "")
 BUILTIN(__builtin_ia32_gatherq_d, "V4iV4iV4iC*V2LLiV4iIc", "")
 BUILTIN(__builtin_ia32_gatherq_d256, "V4iV4iV4iC*V4LLiV4iIc", "")
 
 // F16C
 BUILTIN(__builtin_ia32_vcvtps2ph, "V8sV4fIi", "")
 BUILTIN(__builtin_ia32_vcvtps2ph256, "V8sV8fIi", "")
 BUILTIN(__builtin_ia32_vcvtps2ph512, "V16sV16fIi", "")
 BUILTIN(__builtin_ia32_vcvtph2ps, "V4fV8s", "")
 BUILTIN(__builtin_ia32_vcvtph2ps256, "V8fV8s", "")
 BUILTIN(__builtin_ia32_vcvtph2ps512, "V16fV16s", "")
 
 // RDRAND
 BUILTIN(__builtin_ia32_rdrand16_step, "UiUs*", "")
 BUILTIN(__builtin_ia32_rdrand32_step, "UiUi*", "")
 BUILTIN(__builtin_ia32_rdrand64_step, "UiULLi*", "")
 
 // ADX
 BUILTIN(__builtin_ia32_addcarryx_u32, "UcUcUiUiUi*", "")
 BUILTIN(__builtin_ia32_addcarryx_u64, "UcUcULLiULLiULLi*", "")
+BUILTIN(__builtin_ia32_addcarry_u32, "UcUcUiUiUi*", "")
+BUILTIN(__builtin_ia32_addcarry_u64, "UcUcULLiULLiULLi*", "")
+BUILTIN(__builtin_ia32_subborrow_u32, "UcUcUiUiUi*", "")
+BUILTIN(__builtin_ia32_subborrow_u64, "UcUcULLiULLiULLi*", "")
 
 // RDSEED
 BUILTIN(__builtin_ia32_rdseed16_step, "UiUs*", "")
 BUILTIN(__builtin_ia32_rdseed32_step, "UiUi*", "")
 BUILTIN(__builtin_ia32_rdseed64_step, "UiULLi*", "")
 
 // BMI
 BUILTIN(__builtin_ia32_bextr_u32, "UiUiUi", "")
 BUILTIN(__builtin_ia32_bextr_u64, "ULLiULLiULLi", "")
 
 // BMI2
 BUILTIN(__builtin_ia32_bzhi_si, "UiUiUi", "")
 BUILTIN(__builtin_ia32_bzhi_di, "ULLiULLiULLi", "")
 BUILTIN(__builtin_ia32_pdep_si, "UiUiUi", "")
 BUILTIN(__builtin_ia32_pdep_di, "ULLiULLiULLi", "")
 BUILTIN(__builtin_ia32_pext_si, "UiUiUi", "")
 BUILTIN(__builtin_ia32_pext_di, "ULLiULLiULLi", "")
 
 // TBM
 BUILTIN(__builtin_ia32_bextri_u32, "UiUiIUi", "")
diff --git a/lib/Headers/adxintrin.h b/lib/Headers/adxintrin.h
index 650279e..67d63d2 100644
--- a/lib/Headers/adxintrin.h
+++ b/lib/Headers/adxintrin.h
@@ -29,21 +29,53 @@
 #define __ADXINTRIN_H
 
 #ifdef __ADX__
 static __inline unsigned char __attribute__((__always_inline__, __nodebug__))
 _addcarryx_u32(unsigned char __cf, unsigned int __x, unsigned int __y,
                unsigned int *__p)
 {
   return __builtin_ia32_addcarryx_u32(__cf, __x, __y, __p);
 }
 
 #ifdef __x86_64__
 static __inline unsigned char __attribute__((__always_inline__, __nodebug__))
 _addcarryx_u64(unsigned char __cf, unsigned long __x, unsigned long __y,
                unsigned long long  *__p)
 {
   return __builtin_ia32_addcarryx_u64(__cf, __x, __y, __p);
 }
 #endif
 #endif
 
+static __inline unsigned char __attribute__((__always_inline__, __nodebug__))
+_addcarry_u32(unsigned char __cf, unsigned int __x, unsigned int __y,
+              unsigned int *__p)
+{
+  return __builtin_ia32_addcarry_u32(__cf, __x, __y, __p);
+}
+
+#ifdef __x86_64__
+static __inline unsigned char __attribute__((__always_inline__, __nodebug__))
+_addcarry_u64(unsigned char __cf, unsigned long __x, unsigned long __y,
+              unsigned long long  *__p)
+{
+  return __builtin_ia32_addcarry_u64(__cf, __x, __y, __p);
+}
+#endif
+
+static __inline unsigned char __attribute__((__always_inline__, __nodebug__))
+_subborrow_u32(unsigned char __cf, unsigned int __x, unsigned int __y,
+              unsigned int *__p)
+{
+  return __builtin_ia32_subborrow_u32(__cf, __x, __y, __p);
+}
+
+#ifdef __x86_64__
+static __inline unsigned char __attribute__((__always_inline__, __nodebug__))
+_subborrow_u64(unsigned char __cf, unsigned long __x, unsigned long __y,
+              unsigned long long  *__p)
+{
+  return __builtin_ia32_subborrow_u64(__cf, __x, __y, __p);
+}
+#endif
+
 #endif /* __ADXINTRIN_H */
diff --git a/test/CodeGen/adc-builtins.c b/test/CodeGen/adc-builtins.c
new file mode 100644
index 0000000..dfcd53e
--- /dev/null
+++ b/test/CodeGen/adc-builtins.c
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
+
+// Don't include mm_malloc.h, it's system specific.
+#define __MM_MALLOC_H
+
+#include <x86intrin.h>
+
+unsigned char test_addcarry_u32(unsigned char __cf, unsigned int __x,
+                                unsigned int __y, unsigned int *__p) {
+// CHECK-LABEL: test_addcarry_u32
+// CHECK: call i8 @llvm.x86.addcarry.u32
+  return _addcarry_u32(__cf, __x, __y, __p);
+}
+
+unsigned char test_addcarry_u64(unsigned char __cf, unsigned long __x,
+                                unsigned long __y, unsigned long long *__p) {
+// CHECK-LABEL: test_addcarry_u64
+// CHECK: call i8 @llvm.x86.addcarry.u64
+  return _addcarry_u64(__cf, __x, __y, __p);
+}
+
+unsigned char test_subborrow_u32(unsigned char __cf, unsigned int __x,
+                                unsigned int __y, unsigned int *__p) {
+// CHECK-LABEL: test_subborrow_u32
+// CHECK: call i8 @llvm.x86.subborrow.u32
+  return _subborrow_u32(__cf, __x, __y, __p);
+}
+
+unsigned char test_subborrow_u64(unsigned char __cf, unsigned long __x,
+                                unsigned long __y, unsigned long long *__p) {
+// CHECK-LABEL: test_subborrow_u64
+// CHECK: call i8 @llvm.x86.subborrow.u64
+  return _subborrow_u64(__cf, __x, __y, __p);
+}
