cf.return.early.hlsl 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Run: %dxc -T ps_6_0 -E main
  2. void main() {
  3. int a, b;
  4. bool cond = true;
  5. while(cond) {
  6. switch(b) {
  7. // CHECK: %switch_1 = OpLabel
  8. case 1:
  9. a = 1;
  10. // CHECK: OpReturn
  11. return;
  12. // CHECK-NEXT: %switch_2 = OpLabel
  13. case 2: {
  14. a = 3;
  15. // CHECK: OpReturn
  16. {return;} // Return from function.
  17. a = 4; // No SPIR-V should be emitted for this statement.
  18. break; // No SPIR-V should be emitted for this statement.
  19. }
  20. // CHECK-NEXT: %switch_5 = OpLabel
  21. case 5 : {
  22. a = 5;
  23. // CHECK: OpReturn
  24. {{return;}} // Return from function.
  25. a = 6; // No SPIR-V should be emitted for this statement.
  26. }
  27. // CHECK-NEXT: %switch_default = OpLabel
  28. default:
  29. for (int i=0; i<10; ++i) {
  30. if (cond) {
  31. // CHECK: %if_true = OpLabel
  32. // CHECK-NEXT: OpReturn
  33. return; // Return from function.
  34. return; // No SPIR-V should be emitted for this statement.
  35. continue; // No SPIR-V should be emitted for this statement.
  36. break; // No SPIR-V should be emitted for this statement.
  37. ++a; // No SPIR-V should be emitted for this statement.
  38. } else {
  39. // CHECK-NEXT: %if_false = OpLabel
  40. // CHECK-NEXT: OpReturn
  41. return; // Return from function
  42. continue; // No SPIR-V should be emitted for this statement.
  43. break; // No SPIR-V should be emitted for this statement.
  44. ++a; // No SPIR-V should be emitted for this statement.
  45. }
  46. }
  47. // CHECK: %for_merge = OpLabel
  48. // CHECK-NEXT: OpReturn
  49. // Return from function.
  50. // Even though this statement will never be executed [because both "if" and "else" above have return statements],
  51. // SPIR-V code should be emitted for it as we do not analyze the logic.
  52. return;
  53. }
  54. // CHECK: %switch_merge = OpLabel
  55. // CHECK-NEXT: OpReturn
  56. // Return from function.
  57. // Even though this statement will never be executed [because all "case" statements above contain a return statement],
  58. // SPIR-V code should be emitted for it as we do not analyze the logic.
  59. return;
  60. }
  61. // CHECK: %while_merge = OpLabel
  62. // CHECK-NEXT: OpReturn
  63. // CHECK-NEXT: OpFunctionEnd
  64. }