gallivm: Never emit llvm.fmuladd on LLVM 3.3.
authorJose Fonseca <jfonseca@vmware.com>
Fri, 10 Jun 2016 14:42:55 +0000 (15:42 +0100)
committerJose Fonseca <jfonseca@vmware.com>
Fri, 10 Jun 2016 15:17:04 +0000 (16:17 +0100)
Besides the old JIT bug, it seems the X86 backend on LLVM 3.3 doesn't
handle llvm.fmuladd and instead it fall backs to a C function.  Which in
turn causes a segfault on Windows.

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
src/gallium/auxiliary/gallivm/lp_bld_arit.c
src/gallium/auxiliary/gallivm/lp_bld_misc.cpp

index 5d6a0335654085f2ce5c6c402ee4d26596970ffd..114c76665f96f50a77f1fa96382c5a92a1d14038 100644 (file)
@@ -270,6 +270,12 @@ lp_build_fmuladd(LLVMBuilderRef builder,
    LLVMTypeRef type = LLVMTypeOf(a);
    assert(type == LLVMTypeOf(b));
    assert(type == LLVMTypeOf(c));
+   if (HAVE_LLVM < 0x0304) {
+      /* XXX: LLVM 3.3 does not breakdown llvm.fmuladd into mul+add when FMA is
+       * not supported, and instead it falls-back to a C function.
+       */
+      return LLVMBuildFAdd(builder, LLVMBuildFMul(builder, a, b, ""), c, "");
+   }
    char intrinsic[32];
    lp_format_intrinsic(intrinsic, sizeof intrinsic, "llvm.fmuladd", type);
    LLVMValueRef args[] = { a, b, c };
index 5ffe09c9a1b6732698a41f0a80cf4ecd8437123c..23ef3edeae7d1001d0675df28e390e24f1cb4b93 100644 (file)
@@ -570,7 +570,7 @@ lp_build_create_jit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
     */
    MAttrs.push_back(util_cpu_caps.has_avx  ? "+avx"  : "-avx");
    MAttrs.push_back(util_cpu_caps.has_f16c ? "+f16c" : "-f16c");
-   if (HAVE_LLVM >= 0x0304 || useMCJIT) {
+   if (HAVE_LLVM >= 0x0304) {
       MAttrs.push_back(util_cpu_caps.has_fma  ? "+fma"  : "-fma");
    } else {
       /*