AMDGPU: llvm.SI.fs.constant is a source of divergence
authorNicolai Haehnle <nhaehnle@gmail.com>
Mon, 2 May 2016 17:37:01 +0000 (17:37 +0000)
committerNicolai Haehnle <nhaehnle@gmail.com>
Mon, 2 May 2016 17:37:01 +0000 (17:37 +0000)
Summary:
This intrinsic is used to get flat-shaded fragment shader inputs. Those are
uniform across a primitive, but a fragment shader wave may process pixels from
multiple primitives (as indicated by the prim_mask), and so that's where
divergence can arise.

Reviewers: arsenm, tstellarAMD

Subscribers: arsenm, llvm-commits

Differential Revision: http://reviews.llvm.org/D19747

llvm-svn: 268259

llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp
llvm/test/Analysis/DivergenceAnalysis/AMDGPU/interp-intrinsics.ll [new file with mode: 0644]

index 39da9dd..fabec27 100644 (file)
@@ -260,6 +260,7 @@ static bool isIntrinsicSourceOfDivergence(const TargetIntrinsicInfo *TII,
     return false;
   case AMDGPUIntrinsic::SI_tid:
   case AMDGPUIntrinsic::SI_fs_interp:
+  case AMDGPUIntrinsic::SI_fs_constant:
     return true;
   }
 }
diff --git a/llvm/test/Analysis/DivergenceAnalysis/AMDGPU/interp-intrinsics.ll b/llvm/test/Analysis/DivergenceAnalysis/AMDGPU/interp-intrinsics.ll
new file mode 100644 (file)
index 0000000..d1c90ba
--- /dev/null
@@ -0,0 +1,22 @@
+; RUN: opt  -mtriple amdgcn--- -analyze -divergence %s | FileCheck %s
+
+; CHECK-LABEL: 'fs_interp'
+; CHECK: DIVERGENT: %v = call float @llvm.SI.fs.interp(
+define amdgpu_ps void @fs_interp(i32 inreg %prim_mask, <2 x i32> %interp_param) #1 {
+  %v = call float @llvm.SI.fs.interp(i32 0, i32 0, i32 %prim_mask, <2 x i32> %interp_param)
+  store volatile float %v, float addrspace(1)* undef
+  ret void
+}
+
+; CHECK-LABEL: 'fs_constant'
+; CHECK: DIVERGENT: %v = call float @llvm.SI.fs.constant(
+define amdgpu_ps void @fs_constant(i32 inreg %prim_mask, <2 x i32> %interp_param) #1 {
+  %v = call float @llvm.SI.fs.constant(i32 0, i32 0, i32 %prim_mask)
+  store volatile float %v, float addrspace(1)* undef
+  ret void
+}
+
+declare float @llvm.SI.fs.interp(i32, i32, i32, <2 x i32>) #0
+declare float @llvm.SI.fs.constant(i32, i32, i32) #0
+
+attributes #0 = { nounwind readnone }