From 77afe15b0dba794cda62077f222c1cc8c7922d3c Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Fri, 11 Oct 2019 17:46:39 -0700 Subject: [PATCH] Not fold gep 0, ... 0 for HLSL. (#2519) not fold gep 0, ... 0 for HLSL. --- lib/IR/ConstantFold.cpp | 1 + .../hlsl/classes/mismatch_type_in_memcpy.hlsl | 43 +++++++++++++++++++ .../unary/asfloat_store_combine.hlsl | 14 ++++++ 3 files changed, 58 insertions(+) create mode 100644 tools/clang/test/HLSLFileCheck/hlsl/classes/mismatch_type_in_memcpy.hlsl create mode 100644 tools/clang/test/HLSLFileCheck/hlsl/operators/unary/asfloat_store_combine.hlsl diff --git a/lib/IR/ConstantFold.cpp b/lib/IR/ConstantFold.cpp index 46bb20e0d..47bcd2784 100644 --- a/lib/IR/ConstantFold.cpp +++ b/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) { diff --git a/tools/clang/test/HLSLFileCheck/hlsl/classes/mismatch_type_in_memcpy.hlsl b/tools/clang/test/HLSLFileCheck/hlsl/classes/mismatch_type_in_memcpy.hlsl new file mode 100644 index 000000000..406dfb23b --- /dev/null +++ b/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; +} \ No newline at end of file diff --git a/tools/clang/test/HLSLFileCheck/hlsl/operators/unary/asfloat_store_combine.hlsl b/tools/clang/test/HLSLFileCheck/hlsl/operators/unary/asfloat_store_combine.hlsl new file mode 100644 index 000000000..e1c773b34 --- /dev/null +++ b/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)); + } +} \ No newline at end of file