From: David Majnemer Date: Wed, 3 Jun 2015 00:26:35 +0000 (+0000) Subject: [Sema] Make the atomic builtins more efficient by reducing volatility X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=859130900e6c46720bdc333efab678a8b04c7761;p=clang [Sema] Make the atomic builtins more efficient by reducing volatility The parameter types and return type do not need to be volatile just because the pointer type's pointee type is volatile qualified. This is an unnecessary pessimization. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@238892 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 23a6fc3c4c..c3b81b6683 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -1604,6 +1604,10 @@ ExprResult Sema::SemaAtomicOpsOverloaded(ExprResult TheCallResult, return ExprError(); } + // atomic_fetch_or takes a pointer to a volatile 'A'. We shouldn't let the + // volatile-ness of the pointee-type inject itself into the result or the + // other operands. + ValType.removeLocalVolatile(); QualType ResultType = ValType; if (Form == Copy || Form == GNUXchg || Form == Init) ResultType = Context.VoidTy; diff --git a/test/CodeGen/atomic-ops.c b/test/CodeGen/atomic-ops.c index 733c60eb85..13ab5f117f 100644 --- a/test/CodeGen/atomic-ops.c +++ b/test/CodeGen/atomic-ops.c @@ -105,6 +105,14 @@ int fi3e(atomic_int *i) { return atomic_fetch_or(i, 1); } +int fi3f(int *i) { + // CHECK-LABEL: @fi3f + // CHECK-NOT: store volatile + // CHECK: atomicrmw or + // CHECK-NOT: {{ or }} + return __atomic_fetch_or(i, (short)1, memory_order_seq_cst); +} + _Bool fi4(_Atomic(int) *i) { // CHECK-LABEL: @fi4( // CHECK: [[PAIR:%[.0-9A-Z_a-z]+]] = cmpxchg i32* [[PTR:%[.0-9A-Z_a-z]+]], i32 [[EXPECTED:%[.0-9A-Z_a-z]+]], i32 [[DESIRED:%[.0-9A-Z_a-z]+]]