r238892 - [Sema] Make the atomic builtins more efficient by reducing volatility
David Majnemer
david.majnemer at gmail.com
Tue Jun 2 17:26:35 PDT 2015
Author: majnemer
Date: Tue Jun 2 19:26:35 2015
New Revision: 238892
URL: http://llvm.org/viewvc/llvm-project?rev=238892&view=rev
Log:
[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.
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/CodeGen/atomic-ops.c
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=238892&r1=238891&r2=238892&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Jun 2 19:26:35 2015
@@ -1604,6 +1604,10 @@ ExprResult Sema::SemaAtomicOpsOverloaded
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;
Modified: cfe/trunk/test/CodeGen/atomic-ops.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/atomic-ops.c?rev=238892&r1=238891&r2=238892&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/atomic-ops.c (original)
+++ cfe/trunk/test/CodeGen/atomic-ops.c Tue Jun 2 19:26:35 2015
@@ -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]+]]
More information about the cfe-commits
mailing list