README.txt 6.2 KB

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