[flang-commits] [flang] [llvm] [mlir] [OpenMPIRBuilder] Emit __atomic_load and __atomic_compare_exchange libcalls for complex types in atomic update (PR #92364)
Kiran Chandramohan via flang-commits
flang-commits at lists.llvm.org
Fri May 17 02:37:56 PDT 2024
kiranchandramohan wrote:
I was looking through a C example (given below),
```
#include <complex.h>
#include <stdio.h>
#include <tgmath.h>
float complex sub(float complex *z1, float complex *z2)
{
#pragma omp atomic update
*z1 = *z1 + *z2;
return *z1;
}
```
and the LLVM IR generated by Clang looks a bit different (as given below)
```
call void @__atomic_load(i64 noundef 8, ptr noundef %0, ptr noundef %atomic-temp, i32 noundef 0)
br label %atomic_cont
atomic_cont: ; preds = %atomic_cont, %entry
%atomic-temp.realp = getelementptr inbounds { float, float }, ptr %atomic-temp, i32 0, i32 0
%atomic-temp.real = load float, ptr %atomic-temp.realp, align 4
%atomic-temp.imagp = getelementptr inbounds { float, float }, ptr %atomic-temp, i32 0, i32 1
%atomic-temp.imag = load float, ptr %atomic-temp.imagp, align 4
%add.r = fadd float %atomic-temp.real, %.real
%add.i = fadd float %atomic-temp.imag, %.imag
%atomic-temp1.realp = getelementptr inbounds { float, float }, ptr %atomic-temp1, i32 0, i32 0
%atomic-temp1.imagp = getelementptr inbounds { float, float }, ptr %atomic-temp1, i32 0, i32 1
store float %add.r, ptr %atomic-temp1.realp, align 4
store float %add.i, ptr %atomic-temp1.imagp, align 4
%call = call i1 @__atomic_compare_exchange(i64 noundef 8, ptr noundef %0, ptr noundef %atomic-temp, ptr noundef %atomic-temp1, i32 noundef 0, i32 noundef 0)
br i1 %call, label %atomic_exit, label %atomic_cont
```
The code that gets called is `AtomicInfo::EmitAtomicUpdateLibcal` in `clang/lib/CodeGen/CGAtomic.cpp`. Is this the code that you used? Did you face any issue using this code?
https://github.com/llvm/llvm-project/blob/33bf08ec36efc2fc2df8217eddd751cef9bc6be6/clang/lib/CodeGen/CGAtomic.cpp#L1764
https://github.com/llvm/llvm-project/pull/92364
More information about the flang-commits
mailing list