_gcm2.ssa 976 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Programs from "Global Code Motion Global Value Numbering" by Cliff Click
  2. # https://courses.cs.washington.edu/courses/cse501/06wi/reading/click-pldi95.pdf
  3. # GCM program in Figure 1
  4. function w $gcm_test(w %a){
  5. @start
  6. %i.0 =w copy 0
  7. @loop
  8. %i.1 =w phi @start %i.0, @loop %i.2
  9. %b =w add %a, 1 # early schedule moves to @start
  10. %i.2 =w add %i.1, %b
  11. %c =w mul %i.2, 2 # late schedule moves to @end
  12. %x =w csltw %i.2, 10
  13. jnz %x, @loop, @end
  14. @end
  15. ret %c
  16. }
  17. # GCM program in "Figure 3 x's definition does not dominate it's use"
  18. #
  19. # SSA contruction will insert phi instruction for "x" in @if_false
  20. # preventing the "add" in @if_false from being moved to @if_true
  21. function $gcm_test2 (w %a){
  22. @start
  23. %f =w copy 1
  24. %x =w copy 0
  25. %s.0 =w copy 0
  26. @loop
  27. %s.1 = w phi @start %s.0, @if_false %s.2
  28. jnz %a, @if, @end
  29. @if
  30. jnz %f, @if_true, @if_false
  31. @if_true
  32. %f =w copy 0
  33. %x =w add %x, 1
  34. @if_false
  35. %s.2 =w add %s.1, %x
  36. jmp @loop
  37. @end
  38. ret
  39. }