cf.return.early.float4.hlsl 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Run: %dxc -T ps_6_0 -E main
  2. // CHECK: [[v4f1:%\d+]] = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
  3. // CHECK: [[v4f2:%\d+]] = OpConstantComposite %v4float %float_2 %float_2 %float_2 %float_2
  4. // CHECK: [[v4f3:%\d+]] = OpConstantComposite %v4float %float_3 %float_3 %float_3 %float_3
  5. // CHECK: [[v4f4:%\d+]] = OpConstantComposite %v4float %float_4 %float_4 %float_4 %float_4
  6. // CHECK: [[v4f5:%\d+]] = OpConstantComposite %v4float %float_5 %float_5 %float_5 %float_5
  7. // CHECK: [[v4f6:%\d+]] = OpConstantComposite %v4float %float_6 %float_6 %float_6 %float_6
  8. // CHECK: [[v4f7:%\d+]] = OpConstantComposite %v4float %float_7 %float_7 %float_7 %float_7
  9. // CHECK: [[v4f8:%\d+]] = OpConstantComposite %v4float %float_8 %float_8 %float_8 %float_8
  10. // CHECK: [[v4f9:%\d+]] = OpConstantComposite %v4float %float_9 %float_9 %float_9 %float_9
  11. float4 myfunc() {
  12. int a, b;
  13. bool cond = true;
  14. while(cond) {
  15. switch(b) {
  16. // CHECK: %switch_1 = OpLabel
  17. case 1:
  18. a = 1;
  19. // CHECK: OpReturnValue [[v4f1]]
  20. return float4(1.0, 1.0, 1.0, 1.0);
  21. // CHECK-NEXT: %switch_2 = OpLabel
  22. case 2: {
  23. a = 3;
  24. // CHECK: OpReturnValue [[v4f2]]
  25. {return float4(2.0, 2.0, 2.0, 2.0);} // Return from function.
  26. a = 4; // No SPIR-V should be emitted for this statement.
  27. break; // No SPIR-V should be emitted for this statement.
  28. }
  29. // CHECK-NEXT: %switch_5 = OpLabel
  30. case 5 : {
  31. a = 5;
  32. // CHECK: OpReturnValue [[v4f3]]
  33. {{return float4(3.0, 3.0, 3.0, 3.0);}} // Return from function.
  34. a = 6; // No SPIR-V should be emitted for this statement.
  35. }
  36. // CHECK-NEXT: %switch_default = OpLabel
  37. default:
  38. for (int i=0; i<10; ++i) {
  39. if (cond) {
  40. // CHECK: %if_true = OpLabel
  41. // CHECK-NEXT: OpReturnValue [[v4f4]]
  42. return float4(4.0, 4.0, 4.0, 4.0); // Return from function.
  43. return float4(5.0, 5.0, 5.0, 5.0); // No SPIR-V should be emitted for this statement.
  44. continue; // No SPIR-V should be emitted for this statement.
  45. break; // No SPIR-V should be emitted for this statement.
  46. ++a; // No SPIR-V should be emitted for this statement.
  47. } else {
  48. // CHECK-NEXT: %if_false = OpLabel
  49. // CHECK-NEXT: OpReturnValue [[v4f6]]
  50. return float4(6.0, 6.0, 6.0, 6.0);; // Return from function
  51. continue; // No SPIR-V should be emitted for this statement.
  52. break; // No SPIR-V should be emitted for this statement.
  53. ++a; // No SPIR-V should be emitted for this statement.
  54. }
  55. }
  56. // CHECK: %for_merge = OpLabel
  57. // CHECK-NEXT: OpReturnValue [[v4f7]]
  58. // Return from function.
  59. // Even though this statement will never be executed [because both "if" and "else" above have return statements],
  60. // SPIR-V code should be emitted for it as we do not analyze the logic.
  61. return float4(7.0, 7.0, 7.0, 7.0);
  62. }
  63. // CHECK: %switch_merge = OpLabel
  64. // CHECK-NEXT: OpReturnValue [[v4f8]]
  65. // Return from function.
  66. // Even though this statement will never be executed [because all "case" statements above contain a return statement],
  67. // SPIR-V code should be emitted for it as we do not analyze the logic.
  68. return float4(8.0, 8.0, 8.0, 8.0);
  69. }
  70. // CHECK: %while_merge = OpLabel
  71. // CHECK-NEXT: OpReturnValue [[v4f9]]
  72. // Return from function.
  73. // Even though this statement will never be executed [because any iteration of the loop above executes a return statement],
  74. // SPIR-V code should be emitted for it as we do not analyze the logic.
  75. return float4(9.0, 9.0, 9.0, 9.0);
  76. // CHECK-NEXT: OpFunctionEnd
  77. }
  78. void main() {
  79. float4 result = myfunc();
  80. }