README.txt 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. //===---------------------------------------------------------------------===//
  2. // Random ideas for the ARM backend.
  3. //===---------------------------------------------------------------------===//
  4. Reimplement 'select' in terms of 'SEL'.
  5. * We would really like to support UXTAB16, but we need to prove that the
  6. add doesn't need to overflow between the two 16-bit chunks.
  7. * Implement pre/post increment support. (e.g. PR935)
  8. * Implement smarter constant generation for binops with large immediates.
  9. A few ARMv6T2 ops should be pattern matched: BFI, SBFX, and UBFX
  10. Interesting optimization for PIC codegen on arm-linux:
  11. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43129
  12. //===---------------------------------------------------------------------===//
  13. Crazy idea: Consider code that uses lots of 8-bit or 16-bit values. By the
  14. time regalloc happens, these values are now in a 32-bit register, usually with
  15. the top-bits known to be sign or zero extended. If spilled, we should be able
  16. to spill these to a 8-bit or 16-bit stack slot, zero or sign extending as part
  17. of the reload.
  18. Doing this reduces the size of the stack frame (important for thumb etc), and
  19. also increases the likelihood that we will be able to reload multiple values
  20. from the stack with a single load.
  21. //===---------------------------------------------------------------------===//
  22. The constant island pass is in good shape. Some cleanups might be desirable,
  23. but there is unlikely to be much improvement in the generated code.
  24. 1. There may be some advantage to trying to be smarter about the initial
  25. placement, rather than putting everything at the end.
  26. 2. There might be some compile-time efficiency to be had by representing
  27. consecutive islands as a single block rather than multiple blocks.
  28. 3. Use a priority queue to sort constant pool users in inverse order of
  29. position so we always process the one closed to the end of functions
  30. first. This may simply CreateNewWater.
  31. //===---------------------------------------------------------------------===//
  32. Eliminate copysign custom expansion. We are still generating crappy code with
  33. default expansion + if-conversion.
  34. //===---------------------------------------------------------------------===//
  35. Eliminate one instruction from:
  36. define i32 @_Z6slow4bii(i32 %x, i32 %y) {
  37. %tmp = icmp sgt i32 %x, %y
  38. %retval = select i1 %tmp, i32 %x, i32 %y
  39. ret i32 %retval
  40. }
  41. __Z6slow4bii:
  42. cmp r0, r1
  43. movgt r1, r0
  44. mov r0, r1
  45. bx lr
  46. =>
  47. __Z6slow4bii:
  48. cmp r0, r1
  49. movle r0, r1
  50. bx lr
  51. //===---------------------------------------------------------------------===//
  52. Implement long long "X-3" with instructions that fold the immediate in. These
  53. were disabled due to badness with the ARM carry flag on subtracts.
  54. //===---------------------------------------------------------------------===//
  55. More load / store optimizations:
  56. 1) Better representation for block transfer? This is from Olden/power:
  57. fldd d0, [r4]
  58. fstd d0, [r4, #+32]
  59. fldd d0, [r4, #+8]
  60. fstd d0, [r4, #+40]
  61. fldd d0, [r4, #+16]
  62. fstd d0, [r4, #+48]
  63. fldd d0, [r4, #+24]
  64. fstd d0, [r4, #+56]
  65. If we can spare the registers, it would be better to use fldm and fstm here.
  66. Need major register allocator enhancement though.
  67. 2) Can we recognize the relative position of constantpool entries? i.e. Treat
  68. ldr r0, LCPI17_3
  69. ldr r1, LCPI17_4
  70. ldr r2, LCPI17_5
  71. as
  72. ldr r0, LCPI17
  73. ldr r1, LCPI17+4
  74. ldr r2, LCPI17+8
  75. Then the ldr's can be combined into a single ldm. See Olden/power.
  76. Note for ARM v4 gcc uses ldmia to load a pair of 32-bit values to represent a
  77. double 64-bit FP constant:
  78. adr r0, L6
  79. ldmia r0, {r0-r1}
  80. .align 2
  81. L6:
  82. .long -858993459
  83. .long 1074318540
  84. 3) struct copies appear to be done field by field
  85. instead of by words, at least sometimes:
  86. struct foo { int x; short s; char c1; char c2; };
  87. void cpy(struct foo*a, struct foo*b) { *a = *b; }
  88. llvm code (-O2)
  89. ldrb r3, [r1, #+6]
  90. ldr r2, [r1]
  91. ldrb r12, [r1, #+7]
  92. ldrh r1, [r1, #+4]
  93. str r2, [r0]
  94. strh r1, [r0, #+4]
  95. strb r3, [r0, #+6]
  96. strb r12, [r0, #+7]
  97. gcc code (-O2)
  98. ldmia r1, {r1-r2}
  99. stmia r0, {r1-r2}
  100. In this benchmark poor handling of aggregate copies has shown up as
  101. having a large effect on size, and possibly speed as well (we don't have
  102. a good way to measure on ARM).
  103. //===---------------------------------------------------------------------===//
  104. * Consider this silly example:
  105. double bar(double x) {
  106. double r = foo(3.1);
  107. return x+r;
  108. }
  109. _bar:
  110. stmfd sp!, {r4, r5, r7, lr}
  111. add r7, sp, #8
  112. mov r4, r0
  113. mov r5, r1
  114. fldd d0, LCPI1_0
  115. fmrrd r0, r1, d0
  116. bl _foo
  117. fmdrr d0, r4, r5
  118. fmsr s2, r0
  119. fsitod d1, s2
  120. faddd d0, d1, d0
  121. fmrrd r0, r1, d0
  122. ldmfd sp!, {r4, r5, r7, pc}
  123. Ignore the prologue and epilogue stuff for a second. Note
  124. mov r4, r0
  125. mov r5, r1
  126. the copys to callee-save registers and the fact they are only being used by the
  127. fmdrr instruction. It would have been better had the fmdrr been scheduled
  128. before the call and place the result in a callee-save DPR register. The two
  129. mov ops would not have been necessary.
  130. //===---------------------------------------------------------------------===//
  131. Calling convention related stuff:
  132. * gcc's parameter passing implementation is terrible and we suffer as a result:
  133. e.g.
  134. struct s {
  135. double d1;
  136. int s1;
  137. };
  138. void foo(struct s S) {
  139. printf("%g, %d\n", S.d1, S.s1);
  140. }
  141. 'S' is passed via registers r0, r1, r2. But gcc stores them to the stack, and
  142. then reload them to r1, r2, and r3 before issuing the call (r0 contains the
  143. address of the format string):
  144. stmfd sp!, {r7, lr}
  145. add r7, sp, #0
  146. sub sp, sp, #12
  147. stmia sp, {r0, r1, r2}
  148. ldmia sp, {r1-r2}
  149. ldr r0, L5
  150. ldr r3, [sp, #8]
  151. L2:
  152. add r0, pc, r0
  153. bl L_printf$stub
  154. Instead of a stmia, ldmia, and a ldr, wouldn't it be better to do three moves?
  155. * Return an aggregate type is even worse:
  156. e.g.
  157. struct s foo(void) {
  158. struct s S = {1.1, 2};
  159. return S;
  160. }
  161. mov ip, r0
  162. ldr r0, L5
  163. sub sp, sp, #12
  164. L2:
  165. add r0, pc, r0
  166. @ lr needed for prologue
  167. ldmia r0, {r0, r1, r2}
  168. stmia sp, {r0, r1, r2}
  169. stmia ip, {r0, r1, r2}
  170. mov r0, ip
  171. add sp, sp, #12
  172. bx lr
  173. r0 (and later ip) is the hidden parameter from caller to store the value in. The
  174. first ldmia loads the constants into r0, r1, r2. The last stmia stores r0, r1,
  175. r2 into the address passed in. However, there is one additional stmia that
  176. stores r0, r1, and r2 to some stack location. The store is dead.
  177. The llvm-gcc generated code looks like this:
  178. csretcc void %foo(%struct.s* %agg.result) {
  179. entry:
  180. %S = alloca %struct.s, align 4 ; <%struct.s*> [#uses=1]
  181. %memtmp = alloca %struct.s ; <%struct.s*> [#uses=1]
  182. cast %struct.s* %S to sbyte* ; <sbyte*>:0 [#uses=2]
  183. call void %llvm.memcpy.i32( sbyte* %0, sbyte* cast ({ double, int }* %C.0.904 to sbyte*), uint 12, uint 4 )
  184. cast %struct.s* %agg.result to sbyte* ; <sbyte*>:1 [#uses=2]
  185. call void %llvm.memcpy.i32( sbyte* %1, sbyte* %0, uint 12, uint 0 )
  186. cast %struct.s* %memtmp to sbyte* ; <sbyte*>:2 [#uses=1]
  187. call void %llvm.memcpy.i32( sbyte* %2, sbyte* %1, uint 12, uint 0 )
  188. ret void
  189. }
  190. llc ends up issuing two memcpy's (the first memcpy becomes 3 loads from
  191. constantpool). Perhaps we should 1) fix llvm-gcc so the memcpy is translated
  192. into a number of load and stores, or 2) custom lower memcpy (of small size) to
  193. be ldmia / stmia. I think option 2 is better but the current register
  194. allocator cannot allocate a chunk of registers at a time.
  195. A feasible temporary solution is to use specific physical registers at the
  196. lowering time for small (<= 4 words?) transfer size.
  197. * ARM CSRet calling convention requires the hidden argument to be returned by
  198. the callee.
  199. //===---------------------------------------------------------------------===//
  200. We can definitely do a better job on BB placements to eliminate some branches.
  201. It's very common to see llvm generated assembly code that looks like this:
  202. LBB3:
  203. ...
  204. LBB4:
  205. ...
  206. beq LBB3
  207. b LBB2
  208. If BB4 is the only predecessor of BB3, then we can emit BB3 after BB4. We can
  209. then eliminate beq and turn the unconditional branch to LBB2 to a bne.
  210. See McCat/18-imp/ComputeBoundingBoxes for an example.
  211. //===---------------------------------------------------------------------===//
  212. Pre-/post- indexed load / stores:
  213. 1) We should not make the pre/post- indexed load/store transform if the base ptr
  214. is guaranteed to be live beyond the load/store. This can happen if the base
  215. ptr is live out of the block we are performing the optimization. e.g.
  216. mov r1, r2
  217. ldr r3, [r1], #4
  218. ...
  219. vs.
  220. ldr r3, [r2]
  221. add r1, r2, #4
  222. ...
  223. In most cases, this is just a wasted optimization. However, sometimes it can
  224. negatively impact the performance because two-address code is more restrictive
  225. when it comes to scheduling.
  226. Unfortunately, liveout information is currently unavailable during DAG combine
  227. time.
  228. 2) Consider spliting a indexed load / store into a pair of add/sub + load/store
  229. to solve #1 (in TwoAddressInstructionPass.cpp).
  230. 3) Enhance LSR to generate more opportunities for indexed ops.
  231. 4) Once we added support for multiple result patterns, write indexed loads
  232. patterns instead of C++ instruction selection code.
  233. 5) Use VLDM / VSTM to emulate indexed FP load / store.
  234. //===---------------------------------------------------------------------===//
  235. Implement support for some more tricky ways to materialize immediates. For
  236. example, to get 0xffff8000, we can use:
  237. mov r9, #&3f8000
  238. sub r9, r9, #&400000
  239. //===---------------------------------------------------------------------===//
  240. We sometimes generate multiple add / sub instructions to update sp in prologue
  241. and epilogue if the inc / dec value is too large to fit in a single immediate
  242. operand. In some cases, perhaps it might be better to load the value from a
  243. constantpool instead.
  244. //===---------------------------------------------------------------------===//
  245. GCC generates significantly better code for this function.
  246. int foo(int StackPtr, unsigned char *Line, unsigned char *Stack, int LineLen) {
  247. int i = 0;
  248. if (StackPtr != 0) {
  249. while (StackPtr != 0 && i < (((LineLen) < (32768))? (LineLen) : (32768)))
  250. Line[i++] = Stack[--StackPtr];
  251. if (LineLen > 32768)
  252. {
  253. while (StackPtr != 0 && i < LineLen)
  254. {
  255. i++;
  256. --StackPtr;
  257. }
  258. }
  259. }
  260. return StackPtr;
  261. }
  262. //===---------------------------------------------------------------------===//
  263. This should compile to the mlas instruction:
  264. int mlas(int x, int y, int z) { return ((x * y + z) < 0) ? 7 : 13; }
  265. //===---------------------------------------------------------------------===//
  266. At some point, we should triage these to see if they still apply to us:
  267. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19598
  268. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18560
  269. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27016
  270. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11831
  271. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11826
  272. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11825
  273. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11824
  274. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11823
  275. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11820
  276. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=10982
  277. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=10242
  278. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=9831
  279. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=9760
  280. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=9759
  281. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=9703
  282. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=9702
  283. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=9663
  284. http://www.inf.u-szeged.hu/gcc-arm/
  285. http://citeseer.ist.psu.edu/debus04linktime.html
  286. //===---------------------------------------------------------------------===//
  287. gcc generates smaller code for this function at -O2 or -Os:
  288. void foo(signed char* p) {
  289. if (*p == 3)
  290. bar();
  291. else if (*p == 4)
  292. baz();
  293. else if (*p == 5)
  294. quux();
  295. }
  296. llvm decides it's a good idea to turn the repeated if...else into a
  297. binary tree, as if it were a switch; the resulting code requires -1
  298. compare-and-branches when *p<=2 or *p==5, the same number if *p==4
  299. or *p>6, and +1 if *p==3. So it should be a speed win
  300. (on balance). However, the revised code is larger, with 4 conditional
  301. branches instead of 3.
  302. More seriously, there is a byte->word extend before
  303. each comparison, where there should be only one, and the condition codes
  304. are not remembered when the same two values are compared twice.
  305. //===---------------------------------------------------------------------===//
  306. More LSR enhancements possible:
  307. 1. Teach LSR about pre- and post- indexed ops to allow iv increment be merged
  308. in a load / store.
  309. 2. Allow iv reuse even when a type conversion is required. For example, i8
  310. and i32 load / store addressing modes are identical.
  311. //===---------------------------------------------------------------------===//
  312. This:
  313. int foo(int a, int b, int c, int d) {
  314. long long acc = (long long)a * (long long)b;
  315. acc += (long long)c * (long long)d;
  316. return (int)(acc >> 32);
  317. }
  318. Should compile to use SMLAL (Signed Multiply Accumulate Long) which multiplies
  319. two signed 32-bit values to produce a 64-bit value, and accumulates this with
  320. a 64-bit value.
  321. We currently get this with both v4 and v6:
  322. _foo:
  323. smull r1, r0, r1, r0
  324. smull r3, r2, r3, r2
  325. adds r3, r3, r1
  326. adc r0, r2, r0
  327. bx lr
  328. //===---------------------------------------------------------------------===//
  329. This:
  330. #include <algorithm>
  331. std::pair<unsigned, bool> full_add(unsigned a, unsigned b)
  332. { return std::make_pair(a + b, a + b < a); }
  333. bool no_overflow(unsigned a, unsigned b)
  334. { return !full_add(a, b).second; }
  335. Should compile to:
  336. _Z8full_addjj:
  337. adds r2, r1, r2
  338. movcc r1, #0
  339. movcs r1, #1
  340. str r2, [r0, #0]
  341. strb r1, [r0, #4]
  342. mov pc, lr
  343. _Z11no_overflowjj:
  344. cmn r0, r1
  345. movcs r0, #0
  346. movcc r0, #1
  347. mov pc, lr
  348. not:
  349. __Z8full_addjj:
  350. add r3, r2, r1
  351. str r3, [r0]
  352. mov r2, #1
  353. mov r12, #0
  354. cmp r3, r1
  355. movlo r12, r2
  356. str r12, [r0, #+4]
  357. bx lr
  358. __Z11no_overflowjj:
  359. add r3, r1, r0
  360. mov r2, #1
  361. mov r1, #0
  362. cmp r3, r0
  363. movhs r1, r2
  364. mov r0, r1
  365. bx lr
  366. //===---------------------------------------------------------------------===//
  367. Some of the NEON intrinsics may be appropriate for more general use, either
  368. as target-independent intrinsics or perhaps elsewhere in the ARM backend.
  369. Some of them may also be lowered to target-independent SDNodes, and perhaps
  370. some new SDNodes could be added.
  371. For example, maximum, minimum, and absolute value operations are well-defined
  372. and standard operations, both for vector and scalar types.
  373. The current NEON-specific intrinsics for count leading zeros and count one
  374. bits could perhaps be replaced by the target-independent ctlz and ctpop
  375. intrinsics. It may also make sense to add a target-independent "ctls"
  376. intrinsic for "count leading sign bits". Likewise, the backend could use
  377. the target-independent SDNodes for these operations.
  378. ARMv6 has scalar saturating and halving adds and subtracts. The same
  379. intrinsics could possibly be used for both NEON's vector implementations of
  380. those operations and the ARMv6 scalar versions.
  381. //===---------------------------------------------------------------------===//
  382. Split out LDR (literal) from normal ARM LDR instruction. Also consider spliting
  383. LDR into imm12 and so_reg forms. This allows us to clean up some code. e.g.
  384. ARMLoadStoreOptimizer does not need to look at LDR (literal) and LDR (so_reg)
  385. while ARMConstantIslandPass only need to worry about LDR (literal).
  386. //===---------------------------------------------------------------------===//
  387. Constant island pass should make use of full range SoImm values for LEApcrel.
  388. Be careful though as the last attempt caused infinite looping on lencod.
  389. //===---------------------------------------------------------------------===//
  390. Predication issue. This function:
  391. extern unsigned array[ 128 ];
  392. int foo( int x ) {
  393. int y;
  394. y = array[ x & 127 ];
  395. if ( x & 128 )
  396. y = 123456789 & ( y >> 2 );
  397. else
  398. y = 123456789 & y;
  399. return y;
  400. }
  401. compiles to:
  402. _foo:
  403. and r1, r0, #127
  404. ldr r2, LCPI1_0
  405. ldr r2, [r2]
  406. ldr r1, [r2, +r1, lsl #2]
  407. mov r2, r1, lsr #2
  408. tst r0, #128
  409. moveq r2, r1
  410. ldr r0, LCPI1_1
  411. and r0, r2, r0
  412. bx lr
  413. It would be better to do something like this, to fold the shift into the
  414. conditional move:
  415. and r1, r0, #127
  416. ldr r2, LCPI1_0
  417. ldr r2, [r2]
  418. ldr r1, [r2, +r1, lsl #2]
  419. tst r0, #128
  420. movne r1, r1, lsr #2
  421. ldr r0, LCPI1_1
  422. and r0, r1, r0
  423. bx lr
  424. it saves an instruction and a register.
  425. //===---------------------------------------------------------------------===//
  426. It might be profitable to cse MOVi16 if there are lots of 32-bit immediates
  427. with the same bottom half.
  428. //===---------------------------------------------------------------------===//
  429. Robert Muth started working on an alternate jump table implementation that
  430. does not put the tables in-line in the text. This is more like the llvm
  431. default jump table implementation. This might be useful sometime. Several
  432. revisions of patches are on the mailing list, beginning at:
  433. http://lists.llvm.org/pipermail/llvm-dev/2009-June/022763.html
  434. //===---------------------------------------------------------------------===//
  435. Make use of the "rbit" instruction.
  436. //===---------------------------------------------------------------------===//
  437. Take a look at test/CodeGen/Thumb2/machine-licm.ll. ARM should be taught how
  438. to licm and cse the unnecessary load from cp#1.
  439. //===---------------------------------------------------------------------===//
  440. The CMN instruction sets the flags like an ADD instruction, while CMP sets
  441. them like a subtract. Therefore to be able to use CMN for comparisons other
  442. than the Z bit, we'll need additional logic to reverse the conditionals
  443. associated with the comparison. Perhaps a pseudo-instruction for the comparison,
  444. with a post-codegen pass to clean up and handle the condition codes?
  445. See PR5694 for testcase.
  446. //===---------------------------------------------------------------------===//
  447. Given the following on armv5:
  448. int test1(int A, int B) {
  449. return (A&-8388481)|(B&8388480);
  450. }
  451. We currently generate:
  452. ldr r2, .LCPI0_0
  453. and r0, r0, r2
  454. ldr r2, .LCPI0_1
  455. and r1, r1, r2
  456. orr r0, r1, r0
  457. bx lr
  458. We should be able to replace the second ldr+and with a bic (i.e. reuse the
  459. constant which was already loaded). Not sure what's necessary to do that.
  460. //===---------------------------------------------------------------------===//
  461. The code generated for bswap on armv4/5 (CPUs without rev) is less than ideal:
  462. int a(int x) { return __builtin_bswap32(x); }
  463. a:
  464. mov r1, #255, 24
  465. mov r2, #255, 16
  466. and r1, r1, r0, lsr #8
  467. and r2, r2, r0, lsl #8
  468. orr r1, r1, r0, lsr #24
  469. orr r0, r2, r0, lsl #24
  470. orr r0, r0, r1
  471. bx lr
  472. Something like the following would be better (fewer instructions/registers):
  473. eor r1, r0, r0, ror #16
  474. bic r1, r1, #0xff0000
  475. mov r1, r1, lsr #8
  476. eor r0, r1, r0, ror #8
  477. bx lr
  478. A custom Thumb version would also be a slight improvement over the generic
  479. version.
  480. //===---------------------------------------------------------------------===//
  481. Consider the following simple C code:
  482. void foo(unsigned char *a, unsigned char *b, int *c) {
  483. if ((*a | *b) == 0) *c = 0;
  484. }
  485. currently llvm-gcc generates something like this (nice branchless code I'd say):
  486. ldrb r0, [r0]
  487. ldrb r1, [r1]
  488. orr r0, r1, r0
  489. tst r0, #255
  490. moveq r0, #0
  491. streq r0, [r2]
  492. bx lr
  493. Note that both "tst" and "moveq" are redundant.
  494. //===---------------------------------------------------------------------===//
  495. When loading immediate constants with movt/movw, if there are multiple
  496. constants needed with the same low 16 bits, and those values are not live at
  497. the same time, it would be possible to use a single movw instruction, followed
  498. by multiple movt instructions to rewrite the high bits to different values.
  499. For example:
  500. volatile store i32 -1, i32* inttoptr (i32 1342210076 to i32*), align 4,
  501. !tbaa
  502. !0
  503. volatile store i32 -1, i32* inttoptr (i32 1342341148 to i32*), align 4,
  504. !tbaa
  505. !0
  506. is compiled and optimized to:
  507. movw r0, #32796
  508. mov.w r1, #-1
  509. movt r0, #20480
  510. str r1, [r0]
  511. movw r0, #32796 @ <= this MOVW is not needed, value is there already
  512. movt r0, #20482
  513. str r1, [r0]
  514. //===---------------------------------------------------------------------===//
  515. Improve codegen for select's:
  516. if (x != 0) x = 1
  517. if (x == 1) x = 1
  518. ARM codegen used to look like this:
  519. mov r1, r0
  520. cmp r1, #1
  521. mov r0, #0
  522. moveq r0, #1
  523. The naive lowering select between two different values. It should recognize the
  524. test is equality test so it's more a conditional move rather than a select:
  525. cmp r0, #1
  526. movne r0, #0
  527. Currently this is a ARM specific dag combine. We probably should make it into a
  528. target-neutral one.
  529. //===---------------------------------------------------------------------===//
  530. Optimize unnecessary checks for zero with __builtin_clz/ctz. Those builtins
  531. are specified to be undefined at zero, so portable code must check for zero
  532. and handle it as a special case. That is unnecessary on ARM where those
  533. operations are implemented in a way that is well-defined for zero. For
  534. example:
  535. int f(int x) { return x ? __builtin_clz(x) : sizeof(int)*8; }
  536. should just be implemented with a CLZ instruction. Since there are other
  537. targets, e.g., PPC, that share this behavior, it would be best to implement
  538. this in a target-independent way: we should probably fold that (when using
  539. "undefined at zero" semantics) to set the "defined at zero" bit and have
  540. the code generator expand out the right code.
  541. //===---------------------------------------------------------------------===//
  542. Clean up the test/MC/ARM files to have more robust register choices.
  543. R0 should not be used as a register operand in the assembler tests as it's then
  544. not possible to distinguish between a correct encoding and a missing operand
  545. encoding, as zero is the default value for the binary encoder.
  546. e.g.,
  547. add r0, r0 // bad
  548. add r3, r5 // good
  549. Register operands should be distinct. That is, when the encoding does not
  550. require two syntactical operands to refer to the same register, two different
  551. registers should be used in the test so as to catch errors where the
  552. operands are swapped in the encoding.
  553. e.g.,
  554. subs.w r1, r1, r1 // bad
  555. subs.w r1, r2, r3 // good