Skip to content

Commit

Permalink
decorate libclc functions with noimplicitFloat (#1256)
Browse files Browse the repository at this point in the history
Ref #1253
  • Loading branch information
rjodinchr authored Nov 8, 2023
1 parent d9d9172 commit e3dc5f1
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/NativeMathPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ bool is_libclc_builtin(llvm::Function *F) {
}
return false;
}
bool builtin_needs_noimplicitfloat(const StringRef &builtin) {
// Using noimplicitfloat for those functions allow to have compliant OpenCL
// implementation of them even with native version of fabs.
DenseSet<StringRef> list = {"cbrt", "frexp", "powr"};
return list.contains(builtin);
}
} // namespace

PreservedAnalyses clspv::NativeMathPass::run(Module &M,
Expand All @@ -63,6 +69,11 @@ PreservedAnalyses clspv::NativeMathPass::run(Module &M,
// that we will not do it, let's remove the attribute so that they
// can be inline if appropriate.
F.removeFnAttr(Attribute::AttrKind::NoInline);

// Prevent unwanted transformation from InstCombine (Ref #1253).
if (builtin_needs_noimplicitfloat(F.getName())) {
F.addFnAttr(Attribute::AttrKind::NoImplicitFloat);
}
}
}

Expand Down

0 comments on commit e3dc5f1

Please sign in to comment.