From: Jingyue Wu Date: Mon, 31 Aug 2015 17:25:51 +0000 (+0000) Subject: [CUDA] fix codegen for __nvvm_atom_min/max_gen_u* X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=88755a81c3b2b89c91394a201e7477e025414f8d;p=clang [CUDA] fix codegen for __nvvm_atom_min/max_gen_u* Summary: Clang should emit "atomicrmw umin/umax" instead of "atomicrmw min/max". Reviewers: eliben, tra Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D12487 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@246455 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp index 955dcfc96c..6966b03ef3 100644 --- a/lib/CodeGen/CGBuiltin.cpp +++ b/lib/CodeGen/CGBuiltin.cpp @@ -6985,18 +6985,22 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, case NVPTX::BI__nvvm_atom_max_gen_i: case NVPTX::BI__nvvm_atom_max_gen_l: case NVPTX::BI__nvvm_atom_max_gen_ll: + return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Max, E); + case NVPTX::BI__nvvm_atom_max_gen_ui: case NVPTX::BI__nvvm_atom_max_gen_ul: case NVPTX::BI__nvvm_atom_max_gen_ull: - return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Max, E); + return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::UMax, E); case NVPTX::BI__nvvm_atom_min_gen_i: case NVPTX::BI__nvvm_atom_min_gen_l: case NVPTX::BI__nvvm_atom_min_gen_ll: + return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Min, E); + case NVPTX::BI__nvvm_atom_min_gen_ui: case NVPTX::BI__nvvm_atom_min_gen_ul: case NVPTX::BI__nvvm_atom_min_gen_ull: - return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Min, E); + return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::UMin, E); case NVPTX::BI__nvvm_atom_cas_gen_i: case NVPTX::BI__nvvm_atom_cas_gen_l: diff --git a/test/CodeGen/builtins-nvptx.c b/test/CodeGen/builtins-nvptx.c index ebf20673dd..498da476d1 100644 --- a/test/CodeGen/builtins-nvptx.c +++ b/test/CodeGen/builtins-nvptx.c @@ -234,30 +234,30 @@ __device__ void nvvm_atom(float *fp, float f, int *ip, int i, long *lp, long l, // CHECK: atomicrmw xchg __nvvm_atom_xchg_gen_ll(&sll, ll); - // CHECK: atomicrmw max + // CHECK: atomicrmw max i32* __nvvm_atom_max_gen_i(ip, i); - // CHECK: atomicrmw max + // CHECK: atomicrmw umax i32* __nvvm_atom_max_gen_ui((unsigned int *)ip, i); // CHECK: atomicrmw max __nvvm_atom_max_gen_l(&dl, l); - // CHECK: atomicrmw max + // CHECK: atomicrmw umax __nvvm_atom_max_gen_ul((unsigned long *)&dl, l); - // CHECK: atomicrmw max + // CHECK: atomicrmw max i64* __nvvm_atom_max_gen_ll(&sll, ll); - // CHECK: atomicrmw max + // CHECK: atomicrmw umax i64* __nvvm_atom_max_gen_ull((unsigned long long *)&sll, ll); - // CHECK: atomicrmw min + // CHECK: atomicrmw min i32* __nvvm_atom_min_gen_i(ip, i); - // CHECK: atomicrmw min + // CHECK: atomicrmw umin i32* __nvvm_atom_min_gen_ui((unsigned int *)ip, i); // CHECK: atomicrmw min __nvvm_atom_min_gen_l(&dl, l); - // CHECK: atomicrmw min + // CHECK: atomicrmw umin __nvvm_atom_min_gen_ul((unsigned long *)&dl, l); - // CHECK: atomicrmw min + // CHECK: atomicrmw min i64* __nvvm_atom_min_gen_ll(&sll, ll); - // CHECK: atomicrmw min + // CHECK: atomicrmw umin i64* __nvvm_atom_min_gen_ull((unsigned long long *)&sll, ll); // CHECK: cmpxchg