Browse Source

Don't replace readfirstlane in GVN::propagateEquality. (#3504)

Xiang Li 4 years ago
parent
commit
9eb7f4f40e

+ 10 - 0
lib/Transforms/Scalar/GVN.cpp

@@ -52,6 +52,7 @@
 #include "llvm/Transforms/Utils/SSAUpdater.h"
 #include <vector>
 #include "dxc/DXIL/DxilConstants.h"  // HLSL Change
+#include "dxc/DXIL/DxilOperations.h" // HLSL Change
 using namespace llvm;
 using namespace PatternMatch;
 
@@ -2127,6 +2128,15 @@ bool GVN::propagateEquality(Value *LHS, Value *RHS,
     // LHS always has at least one use that is not dominated by Root, this will
     // never do anything if LHS has only one use.
     if (!LHS->hasOneUse()) {
+      // HLSL Change Begin - Don't replace readfirstlane to help propagate
+      // uniform info.
+      if (CallInst *CI = dyn_cast<CallInst>(LHS)) {
+        if (hlsl::OP::IsDxilOpFuncCallInst(
+                CI, hlsl::DXIL::OpCode::WaveReadLaneFirst)) {
+          continue;
+        }
+      }
+      // HLSL Change End
       unsigned NumReplacements = replaceDominatedUsesWith(LHS, RHS, *DT, Root);
       Changed |= NumReplacements > 0;
       NumGVNEqProp += NumReplacements;

+ 16 - 0
tools/clang/test/HLSLFileCheck/passes/llvm/gvn/GVN_readfirstlane.hlsl

@@ -0,0 +1,16 @@
+// RUN: %dxc -E main -T ps_6_0 %s  | FileCheck %s
+
+//CHECK:%[[FirstLane:[a-zA-Z0-9]+]] = call i32 @dx.op.waveReadLaneFirst.i32(i32 118,
+// Make sure use FirstLane.
+//CHECK:uitofp i32 %[[FirstLane]] to float
+
+
+float main(uint i:I) : SV_Target {
+  const uint uniformIndex = WaveReadLaneFirst ( i ) ;
+  if ( uniformIndex == i)
+  {
+    return sin(uniformIndex);
+  } else {
+    return 13;
+  }
+}