forked from microsoft/DirectXShaderCompiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPIR-V] Emit OpUndef for undefined values (microsoft#6686)
Before this change, OpConstantNull was emitted when an undef value was required. This causes an issue for some types which cannot have the OpConstantNull value. In addition, it mixed well-defined values with undefined values, which prevents any kind of optimization/analysis later on. Fixes microsoft#6653 --------- Signed-off-by: Nathan Gauër <[email protected]>
- Loading branch information
Showing
13 changed files
with
167 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
tools/clang/test/CodeGenSPIRV/spirv.cf.ret-missing-resource.hlsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// RUN: %dxc -T vs_6_0 -E main -fcgl %s -spirv | FileCheck %s | ||
|
||
// CHECK: [[undef:%[0-9]+]] = OpUndef %type_2d_image | ||
|
||
Texture2D texA; | ||
Texture2D texB; | ||
|
||
// CHECK: %select = OpFunction | ||
Texture2D select(bool lhs) { | ||
|
||
// CHECK: %if_true = OpLabel | ||
if (lhs) | ||
return texA; | ||
// CHECK: %if_false = OpLabel | ||
else | ||
return texB; | ||
|
||
// no return for dead branch. | ||
// CHECK: %if_merge = OpLabel | ||
// CHECK-NEXT: OpReturnValue [[undef]] | ||
} | ||
// CHECK-NEXT: OpFunctionEnd | ||
|
||
float main(bool a: A) : B { | ||
Texture2D tex = select(true); | ||
return 1.0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
// RUN: %dxc -T vs_6_0 -E main -Wno-return-type -fcgl %s -spirv | FileCheck %s | ||
|
||
// CHECK:[[null:%[0-9]+]] = OpConstantNull %float | ||
// CHECK:[[undef:%[0-9]+]] = OpUndef %float | ||
|
||
float main(bool a: A) : B { | ||
if (a) return 1.0; | ||
// No return value for else | ||
|
||
// CHECK: %if_merge = OpLabel | ||
// CHECK-NEXT: OpReturnValue [[null]] | ||
// CHECK-NEXT: OpReturnValue [[undef]] | ||
// CHECK-NEXT: OpFunctionEnd | ||
} |
31 changes: 31 additions & 0 deletions
31
tools/clang/test/CodeGenSPIRV/spirv.cf.ret-undef-shared.hlsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// RUN: %dxc -T vs_6_0 -E main -fcgl %s -spirv | FileCheck %s | ||
|
||
// CHECK: [[undef:%[0-9]+]] = OpUndef %type_2d_image | ||
// CHECK-NOT: OpUndef %type_2d_image | ||
|
||
|
||
Texture2D texA; | ||
Texture2D texB; | ||
|
||
Texture2D select1(bool lhs) { | ||
if (lhs) | ||
return texA; | ||
else | ||
return texB; | ||
// no return for dead branch. | ||
} | ||
|
||
Texture2D select2(bool lhs) { | ||
if (lhs) | ||
return texA; | ||
else | ||
return texB; | ||
// no return for dead branch. | ||
} | ||
|
||
float main(bool a: A) : B { | ||
Texture2D x = select1(true); | ||
Texture2D y = select2(true); | ||
return 1.0; | ||
} | ||
|