2
0

README.txt 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. //===---------------------------------------------------------------------===//
  2. //===---------------------------------------------------------------------===//
  3. Common register allocation / spilling problem:
  4. mul lr, r4, lr
  5. str lr, [sp, #+52]
  6. ldr lr, [r1, #+32]
  7. sxth r3, r3
  8. ldr r4, [sp, #+52]
  9. mla r4, r3, lr, r4
  10. can be:
  11. mul lr, r4, lr
  12. mov r4, lr
  13. str lr, [sp, #+52]
  14. ldr lr, [r1, #+32]
  15. sxth r3, r3
  16. mla r4, r3, lr, r4
  17. and then "merge" mul and mov:
  18. mul r4, r4, lr
  19. str r4, [sp, #+52]
  20. ldr lr, [r1, #+32]
  21. sxth r3, r3
  22. mla r4, r3, lr, r4
  23. It also increase the likelihood the store may become dead.
  24. //===---------------------------------------------------------------------===//
  25. bb27 ...
  26. ...
  27. %reg1037 = ADDri %reg1039, 1
  28. %reg1038 = ADDrs %reg1032, %reg1039, %NOREG, 10
  29. Successors according to CFG: 0x8b03bf0 (#5)
  30. bb76 (0x8b03bf0, LLVM BB @0x8b032d0, ID#5):
  31. Predecessors according to CFG: 0x8b0c5f0 (#3) 0x8b0a7c0 (#4)
  32. %reg1039 = PHI %reg1070, mbb<bb76.outer,0x8b0c5f0>, %reg1037, mbb<bb27,0x8b0a7c0>
  33. Note ADDri is not a two-address instruction. However, its result %reg1037 is an
  34. operand of the PHI node in bb76 and its operand %reg1039 is the result of the
  35. PHI node. We should treat it as a two-address code and make sure the ADDri is
  36. scheduled after any node that reads %reg1039.
  37. //===---------------------------------------------------------------------===//
  38. Use local info (i.e. register scavenger) to assign it a free register to allow
  39. reuse:
  40. ldr r3, [sp, #+4]
  41. add r3, r3, #3
  42. ldr r2, [sp, #+8]
  43. add r2, r2, #2
  44. ldr r1, [sp, #+4] <==
  45. add r1, r1, #1
  46. ldr r0, [sp, #+4]
  47. add r0, r0, #2
  48. //===---------------------------------------------------------------------===//
  49. LLVM aggressively lift CSE out of loop. Sometimes this can be negative side-
  50. effects:
  51. R1 = X + 4
  52. R2 = X + 7
  53. R3 = X + 15
  54. loop:
  55. load [i + R1]
  56. ...
  57. load [i + R2]
  58. ...
  59. load [i + R3]
  60. Suppose there is high register pressure, R1, R2, R3, can be spilled. We need
  61. to implement proper re-materialization to handle this:
  62. R1 = X + 4
  63. R2 = X + 7
  64. R3 = X + 15
  65. loop:
  66. R1 = X + 4 @ re-materialized
  67. load [i + R1]
  68. ...
  69. R2 = X + 7 @ re-materialized
  70. load [i + R2]
  71. ...
  72. R3 = X + 15 @ re-materialized
  73. load [i + R3]
  74. Furthermore, with re-association, we can enable sharing:
  75. R1 = X + 4
  76. R2 = X + 7
  77. R3 = X + 15
  78. loop:
  79. T = i + X
  80. load [T + 4]
  81. ...
  82. load [T + 7]
  83. ...
  84. load [T + 15]
  85. //===---------------------------------------------------------------------===//
  86. It's not always a good idea to choose rematerialization over spilling. If all
  87. the load / store instructions would be folded then spilling is cheaper because
  88. it won't require new live intervals / registers. See 2003-05-31-LongShifts for
  89. an example.
  90. //===---------------------------------------------------------------------===//
  91. With a copying garbage collector, derived pointers must not be retained across
  92. collector safe points; the collector could move the objects and invalidate the
  93. derived pointer. This is bad enough in the first place, but safe points can
  94. crop up unpredictably. Consider:
  95. %array = load { i32, [0 x %obj] }** %array_addr
  96. %nth_el = getelementptr { i32, [0 x %obj] }* %array, i32 0, i32 %n
  97. %old = load %obj** %nth_el
  98. %z = div i64 %x, %y
  99. store %obj* %new, %obj** %nth_el
  100. If the i64 division is lowered to a libcall, then a safe point will (must)
  101. appear for the call site. If a collection occurs, %array and %nth_el no longer
  102. point into the correct object.
  103. The fix for this is to copy address calculations so that dependent pointers
  104. are never live across safe point boundaries. But the loads cannot be copied
  105. like this if there was an intervening store, so may be hard to get right.
  106. Only a concurrent mutator can trigger a collection at the libcall safe point.
  107. So single-threaded programs do not have this requirement, even with a copying
  108. collector. Still, LLVM optimizations would probably undo a front-end's careful
  109. work.
  110. //===---------------------------------------------------------------------===//
  111. The ocaml frametable structure supports liveness information. It would be good
  112. to support it.
  113. //===---------------------------------------------------------------------===//
  114. The FIXME in ComputeCommonTailLength in BranchFolding.cpp needs to be
  115. revisited. The check is there to work around a misuse of directives in inline
  116. assembly.
  117. //===---------------------------------------------------------------------===//
  118. It would be good to detect collector/target compatibility instead of silently
  119. doing the wrong thing.
  120. //===---------------------------------------------------------------------===//
  121. It would be really nice to be able to write patterns in .td files for copies,
  122. which would eliminate a bunch of explicit predicates on them (e.g. no side
  123. effects). Once this is in place, it would be even better to have tblgen
  124. synthesize the various copy insertion/inspection methods in TargetInstrInfo.
  125. //===---------------------------------------------------------------------===//
  126. Stack coloring improvements:
  127. 1. Do proper LiveStackAnalysis on all stack objects including those which are
  128. not spill slots.
  129. 2. Reorder objects to fill in gaps between objects.
  130. e.g. 4, 1, <gap>, 4, 1, 1, 1, <gap>, 4 => 4, 1, 1, 1, 1, 4, 4
  131. //===---------------------------------------------------------------------===//
  132. The scheduler should be able to sort nearby instructions by their address. For
  133. example, in an expanded memset sequence it's not uncommon to see code like this:
  134. movl $0, 4(%rdi)
  135. movl $0, 8(%rdi)
  136. movl $0, 12(%rdi)
  137. movl $0, 0(%rdi)
  138. Each of the stores is independent, and the scheduler is currently making an
  139. arbitrary decision about the order.
  140. //===---------------------------------------------------------------------===//
  141. Another opportunitiy in this code is that the $0 could be moved to a register:
  142. movl $0, 4(%rdi)
  143. movl $0, 8(%rdi)
  144. movl $0, 12(%rdi)
  145. movl $0, 0(%rdi)
  146. This would save substantial code size, especially for longer sequences like
  147. this. It would be easy to have a rule telling isel to avoid matching MOV32mi
  148. if the immediate has more than some fixed number of uses. It's more involved
  149. to teach the register allocator how to do late folding to recover from
  150. excessive register pressure.