Skip to content

Commit e82f56d

Browse files
committed
Updated per review.
1 parent 212f9d9 commit e82f56d

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
lines changed

clang/lib/CodeGen/CGAtomic.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,7 @@ namespace {
272272
llvm::AtomicOrdering::SequentiallyConsistent,
273273
llvm::AtomicOrdering Failure =
274274
llvm::AtomicOrdering::SequentiallyConsistent);
275-
/// Emits atomic compare-and-exchange op as LLVM instruction. Operands
276-
/// must be of integer or pointer type, so float must be casted.
277-
/// TODO: this could change - see comment in AtomicExpandPass.cpp.
275+
/// Emits atomic compare-and-exchange op as LLVM instruction.
278276
std::pair<llvm::Value *, llvm::Value *> EmitAtomicCompareExchangeOp(
279277
llvm::Value *ExpectedVal, llvm::Value *DesiredVal,
280278
llvm::AtomicOrdering Success =
@@ -1403,11 +1401,15 @@ RValue AtomicInfo::convertAtomicTempToRValue(Address addr,
14031401
LVal.getBaseInfo(), TBAAAccessInfo()));
14041402
}
14051403

1404+
/// Return true if \param ValTy is a type that should be casted to integer
1405+
/// around the atomic memory operation. If \param CmpXchg is true, then the
1406+
/// cast of a floating point type is made as that instruction can not have
1407+
/// floating point operands. TODO: Allow compare-and-exchange and FP - see
1408+
/// comment in AtomicExpandPass.cpp.
14061409
static bool shouldCastToInt(llvm::Type *ValTy, bool CmpXchg) {
1407-
bool KeepType =
1408-
(ValTy->isIntegerTy() || ValTy->isPointerTy() ||
1409-
(ValTy->isFloatingPointTy() && !ValTy->isX86_FP80Ty() && !CmpXchg));
1410-
return !KeepType;
1410+
if (ValTy->isFloatingPointTy())
1411+
return ValTy->isX86_FP80Ty() || CmpXchg;
1412+
return !ValTy->isIntegerTy() && !ValTy->isPointerTy();
14111413
}
14121414

14131415
RValue AtomicInfo::ConvertToValueOrAtomic(llvm::Value *Val,
@@ -1431,7 +1433,8 @@ RValue AtomicInfo::ConvertToValueOrAtomic(llvm::Value *Val,
14311433
assert((!ValTy->isIntegerTy() || Val->getType() == ValTy) &&
14321434
"Different integer types.");
14331435
return RValue::get(CGF.EmitFromMemory(Val, ValueTy));
1434-
} else if (llvm::CastInst::isBitCastable(Val->getType(), ValTy))
1436+
}
1437+
if (llvm::CastInst::isBitCastable(Val->getType(), ValTy))
14351438
return RValue::get(CGF.Builder.CreateBitCast(Val, ValTy));
14361439
}
14371440

clang/test/CodeGen/atomic.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
// RUN: %clang_cc1 %s -emit-llvm -o - -triple=i686-apple-darwin9 | FileCheck %s
1+
// RUN: %clang_cc1 %s -emit-llvm -o - -triple=i686-apple-darwin9 | FileCheck %s --check-prefixes=CHECK,X86
2+
// RUN: %clang_cc1 %s -emit-llvm -o - -triple=s390x-linux-gnu | FileCheck %s --check-prefixes=CHECK,SYSTEMZ
23

34
// CHECK: @[[NONSTATIC_GLOB_POINTER_FROM_INT:.+]] = global ptr null
45
// CHECK: @[[GLOB_POINTER:.+]] = internal global ptr null
56
// CHECK: @[[GLOB_POINTER_FROM_INT:.+]] = internal global ptr null
67
// CHECK: @[[GLOB_INT:.+]] = internal global i32 0
78
// CHECK: @[[GLOB_FLT:.+]] = internal global float {{[0e\+-\.]+}}, align
9+
// CHECK: @[[GLOB_DBL:.+]] = internal global double {{[0e\+-\.]+}}, align
10+
// X86: @[[GLOB_LONGDBL:.+]] = internal global x86_fp80 {{[0xK]+}}, align
11+
// SYSTEMZ: @[[GLOB_LONGDBL:.+]] = internal global fp128 {{[0xL]+}}, align
812

913
int atomic(void) {
1014
// non-sensical test for sync functions
@@ -79,8 +83,10 @@ int atomic(void) {
7983
// CHECK: atomicrmw nand ptr %valc, i8 6 seq_cst, align 1
8084

8185
__sync_val_compare_and_swap((void **)0, (void *)0, (void *)0);
82-
// CHECK: [[PAIR:%[a-z0-9_.]+]] = cmpxchg ptr null, i32 0, i32 0 seq_cst seq_cst, align 4
83-
// CHECK: extractvalue { i32, i1 } [[PAIR]], 0
86+
// X86: [[PAIR:%[a-z0-9_.]+]] = cmpxchg ptr null, i32 0, i32 0 seq_cst seq_cst, align 4
87+
// X86-NEXT: extractvalue { i32, i1 } [[PAIR]], 0
88+
// SYSTEMZ: [[PAIR:%[a-z0-9_.]+]] = cmpxchg ptr null, i64 0, i64 0 seq_cst seq_cst, align 8
89+
// SYSTEMZ-NEXT: extractvalue { i64, i1 } [[PAIR]], 0
8490

8591
if ( __sync_val_compare_and_swap(&valb, 0, 1)) {
8692
// CHECK: [[PAIR:%[a-z0-9_.]+]] = cmpxchg ptr %valb, i8 0, i8 1 seq_cst seq_cst, align 1
@@ -90,13 +96,15 @@ int atomic(void) {
9096
}
9197

9298
__sync_bool_compare_and_swap((void **)0, (void *)0, (void *)0);
93-
// CHECK: cmpxchg ptr null, i32 0, i32 0 seq_cst seq_cst, align 4
99+
// X86: cmpxchg ptr null, i32 0, i32 0 seq_cst seq_cst, align 4
100+
// SYSTEMZ: cmpxchg ptr null, i64 0, i64 0 seq_cst seq_cst, align 8
94101

95102
__sync_lock_release(&val);
96103
// CHECK: store atomic i32 0, {{.*}} release, align 4
97104

98105
__sync_lock_release(&ptrval);
99-
// CHECK: store atomic i32 0, {{.*}} release, align 4
106+
// X86: store atomic i32 0, {{.*}} release, align 4
107+
// SYSTEMZ: store atomic i64 0, {{.*}} release, align 8
100108

101109
__sync_synchronize ();
102110
// CHECK: fence seq_cst
@@ -131,16 +139,25 @@ static _Atomic(int *) glob_pointer_from_int = 0;
131139
_Atomic(int *) nonstatic_glob_pointer_from_int = 0LL;
132140
static _Atomic int glob_int = 0;
133141
static _Atomic float glob_flt = 0.0f;
142+
static _Atomic double glob_dbl = 0.0f;
143+
static _Atomic long double glob_longdbl = 0.0f;
134144

135145
void force_global_uses(void) {
146+
// X86: %atomic-temp = alloca x86_fp80, align 16
136147
(void)glob_pointer;
137148
// CHECK: load atomic ptr, ptr @[[GLOB_POINTER]] seq_cst
138149
(void)glob_pointer_from_int;
139150
// CHECK-NEXT: load atomic ptr, ptr @[[GLOB_POINTER_FROM_INT]] seq_cst
140151
(void)nonstatic_glob_pointer_from_int;
141152
// CHECK-NEXT: load atomic ptr, ptr @[[NONSTATIC_GLOB_POINTER_FROM_INT]] seq_cst
142153
(void)glob_int;
143-
// CHECK: load atomic i32, ptr @[[GLOB_INT]] seq_cst
154+
// CHECK-NEXT: load atomic i32, ptr @[[GLOB_INT]] seq_cst
144155
(void)glob_flt;
145-
// CHECK: load atomic float, ptr @[[GLOB_FLT]] seq_cst
156+
// CHECK-NEXT: load atomic float, ptr @[[GLOB_FLT]] seq_cst
157+
(void)glob_dbl;
158+
// CHECK-NEXT: load atomic double, ptr @[[GLOB_DBL]] seq_cst
159+
(void)glob_longdbl;
160+
// X86: call void @__atomic_load(i32 noundef 16, ptr noundef @glob_longdbl, ptr noundef %atomic-temp
161+
// X86-NEXT: %0 = load x86_fp80, ptr %atomic-temp, align 16
162+
// SYSTEMZ: load atomic fp128, ptr @[[GLOB_LONGDBL]] seq_cst
146163
}

0 commit comments

Comments
 (0)