Skip to content

[clang][CodeGen][OpenMP] Fix casting of atomic update of ptr types #88215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion clang/lib/CodeGen/CGAtomic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1806,7 +1806,11 @@ void AtomicInfo::EmitAtomicUpdateOp(
/*NumReservedValues=*/2);
PHI->addIncoming(OldVal, CurBB);
Address NewAtomicAddr = CreateTempAlloca();
Address NewAtomicIntAddr = castToAtomicIntPointer(NewAtomicAddr);
Address NewAtomicIntAddr =
shouldCastToInt(NewAtomicAddr.getElementType(), /*CmpXchg=*/true)
? castToAtomicIntPointer(NewAtomicAddr)
: NewAtomicAddr;

if ((LVal.isBitField() && BFI.Size != ValueSizeInBits) ||
requiresMemSetZero(getAtomicAddress().getElementType())) {
CGF.Builder.CreateStore(PHI, NewAtomicIntAddr);
Expand Down
11 changes: 11 additions & 0 deletions clang/test/OpenMP/atomic_update_codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ long double ldv, ldx;
_Complex int civ, cix;
_Complex float cfv, cfx;
_Complex double cdv, cdx;
char *cpx;

typedef int int4 __attribute__((__vector_size__(16)));
int4 int4x;
Expand Down Expand Up @@ -851,6 +852,16 @@ int main(void) {
// CHECK: call{{.*}} @__kmpc_flush(
#pragma omp atomic seq_cst
rix = dv / rix;

// CHECK: [[LD_CPX:%.+]] = load atomic ptr, ptr @cpx monotonic
// CHECK: br label %[[CONT:.+]]
// CHECK: [[CONT]]
// CHECK: [[PHI:%.+]] = phi ptr
// CHECK: [[RES:%.+]] = cmpxchg ptr @cpx,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really end up emitting a cmpxchg in the frontend just because atomicrmw doesn't have pointer typed add? This is horrible

// CHECK: br i1 %{{.+}}, label %[[EXIT:.+]], label %[[CONT]]
#pragma omp atomic update
cpx += 1;

return 0;
}

Expand Down