Add __builtin_assume and __builtin_assume_aligned using @llvm.assume.

This makes use of the recently-added @llvm.assume intrinsic to implement a
__builtin_assume(bool) intrinsic (to provide additional information to the
optimizer). This hooks up __assume in MS-compatibility mode to mirror
__builtin_assume (the semantics have been intentionally kept compatible), and
implements GCC's __builtin_assume_aligned as assume((p - o) & mask == 0). LLVM
now contains special logic to deal with assumptions of this form.

llvm-svn: 217349
diff --git a/clang/test/Sema/builtin-assume-aligned.c b/clang/test/Sema/builtin-assume-aligned.c
new file mode 100644
index 0000000..884a7fb
--- /dev/null
+++ b/clang/test/Sema/builtin-assume-aligned.c
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int test1(int *a) {
+  a = __builtin_assume_aligned(a, 32, 0ull);
+  return a[0];
+}
+
+int test2(int *a) {
+  a = __builtin_assume_aligned(a, 32, 0);
+  return a[0];
+}
+
+int test3(int *a) {
+  a = __builtin_assume_aligned(a, 32);
+  return a[0];
+}
+
+int test4(int *a) {
+  a = __builtin_assume_aligned(a, -32); // expected-error {{requested alignment is not a power of 2}}
+  a = __builtin_assume_aligned(a, 1ULL << 63);
+  return a[0];
+}
+
+int test5(int *a, unsigned *b) {
+  a = __builtin_assume_aligned(a, 32, b); // expected-warning {{incompatible pointer to integer conversion passing 'unsigned int *' to parameter of type}}
+  return a[0];
+}
+
+int test6(int *a) {
+  a = __builtin_assume_aligned(a, 32, 0, 0); // expected-error {{too many arguments to function call, expected at most 3, have 4}}
+  return a[0];
+}
+
+int test7(int *a) {
+  a = __builtin_assume_aligned(a, 31); // expected-error {{requested alignment is not a power of 2}}
+  return a[0];
+}
+
+int test8(int *a, int j) {
+  a = __builtin_assume_aligned(a, j); // expected-error {{must be a constant integer}}
+  return a[0];
+}
+
diff --git a/clang/test/Sema/builtin-assume.c b/clang/test/Sema/builtin-assume.c
index 1f6a3a0..512eeec 100644
--- a/clang/test/Sema/builtin-assume.c
+++ b/clang/test/Sema/builtin-assume.c
@@ -1,11 +1,18 @@
 // RUN: %clang_cc1 -triple i386-mingw32 -fms-extensions -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
 
 int foo(int *a, int i) {
+#ifdef _MSC_VER
   __assume(i != 4);
-  __assume(++i > 2); //expected-warning {{the argument to __assume has side effects that will be discarded}}
+  __assume(++i > 2); //expected-warning {{the argument to '__assume' has side effects that will be discarded}}
 
   int test = sizeof(struct{char qq[(__assume(i != 5), 7)];});
+#else
+  __builtin_assume(i != 4);
+  __builtin_assume(++i > 2); //expected-warning {{the argument to '__builtin_assume' has side effects that will be discarded}}
 
+  int test = sizeof(struct{char qq[(__builtin_assume(i != 5), 7)];});
+#endif
   return a[i];
 }