aoptcpu.pas 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. {
  2. Copyright (c) 1998-2002 by Jonas Maebe, member of the Free Pascal
  3. Development Team
  4. This unit implements the PowerPC optimizer object
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. Unit aoptcpu;
  19. Interface
  20. {$i fpcdefs.inc}
  21. uses cpubase, cgbase, aoptobj, aoptcpub, aopt, aasmtai,aasmdata, aasmcpu;
  22. Type
  23. TCpuAsmOptimizer = class(TAsmOptimizer)
  24. function RegLoadedWithNewValue(reg : tregister; hp : tai) : boolean; override;
  25. { uses the same constructor as TAopObj }
  26. function PeepHoleOptPass1Cpu(var p: tai): boolean; override;
  27. function PostPeepHoleOptsCpu(var p: tai): boolean; override;
  28. private
  29. function cmpi_mfcr_opt(p, next1, next2: taicpu): boolean;
  30. End;
  31. Implementation
  32. uses
  33. cutils, verbose, cgcpu, cgobj;
  34. function TCpuAsmOptimizer.RegLoadedWithNewValue(reg: tregister; hp: tai): boolean;
  35. var
  36. p: taicpu;
  37. begin
  38. p := taicpu(hp);
  39. Result := false;
  40. if not(assigned(hp) and (hp.typ = ait_instruction) and (p.ops > 0)) then
  41. exit;
  42. case p.opcode of
  43. A_CMP,
  44. A_CMPI,
  45. A_CMPL,
  46. A_CMPLI:
  47. begin
  48. result:=reg=NR_CR;
  49. exit;
  50. end;
  51. A_STB,
  52. { the register forming the address is modified so no new value is loaded }
  53. A_STBU,
  54. A_STBUX,
  55. A_STBX,
  56. A_STH,
  57. A_STHBRX,
  58. A_STHU,
  59. A_STHUX,
  60. A_STHX,
  61. A_STMW:
  62. exit;
  63. else
  64. ;
  65. end;
  66. case p.oper[0]^.typ of
  67. top_reg:
  68. Result := (p.oper[0]^.reg = reg) ;
  69. else
  70. ;
  71. end;
  72. end;
  73. function TCpuAsmOptimizer.cmpi_mfcr_opt(p, next1, next2: taicpu): boolean;
  74. var
  75. next3, prev: tai;
  76. inverse, prevrlwinm: boolean;
  77. begin
  78. result := true;
  79. inverse :=
  80. getnextinstruction(next2,next3) and
  81. (next3.typ = ait_instruction) and
  82. (taicpu(next3).opcode = A_XORI) and
  83. (taicpu(next3).oper[0]^.reg = taicpu(next3).oper[1]^.reg) and
  84. (taicpu(next3).oper[0]^.reg = taicpu(next2).oper[0]^.reg) and
  85. (taicpu(next3).oper[2]^.val = 1);
  86. case taicpu(next2).oper[2]^.val of
  87. 1:
  88. begin
  89. // less than zero or greater/equal than zero (the xori remains in
  90. // in the latter case). Doesn't make sense for unsigned comparisons.
  91. if (p.opcode = A_CMPWI) then
  92. begin
  93. p.opcode := A_SRWI;
  94. p.ops := 3;
  95. p.loadreg(1,p.oper[0]^.reg);
  96. p.loadreg(0,next1.oper[0]^.reg);
  97. p.loadconst(2,31);
  98. asml.remove(next1);
  99. next1.free;
  100. asml.remove(next2);
  101. next2.free;
  102. end
  103. else
  104. result := false;
  105. end;
  106. {
  107. needs two registers to work with
  108. 2:
  109. begin
  110. // greater or less/equal to zero
  111. end;
  112. }
  113. 3:
  114. begin
  115. prevrlwinm :=
  116. getlastinstruction(p,prev) and
  117. (prev.typ = ait_instruction) and
  118. ((taicpu(prev).opcode = A_RLWINM) or
  119. (taicpu(prev).opcode = A_RLWINM_)) and
  120. (taicpu(prev).oper[0]^.reg = p.oper[0]^.reg) and
  121. (taicpu(prev).oper[3]^.val = taicpu(prev).oper[4]^.val);
  122. if (prevrlwinm) then
  123. begin
  124. // isolate the bit we need
  125. if (taicpu(prev).oper[3]^.val <> 31) then
  126. begin
  127. p.opcode := A_RLWINM;
  128. p.ops := 5;
  129. p.loadreg(1,p.oper[0]^.reg);
  130. p.loadreg(0,next1.oper[0]^.reg);
  131. p.loadconst(2,taicpu(prev).oper[3]^.val + 1);
  132. p.loadconst(3,31);
  133. p.loadconst(4,31);
  134. end
  135. else { if (taicpu(prev).oper[0]^.reg <> next1.oper[0]^.reg) then }
  136. begin
  137. p.opcode := A_MR;
  138. p.loadreg(1,p.oper[0]^.reg);
  139. p.loadreg(0,next1.oper[0]^.reg);
  140. end;
  141. if not inverse then
  142. begin
  143. next1.ops := 3;
  144. next1.opcode := A_XORI;
  145. next1.loadreg(1,next1.oper[0]^.reg);
  146. next1.loadconst(2,1);
  147. end
  148. else
  149. begin
  150. asml.remove(next1);
  151. next1.free;
  152. asml.remove(next3);
  153. next3.free;
  154. end;
  155. asml.remove(next2);
  156. next2.free;
  157. end
  158. else
  159. begin
  160. // equal/not equal to zero (the xori remains in the latter case;
  161. // there's a more optimal sequence without it, but needs extra
  162. // register)
  163. p.opcode := A_CNTLZW;
  164. p.loadreg(1,p.oper[0]^.reg);
  165. p.loadreg(0,next1.oper[0]^.reg);
  166. next1.ops := 3;
  167. next1.opcode := A_SRWI;
  168. next1.loadreg(1,next1.oper[0]^.reg);
  169. next1.loadconst(2,5);
  170. asml.remove(next2);
  171. next2.free;
  172. end;
  173. end;
  174. else
  175. result := false;
  176. end;
  177. end;
  178. function rlwinm2mask(l1,l2: longint): longint;
  179. begin
  180. // 1 shl 32 = 1 instead of 0 on x86
  181. if (l1 <> 0) then
  182. result := longint(cardinal(1) shl (32 - l1) - 1) xor (cardinal(1) shl (31 - l2) - 1)
  183. else
  184. result := longint(not(cardinal(1) shl (31 - l2) - 1));
  185. if (l1 > l2) then
  186. result := not(result);
  187. end;
  188. function TCpuAsmOptimizer.PeepHoleOptPass1Cpu(var p: tai): boolean;
  189. var
  190. next1, next2: tai;
  191. l1, l2, shlcount: longint;
  192. begin
  193. result := false;
  194. case p.typ of
  195. ait_instruction:
  196. begin
  197. case taicpu(p).opcode of
  198. A_CMPWI,
  199. A_CMPLWI:
  200. begin
  201. if (taicpu(p).oper[1]^.typ = top_const) and
  202. (taicpu(p).oper[1]^.val = 0) and
  203. getnextinstruction(p,next1) and
  204. (next1.typ = ait_instruction) and
  205. (taicpu(next1).opcode = A_MFCR) and
  206. getnextinstruction(next1,next2) and
  207. (taicpu(next2).opcode = A_RLWINM) and
  208. (taicpu(next2).oper[0]^.reg = taicpu(next2).oper[1]^.reg) and
  209. (taicpu(next2).oper[0]^.reg = taicpu(next1).oper[0]^.reg) and
  210. (taicpu(next2).oper[3]^.val = 31) and
  211. (taicpu(next2).oper[4]^.val = 31) and
  212. cmpi_mfcr_opt(taicpu(p),taicpu(next1),taicpu(next2)) then
  213. result := true;
  214. end;
  215. { seems the register allocator doesn't generate superfluous fmr's }
  216. { A_FMR, }
  217. A_MR:
  218. begin
  219. if getnextinstruction(p,next1) and
  220. (next1.typ = ait_instruction) and
  221. (taicpu(next1).ops >= 1) and
  222. { spilling_get_operation_type does not support lmw/stmw }
  223. (taicpu(next1).opcode <> A_LMW) and
  224. (taicpu(next1).opcode <> A_STMW) and
  225. (taicpu(next1).spilling_get_operation_type(0) = operand_write) and
  226. (taicpu(next1).oper[0]^.reg = taicpu(p).oper[0]^.reg) then
  227. begin
  228. for l1 := 1 to taicpu(next1).ops - 1 do
  229. case taicpu(next1).oper[l1]^.typ of
  230. top_reg:
  231. if taicpu(next1).oper[l1]^.reg = taicpu(p).oper[0]^.reg then
  232. taicpu(next1).loadreg(l1,taicpu(p).oper[1]^.reg);
  233. top_ref:
  234. begin
  235. if taicpu(next1).oper[l1]^.ref^.base = taicpu(p).oper[0]^.reg then
  236. taicpu(next1).oper[l1]^.ref^.base := taicpu(p).oper[1]^.reg;
  237. if taicpu(next1).oper[l1]^.ref^.index = taicpu(p).oper[0]^.reg then
  238. taicpu(next1).oper[l1]^.ref^.index := taicpu(p).oper[1]^.reg;
  239. end;
  240. else
  241. ;
  242. end;
  243. asml.remove(p);
  244. p.free;
  245. p := next1;
  246. result := true;
  247. end;
  248. end;
  249. A_SLWI:
  250. begin
  251. if getnextinstruction(p,next1) and
  252. (next1.typ = ait_instruction) and
  253. ((taicpu(next1).opcode = A_RLWINM) or
  254. (taicpu(next1).opcode = A_SLWI) or
  255. (taicpu(next1).opcode = A_SRWI)) and
  256. (taicpu(next1).oper[0]^.reg = taicpu(p).oper[0]^.reg) and
  257. (taicpu(next1).oper[1]^.reg = taicpu(p).oper[0]^.reg) then
  258. begin
  259. { convert slwi to rlwinm and see if the rlwinm }
  260. { optimization can do something with it }
  261. taicpu(p).opcode := A_RLWINM;
  262. taicpu(p).ops := 5;
  263. taicpu(p).loadconst(2,taicpu(p).oper[2]^.val);
  264. taicpu(p).loadconst(3,0);
  265. taicpu(p).loadconst(4,31-taicpu(p).oper[2]^.val);
  266. result := true;
  267. end;
  268. end;
  269. A_SRWI:
  270. begin
  271. if getnextinstruction(p,next1) and
  272. (next1.typ = ait_instruction) and
  273. ((taicpu(next1).opcode = A_SLWI) or
  274. (taicpu(next1).opcode = A_RLWINM) or
  275. (taicpu(next1).opcode = A_SRWI)) and
  276. (taicpu(next1).oper[0]^.reg = taicpu(p).oper[0]^.reg) and
  277. (taicpu(next1).oper[1]^.reg = taicpu(p).oper[0]^.reg) then
  278. case taicpu(next1).opcode of
  279. A_SLWI:
  280. begin
  281. taicpu(p).opcode := A_RLWINM;
  282. taicpu(p).ops := 5;
  283. taicpu(p).loadconst(2,taicpu(next1).oper[2]^.val-taicpu(p).oper[2]^.val);
  284. if (taicpu(p).oper[2]^.val < 0) then
  285. begin
  286. taicpu(p).loadconst(3,-taicpu(p).oper[2]^.val);
  287. taicpu(p).loadconst(4,31-taicpu(next1).oper[2]^.val);
  288. inc(taicpu(p).oper[2]^.val,32);
  289. end
  290. else
  291. begin
  292. taicpu(p).loadconst(3,0);
  293. taicpu(p).loadconst(4,31-taicpu(next1).oper[2]^.val);
  294. end;
  295. asml.remove(next1);
  296. next1.free;
  297. result := true;
  298. end;
  299. A_RLWINM:
  300. begin
  301. { convert srwi to rlwinm and see if the rlwinm }
  302. { optimization can do something with it }
  303. taicpu(p).opcode := A_RLWINM;
  304. taicpu(p).ops := 5;
  305. taicpu(p).loadconst(3,taicpu(p).oper[2]^.val);
  306. taicpu(p).loadconst(4,31);
  307. taicpu(p).loadconst(2,(32-taicpu(p).oper[2]^.val) and 31);
  308. result := true;
  309. end;
  310. else
  311. internalerror(2019050941);
  312. end;
  313. end;
  314. A_RLWINM:
  315. begin
  316. if getnextinstruction(p,next1) and
  317. (next1.typ = ait_instruction) and
  318. ((taicpu(next1).opcode = A_RLWINM) or
  319. (taicpu(next1).opcode = A_SRWI) or
  320. (taicpu(next1).opcode = A_SLWI)) and
  321. (taicpu(next1).oper[0]^.reg = taicpu(p).oper[0]^.reg) and
  322. // both source and target of next1 must equal target of p
  323. (taicpu(next1).oper[1]^.reg = taicpu(p).oper[0]^.reg) then
  324. begin
  325. case taicpu(next1).opcode of
  326. A_RLWINM:
  327. begin
  328. shlcount := taicpu(next1).oper[2]^.val;
  329. l2 := rlwinm2mask(taicpu(next1).oper[3]^.val,taicpu(next1).oper[4]^.val);
  330. end;
  331. A_SLWI:
  332. begin
  333. shlcount := taicpu(next1).oper[2]^.val;
  334. l2 := (-1) shl shlcount;
  335. end;
  336. A_SRWI:
  337. begin
  338. shlcount := 32-taicpu(next1).oper[2]^.val;
  339. l2 := (-1) shr taicpu(next1).oper[2]^.val;
  340. end;
  341. else
  342. internalerror(2013113008);
  343. end;
  344. l1 := rlwinm2mask((taicpu(p).oper[3]^.val-shlcount) and 31,(taicpu(p).oper[4]^.val-shlcount) and 31);
  345. l1 := l1 and l2;
  346. case l1 of
  347. -1:
  348. begin
  349. taicpu(p).oper[2]^.val := (taicpu(p).oper[2]^.val + shlcount) and 31;
  350. asml.remove(next1);
  351. next1.free;
  352. if (taicpu(p).oper[2]^.val = 0) then
  353. begin
  354. next1 := tai(p.next);
  355. asml.remove(p);
  356. p.free;
  357. p := next1;
  358. result := true;
  359. end;
  360. end;
  361. 0:
  362. begin
  363. // masks have no bits in common
  364. taicpu(p).opcode := A_LI;
  365. taicpu(p).loadconst(1,0);
  366. taicpu(p).freeop(2);
  367. taicpu(p).freeop(3);
  368. taicpu(p).freeop(4);
  369. taicpu(p).ops := 2;
  370. taicpu(p).opercnt := 2;
  371. asml.remove(next1);
  372. next1.free;
  373. result := true;
  374. end
  375. else if tcgppc(cg).get_rlwi_const(l1,l1,l2) then
  376. begin
  377. taicpu(p).oper[2]^.val := (taicpu(p).oper[2]^.val + shlcount) and 31;
  378. taicpu(p).oper[3]^.val := l1;
  379. taicpu(p).oper[4]^.val := l2;
  380. asml.remove(next1);
  381. next1.free;
  382. result := true;
  383. end;
  384. end;
  385. end;
  386. end;
  387. else
  388. ;
  389. end;
  390. end;
  391. else
  392. ;
  393. end;
  394. end;
  395. const
  396. modifyflags: array[tasmop] of tasmop =
  397. (a_none, a_add_, a_add_, a_addo_, a_addo_, a_addc_, a_addc_, a_addco_, a_addco_,
  398. a_adde_, a_adde_, a_addeo_, a_addeo_, {a_addi could be addic_ if sure doesn't disturb carry} a_none, a_addic_, a_addic_, a_none,
  399. a_addme_, a_addme_, a_addmeo_, a_addmeo_, a_addze_, a_addze_, a_addzeo_,
  400. a_addzeo_, a_and_, a_and_, a_andc_, a_andc_, a_andi_, a_andis_, a_none,
  401. a_none, a_none, a_none, a_none, a_none, a_none, a_none, a_none, a_none, a_none,
  402. a_none, a_none, a_none, a_none, a_none, a_cntlzw_, a_cntlzw_, a_none,
  403. a_none, a_none, a_none, a_none, a_none, a_none, a_none, a_none,
  404. a_none, a_none, a_none, a_none, a_none, a_none, a_divw_, a_divw_, a_divwo_, a_divwo_,
  405. a_divwu_, a_divwu_, a_divwuo_, a_divwuo_, a_none, a_none, a_none, a_eqv_,
  406. a_eqv_, a_extsb_, a_extsb_, a_extsh_, a_extsh_, a_none, a_none, a_none,
  407. a_none, a_none, a_none, a_none, a_none, a_none, a_none, a_none,
  408. a_none, a_none, a_none, a_none, a_none, a_none, a_none, a_none,
  409. a_none, a_none, a_none, a_none, a_none, a_none, a_none, a_none,
  410. a_none, a_none, a_none, a_none, a_none, a_none, a_none,
  411. a_none, a_none, a_none, a_none, a_none, a_none,
  412. a_none, a_none, a_none, a_none,
  413. a_none, a_none, a_none, a_none, a_none, a_none, a_none,
  414. a_none, a_none, a_none, a_none, a_none, a_none, a_none, a_none,
  415. a_none, a_none, a_none, a_none, a_none, a_none, a_none, a_none,
  416. a_none, a_none, a_none, a_none, a_none, a_none, a_none, a_none, a_none,
  417. a_none, a_none, a_none, a_none, a_none, a_none, a_none, a_none, a_none,
  418. a_none, a_none, a_none, a_none, a_none, a_none, a_none, a_none, a_none,
  419. a_none, a_none, a_none, a_mffs, a_mffs_, a_mfmsr, a_mfspr, a_mfsr,
  420. a_mfsrin, a_mftb, a_mtcrf, a_none, a_none, a_none, a_none,
  421. a_none, a_none, a_none, a_none, a_none, a_none, a_mulhw_,
  422. a_mulhw_, a_mulhwu_, a_mulhwu_, a_none, a_mullw_, a_mullw_, a_mullwo_,
  423. a_mullwo_, a_nand_, a_nand_, a_neg_, a_neg_, a_nego_, a_nego_, a_nor_, a_nor_,
  424. a_or_, a_or_, a_orc_, a_orc_, a_none, a_none, a_none, a_rlwimi_, a_rlwimi_,
  425. a_rlwinm_, a_rlwinm_, a_rlwnm_, a_rlwnm_, a_none, a_slw_, a_slw_, a_sraw_, a_sraw_,
  426. a_srawi_, a_srawi_,a_srw_, a_srw_, a_none, a_none, a_none, a_none, a_none,
  427. a_none, a_none, a_none, a_none, a_none, a_none, a_none, a_none,
  428. a_none, a_none, a_none, a_none, a_none, a_none, a_none, a_none, a_none,
  429. a_none, a_none, a_none, a_none, a_none, a_subf_, a_subf_, a_subfo_,
  430. a_subfo_, a_subfc_, a_subfc_, a_subfco_, a_subfco_, a_subfe_, a_subfe_,
  431. a_subfeo_, a_subfeo_, a_none, a_subfme_, a_subfme_, a_subfmeo_, a_subfmeo_,
  432. a_subfze_, a_subfze_, a_subfzeo_, a_subfzeo_, a_none, a_none, a_none,
  433. a_none, a_none, a_none, a_xor_, a_xor_, a_none, a_none,
  434. { simplified mnemonics }
  435. a_none, a_none, a_subic_, a_subic_, a_sub_, a_sub_, a_subo_, a_subo_,
  436. a_subc_, a_subc_, a_subco_, a_subco_, a_none, a_none, a_none, a_none,
  437. a_extlwi_, a_extlwi_, a_extrwi_, a_extrwi_, a_inslwi_, a_inslwi_, a_insrwi_,
  438. a_insrwi_, a_rotlwi_, a_rotlwi_, a_rotlw_, a_rotlw_, a_slwi_, a_slwi_,
  439. a_srwi_, a_srwi_, a_clrlwi_, a_clrlwi_, a_clrrwi_, a_clrrwi_, a_clrslwi_,
  440. a_clrslwi_, a_none, a_none, a_none, a_none, a_none, a_none, a_none,
  441. a_none, a_none {move to special purpose reg}, a_none {move from special purpose reg},
  442. a_none, a_none, a_none, a_none, a_mr_, a_mr_, a_not_, a_not_, a_none, a_none, a_none,
  443. a_none, a_none, a_none, a_none,
  444. a_none, a_none, a_none, a_none, a_none);
  445. function changetomodifyflags(p: taicpu): boolean;
  446. begin
  447. result := false;
  448. if (modifyflags[p.opcode] <> a_none) then
  449. begin
  450. p.opcode := modifyflags[p.opcode];
  451. result := true;
  452. end;
  453. end;
  454. function TCpuAsmOptimizer.PostPeepHoleOptsCpu(var p: tai): boolean;
  455. var
  456. next1: tai;
  457. begin
  458. result := false;
  459. case p.typ of
  460. ait_instruction:
  461. begin
  462. case taicpu(p).opcode of
  463. A_RLWINM_:
  464. begin
  465. // rlwinm_ is cracked on the G5, andi_/andis_ aren't
  466. if (taicpu(p).oper[2]^.val = 0) then
  467. if (taicpu(p).oper[3]^.val < 16) and
  468. (taicpu(p).oper[4]^.val < 16) then
  469. begin
  470. taicpu(p).opcode := A_ANDIS_;
  471. taicpu(p).oper[2]^.val := word(
  472. ((1 shl (16-taicpu(p).oper[3]^.val)) - 1) xor
  473. ((1 shl (15-taicpu(p).oper[4]^.val)) - 1));
  474. taicpu(p).freeop(3);
  475. taicpu(p).freeop(4);
  476. taicpu(p).ops := 3;
  477. taicpu(p).opercnt := 3;
  478. end
  479. else if (taicpu(p).oper[3]^.val >= 16) and
  480. (taicpu(p).oper[4]^.val >= 16) then
  481. begin
  482. taicpu(p).opcode := A_ANDI_;
  483. taicpu(p).oper[2]^.val := word(rlwinm2mask(taicpu(p).oper[3]^.val,taicpu(p).oper[4]^.val));
  484. taicpu(p).freeop(3);
  485. taicpu(p).freeop(4);
  486. taicpu(p).ops := 3;
  487. taicpu(p).opercnt := 3;
  488. end;
  489. end;
  490. else
  491. ;
  492. end;
  493. // change "integer operation with destination reg" followed by a
  494. // comparison to zero of that reg, with a variant of that integer
  495. // operation which sets the flags (if it exists)
  496. if not(result) and
  497. (taicpu(p).ops >= 2) and
  498. (taicpu(p).oper[0]^.typ = top_reg) and
  499. (taicpu(p).oper[1]^.typ = top_reg) and
  500. getnextinstruction(p,next1) and
  501. (next1.typ = ait_instruction) and
  502. (taicpu(next1).opcode = A_CMPWI) and
  503. // make sure it the result goes to cr0
  504. (((taicpu(next1).ops = 2) and
  505. (taicpu(next1).oper[1]^.val = 0) and
  506. (taicpu(next1).oper[0]^.reg = taicpu(p).oper[0]^.reg)) or
  507. ((taicpu(next1).ops = 3) and
  508. (taicpu(next1).oper[2]^.val = 0) and
  509. (taicpu(next1).oper[0]^.typ = top_reg) and
  510. (getsupreg(taicpu(next1).oper[0]^.reg) = RS_CR0) and
  511. (taicpu(next1).oper[1]^.reg = taicpu(p).oper[0]^.reg))) and
  512. changetomodifyflags(taicpu(p)) then
  513. begin
  514. asml.remove(next1);
  515. next1.free;
  516. result := true;
  517. end;
  518. end;
  519. else
  520. ;
  521. end;
  522. end;
  523. begin
  524. casmoptimizer:=TCpuAsmOptimizer;
  525. End.