cse_switch.sol 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // RUN: --target solana --emit cfg
  2. contract foo {
  3. // BEGIN-CHECK: foo::foo::function::test
  4. function test(uint x) public {
  5. uint256 yy=0;
  6. assembly {
  7. // Ensure the CSE temp is not before the switch
  8. // CHECK: ty:uint256 %y = uint256 5
  9. // CHECK: switch ((arg #0) & uint256 3):
  10. let y := 5
  11. switch and(x, 3)
  12. case 0 {
  13. y := 5
  14. x := 5
  15. }
  16. case 1 {
  17. y := 7
  18. x := 9
  19. }
  20. case 3 {
  21. y := 10
  22. x := 80
  23. }
  24. // CHECK: block1: # end_switch
  25. // CHECK: ty:uint256 %1.cse_temp = (overflowing %x + %y)
  26. // CHECK: branchcond (%1.cse_temp == uint256 90), block5, block6
  27. if eq(add(x, y), 90) {
  28. yy := 9
  29. }
  30. // CHECK: branchcond (%1.cse_temp == uint256 80), block7, block8
  31. if eq(add(x, y), 80) {
  32. yy := 90
  33. }
  34. }
  35. }
  36. }