Skip to content

Commit

Permalink
Fix Clang warning with __builtin_assume (#1788)
Browse files Browse the repository at this point in the history
Building the project with `Clang` generates the following warning:
```
the argument to '__builtin_assume' has side effects that will be discarded [-Wassume]
```

Seems like Clang doesn't handle the hint well unless we pass a
const/pure attribute to the function call inside the assume. See:
llvm/llvm-project#55636 and
llvm/llvm-project#93077

With this change performance for the fn fused nabla examples is
significantly improved on clang-cuda and is now much faster than (our
old) nvcc, which doesn't have `assume` support.
  • Loading branch information
iomaganaris authored Jun 24, 2024
1 parent 6622c1d commit f489c51
Show file tree
Hide file tree
Showing 7 changed files with 86,928 additions and 86,071 deletions.
3 changes: 2 additions & 1 deletion include/gridtools/fn/unstructured.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ namespace gridtools::fn {
int m_index;
};

/// gnu::pure attribute is necessary to enable __builtin_assume() optimization with Clang
template <class Tag, class Ptr, class Strides, class Domain>
GT_FUNCTION constexpr bool can_deref(iterator<Tag, Ptr, Strides, Domain> const &it) {
[[gnu::pure]] GT_FUNCTION constexpr bool can_deref(iterator<Tag, Ptr, Strides, Domain> const &it) {
return it.m_index != -1;
}

Expand Down
Loading

0 comments on commit f489c51

Please sign in to comment.