r213206 - Add basic (noop) CodeGen support for __assume

Hal Finkel hfinkel at anl.gov
Wed Jul 16 15:44:55 PDT 2014


Author: hfinkel
Date: Wed Jul 16 17:44:54 2014
New Revision: 213206

URL: http://llvm.org/viewvc/llvm-project?rev=213206&view=rev
Log:
Add basic (noop) CodeGen support for __assume

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.

Added:
    cfe/trunk/test/CodeGen/builtin-assume.c
Modified:
    cfe/trunk/lib/CodeGen/CGBuiltin.cpp

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=213206&r1=213205&r2=213206&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Wed Jul 16 17:44:54 2014
@@ -1517,6 +1517,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(
   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);

Added: cfe/trunk/test/CodeGen/builtin-assume.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtin-assume.c?rev=213206&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/builtin-assume.c (added)
+++ cfe/trunk/test/CodeGen/builtin-assume.c Wed Jul 16 17:44:54 2014
@@ -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];
+}
+





More information about the cfe-commits mailing list