Browse Source

Not fold gep 0, ... 0 for HLSL. (#2519)

not fold gep 0, ... 0 for HLSL.
Xiang Li 5 năm trước cách đây
mục cha
commit
77afe15b0d

+ 1 - 0
lib/IR/ConstantFold.cpp

@@ -544,6 +544,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V,
       if (unsigned newOpc = foldConstantCastPair(opc, CE, DestTy))
         return ConstantExpr::getCast(newOpc, CE->getOperand(0), DestTy);
     } else if (CE->getOpcode() == Instruction::GetElementPtr &&
+               false && // HLSL change - not fold gep 0, ... 0 for HLSL.
                // Do not fold addrspacecast (gep 0, .., 0). It might make the
                // addrspacecast uncanonicalized.
                opc != Instruction::AddrSpaceCast) {

+ 43 - 0
tools/clang/test/HLSLFileCheck/hlsl/classes/mismatch_type_in_memcpy.hlsl

@@ -0,0 +1,43 @@
+// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
+
+// Make sure memcpy on _b.a = b.a not crash.
+// CHECK:define void @main()
+
+
+struct A
+{
+    float a;
+    float b;
+};
+
+struct B
+{
+    A a;
+};
+
+struct C
+{
+    float c;
+    B b;
+
+    B GetB()
+    {
+        B _b;
+        _b.a = b.a;
+        return _b;
+    }
+};
+
+C CreateC()
+{
+    C c;
+    return c;
+}
+
+static const C c = CreateC();
+static const B b = c.GetB();
+
+float4 main() : SV_Target
+{
+    return (float4)0;
+}

+ 14 - 0
tools/clang/test/HLSLFileCheck/hlsl/operators/unary/asfloat_store_combine.hlsl

@@ -0,0 +1,14 @@
+// RUN: %dxc /T cs_6_0 /E main %s | FileCheck %s
+
+// Make sure asfloat and store not crash.
+// CHECK:define void @main
+
+groupshared float2 s[2];
+
+[numthreads(8, 8, 1)]
+void main(uint2 DTid : SV_DispatchThreadID) {
+    for (int j = 0; j < 2; j++)
+    {
+        s[j] = float2(asfloat(DTid.x), asfloat((0xFFFFFFFF << DTid.y) << j));
+    }
+}