Quellcode durchsuchen

Fixed the infinite loop in scalarizer (#1964)

Adam Yang vor 6 Jahren
Ursprung
Commit
f28cfd2a26

+ 3 - 21
lib/Transforms/Scalar/Scalarizer.cpp

@@ -719,8 +719,8 @@ bool Scalarizer::finish() {
     if (!Op->use_empty()) {
     if (!Op->use_empty()) {
       // HLSL Change Begins.
       // HLSL Change Begins.
       // Remove the extract element users if possible.
       // Remove the extract element users if possible.
-      for (auto UI = Op->user_begin(); UI != Op->user_end(); ) {
-        if (ExtractElementInst *EEI = dyn_cast<ExtractElementInst>(*(UI++))) {
+      for (User *UI : Op->users()) {
+        if (ExtractElementInst *EEI = dyn_cast<ExtractElementInst>(UI)) {
           Value *Idx = EEI->getIndexOperand();
           Value *Idx = EEI->getIndexOperand();
           if (!isa<ConstantInt>(Idx))
           if (!isa<ConstantInt>(Idx))
             continue;
             continue;
@@ -737,25 +737,7 @@ bool Scalarizer::finish() {
             } else
             } else
               break;
               break;
           }
           }
-          if (HasDbgInfo) {
-            if (auto *L = LocalAsMetadata::getIfExists(CV[immIdx])) {
-              if (auto *DINode = MetadataAsValue::getIfExists(Ctx, L)) {
-                // Putting old users in an array, so we don't keep looping over new
-                // users as we add more.
-                SmallVector<User *, 4> OldUsers(DINode->user_begin(), DINode->user_end());
-                for (User *U : OldUsers)
-                  if (DbgValueInst *DVI = dyn_cast<DbgValueInst>(U)) {
-                    auto *Expr = DVI->getExpression();
-                    DIBuilder DIB(M, /*AllowUnresolved*/ false);
-                    auto *VarInfo = DVI->getVariable();
-                    DebugLoc DbgLoc = DVI->getDebugLoc();
-                    unsigned Offset = 0;
-                    DIB.insertDbgValueIntrinsic(EEI, Offset, VarInfo, Expr,
-                                                DbgLoc, DVI);
-                  }
-              }
-            }
-          }
+
           EEI->replaceAllUsesWith(Elt);
           EEI->replaceAllUsesWith(Elt);
 
 
           EltMap[EEI] = Elt;
           EltMap[EEI] = Elt;

+ 28 - 0
tools/clang/test/CodeGenHLSL/debug/scalar_inf_loop.hlsl

@@ -0,0 +1,28 @@
+// RUN: %dxc -T ps_6_0 -E main -Zi -O3 %s | FileCheck %s
+
+// CHECK: @main
+
+// Test for an infinite loop in scalarizer when generating
+
+
+float3 fn(float3 a, float3 b, float3 c) {
+  float3 x = (a - b) * a;
+  float j = dot(x, c);
+  float k = dot(x, c);
+  return float3(j, k, 1);
+}
+
+float4x4 mat;
+
+float3 main() : SV_Target0 {
+  float3 myVar = normalize(mul(float3(1,1,1), (float3x3)mat));
+  float3 accum = float3(0,0,0);
+  [unroll] for(int i = 0; i < 2 ; i++) {
+     [unroll] for(uint j = 0; j < 4 ; j++) {
+      float3 ret = fn(float3(1,2,3), float3(0,0,0), myVar);
+      accum = lerp(accum, float3(ret.xy, 1), ret.z);
+     }
+  }
+  return accum;
+}
+