common_subexpression_elimination.sol 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // RUN: --target solana --emit cfg
  2. contract testing {
  3. // BEGIN-CHECK: testing::testing::function::general_test__uint64
  4. function general_test(uint64 a) public view returns (uint64, uint256) {
  5. uint64 g = 0;
  6. uint256 h = 0;
  7. assembly {
  8. function sum(a, b) -> ret1 {
  9. ret1 := add(a, b)
  10. }
  11. function mix(a, b) -> ret1, ret2 {
  12. ret1 := mul(a, b)
  13. ret2 := add(a, b)
  14. }
  15. // CHECK: block1: # cond
  16. // CHECK: ty:uint256 %1.cse_temp = (zext uint256 (arg #0))
  17. for {let i := 0} lt(i, 10) {i := add(i, 1)} {
  18. // CHECK: block3: # body
  19. // CHECK: branchcond (%1.cse_temp == uint256 259), block5, block6
  20. if eq(a, 259) {
  21. break
  22. }
  23. // This is the if-condition after the loop
  24. // block4: # end_for
  25. // CHECK: branchcond ((unsigned less %1.cse_temp < uint256 10) | (%1.cse_temp == uint256 259)), block9, block10
  26. g := sum(g, 2)
  27. // CHECK: block6: # endif
  28. // CHECK: branchcond (unsigned more %1.cse_temp > uint256 10), block7, block8
  29. if gt(a, 10) {
  30. continue
  31. }
  32. g := sub(g, 1)
  33. }
  34. if or(lt(a, 10), eq(a, 259)) {
  35. g, h := mix(g, 10)
  36. }
  37. }
  38. return (g, h);
  39. }
  40. }