A lot of library calls cannot be used to synchronize with other threads
of execution. This is useful to know, e.g., for heap-2-stack on GPUs.
|140 ms||x64 debian > LLVM.Transforms/InferFunctionAttrs::annotate.ll|
Script: -- : 'RUN: at line 1'; /mnt/disks/ssd0/agent/llvm-project/build/bin/opt < /mnt/disks/ssd0/agent/llvm-project/llvm/test/Transforms/InferFunctionAttrs/annotate.ll -mtriple=x86_64-- -inferattrs -S | /mnt/disks/ssd0/agent/llvm-project/build/bin/FileCheck -check-prefix=CHECK-UNKNOWN /mnt/disks/ssd0/agent/llvm-project/llvm/test/Transforms/InferFunctionAttrs/annotate.ll
|30 ms||x64 debian > LLVM.Transforms/LICM::strlen.ll|
Script: -- : 'RUN: at line 1'; /mnt/disks/ssd0/agent/llvm-project/build/bin/opt -S -inferattrs -basic-aa -licm < /mnt/disks/ssd0/agent/llvm-project/llvm/test/Transforms/LICM/strlen.ll | /mnt/disks/ssd0/agent/llvm-project/build/bin/FileCheck /mnt/disks/ssd0/agent/llvm-project/llvm/test/Transforms/LICM/strlen.ll
|80 ms||x64 debian > LLVM.Transforms/LoopIdiom::basic.ll|
Script: -- : 'RUN: at line 2'; /mnt/disks/ssd0/agent/llvm-project/build/bin/opt -basic-aa -loop-idiom < /mnt/disks/ssd0/agent/llvm-project/llvm/test/Transforms/LoopIdiom/basic.ll -S | /mnt/disks/ssd0/agent/llvm-project/build/bin/FileCheck /mnt/disks/ssd0/agent/llvm-project/llvm/test/Transforms/LoopIdiom/basic.ll
|260 ms||x64 windows > LLVM.Transforms/InferFunctionAttrs::annotate.ll|
Script: -- : 'RUN: at line 1'; c:\ws\w16e2-1\llvm-project\premerge-checks\build\bin\opt.exe < C:\ws\w16e2-1\llvm-project\premerge-checks\llvm\test\Transforms\InferFunctionAttrs\annotate.ll -mtriple=x86_64-- -inferattrs -S | c:\ws\w16e2-1\llvm-project\premerge-checks\build\bin\filecheck.exe -check-prefix=CHECK-UNKNOWN C:\ws\w16e2-1\llvm-project\premerge-checks\llvm\test\Transforms\InferFunctionAttrs\annotate.ll
|60 ms||x64 windows > LLVM.Transforms/LICM::strlen.ll|
Script: -- : 'RUN: at line 1'; c:\ws\w16e2-1\llvm-project\premerge-checks\build\bin\opt.exe -S -inferattrs -basic-aa -licm < C:\ws\w16e2-1\llvm-project\premerge-checks\llvm\test\Transforms\LICM\strlen.ll | c:\ws\w16e2-1\llvm-project\premerge-checks\build\bin\filecheck.exe C:\ws\w16e2-1\llvm-project\premerge-checks\llvm\test\Transforms\LICM\strlen.ll
|View Full Test Results (6 Failed)|
To be safe, what do you think about marking nosync to ops that can be represented as a series of loads/stores or scalar ops only? For example, I believe memset is nosync because it is equivalent to a series of nonatomic stores.
For side-effecting operations, such as printf, I'm not 100% sure whether it is nosync. printf interacts with cout to properly flush buffers, which might do some interactions.
C17's 7.22.3 Memory management functions has this paragraph:
Should we conservatively assume that allocation/deallocation fns may synchronize with other threads?
This implies that if comparator fn executs any atomic operation then qsort raises UB, IIUC.
These functions may raise FE exceptions; would it be safe to assume that calling two ldexp, both of which setting FE exceptions, is UB?
I tried to avoid all file operations, we can also avoid printf and friends.
My original purpose was to add nosync to malloc and free :(
I guess what this says is that if you have two threads.
You now know T1 deallocated P.
Worst case we could derive this for call sites if the pointer P was never observed (=captured).
I don't understand the question.
I think it is safer and okay maybe, but since a few malloc implementation such as glibc's one typically has a lock to correctly manipulate allocated areas inside, showing the validity of attaching nosync seems non-trivial to me.
I have a question about the background btw - Does GPU's malloc need to use atomic operations? If GPU's malloc is simpler and they are not guaranteed to synchronize, attaching nosync can be justified.
My question was whether math library fns can use atomic operations to update errno.
I just found that errno is defined as a thread-local storage; I believe it's okay now.
I'll send an email to cfe-dev at some point soon to ask about the malloc/free semantics, wrt. nosync but also other things.
Thanks for the input, I might update this to only include the safe things before the email is send.
The question is not necessarily if the impl. uses an atomic or is synchronized but if it "leaks" out. So can the user establish a proper happens-before relation between two threads with malloc/free. If it doesn't, nosync is fine regardless of the impl. because of the "as-if" rule.
If no issue is found, I believe defining malloc that is never escaped as returning an isolated allocation that can never be used to communicate with the outer world (unknown functions or threads) will be great too.