r222615 - CodeGen: Make atomic operations play nice with address spaces
David Majnemer
david.majnemer at gmail.com
Sat Nov 22 02:44:13 PST 2014
Author: majnemer
Date: Sat Nov 22 04:44:12 2014
New Revision: 222615
URL: http://llvm.org/viewvc/llvm-project?rev=222615&view=rev
Log:
CodeGen: Make atomic operations play nice with address spaces
We were being a little sloppy with our pointer/address space casts.
This fixes PR21643.
Modified:
cfe/trunk/lib/CodeGen/CGAtomic.cpp
cfe/trunk/test/CodeGen/atomic-ops.c
Modified: cfe/trunk/lib/CodeGen/CGAtomic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGAtomic.cpp?rev=222615&r1=222614&r2=222615&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGAtomic.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGAtomic.cpp Sat Nov 22 04:44:12 2014
@@ -765,13 +765,15 @@ RValue CodeGenFunction::EmitAtomicExpr(A
E->getOp() == AtomicExpr::AO__atomic_load ||
E->getOp() == AtomicExpr::AO__atomic_load_n;
- llvm::Type *IPtrTy =
- llvm::IntegerType::get(getLLVMContext(), Size * 8)->getPointerTo();
+ llvm::Type *ITy =
+ llvm::IntegerType::get(getLLVMContext(), Size * 8);
llvm::Value *OrigDest = Dest;
- Ptr = Builder.CreateBitCast(Ptr, IPtrTy);
- if (Val1) Val1 = Builder.CreateBitCast(Val1, IPtrTy);
- if (Val2) Val2 = Builder.CreateBitCast(Val2, IPtrTy);
- if (Dest && !E->isCmpXChg()) Dest = Builder.CreateBitCast(Dest, IPtrTy);
+ Ptr = Builder.CreateBitCast(
+ Ptr, ITy->getPointerTo(Ptr->getType()->getPointerAddressSpace()));
+ if (Val1) Val1 = Builder.CreateBitCast(Val1, ITy->getPointerTo());
+ if (Val2) Val2 = Builder.CreateBitCast(Val2, ITy->getPointerTo());
+ if (Dest && !E->isCmpXChg())
+ Dest = Builder.CreateBitCast(Dest, ITy->getPointerTo());
if (isa<llvm::ConstantInt>(Order)) {
int ord = cast<llvm::ConstantInt>(Order)->getZExtValue();
Modified: cfe/trunk/test/CodeGen/atomic-ops.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/atomic-ops.c?rev=222615&r1=222614&r2=222615&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/atomic-ops.c (original)
+++ cfe/trunk/test/CodeGen/atomic-ops.c Sat Nov 22 04:44:12 2014
@@ -543,4 +543,19 @@ void EMIT_ALL_THE_THINGS(int *ptr, int *
// CHECK: = cmpxchg weak {{.*}} seq_cst seq_cst
}
+int PR21643() {
+ return __atomic_or_fetch((int __attribute__((address_space(257))) *)0x308, 1,
+ __ATOMIC_RELAXED);
+ // CHECK: %[[atomictmp:.*]] = alloca i32, align 4
+ // CHECK: %[[atomicdst:.*]] = alloca i32, align 4
+ // CHECK: store i32 1, i32* %[[atomictmp]]
+ // CHECK: %[[one:.*]] = load i32* %[[atomictmp]], align 4
+ // CHECK: %[[old:.*]] = atomicrmw or i32 addrspace(257)* inttoptr (i32 776 to i32 addrspace(257)*), i32 %[[one]] monotonic
+ // CHECK: %[[new:.*]] = or i32 %[[old]], %[[one]]
+ // CHECK: store i32 %[[new]], i32* %[[atomicdst]], align 4
+ // CHECK: %[[ret:.*]] = load i32* %[[atomicdst]], align 4
+ // CHECK: ret i32 %[[ret]]
+
+}
+
#endif
More information about the cfe-commits
mailing list