[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
jrtc27 wrote: Part of that confusion comes from SPARC's own naming. V9 is the CPU, but a V9 CPU being used for 32-bit code is called V8+... https://github.com/llvm/llvm-project/pull/73176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
jyknight wrote: What config is this bot using? Is it "-target sparc-solaris -mcpu=v9" (that is: 32-bit sparc, but with v9 cpu available)? I see that SparcV9TargetInfo sets MaxAtomicInlineWidth to 64 unconditionally. But, the message `warning: large atomic operation may incur significant performance penalty; the access size (8 bytes) exceeds the max lock-free size (4 bytes) [-Watomic-alignment]` indicates that MaxAtomicInlineWidth is 32. OK, wait, this class is poorly-named. SparcV8TargetInfo really means "sparc 32-bit" and SparcV9TargetInfo really means "sparc 64-bit". So: this is actually using SparcV8TargetInfo, instead. Yet, even then, SparcV8TargetInfo appears to [intend to configure](https://github.com/llvm/llvm-project/blob/16140ff219b68f61fedf92df13019d89a4990a47/clang/lib/Basic/Targets/Sparc.h#L168) MaxAtomicInlineWidth to 64 when using a V9 CPU. That doesn't seem to be actually happening, though. OK, so the frontend is apparently buggily configured to only support 32-bit atomics in 32-bit mode, even when a V9 CPU is available. That, then, was covering up a bug in the backend. The backend claims to (and should be able to!) support 64-bit atomics in 32-bit mode. But it doesn't actually, right now. I'll send a patch to fix this by limiting atomics to 32-bit in the backend when `!Subtarget->is64Bit()`, which will get things back to working, though it doesn't address those deeper issues. https://github.com/llvm/llvm-project/pull/73176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
efriedma-quic wrote: Looks like a bug in the SPARC backend. https://github.com/llvm/llvm-project/pull/73176#pullrequestreview-1811677691 indicated that atomic expansion was working correctly for all backends, but I guess it isn't working correctly on SPARC. https://github.com/llvm/llvm-project/pull/73176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
rorth wrote: The libcalls per se wouldn't be a problem since on 32-bit Solaris/sparc `-latomic` is always linked due to that. However, the `__sync_*` libcalls aren't defined in `libatomic.so`, thus the link failure. https://github.com/llvm/llvm-project/pull/73176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
Logikable wrote: https://reviews.llvm.org/D118021 likely related, looking into this. https://github.com/llvm/llvm-project/pull/73176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
rorth wrote: Confirmed: reverting the patch locally restores the build. https://github.com/llvm/llvm-project/pull/73176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
rorth wrote: I'm pretty certain this patch broke the [Solaris/sparcv9 buildbot](https://lab.llvm.org/buildbot/#/builders/72/builds/2541). https://github.com/llvm/llvm-project/pull/73176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
https://github.com/MaskRay closed https://github.com/llvm/llvm-project/pull/73176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
https://github.com/jyknight approved this pull request. Sorry for the delay. This looks good to me now! https://github.com/llvm/llvm-project/pull/73176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
Logikable wrote: Gentle bump on this. Is there anything I can do now to make this easier to review? https://github.com/llvm/llvm-project/pull/73176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
https://github.com/Logikable edited https://github.com/llvm/llvm-project/pull/73176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
jyknight wrote: BTW, please don't rebase/amend commits and force-push, it makes a it extremely difficult to review the changes since the previous review -- especially if the new changes are commingled with a rebase. Much better to simply push new commits on top of your existing branch. And if you need an updated baseline, you can `git merge origin/main` in your PR branch. https://github.com/llvm/llvm-project/pull/73176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
Logikable wrote: Updated with suggestions. How does this look? https://github.com/llvm/llvm-project/pull/73176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
https://github.com/Logikable updated https://github.com/llvm/llvm-project/pull/73176 >From 9dfcc46c600a0c4720553faf7e070862650792bc Mon Sep 17 00:00:00 2001 From: Sean Luchen Date: Fri, 17 Nov 2023 17:29:52 + Subject: [PATCH] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. In the beginning, Clang only emitted atomic IR for operations it knew the underlying microarch had instructions for, meaning it required significant knowledge of the target. Later, the backend acquired the ability to lower IR to libcalls. To avoid duplicating logic and improve logic locality, we'd like to move as much as possible to the backend. There are many ways to describe this change. For example, this change reduces the variables Clang uses to decide whether to emit libcalls or IR, down to only the atomic's size. --- clang/lib/CodeGen/CGAtomic.cpp| 321 +++--- clang/test/CodeGen/LoongArch/atomics.c| 16 +- clang/test/CodeGen/PowerPC/quadword-atomics.c | 50 +-- clang/test/CodeGen/RISCV/riscv-atomics.c | 68 +--- .../SystemZ/gnu-atomic-builtins-i128-8Al.c| 119 +++ clang/test/CodeGen/arm-atomics-m.c| 8 +- clang/test/CodeGen/arm-atomics-m0.c | 16 +- clang/test/CodeGen/atomic-ops-libcall.c | 310 ++--- clang/test/CodeGen/atomic-ops.c | 27 +- clang/test/CodeGen/atomics-inlining.c | 38 +-- clang/test/CodeGen/c11atomics.c | 30 +- clang/test/CodeGenCXX/atomic-inline.cpp | 6 +- .../test/CodeGenOpenCL/atomic-ops-libcall.cl | 57 ++-- 13 files changed, 497 insertions(+), 569 deletions(-) diff --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp index 52e6ddb7d6afb0..a8d846b4f6a592 100644 --- a/clang/lib/CodeGen/CGAtomic.cpp +++ b/clang/lib/CodeGen/CGAtomic.cpp @@ -811,29 +811,6 @@ static void EmitAtomicOp(CodeGenFunction , AtomicExpr *Expr, Address Dest, Builder.SetInsertPoint(ContBB); } -static void -AddDirectArgument(CodeGenFunction , CallArgList , - bool UseOptimizedLibcall, llvm::Value *Val, QualType ValTy, - SourceLocation Loc, CharUnits SizeInChars) { - if (UseOptimizedLibcall) { -// Load value and pass it to the function directly. -CharUnits Align = CGF.getContext().getTypeAlignInChars(ValTy); -int64_t SizeInBits = CGF.getContext().toBits(SizeInChars); -ValTy = -CGF.getContext().getIntTypeForBitwidth(SizeInBits, /*Signed=*/false); -llvm::Type *ITy = llvm::IntegerType::get(CGF.getLLVMContext(), SizeInBits); -Address Ptr = Address(Val, ITy, Align); -Val = CGF.EmitLoadOfScalar(Ptr, false, - CGF.getContext().getPointerType(ValTy), - Loc); -// Coerce the value into an appropriately sized integer type. -Args.add(RValue::get(Val), ValTy); - } else { -// Non-optimized functions always take a reference. -Args.add(RValue::get(Val), CGF.getContext().VoidPtrTy); - } -} - RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) { QualType AtomicTy = E->getPtr()->getType()->getPointeeType(); QualType MemTy = AtomicTy; @@ -857,22 +834,16 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) { uint64_t Size = TInfo.Width.getQuantity(); unsigned MaxInlineWidthInBits = getTarget().getMaxAtomicInlineWidth(); - bool Oversized = getContext().toBits(TInfo.Width) > MaxInlineWidthInBits; - bool Misaligned = (Ptr.getAlignment() % TInfo.Width) != 0; - bool UseLibcall = Misaligned | Oversized; - bool ShouldCastToIntPtrTy = true; - CharUnits MaxInlineWidth = getContext().toCharUnitsFromBits(MaxInlineWidthInBits); - DiagnosticsEngine = CGM.getDiags(); - + bool Misaligned = (Ptr.getAlignment() % TInfo.Width) != 0; + bool Oversized = getContext().toBits(TInfo.Width) > MaxInlineWidthInBits; if (Misaligned) { Diags.Report(E->getBeginLoc(), diag::warn_atomic_op_misaligned) << (int)TInfo.Width.getQuantity() << (int)Ptr.getAlignment().getQuantity(); } - if (Oversized) { Diags.Report(E->getBeginLoc(), diag::warn_atomic_op_oversized) << (int)TInfo.Width.getQuantity() << (int)MaxInlineWidth.getQuantity(); @@ -881,6 +852,7 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) { llvm::Value *Order = EmitScalarExpr(E->getOrder()); llvm::Value *Scope = E->getScopeModel() ? EmitScalarExpr(E->getScope()) : nullptr; + bool ShouldCastToIntPtrTy = true; switch (E->getOp()) { case AtomicExpr::AO__c11_atomic_init: @@ -1047,122 +1019,25 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) { Dest = Atomics.castToAtomicIntPointer(Dest); } - // Use a library call. See: http://gcc.gnu.org/wiki/Atomic/GCCMM/LIbrary . + bool PowerOf2Size = (Size & (Size - 1)) == 0; + bool UseLibcall = !PowerOf2Size || (Size > 16); + + // For atomics larger than 16 bytes, emit a libcall from the frontend. This + // avoids the overhead
[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
https://github.com/arichardson commented: Overall this looks great to me, very happy to see reduced duplication between clang and llvm. It would be great if we could just emit the atomic IR in all cases but unfortunately non-power-of-two sizes result in a verifier error. We could probably emit the atomic IR for power-of-two sizes and let the expand pass deal with it but since we still need the fallback for other sizes we might as well keep it. https://github.com/llvm/llvm-project/pull/73176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
@@ -1047,122 +1019,19 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) { Dest = Atomics.castToAtomicIntPointer(Dest); } - // Use a library call. See: http://gcc.gnu.org/wiki/Atomic/GCCMM/LIbrary . - if (UseLibcall) { -bool UseOptimizedLibcall = false; -switch (E->getOp()) { -case AtomicExpr::AO__c11_atomic_init: -case AtomicExpr::AO__opencl_atomic_init: - llvm_unreachable("Already handled above with EmitAtomicInit!"); - -case AtomicExpr::AO__atomic_fetch_add: -case AtomicExpr::AO__atomic_fetch_and: -case AtomicExpr::AO__atomic_fetch_max: -case AtomicExpr::AO__atomic_fetch_min: -case AtomicExpr::AO__atomic_fetch_nand: -case AtomicExpr::AO__atomic_fetch_or: -case AtomicExpr::AO__atomic_fetch_sub: -case AtomicExpr::AO__atomic_fetch_xor: -case AtomicExpr::AO__atomic_add_fetch: -case AtomicExpr::AO__atomic_and_fetch: -case AtomicExpr::AO__atomic_max_fetch: -case AtomicExpr::AO__atomic_min_fetch: -case AtomicExpr::AO__atomic_nand_fetch: -case AtomicExpr::AO__atomic_or_fetch: -case AtomicExpr::AO__atomic_sub_fetch: -case AtomicExpr::AO__atomic_xor_fetch: -case AtomicExpr::AO__c11_atomic_fetch_add: -case AtomicExpr::AO__c11_atomic_fetch_and: -case AtomicExpr::AO__c11_atomic_fetch_max: -case AtomicExpr::AO__c11_atomic_fetch_min: -case AtomicExpr::AO__c11_atomic_fetch_nand: -case AtomicExpr::AO__c11_atomic_fetch_or: -case AtomicExpr::AO__c11_atomic_fetch_sub: -case AtomicExpr::AO__c11_atomic_fetch_xor: -case AtomicExpr::AO__hip_atomic_fetch_add: -case AtomicExpr::AO__hip_atomic_fetch_and: -case AtomicExpr::AO__hip_atomic_fetch_max: -case AtomicExpr::AO__hip_atomic_fetch_min: -case AtomicExpr::AO__hip_atomic_fetch_or: -case AtomicExpr::AO__hip_atomic_fetch_sub: -case AtomicExpr::AO__hip_atomic_fetch_xor: -case AtomicExpr::AO__opencl_atomic_fetch_add: -case AtomicExpr::AO__opencl_atomic_fetch_and: -case AtomicExpr::AO__opencl_atomic_fetch_max: -case AtomicExpr::AO__opencl_atomic_fetch_min: -case AtomicExpr::AO__opencl_atomic_fetch_or: -case AtomicExpr::AO__opencl_atomic_fetch_sub: -case AtomicExpr::AO__opencl_atomic_fetch_xor: -case AtomicExpr::AO__scoped_atomic_fetch_add: -case AtomicExpr::AO__scoped_atomic_fetch_and: -case AtomicExpr::AO__scoped_atomic_fetch_max: -case AtomicExpr::AO__scoped_atomic_fetch_min: -case AtomicExpr::AO__scoped_atomic_fetch_nand: -case AtomicExpr::AO__scoped_atomic_fetch_or: -case AtomicExpr::AO__scoped_atomic_fetch_sub: -case AtomicExpr::AO__scoped_atomic_fetch_xor: -case AtomicExpr::AO__scoped_atomic_add_fetch: -case AtomicExpr::AO__scoped_atomic_and_fetch: -case AtomicExpr::AO__scoped_atomic_max_fetch: -case AtomicExpr::AO__scoped_atomic_min_fetch: -case AtomicExpr::AO__scoped_atomic_nand_fetch: -case AtomicExpr::AO__scoped_atomic_or_fetch: -case AtomicExpr::AO__scoped_atomic_sub_fetch: -case AtomicExpr::AO__scoped_atomic_xor_fetch: - // For these, only library calls for certain sizes exist. - UseOptimizedLibcall = true; - break; - -case AtomicExpr::AO__atomic_load: -case AtomicExpr::AO__atomic_store: -case AtomicExpr::AO__atomic_exchange: -case AtomicExpr::AO__atomic_compare_exchange: -case AtomicExpr::AO__scoped_atomic_load: -case AtomicExpr::AO__scoped_atomic_store: -case AtomicExpr::AO__scoped_atomic_exchange: -case AtomicExpr::AO__scoped_atomic_compare_exchange: - // Use the generic version if we don't know that the operand will be - // suitably aligned for the optimized version. - if (Misaligned) -break; - [[fallthrough]]; -case AtomicExpr::AO__atomic_load_n: -case AtomicExpr::AO__atomic_store_n: -case AtomicExpr::AO__atomic_exchange_n: -case AtomicExpr::AO__atomic_compare_exchange_n: -case AtomicExpr::AO__c11_atomic_load: -case AtomicExpr::AO__c11_atomic_store: -case AtomicExpr::AO__c11_atomic_exchange: -case AtomicExpr::AO__c11_atomic_compare_exchange_weak: -case AtomicExpr::AO__c11_atomic_compare_exchange_strong: -case AtomicExpr::AO__hip_atomic_load: -case AtomicExpr::AO__hip_atomic_store: -case AtomicExpr::AO__hip_atomic_exchange: -case AtomicExpr::AO__hip_atomic_compare_exchange_weak: -case AtomicExpr::AO__hip_atomic_compare_exchange_strong: -case AtomicExpr::AO__opencl_atomic_load: -case AtomicExpr::AO__opencl_atomic_store: -case AtomicExpr::AO__opencl_atomic_exchange: -case AtomicExpr::AO__opencl_atomic_compare_exchange_weak: -case AtomicExpr::AO__opencl_atomic_compare_exchange_strong: -case AtomicExpr::AO__scoped_atomic_load_n: -case AtomicExpr::AO__scoped_atomic_store_n: -case AtomicExpr::AO__scoped_atomic_exchange_n: -case AtomicExpr::AO__scoped_atomic_compare_exchange_n: - // Only use optimized library calls for sizes for
[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
@@ -33,9 +33,9 @@ void test_i32_atomics(_Atomic(int32_t) * a, int32_t b) { } void test_i64_atomics(_Atomic(int64_t) * a, int64_t b) { - // LA32: call i64 @__atomic_load_8 - // LA32: call void @__atomic_store_8 - // LA32: call i64 @__atomic_fetch_add_8 + // LA32: load atomic i64, ptr %a seq_cst, align 8 + // LA32: store atomic i64 %b, ptr %a seq_cst, align 8 + // LA32: atomicrmw add ptr %a, i64 %b seq_cst // LA64: load atomic i64, ptr %a seq_cst, align 8 // LA64: store atomic i64 %b, ptr %a seq_cst, align 8 // LA64: atomicrmw add ptr %a, i64 %b seq_cst arichardson wrote: Also missing alignment here https://github.com/llvm/llvm-project/pull/73176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
@@ -33,9 +33,9 @@ void test_i32_atomics(_Atomic(int32_t) * a, int32_t b) { } void test_i64_atomics(_Atomic(int64_t) * a, int64_t b) { - // LA32: call i64 @__atomic_load_8 - // LA32: call void @__atomic_store_8 - // LA32: call i64 @__atomic_fetch_add_8 + // LA32: load atomic i64, ptr %a seq_cst, align 8 + // LA32: store atomic i64 %b, ptr %a seq_cst, align 8 + // LA32: atomicrmw add ptr %a, i64 %b seq_cst jyknight wrote: Missing `, align 8`? https://github.com/llvm/llvm-project/pull/73176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
@@ -23,7 +23,7 @@ typedef __int128_t int128_t; // PPC64-QUADWORD-ATOMICS:[[TMP3:%.*]] = load atomic i128, ptr [[TMP1:%.*]] acquire, align 16 // // PPC64-LABEL: @test_load( -// PPC64:call void @__atomic_load(i64 noundef 16, ptr noundef [[TMP3:%.*]], ptr noundef [[TMP4:%.*]], i32 noundef signext 2) +// PPC64:[[TMP3:%.*]] = load atomic i128, ptr [[TMP1:%.*]] acquire, align 16 jyknight wrote: A lot of these are now redundant with PPC64-QUADWORD-ATOMICS. I'd make the tests use `--check-prefixes=PPC64,PPC64-QUADWORD-ATOMICS` and `--check-prefixes=PPC64,PPC64-NO-QUADWORD-ATOMICS` so you can share the check lines for the cases where it doesn't differ. https://github.com/llvm/llvm-project/pull/73176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
https://github.com/jyknight commented: Overall, I think this is a great improvement. And I believe it should be correct to do now, after fixing the backends' MaxAtomicSizeInBitsSupported in #75703 #75185 #75112 #74385 #74389, and fixing Clang's propagation of alignment to atomicrmw/cmpxchg in #74349. Just a few more comments. https://github.com/llvm/llvm-project/pull/73176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
@@ -7,22 +7,19 @@ // RUN: %clang_cc1 -triple riscv64 -target-feature +a -O1 -emit-llvm %s -o - \ // RUN: | FileCheck %s -check-prefix=RV64IA -// This test demonstrates that MaxAtomicInlineWidth is set appropriately when jyknight wrote: I think this test needs to be redone as a "-verify" test checking for diagnostics, like `clang/test/CodeGen/atomics-sema-alignment.c` does for aarch64, in order to continue testing what it's supposed to test. https://github.com/llvm/llvm-project/pull/73176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
@@ -1,120 +1,147 @@ -// RUN: %clang_cc1 < %s -triple armv5e-none-linux-gnueabi -emit-llvm -O1 | FileCheck %s - -// FIXME: This file should not be checking -O1 output. -// Ie, it is testing many IR optimizer passes as part of front-end verification. +// RUN: %clang_cc1 < %s -triple armv5e-none-linux-gnueabi -emit-llvm | FileCheck %s jyknight wrote: Maybe the checks in this file should be generated with llvm/utils/update_cc_test_checks.py? https://github.com/llvm/llvm-project/pull/73176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
@@ -1047,122 +1019,19 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) { Dest = Atomics.castToAtomicIntPointer(Dest); } - // Use a library call. See: http://gcc.gnu.org/wiki/Atomic/GCCMM/LIbrary . - if (UseLibcall) { -bool UseOptimizedLibcall = false; -switch (E->getOp()) { -case AtomicExpr::AO__c11_atomic_init: -case AtomicExpr::AO__opencl_atomic_init: - llvm_unreachable("Already handled above with EmitAtomicInit!"); - -case AtomicExpr::AO__atomic_fetch_add: -case AtomicExpr::AO__atomic_fetch_and: -case AtomicExpr::AO__atomic_fetch_max: -case AtomicExpr::AO__atomic_fetch_min: -case AtomicExpr::AO__atomic_fetch_nand: -case AtomicExpr::AO__atomic_fetch_or: -case AtomicExpr::AO__atomic_fetch_sub: -case AtomicExpr::AO__atomic_fetch_xor: -case AtomicExpr::AO__atomic_add_fetch: -case AtomicExpr::AO__atomic_and_fetch: -case AtomicExpr::AO__atomic_max_fetch: -case AtomicExpr::AO__atomic_min_fetch: -case AtomicExpr::AO__atomic_nand_fetch: -case AtomicExpr::AO__atomic_or_fetch: -case AtomicExpr::AO__atomic_sub_fetch: -case AtomicExpr::AO__atomic_xor_fetch: -case AtomicExpr::AO__c11_atomic_fetch_add: -case AtomicExpr::AO__c11_atomic_fetch_and: -case AtomicExpr::AO__c11_atomic_fetch_max: -case AtomicExpr::AO__c11_atomic_fetch_min: -case AtomicExpr::AO__c11_atomic_fetch_nand: -case AtomicExpr::AO__c11_atomic_fetch_or: -case AtomicExpr::AO__c11_atomic_fetch_sub: -case AtomicExpr::AO__c11_atomic_fetch_xor: -case AtomicExpr::AO__hip_atomic_fetch_add: -case AtomicExpr::AO__hip_atomic_fetch_and: -case AtomicExpr::AO__hip_atomic_fetch_max: -case AtomicExpr::AO__hip_atomic_fetch_min: -case AtomicExpr::AO__hip_atomic_fetch_or: -case AtomicExpr::AO__hip_atomic_fetch_sub: -case AtomicExpr::AO__hip_atomic_fetch_xor: -case AtomicExpr::AO__opencl_atomic_fetch_add: -case AtomicExpr::AO__opencl_atomic_fetch_and: -case AtomicExpr::AO__opencl_atomic_fetch_max: -case AtomicExpr::AO__opencl_atomic_fetch_min: -case AtomicExpr::AO__opencl_atomic_fetch_or: -case AtomicExpr::AO__opencl_atomic_fetch_sub: -case AtomicExpr::AO__opencl_atomic_fetch_xor: -case AtomicExpr::AO__scoped_atomic_fetch_add: -case AtomicExpr::AO__scoped_atomic_fetch_and: -case AtomicExpr::AO__scoped_atomic_fetch_max: -case AtomicExpr::AO__scoped_atomic_fetch_min: -case AtomicExpr::AO__scoped_atomic_fetch_nand: -case AtomicExpr::AO__scoped_atomic_fetch_or: -case AtomicExpr::AO__scoped_atomic_fetch_sub: -case AtomicExpr::AO__scoped_atomic_fetch_xor: -case AtomicExpr::AO__scoped_atomic_add_fetch: -case AtomicExpr::AO__scoped_atomic_and_fetch: -case AtomicExpr::AO__scoped_atomic_max_fetch: -case AtomicExpr::AO__scoped_atomic_min_fetch: -case AtomicExpr::AO__scoped_atomic_nand_fetch: -case AtomicExpr::AO__scoped_atomic_or_fetch: -case AtomicExpr::AO__scoped_atomic_sub_fetch: -case AtomicExpr::AO__scoped_atomic_xor_fetch: - // For these, only library calls for certain sizes exist. - UseOptimizedLibcall = true; - break; - -case AtomicExpr::AO__atomic_load: -case AtomicExpr::AO__atomic_store: -case AtomicExpr::AO__atomic_exchange: -case AtomicExpr::AO__atomic_compare_exchange: -case AtomicExpr::AO__scoped_atomic_load: -case AtomicExpr::AO__scoped_atomic_store: -case AtomicExpr::AO__scoped_atomic_exchange: -case AtomicExpr::AO__scoped_atomic_compare_exchange: - // Use the generic version if we don't know that the operand will be - // suitably aligned for the optimized version. - if (Misaligned) -break; - [[fallthrough]]; -case AtomicExpr::AO__atomic_load_n: -case AtomicExpr::AO__atomic_store_n: -case AtomicExpr::AO__atomic_exchange_n: -case AtomicExpr::AO__atomic_compare_exchange_n: -case AtomicExpr::AO__c11_atomic_load: -case AtomicExpr::AO__c11_atomic_store: -case AtomicExpr::AO__c11_atomic_exchange: -case AtomicExpr::AO__c11_atomic_compare_exchange_weak: -case AtomicExpr::AO__c11_atomic_compare_exchange_strong: -case AtomicExpr::AO__hip_atomic_load: -case AtomicExpr::AO__hip_atomic_store: -case AtomicExpr::AO__hip_atomic_exchange: -case AtomicExpr::AO__hip_atomic_compare_exchange_weak: -case AtomicExpr::AO__hip_atomic_compare_exchange_strong: -case AtomicExpr::AO__opencl_atomic_load: -case AtomicExpr::AO__opencl_atomic_store: -case AtomicExpr::AO__opencl_atomic_exchange: -case AtomicExpr::AO__opencl_atomic_compare_exchange_weak: -case AtomicExpr::AO__opencl_atomic_compare_exchange_strong: -case AtomicExpr::AO__scoped_atomic_load_n: -case AtomicExpr::AO__scoped_atomic_store_n: -case AtomicExpr::AO__scoped_atomic_exchange_n: -case AtomicExpr::AO__scoped_atomic_compare_exchange_n: - // Only use optimized library calls for sizes for
[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
https://github.com/jyknight edited https://github.com/llvm/llvm-project/pull/73176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
@@ -1047,122 +1019,19 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) { Dest = Atomics.castToAtomicIntPointer(Dest); } - // Use a library call. See: http://gcc.gnu.org/wiki/Atomic/GCCMM/LIbrary . - if (UseLibcall) { -bool UseOptimizedLibcall = false; -switch (E->getOp()) { -case AtomicExpr::AO__c11_atomic_init: -case AtomicExpr::AO__opencl_atomic_init: - llvm_unreachable("Already handled above with EmitAtomicInit!"); - -case AtomicExpr::AO__atomic_fetch_add: -case AtomicExpr::AO__atomic_fetch_and: -case AtomicExpr::AO__atomic_fetch_max: -case AtomicExpr::AO__atomic_fetch_min: -case AtomicExpr::AO__atomic_fetch_nand: -case AtomicExpr::AO__atomic_fetch_or: -case AtomicExpr::AO__atomic_fetch_sub: -case AtomicExpr::AO__atomic_fetch_xor: -case AtomicExpr::AO__atomic_add_fetch: -case AtomicExpr::AO__atomic_and_fetch: -case AtomicExpr::AO__atomic_max_fetch: -case AtomicExpr::AO__atomic_min_fetch: -case AtomicExpr::AO__atomic_nand_fetch: -case AtomicExpr::AO__atomic_or_fetch: -case AtomicExpr::AO__atomic_sub_fetch: -case AtomicExpr::AO__atomic_xor_fetch: -case AtomicExpr::AO__c11_atomic_fetch_add: -case AtomicExpr::AO__c11_atomic_fetch_and: -case AtomicExpr::AO__c11_atomic_fetch_max: -case AtomicExpr::AO__c11_atomic_fetch_min: -case AtomicExpr::AO__c11_atomic_fetch_nand: -case AtomicExpr::AO__c11_atomic_fetch_or: -case AtomicExpr::AO__c11_atomic_fetch_sub: -case AtomicExpr::AO__c11_atomic_fetch_xor: -case AtomicExpr::AO__hip_atomic_fetch_add: -case AtomicExpr::AO__hip_atomic_fetch_and: -case AtomicExpr::AO__hip_atomic_fetch_max: -case AtomicExpr::AO__hip_atomic_fetch_min: -case AtomicExpr::AO__hip_atomic_fetch_or: -case AtomicExpr::AO__hip_atomic_fetch_sub: -case AtomicExpr::AO__hip_atomic_fetch_xor: -case AtomicExpr::AO__opencl_atomic_fetch_add: -case AtomicExpr::AO__opencl_atomic_fetch_and: -case AtomicExpr::AO__opencl_atomic_fetch_max: -case AtomicExpr::AO__opencl_atomic_fetch_min: -case AtomicExpr::AO__opencl_atomic_fetch_or: -case AtomicExpr::AO__opencl_atomic_fetch_sub: -case AtomicExpr::AO__opencl_atomic_fetch_xor: -case AtomicExpr::AO__scoped_atomic_fetch_add: -case AtomicExpr::AO__scoped_atomic_fetch_and: -case AtomicExpr::AO__scoped_atomic_fetch_max: -case AtomicExpr::AO__scoped_atomic_fetch_min: -case AtomicExpr::AO__scoped_atomic_fetch_nand: -case AtomicExpr::AO__scoped_atomic_fetch_or: -case AtomicExpr::AO__scoped_atomic_fetch_sub: -case AtomicExpr::AO__scoped_atomic_fetch_xor: -case AtomicExpr::AO__scoped_atomic_add_fetch: -case AtomicExpr::AO__scoped_atomic_and_fetch: -case AtomicExpr::AO__scoped_atomic_max_fetch: -case AtomicExpr::AO__scoped_atomic_min_fetch: -case AtomicExpr::AO__scoped_atomic_nand_fetch: -case AtomicExpr::AO__scoped_atomic_or_fetch: -case AtomicExpr::AO__scoped_atomic_sub_fetch: -case AtomicExpr::AO__scoped_atomic_xor_fetch: - // For these, only library calls for certain sizes exist. - UseOptimizedLibcall = true; - break; - -case AtomicExpr::AO__atomic_load: -case AtomicExpr::AO__atomic_store: -case AtomicExpr::AO__atomic_exchange: -case AtomicExpr::AO__atomic_compare_exchange: -case AtomicExpr::AO__scoped_atomic_load: -case AtomicExpr::AO__scoped_atomic_store: -case AtomicExpr::AO__scoped_atomic_exchange: -case AtomicExpr::AO__scoped_atomic_compare_exchange: - // Use the generic version if we don't know that the operand will be - // suitably aligned for the optimized version. - if (Misaligned) -break; - [[fallthrough]]; -case AtomicExpr::AO__atomic_load_n: -case AtomicExpr::AO__atomic_store_n: -case AtomicExpr::AO__atomic_exchange_n: -case AtomicExpr::AO__atomic_compare_exchange_n: -case AtomicExpr::AO__c11_atomic_load: -case AtomicExpr::AO__c11_atomic_store: -case AtomicExpr::AO__c11_atomic_exchange: -case AtomicExpr::AO__c11_atomic_compare_exchange_weak: -case AtomicExpr::AO__c11_atomic_compare_exchange_strong: -case AtomicExpr::AO__hip_atomic_load: -case AtomicExpr::AO__hip_atomic_store: -case AtomicExpr::AO__hip_atomic_exchange: -case AtomicExpr::AO__hip_atomic_compare_exchange_weak: -case AtomicExpr::AO__hip_atomic_compare_exchange_strong: -case AtomicExpr::AO__opencl_atomic_load: -case AtomicExpr::AO__opencl_atomic_store: -case AtomicExpr::AO__opencl_atomic_exchange: -case AtomicExpr::AO__opencl_atomic_compare_exchange_weak: -case AtomicExpr::AO__opencl_atomic_compare_exchange_strong: -case AtomicExpr::AO__scoped_atomic_load_n: -case AtomicExpr::AO__scoped_atomic_store_n: -case AtomicExpr::AO__scoped_atomic_exchange_n: -case AtomicExpr::AO__scoped_atomic_compare_exchange_n: - // Only use optimized library calls for sizes for
[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
efriedma-quic wrote: When I said "inconsistencies", I just meant the way the responsibility for lowering atomics is split between LLVM and clang; I didn't mean anything was actually broken. https://github.com/llvm/llvm-project/pull/73176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
Logikable wrote: I've rewritten a part of this PR to incorporate @arichardson's suggestion. I wasn't able to find inconsistencies through a cursory review of the backend's AtomicExpand pass, nor through a small set of tests built for common targets. How can I find the gaps I missed? https://github.com/llvm/llvm-project/pull/73176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)
https://github.com/Logikable edited https://github.com/llvm/llvm-project/pull/73176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits