[PATCH][CodeGen] Add missing intrinsic lowering for sin, cos and ceil

Josh Klontz josh.klontz at gmail.com
Mon Aug 4 17:40:41 PDT 2014


Duncan,

Attached is an updated patch with f64 tests added. f128 was not added as
libffi does not seem to support this type (LLVM ERROR: Type could not be
mapped for use with libffi.).

I agree it's odd that `lli` lowers libc & libm functions through a
different interface than the native backend.

v/r,
Josh


On Mon, Aug 4, 2014 at 5:57 PM, Duncan P. N. Exon Smith <
dexonsmith at apple.com> wrote:

> Huh, I'm surprised that IntrinsicLowering is only used in the interpreter.
> I don't know `lli` too well, so anyone else should feel free to chime in
> here.
>
> I did notice that your test only checks the f32 versions -- I think it
> should exercise the full matrix.
>
> > On 2014-Aug-04, at 14:38, Josh Klontz <josh.klontz at gmail.com> wrote:
> >
> > Duncan,
> >
> > Attached is an updated patch with a test case. Note, this required
> extending lit to recognize `LLVM_ENABLE_FFI`.
> >
> > v/r,
> > Josh
> >
> >
> > On Mon, Aug 4, 2014 at 2:02 PM, Duncan P. N. Exon Smith <
> dexonsmith at apple.com> wrote:
> > Testcase?
> >
> > > On 2014-Jul-30, at 05:00, Josh Klontz <josh.klontz at gmail.com> wrote:
> > >
> > > Ping. CC'ing code owner and release manager.
> > > -Josh
> > >
> > >
> > > On Wed, Jul 23, 2014 at 12:01 PM, Josh Klontz <josh.klontz at gmail.com>
> wrote:
> > > This was discovered when trying to run lli on a function with an
> llvm.cos.f32 intrinsic. Hopefully this can get applied to the 3.5 branch as
> well. Thanks!
> > > -Josh
> > >
> > > _______________________________________________
> > > llvm-commits mailing list
> > > llvm-commits at cs.uiuc.edu
> > > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> >
> >
> > <patch.diff>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140804/571aa8a0/attachment.html>
-------------- next part --------------
diff --git a/lib/CodeGen/IntrinsicLowering.cpp b/lib/CodeGen/IntrinsicLowering.cpp
index a8b8600..9482aa6 100644
--- a/lib/CodeGen/IntrinsicLowering.cpp
+++ b/lib/CodeGen/IntrinsicLowering.cpp
@@ -527,6 +527,19 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
     ReplaceFPIntrinsicWithCall(CI, "powf", "pow", "powl");
     break;
   }
+  case Intrinsic::sin: {
+    ReplaceFPIntrinsicWithCall(CI, "sinf", "sin", "sinl");
+    break;
+  }
+  case Intrinsic::cos: {
+    ReplaceFPIntrinsicWithCall(CI, "cosf", "cos", "cosl");
+    break;
+  }
+  case Intrinsic::ceil: {
+    ReplaceFPIntrinsicWithCall(CI, "ceilf", "ceil", "ceill");
+    break;
+  }
+
   case Intrinsic::flt_rounds:
      // Lower to "round to the nearest"
      if (!CI->getType()->isVoidTy())
diff --git a/test/lit.site.cfg.in b/test/lit.site.cfg.in
index 4c0bb2e..8a9582a 100644
--- a/test/lit.site.cfg.in
+++ b/test/lit.site.cfg.in
@@ -22,6 +22,7 @@ config.host_arch = "@HOST_ARCH@"
 config.llvm_use_intel_jitevents = "@LLVM_USE_INTEL_JITEVENTS@"
 config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
 config.have_zlib = "@HAVE_LIBZ@"
+config.enable_ffi = "@LLVM_ENABLE_FFI@"
 
 # Support substitution of the tools_dir with user parameters. This is
 # used when we can't determine the tool dir at configuration time.
diff --git a/test/ExecutionEngine/Interpreter/intrinsics.ll b/test/ExecutionEngine/Interpreter/intrinsics.ll
new file mode 100644
index 0000000..e827b2c
--- /dev/null
+++ b/test/ExecutionEngine/Interpreter/intrinsics.ll
@@ -0,0 +1,12 @@
+; RUN: lli -O0 -force-interpreter < %s
+
+; libffi does not support fp128 so we don’t test it
+declare float  @llvm.sin.f32(float)
+declare double @llvm.sin.f64(double)
+declare float  @llvm.cos.f32(float)
+declare double @llvm.cos.f64(double)
+declare float  @llvm.ceil.f32(float)
+declare double @llvm.ceil.f64(double)
+
+define i32 @main() {
+  %sin32 = call float @llvm.sin.f32(float 0.000000e+00)
+  %sin64 = call double @llvm.sin.f64(double 0.000000e+00)
+  %cos32 = call float @llvm.cos.f32(float 0.000000e+00)
+  %cos64 = call double @llvm.cos.f64(double 0.000000e+00)
+  %ceil32 = call float @llvm.ceil.f32(float 0.000000e+00)
+  %ceil64 = call double @llvm.ceil.f64(double 0.000000e+00)
+  ret i32 0
+}
+
diff --git a/test/ExecutionEngine/Interpreter/lit.local.cfg b/test/ExecutionEngine/Interpreter/lit.local.cfg
new file mode 100644
index 0000000..8cbaf03
--- /dev/null
+++ b/test/ExecutionEngine/Interpreter/lit.local.cfg
@@ -0,0 +1,3 @@
+# These tests require foreign function calls
+if config.enable_ffi != "ON":
+    config.unsupported = True


More information about the llvm-commits mailing list