ソースを参照

Fix crash issue with Matrix index expressions (#1519)

Vishal Sharma 7 年 前
コミット
f534450689

+ 2 - 0
lib/HLSL/HLOperationLower.cpp

@@ -4623,6 +4623,8 @@ Value *GenerateVecEltFromGEP(Value *ldData, GetElementPtrInst *GEP,
       Builder.CreateStore(Elt, Ptr);
     }
     // Load from temp array.
+    // Insert the new GEP just before the old and to-be-deleted GEP
+    Builder.SetInsertPoint(GEP);
     Value *EltGEP = Builder.CreateInBoundsGEP(tempArray, {zero, idx});
     return Builder.CreateLoad(EltGEP);
   }

+ 14 - 0
tools/clang/test/CodeGenHLSL/quick-test/matrix_idx_with_expr_test01.hlsl

@@ -0,0 +1,14 @@
+// RUN: %dxc -E main -T ps_6_0 > %s | FileCheck %s
+
+// CHECK: define void @main()
+// CHECK: %{{[a-z0-9]+}} = shl i32 %{{[a-z0-9]+}}, 2
+// CHECK: %{{[a-z0-9]+}} = and i32 %{{[a-z0-9]+}}, 8
+// CHECK: %{{[a-z0-9]+}} = or i32 %{{[a-z0-9]+}}, 20
+// CHECK: %{{[a-z0-9]+}} = getelementptr inbounds [4 x float], [4 x float]* %{{[a-z0-9]+}}, i32 0, i32 %{{[a-z0-9]+}}
+// CHECK: %{{[a-z0-9]+}} = getelementptr inbounds [4 x float], [4 x float]* %{{[a-z0-9]+}}, i32 0, i32 %{{[a-z0-9]+}}
+// CHECK: entry
+
+float4x4 buf;
+float main(uint a : A) : SV_Target {
+ return buf[a >> 2][(((a & 3) | 5) * 4)] * buf[2][a << 2];
+}