فهرست منبع

Skip inserting redundant phi nodes on struct type (#1748)

Vishal Sharma 6 سال پیش
والد
کامیت
545bf5e0c5
2فایلهای تغییر یافته به همراه88 افزوده شده و 1 حذف شده
  1. 12 1
      lib/Transforms/Utils/LCSSA.cpp
  2. 76 0
      tools/clang/test/CodeGenHLSL/nolcssa-on-struct-type.hlsl

+ 12 - 1
lib/Transforms/Utils/LCSSA.cpp

@@ -215,6 +215,7 @@ blockDominatesAnExit(BasicBlock *BB,
 bool llvm::formLCSSA(Loop &L, DominatorTree &DT, LoopInfo *LI,
                      ScalarEvolution *SE) {
   bool Changed = false;
+  bool shouldExpectLCSSAform = true;
 
   // Get the set of exiting blocks.
   SmallVector<BasicBlock *, 8> ExitBlocks;
@@ -245,6 +246,15 @@ bool llvm::formLCSSA(Loop &L, DominatorTree &DT, LoopInfo *LI,
            !isa<PHINode>(I->user_back())))
         continue;
 
+      // HLSL changes begin
+      // Skip inserting redundant PHI nodes on instruction of struct type
+      // as the resultant IR is not considered a valid DXIL.
+      if (I->getType()->isStructTy()) {
+        shouldExpectLCSSAform = false;
+        continue;
+      }
+      // HLSL changes end
+
       Changed |= processInstruction(L, *I, DT, ExitBlocks, PredCache, LI);
     }
   }
@@ -255,7 +265,8 @@ bool llvm::formLCSSA(Loop &L, DominatorTree &DT, LoopInfo *LI,
   if (SE && Changed)
     SE->forgetLoop(&L);
 
-  assert(L.isLCSSAForm(DT));
+  if(shouldExpectLCSSAform)
+    assert(L.isLCSSAForm(DT));
 
   return Changed;
 }

+ 76 - 0
tools/clang/test/CodeGenHLSL/nolcssa-on-struct-type.hlsl

@@ -0,0 +1,76 @@
+// RUN: %dxc -E main -T ps_6_0 /Zpr /O3 %s | FileCheck %s
+// CHECK-NOT: phi %dx.types.CBufRet.i32
+
+cbuffer cb
+{
+ int cb_a;
+ int cb_b;
+ bool cb_c[1];
+}
+
+static const struct
+{
+ int a;
+ int b;
+ bool c[1];
+} cbstruct = { cb_a, cb_b, cb_c };
+
+
+bool IsPos( float3 pos )
+{
+ float maxpos = max(pos.x, max(pos.y, pos.z) );
+ float minpos = min(pos.x, min(pos.y, pos.z) );
+ return ( maxpos < 32 && minpos > 0 );
+}
+
+float3 GetPos()
+{
+ [branch]
+ if(cbstruct.c[cbstruct.b])
+ {
+  return float3(0,0,0);
+ }
+ else
+ {
+  return float3(1,1,1);
+ }
+}
+
+int GetIdx( )
+{
+ for( int i=0; i< 4 ; i++ )
+ {
+  if( i == cbstruct.b )
+  {
+   return -1;
+  }
+  float3 pos = GetPos();
+  if( IsPos(pos) )
+  {
+   return i;
+  }
+ }
+
+ return -1;
+}
+
+float GetColor()
+{
+ int idx = GetIdx(); 
+ if( idx == cbstruct.a )
+ {
+   return 1.0;
+ }
+ return 0.0;
+}
+
+
+void main(out float4 OutColor : SV_Target0)
+{
+ float x = GetColor();
+ [branch]
+ if ( x < 0.0001f )
+ {
+  OutColor = 0.0f;
+ }
+}