Skip to content

Commit cad5182

Browse files
authored
Translate atomicrmw fmin/fmax into OpAtomicFMinEXT/OpAtomicFMaxEXT (#1768)
Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
1 parent 46623fc commit cad5182

File tree

5 files changed

+112
-3
lines changed

5 files changed

+112
-3
lines changed

lib/SPIRV/OCLUtil.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,8 @@ template <> void LLVMSPIRVAtomicRmwOpCodeMap::init() {
647647
add(llvm::AtomicRMWInst::UMax, OpAtomicUMax);
648648
add(llvm::AtomicRMWInst::UMin, OpAtomicUMin);
649649
add(llvm::AtomicRMWInst::FAdd, OpAtomicFAddEXT);
650+
add(llvm::AtomicRMWInst::FMin, OpAtomicFMinEXT);
651+
add(llvm::AtomicRMWInst::FMax, OpAtomicFMaxEXT);
650652
}
651653

652654
} // namespace SPIRV

lib/SPIRV/SPIRVWriter.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,9 +2172,11 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
21722172

21732173
if (AtomicRMWInst *ARMW = dyn_cast<AtomicRMWInst>(V)) {
21742174
AtomicRMWInst::BinOp Op = ARMW->getOperation();
2175-
bool SupportedAtomicInst = AtomicRMWInst::isFPOperation(Op)
2176-
? Op == AtomicRMWInst::FAdd
2177-
: Op != AtomicRMWInst::Nand;
2175+
bool SupportedAtomicInst =
2176+
AtomicRMWInst::isFPOperation(Op)
2177+
? (Op == AtomicRMWInst::FAdd || Op == AtomicRMWInst::FMin ||
2178+
Op == AtomicRMWInst::FMax)
2179+
: Op != AtomicRMWInst::Nand;
21782180
if (!BM->getErrorLog().checkError(
21792181
SupportedAtomicInst, SPIRVEC_InvalidInstruction, V,
21802182
"Atomic " + AtomicRMWInst::getOperationName(Op).str() +
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
; RUN: llvm-as < %s -o %t.bc
2+
; RUN: llvm-spirv --spirv-ext=+SPV_EXT_shader_atomic_float_min_max %t.bc -o %t.spv
3+
; RUN: spirv-val %t.spv
4+
; RUN: llvm-spirv -to-text %t.spv -o - | FileCheck %s
5+
6+
; CHECK-DAG: Extension "SPV_EXT_shader_atomic_float_min_max"
7+
; CHECK-DAG: Capability AtomicFloat64MinMaxEXT
8+
; CHECK: TypeInt [[Int:[0-9]+]] 32 0
9+
; CHECK-DAG: Constant [[Int]] [[Scope_Device:[0-9]+]] 1 {{$}}
10+
; CHECK-DAG: Constant [[Int]] [[MemSem_SequentiallyConsistent:[0-9]+]] 16
11+
; CHECK: TypeFloat [[Double:[0-9]+]] 64
12+
; CHECK: Variable {{[0-9]+}} [[DoublePointer:[0-9]+]]
13+
; CHECK: Constant [[Double]] [[DoubleValue:[0-9]+]] 0 1078263808
14+
15+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
16+
target triple = "spir64"
17+
18+
@f = common dso_local local_unnamed_addr addrspace(1) global double 0.000000e+00, align 8
19+
20+
; Function Attrs: nounwind
21+
define dso_local spir_func void @test_atomicrmw_fadd() local_unnamed_addr #0 {
22+
entry:
23+
%0 = atomicrmw fmin double addrspace(1)* @f, double 42.000000e+00 seq_cst
24+
; CHECK: AtomicFMinEXT [[Double]] {{[0-9]+}} [[DoublePointer]] [[Scope_Device]] [[MemSem_SequentiallyConsistent]] [[DoubleValue]]
25+
%1 = atomicrmw fmax double addrspace(1)* @f, double 42.000000e+00 seq_cst
26+
; CHECK: AtomicFMaxEXT [[Double]] {{[0-9]+}} [[DoublePointer]] [[Scope_Device]] [[MemSem_SequentiallyConsistent]] [[DoubleValue]]
27+
28+
ret void
29+
}
30+
31+
attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
32+
33+
!llvm.module.flags = !{!0}
34+
35+
!0 = !{i32 1, !"wchar_size", i32 4}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
; RUN: llvm-as < %s -o %t.bc
2+
; RUN: llvm-spirv --spirv-ext=+SPV_EXT_shader_atomic_float_min_max %t.bc -o %t.spv
3+
; RUN: spirv-val %t.spv
4+
; RUN: llvm-spirv -to-text %t.spv -o - | FileCheck %s
5+
6+
; CHECK-DAG: Extension "SPV_EXT_shader_atomic_float_min_max"
7+
; CHECK-DAG: Capability AtomicFloat32MinMaxEXT
8+
; CHECK: TypeInt [[Int:[0-9]+]] 32 0
9+
; CHECK-DAG: Constant [[Int]] [[Scope_Device:[0-9]+]] 1 {{$}}
10+
; CHECK-DAG: Constant [[Int]] [[MemSem_SequentiallyConsistent:[0-9]+]] 16
11+
; CHECK: TypeFloat [[Float:[0-9]+]] 32
12+
; CHECK: Variable {{[0-9]+}} [[FPPointer:[0-9]+]]
13+
; CHECK: Constant [[Float]] [[FPValue:[0-9]+]] 1109917696
14+
15+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
16+
target triple = "spir64"
17+
18+
@f = common dso_local local_unnamed_addr addrspace(1) global float 0.000000e+00, align 4
19+
20+
; Function Attrs: nounwind
21+
define dso_local spir_func void @test_atomicrmw_fadd() local_unnamed_addr #0 {
22+
entry:
23+
%0 = atomicrmw fmin float addrspace(1)* @f, float 42.000000e+00 seq_cst
24+
; CHECK: AtomicFMinEXT [[Float]] {{[0-9]+}} [[FPPointer]] [[Scope_Device]] [[MemSem_SequentiallyConsistent]] [[FPValue]]
25+
%1 = atomicrmw fmax float addrspace(1)* @f, float 42.000000e+00 seq_cst
26+
; CHECK: AtomicFMaxEXT [[Float]] {{[0-9]+}} [[FPPointer]] [[Scope_Device]] [[MemSem_SequentiallyConsistent]] [[FPValue]]
27+
28+
ret void
29+
}
30+
31+
attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
32+
33+
!llvm.module.flags = !{!0}
34+
35+
!0 = !{i32 1, !"wchar_size", i32 4}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
; RUN: llvm-as < %s -o %t.bc
2+
; RUN: llvm-spirv --spirv-ext=+SPV_EXT_shader_atomic_float_min_max %t.bc -o %t.spv
3+
; RUN: spirv-val %t.spv
4+
; RUN: llvm-spirv -to-text %t.spv -o - | FileCheck %s
5+
6+
; CHECK-DAG: Extension "SPV_EXT_shader_atomic_float_min_max"
7+
; CHECK-DAG: Capability AtomicFloat16MinMaxEXT
8+
; CHECK: TypeInt [[Int:[0-9]+]] 32 0
9+
; CHECK-DAG: Constant [[Int]] [[Scope_Device:[0-9]+]] 1 {{$}}
10+
; CHECK-DAG: Constant [[Int]] [[MemSem_SequentiallyConsistent:[0-9]+]] 16
11+
; CHECK: TypeFloat [[Half:[0-9]+]] 16
12+
; CHECK: Variable {{[0-9]+}} [[HalfPointer:[0-9]+]]
13+
; CHECK: Constant [[Half]] [[HalfValue:[0-9]+]] 20800
14+
15+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
16+
target triple = "spir64"
17+
18+
@f = common dso_local local_unnamed_addr addrspace(1) global half 0.000000e+00, align 4
19+
20+
; Function Attrs: nounwind
21+
define dso_local spir_func void @test_atomicrmw_fadd() local_unnamed_addr #0 {
22+
entry:
23+
%0 = atomicrmw fmin half addrspace(1)* @f, half 42.000000e+00 seq_cst
24+
; CHECK: AtomicFMinEXT [[Half]] {{[0-9]+}} [[HalfPointer]] [[Scope_Device]] [[MemSem_SequentiallyConsistent]] [[HalfValue]]
25+
%1 = atomicrmw fmax half addrspace(1)* @f, half 42.000000e+00 seq_cst
26+
; CHECK: AtomicFMaxEXT [[Half]] {{[0-9]+}} [[HalfPointer]] [[Scope_Device]] [[MemSem_SequentiallyConsistent]] [[HalfValue]]
27+
28+
ret void
29+
}
30+
31+
attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
32+
33+
!llvm.module.flags = !{!0}
34+
35+
!0 = !{i32 1, !"wchar_size", i32 4}

0 commit comments

Comments
 (0)