]> granicus.if.org Git - clang/commitdiff
Add basic (noop) CodeGen support for __assume
authorHal Finkel <hfinkel@anl.gov>
Wed, 16 Jul 2014 22:44:54 +0000 (22:44 +0000)
committerHal Finkel <hfinkel@anl.gov>
Wed, 16 Jul 2014 22:44:54 +0000 (22:44 +0000)
Clang supports __assume, at least at the semantic level, when MS extensions are
enabled. Unfortunately, trying to actually compile code using __assume would
result in this error:

  error: cannot compile this builtin function yet

__assume is an optimizer hint, and can be ignored at the IR level. Until LLVM
supports assumptions at the IR level, a noop lowering is valid, and that is
what is done here.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@213206 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGBuiltin.cpp
test/CodeGen/builtin-assume.c [new file with mode: 0644]

index 37347168f3c3e3ee3b31f45a27a1a5530f120594..4bdc87e2d424e0f5a2d35f529c1489c3fc7e3a68 100644 (file)
@@ -1517,6 +1517,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
   case Builtin::BI__noop:
     // __noop always evaluates to an integer literal zero.
     return RValue::get(ConstantInt::get(IntTy, 0));
+  case Builtin::BI__assume:
+    // Until LLVM supports assumptions at the IR level, this becomes nothing.
+    return RValue::get(nullptr);
   case Builtin::BI_InterlockedExchange:
   case Builtin::BI_InterlockedExchangePointer:
     return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Xchg, E);
diff --git a/test/CodeGen/builtin-assume.c b/test/CodeGen/builtin-assume.c
new file mode 100644 (file)
index 0000000..a381a4c
--- /dev/null
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple i386-mingw32 -fms-extensions -emit-llvm -o - %s | FileCheck %s
+
+// CHECK-LABEL: @test1
+int test1(int *a) {
+  __assume(a != 0);
+  return a[0];
+}
+