commit 80be5cd9ec53d57734f67357a3cc6f44d69f980f
Author: Robert Khasanov <robert.khasanov@intel.com>
Date:   Tue Aug 19 14:02:23 2014 +0400

    [x86] Added _addcarryx_u32, _addcarryx_u64 intrinsics

diff --git a/include/clang/Basic/BuiltinsX86.def b/include/clang/Basic/BuiltinsX86.def
index 8c59171..43c7465 100644
--- a/include/clang/Basic/BuiltinsX86.def
+++ b/include/clang/Basic/BuiltinsX86.def
@@ -608,40 +608,44 @@ BUILTIN(__builtin_ia32_gatherd_q256, "V4LLiV4LLiV4LLiC*V4iV4LLiIc", "")
 BUILTIN(__builtin_ia32_gatherq_q, "V2LLiV2LLiV2LLiC*V2LLiV2LLiIc", "")
 BUILTIN(__builtin_ia32_gatherq_q256, "V4LLiV4LLiV4LLiC*V4LLiV4LLiIc", "")
 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*", "")
+
 // 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", "")
 BUILTIN(__builtin_ia32_bextri_u64, "ULLiULLiIULLi", "")
diff --git a/lib/Headers/CMakeLists.txt b/lib/Headers/CMakeLists.txt
index 5b3b49f..d23e212 100644
--- a/lib/Headers/CMakeLists.txt
+++ b/lib/Headers/CMakeLists.txt
@@ -1,21 +1,22 @@
 set(files
+  adxintrin.h
   altivec.h
   ammintrin.h
   arm_acle.h
   avxintrin.h
   avx2intrin.h
   avx512fintrin.h
   avx512erintrin.h
   bmiintrin.h
   bmi2intrin.h
   emmintrin.h
   f16cintrin.h
   float.h
   fma4intrin.h
   fmaintrin.h
   ia32intrin.h
   immintrin.h
   iso646.h
   Intrin.h
   limits.h
   lzcntintrin.h
diff --git a/lib/Headers/adxintrin.h b/lib/Headers/adxintrin.h
new file mode 100644
index 0000000..650279e
--- /dev/null
+++ b/lib/Headers/adxintrin.h
@@ -0,0 +1,49 @@
+/*===---- adxintrin.h - ADX intrinsics -------------------------------------===
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ *===-----------------------------------------------------------------------===
+ */
+
+#ifndef __IMMINTRIN_H
+#error "Never use <adxintrin.h> directly; include <immintrin.h> instead."
+#endif
+
+#ifndef __ADXINTRIN_H
+#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
+
+#endif /* __ADXINTRIN_H */
diff --git a/lib/Headers/immintrin.h b/lib/Headers/immintrin.h
index 00121f4..1f600a6 100644
--- a/lib/Headers/immintrin.h
+++ b/lib/Headers/immintrin.h
@@ -106,21 +106,23 @@ _rdrand64_step(unsigned long long *__p)
 #endif
 #endif /* __RDRND__ */
 
 #ifdef __RTM__
 #include <rtmintrin.h>
 #endif
 
 /* FIXME: check __HLE__ as well when HLE is supported. */
 #if defined (__RTM__)
 static __inline__ int __attribute__((__always_inline__, __nodebug__))
 _xtest(void)
 {
   return __builtin_ia32_xtest();
 }
 #endif
 
 #ifdef __SHA__
 #include <shaintrin.h>
 #endif
 
+#include <adxintrin.h>
+
 #endif /* __IMMINTRIN_H */
diff --git a/test/CodeGen/adx-builtins.c b/test/CodeGen/adx-builtins.c
new file mode 100644
index 0000000..4fc8ae8
--- /dev/null
+++ b/test/CodeGen/adx-builtins.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -target-feature +adx -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_addcarryx_u32(unsigned char __cf, unsigned int __x,
+                                 unsigned int __y, unsigned int *__p) {
+// CHECK-LABEL: test_addcarryx_u32
+// CHECK: call i8 @llvm.x86.addcarryx.u32
+  return _addcarryx_u32(__cf, __x, __y, __p);
+}
+
+unsigned char test_addcarryx_u64(unsigned char __cf, unsigned long __x,
+                                 unsigned long __y, unsigned long long *__p) {
+// CHECK-LABEL: test_addcarryx_u64
+// CHECK: call i8 @llvm.x86.addcarryx.u64
+  return _addcarryx_u64(__cf, __x, __y, __p);
+}
