LLVM intrinsic functions

Hi

May it be assumed that llvm intrinsic functions ( named llvm.* ) are thread safe? And if not, what are the llvm intrinsic functions that are not thread safe?

Thank you,

David Livshin

www.dalsoft.com

This is a bit of a puzzling question and I wonder where it’s coming from. I don’t think there’s a general rule. In practice, most intrinsics are as thread-safe as core IR instructions are thread-safe. For example, an llvm.masked.store is as thread-safe as a regular store.

I am writing LLVM auto-parallelizer ( see www.dalsoft,com ) and must ensure that everything that will become part of a parallel kernel is thread safe.
Also, being on the subject, what are the core IR instructions that are not thread safe.

I believe whatever logic applies to normal function calls would equally apply to intrinsics: if it’s readnone you’re fine, it’s readonly or read/write you may need to worry about dependencies between whatever it is you parallelize.

LLVM intrinsics can do all sort of things. I would strongly recommend against treating them different than calls of unknown functions. As @nhaehnle suggested, look at the function attributes instead, intrinsics come with pre-populated attributes that describe their behavior (or absence of) to a large degree.

I’m trying to introduce ``noread_thread_id` attributes into LLVM (inspired by @nhaehnle ) in ⚙ D132352 Introduce noread_thread_id to address the thread identification problem in coroutines. Although the intention was to solve the thread identification problem in coroutines, now it looks like a good solution too for this problem you raised.

Don’t remember seeing function attribute related to thread safety. Perhaps there is a document similar to System Interfaces Chapter 2 that will solve my problem.

Also, is there any way to disable the intrinsic functions use while generation IR file?

Seems that this might be useful for what I am dealing with, although note that thread safety is much more than memory related issues ( e.g. memory aliasing ). For intrinsic function to be thread safe it is necessary to explicitly state that and require for target specific implementation of that intrinsic to be a such.

see my reply to @ChuanqiXu

Oh, you’re right. noread_thread_id may not be a solution although it may be helpful.

It is clear the answer to my original question ( no answer ).
During discussion two additional questions were raised:

  1. What are the core IR instructions that are not thread safe?
  2. Is there a way to disable the intrinsic functions use while generating IR file?

Would someone please answer these questions.

What are the core IR instructions that are not thread safe?

load, store, cmpxchg, and atomicrmw are the instructions that access memory and may need some thread/synchronization care.

Is there a way to disable the intrinsic functions use while generating IR file?

No. They’re mostly not optional things with a simple alternative IR representation.