Selaa lähdekoodia

Workaround "legalize sample offset" pass introducing illegal alloca i8s. (#2265)

The legalize sample offset pass runs a bunch of optimizations in the hope to turn the offset argument into a constant value. This includes running the vanilla "SROA" pass, which differs from the HLSL one and will promote alloca i1s to alloca i8s, which is invalid dxil. This change modifies the "SROA" pass to leave alloca i1s intact as it is the solution least likely to introduce regressions.
Tristan Labelle 6 vuotta sitten
vanhempi
commit
f3489bc99b

+ 8 - 0
lib/Transforms/Scalar/SROA.cpp

@@ -4372,6 +4372,14 @@ bool SROA::runOnAlloca(AllocaInst &AI) {
   }
   const DataLayout &DL = AI.getModule()->getDataLayout();
 
+  // HLSL Change Begin
+  // This passes only deals with byte-sized types.
+  // We can have i1 allocas for a bool return value when compiling without optimizations
+  // If we let this run, it'll get turned into an i8, which is invalid dxil.
+  if (AI.getAllocatedType()->isIntegerTy(1))
+    return false;
+  // HLSL Change End
+
   // Skip alloca forms that this analysis can't handle.
   if (AI.isArrayAllocation() || !AI.getAllocatedType()->isSized() ||
       hlsl::dxilutil::IsHLSLObjectType(

+ 17 - 0
tools/clang/test/CodeGenHLSL/batch/passes/legalize_sample_offset/alloca_i8_regression.hlsl

@@ -0,0 +1,17 @@
+// RUN: %dxc -T ps_6_2 -E main -Od %s | FileCheck %s
+
+// Regression test for a bug where the legalize sample offset pass would
+// run vanilla SROA which will turn an unoptimized "alloca i1" for a return value
+// into an "alloca i8", which is invalid DXIL.
+
+// CHECK: @main
+
+SamplerState samp;
+Texture1D tex;
+bool ShouldWriteFeedback() { return true; }
+float4 main() : SV_Target
+{
+    ShouldWriteFeedback();
+    int zero = 0;
+    return tex.Sample(samp, 0, zero);
+}

+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/sample-offset-imm-test01.hlsl → tools/clang/test/CodeGenHLSL/batch/passes/legalize_sample_offset/sample-offset-imm-test01.hlsl


+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/sample-offset-imm-test02.hlsl → tools/clang/test/CodeGenHLSL/batch/passes/legalize_sample_offset/sample-offset-imm-test02.hlsl


+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/sample-offset-imm-test03.hlsl → tools/clang/test/CodeGenHLSL/batch/passes/legalize_sample_offset/sample-offset-imm-test03.hlsl


+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/sample-offset-imm-test04.hlsl → tools/clang/test/CodeGenHLSL/batch/passes/legalize_sample_offset/sample-offset-imm-test04.hlsl