popt386.pas 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 by Florian Klaempfl and Jonas Maebe
  4. This unit contains the peephole optimizer.
  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 POpt386;
  19. Interface
  20. Uses Aasm;
  21. Procedure PeepHoleOptPass1(AsmL: PAasmOutput);
  22. Procedure PeepHoleOptPass2(AsmL: PAasmOutput);
  23. Implementation
  24. Uses globals, systems, verbose, hcodegen
  25. {$ifdef i386}
  26. ,i386, DAOpt386
  27. {$endif i386}
  28. ;
  29. Function RegUsedAfterInstruction(Reg: TRegister; p: Pai; Var UsedRegs: TRegSet): Boolean;
  30. Begin
  31. UpdateUsedRegs(UsedRegs, Pai(p^.Next));
  32. RegUsedAfterInstruction := Reg in UsedRegs
  33. End;
  34. Procedure PeepHoleOptPass1(Asml: PAasmOutput);
  35. {First pass of peepholeoptimizations}
  36. Var
  37. p ,hp1, hp2: pai;
  38. TmpBool1, TmpBool2: Boolean;
  39. TmpRef: PReference;
  40. UsedRegs, TmpUsedRegs: TRegSet;
  41. Procedure GetFinalDestination(hp: pai_labeled);
  42. {traces sucessive jumps to their final destination and sets it, e.g.
  43. je l1 je l3
  44. <code> <code>
  45. l1: becomes l1:
  46. je l2 je l3
  47. <code> <code>
  48. l2: l2:
  49. jmp l3 jmp l3}
  50. Var p1: pai;
  51. Function SkipLabels(hp: Pai): Pai;
  52. {skips all labels and returns the next "real" instruction; it is
  53. assumed that hp is of the type ait_label}
  54. Begin
  55. While assigned(hp^.next) and
  56. (pai(hp^.next)^.typ In SkipInstr + [ait_label]) Do
  57. hp := pai(hp^.next);
  58. If assigned(hp^.next)
  59. Then SkipLabels := pai(hp^.next)
  60. Else SkipLabels := hp;
  61. End;
  62. Begin
  63. If (hp^.lab^.nb >= LoLab) and
  64. (hp^.lab^.nb <= HiLab) and {range check, necessary?}
  65. (Pointer(LTable^[hp^.lab^.nb-LoLab].PaiObj) <> Pointer(0)) Then
  66. Begin
  67. p1 := LTable^[hp^.lab^.nb-LoLab].PaiObj; {the jump's destination}
  68. p1 := SkipLabels(p1);
  69. If (pai(p1)^.typ = ait_labeled_instruction) and
  70. ((pai_labeled(p1)^._operator = A_JMP) or
  71. (pai_labeled(p1)^._operator = hp^._operator))
  72. Then
  73. Begin
  74. GetFinalDestination(pai_labeled(p1));
  75. Dec(hp^.lab^.refcount);
  76. If (hp^.lab^.refcount = 0) Then
  77. hp^.lab^.is_used := False;
  78. hp^.lab := pai_labeled(p1)^.lab;
  79. Inc(hp^.lab^.refcount);
  80. End
  81. End
  82. End;
  83. Begin
  84. P := Pai(AsmL^.First);
  85. UsedRegs := [];
  86. While Assigned(P) Do
  87. Begin
  88. UpDateUsedRegs(UsedRegs, Pai(p^.next));
  89. Case P^.Typ Of
  90. Ait_Labeled_Instruction:
  91. Begin
  92. {the following if-block removes all code between a jmp and the next label,
  93. because it can never be executed}
  94. If (pai_labeled(p)^._operator = A_JMP) Then
  95. Begin
  96. hp1 := pai(p^.next);
  97. While GetNextInstruction(p, hp1) and
  98. ((hp1^.typ <> ait_label) or
  99. { skip unused labels, they're not referenced anywhere }
  100. Not(Pai_Label(hp1)^.l^.is_used)) Do
  101. If (hp1^.typ <> ait_label) Then
  102. Begin
  103. AsmL^.Remove(hp1);
  104. Dispose(hp1, done);
  105. End;
  106. End;
  107. If GetNextInstruction(p, hp1) then
  108. Begin
  109. If (pai(hp1)^.typ=ait_labeled_instruction) and
  110. (pai_labeled(hp1)^._operator=A_JMP) and
  111. GetNextInstruction(hp1, hp2) And
  112. FindLabel(pai_labeled(p)^.lab, hp2)
  113. Then
  114. Begin
  115. Case pai_labeled(p)^._operator Of
  116. A_JE : pai_labeled(p)^._operator:=A_JNE;
  117. A_JNE : pai_labeled(p)^._operator:=A_JE;
  118. A_JL : pai_labeled(p)^._operator:=A_JGE;
  119. A_JG : pai_labeled(p)^._operator:=A_JLE;
  120. A_JLE : pai_labeled(p)^._operator:=A_JG;
  121. A_JGE : pai_labeled(p)^._operator:=A_JL;
  122. A_JNZ : pai_labeled(p)^._operator:=A_JZ;
  123. A_JNO : pai_labeled(p)^._operator:=A_JO;
  124. A_JZ : pai_labeled(p)^._operator:=A_JNZ;
  125. A_JS : pai_labeled(p)^._operator:=A_JNS;
  126. A_JNS : pai_labeled(p)^._operator:=A_JS;
  127. A_JO : pai_labeled(p)^._operator:=A_JNO;
  128. A_JC : pai_labeled(p)^._operator:=A_JNC;
  129. A_JNC : pai_labeled(p)^._operator:=A_JC;
  130. A_JA : pai_labeled(p)^._operator:=A_JBE;
  131. A_JAE : pai_labeled(p)^._operator:=A_JB;
  132. A_JB : pai_labeled(p)^._operator:=A_JAE;
  133. A_JBE : pai_labeled(p)^._operator:=A_JA;
  134. Else
  135. begin
  136. If (LabDif <> 0) Then GetFinalDestination(pai_labeled(p));
  137. p:=pai(p^.next);
  138. continue;
  139. end;
  140. end;
  141. Dec(pai_label(hp2)^.l^.refcount);
  142. If (pai_label(hp2)^.l^.refcount = 0) Then
  143. Begin
  144. pai_label(hp2)^.l^.is_used := False;
  145. { AsmL^.remove(hp2);
  146. Dispose(hp2, done);}
  147. End;
  148. pai_labeled(p)^.lab:=pai_labeled(hp1)^.lab;
  149. Inc(pai_labeled(p)^.lab^.refcount);
  150. asml^.remove(hp1);
  151. dispose(hp1,done);
  152. If (LabDif <> 0) Then GetFinalDestination(pai_labeled(p));
  153. end
  154. else
  155. Begin
  156. if FindLabel(pai_labeled(p)^.lab, hp1) then
  157. begin
  158. hp2:=pai(hp1^.next);
  159. asml^.remove(p);
  160. dispose(p,done);
  161. { If Not(pai_label(hp1)^.l^.is_used) Then
  162. Begin
  163. AsmL^.remove(hp1);
  164. Dispose(hp1, done);
  165. End;}
  166. p:=hp2;
  167. continue;
  168. end;
  169. If (LabDif <> 0) Then GetFinalDestination(pai_labeled(p));
  170. end;
  171. end
  172. end;
  173. ait_instruction:
  174. Begin
  175. If (Pai386(p)^.op1t = top_ref) Then
  176. With TReference(Pai386(p)^.op1^) Do
  177. Begin
  178. If (base = R_NO) And
  179. (scalefactor = 1)
  180. Then
  181. Begin
  182. base := index;
  183. index := r_no
  184. End
  185. End;
  186. If (Pai386(p)^.op2t = top_ref) Then
  187. With TReference(Pai386(p)^.op2^) Do
  188. Begin
  189. If (base = R_NO) And
  190. (scalefactor = 1)
  191. Then
  192. Begin
  193. base := index;
  194. index := r_no
  195. End
  196. End;
  197. Case Pai386(p)^._operator Of
  198. A_AND:
  199. Begin
  200. If (Pai386(p)^.op1t = top_const) And
  201. (Pai386(p)^.op2t = top_reg) And
  202. GetNextInstruction(p, hp1) And
  203. (Pai(hp1)^.typ = ait_instruction) And
  204. (Pai386(hp1)^._operator = A_AND) And
  205. (Pai386(hp1)^.op1t = top_const) And
  206. (Pai386(hp1)^.op2t = top_reg) And
  207. (Pai386(hp1)^.op2 = Pai386(hp1)^.op2)
  208. Then
  209. {change "and const1, reg; and const2, reg" to "and (const1 and const2), reg"}
  210. Begin
  211. Pai386(p)^.op1 := Pointer(Longint(Pai386(p)^.op1) And Longint(Pai386(hp1)^.op1));
  212. AsmL^.Remove(hp1);
  213. Dispose(hp1, Done)
  214. End
  215. Else
  216. {change "and x, reg; jxx" to "test x, reg", if reg is deallocated before the
  217. jump}
  218. If (Pai386(p)^.op2t = top_reg) And
  219. GetNextInstruction(p, hp1) And
  220. (hp1^.typ = ait_labeled_instruction) And
  221. Not(TRegister(Pai386(p)^.op2) in UsedRegs)
  222. Then Pai386(p)^._operator := A_TEST;
  223. End;
  224. A_CMP:
  225. Begin
  226. If (Pai386(p)^.op1t = top_const) And
  227. (Pai386(p)^.op2t = top_reg) And
  228. (Pai386(p)^.op1 = Pointer(0)) Then
  229. {change "cmp $0, %reg" to "test %reg, %reg"}
  230. Begin
  231. Pai386(p)^._operator := A_TEST;
  232. Pai386(p)^.opxt := Top_reg+Top_reg shl 4;
  233. Pai386(p)^.op1 := Pai386(p)^.op2;
  234. End;
  235. End;
  236. A_FLD:
  237. Begin
  238. If (Pai386(p)^.op1t = top_ref) And
  239. GetLastInstruction(p, hp1) And
  240. (hp1^.typ = Ait_Instruction) And
  241. ((Pai386(hp1)^._operator = A_FLD) Or
  242. (Pai386(hp1)^._operator = A_FST)) And
  243. (Pai386(hp1)^.size = Pai386(p)^.size) And
  244. (Pai386(hp1)^.op1t = top_ref) And
  245. RefsEqual(TReference(Pai386(p)^.Op1^), TReference(Pai386(hp1)^.Op1^)) Then
  246. { we have "fld/fst mem1; fld mem1 }
  247. If GetNextInstruction(p, hp2) And
  248. (hp2^.typ = Ait_Instruction) And
  249. (Pai386(hp2)^._operator in [A_FMULP, A_FADDP]) And
  250. (Pai386(hp2)^.Op1t = top_reg) And
  251. (Pai386(hp2)^.Op2t = top_reg) And
  252. (TRegister(Pai386(hp2)^.Op1) = R_ST) And
  253. (TRegister(Pai386(hp2)^.Op2) = R_ST1) Then
  254. { change to
  255. fld/fst mem1 fld/fst mem1
  256. fld mem1 fadd/
  257. faddp/ fmul st, st
  258. fmulp st, st1 }
  259. Begin
  260. AsmL^.Remove(p);
  261. Dispose(p, Done);
  262. p := hp1;
  263. If (Pai386(hp2)^._operator = A_FADDP)
  264. Then Pai386(hp2)^._operator := A_FADD
  265. Else Pai386(hp2)^._operator := A_FMUL;
  266. Pai386(hp2)^.op2 := Pointer(R_ST);
  267. End
  268. Else
  269. { change to
  270. fldl/fstl mem1 fldl/fstl mem1
  271. fldl mem1 fldl st}
  272. If (Pai386(p)^.Size in [S_FS,S_FL]) Then
  273. Begin
  274. Pai386(p)^.Size := S_FL;
  275. Clear_Reference(TReference(Pai386(p)^.Op1^));
  276. Pai386(p)^.Op1 := Pointer(R_ST);
  277. Pai386(p)^.Opxt := top_reg;
  278. End;
  279. End;
  280. A_FSTP:
  281. Begin
  282. If (Pai386(p)^.op1t = top_ref) And
  283. GetNextInstruction(p, hp1) And
  284. (Pai(hp1)^.typ = ait_instruction) And
  285. (Pai386(hp1)^._operator = A_FLD) And
  286. (Pai386(hp1)^.op1t = top_ref) And
  287. (Pai386(hp1)^.Size = Pai386(p)^.Size) And
  288. RefsEqual(TReference(Pai386(p)^.op1^), TReference(Pai386(hp1)^.op1^))
  289. Then
  290. Begin
  291. If GetNextInstruction(hp1, hp2) And
  292. (hp2^.typ = ait_instruction) And
  293. ((Pai386(hp2)^._operator = A_LEAVE) Or
  294. (Pai386(hp2)^._operator = A_RET)) And
  295. (TReference(Pai386(p)^.op1^).Base = ProcInfo.FramePointer) And
  296. (TReference(Pai386(p)^.op1^).Offset >= ProcInfo.RetOffset) And
  297. (TReference(Pai386(p)^.op1^).Index = R_NO)
  298. Then
  299. Begin
  300. AsmL^.Remove(p);
  301. AsmL^.Remove(hp1);
  302. Dispose(p, Done);
  303. Dispose(hp1, Done);
  304. p := hp2;
  305. Continue
  306. End
  307. Else
  308. {fst can't store an extended value!}
  309. If (Pai386(p)^.Size <> S_FX) Then
  310. Begin
  311. Pai386(p)^._operator := A_FST;
  312. AsmL^.Remove(hp1);
  313. Dispose(hp1, done)
  314. End
  315. End;
  316. End;
  317. A_IMUL:
  318. {changes certain "imul const, %reg"'s to lea sequences}
  319. Begin
  320. If (Pai386(p)^.op1t = Top_Const) And
  321. (Pai386(p)^.op2t = Top_Reg) And
  322. (Pai386(p)^.Size = S_L) Then
  323. If (Longint(Pai386(p)^.op1) = 1) Then
  324. If (Pai386(p)^.op3t = Top_None) Then
  325. {remove "imul $1, reg"}
  326. Begin
  327. hp1 := Pai(p^.Next);
  328. AsmL^.Remove(p);
  329. Dispose(p, Done);
  330. p := hp1;
  331. Continue;
  332. End
  333. Else
  334. {change "imul $1, reg1, reg2" to "mov reg1, reg2"}
  335. Begin
  336. hp1 := New(Pai386, Op_Reg_Reg(A_MOV, S_L, TRegister(TwoWords(Pai386(p)^.op2).Word1),
  337. TRegister(TwoWords(Pai386(p)^.op2).Word2)));
  338. hp1^.fileinfo := p^.fileinfo;
  339. InsertLLItem(AsmL, p^.previous, p^.next, hp1);
  340. Dispose(p, Done);
  341. p := hp1;
  342. End
  343. Else If
  344. ((Pai386(p)^.op3t = Top_Reg) or
  345. (Pai386(p)^.op3t = Top_None)) And
  346. (aktoptprocessor < ClassP6) And
  347. (Longint(Pai386(p)^.op1) <= 12) And
  348. Not(CS_LittleSize in aktglobalswitches) And
  349. (Not(GetNextInstruction(p, hp1)) Or
  350. {GetNextInstruction(p, hp1) And}
  351. Not((Pai(hp1)^.typ = ait_labeled_instruction) And
  352. ((pai_labeled(hp1)^._operator = A_JO) or
  353. (pai_labeled(hp1)^._operator = A_JNO))))
  354. Then
  355. Begin
  356. New(TmpRef);
  357. TmpRef^.segment := R_DEFAULT_SEG;
  358. TmpRef^.symbol := nil;
  359. TmpRef^.isintvalue := false;
  360. TmpRef^.offset := 0;
  361. Case Longint(Pai386(p)^.op1) Of
  362. 3: Begin
  363. {imul 3, reg1, reg2 to
  364. lea (reg1,reg1,2), reg2
  365. imul 3, reg1 to
  366. lea (reg1,reg1,2), reg1}
  367. TmpRef^.base := TRegister(twowords(Pai386(p)^.op2).Word1);
  368. TmpRef^.Index := TRegister(twowords(Pai386(p)^.op2).Word1);
  369. TmpRef^.ScaleFactor := 2;
  370. If (Pai386(p)^.op3t = Top_None)
  371. Then hp1 := New(Pai386, op_ref_reg(A_LEA, S_L, TmpRef, TRegister(Pai386(p)^.op2)))
  372. Else hp1 := New(Pai386, op_ref_reg(A_LEA, S_L, TmpRef,
  373. TRegister(twowords(Pai386(p)^.op2).word2)));
  374. hp1^.fileinfo := p^.fileinfo;
  375. InsertLLItem(AsmL,p^.previous, p^.next, hp1);
  376. Dispose(p, Done);
  377. p := hp1;
  378. End;
  379. 5: Begin
  380. {imul 5, reg1, reg2 to
  381. lea (reg1,reg1,4), reg2
  382. imul 5, reg1 to
  383. lea (reg1,reg1,4), reg1}
  384. TmpRef^.base := TRegister(twowords(Pai386(p)^.op2).Word1);
  385. TmpRef^.Index := TRegister(twowords(Pai386(p)^.op2).Word1);
  386. TmpRef^.ScaleFactor := 4;
  387. If (Pai386(p)^.op3t = Top_None)
  388. Then hp1 := New(Pai386, op_ref_reg(A_LEA, S_L, TmpRef, TRegister(Pai386(p)^.op2)))
  389. Else hp1 := New(Pai386, op_ref_reg(A_LEA, S_L, TmpRef,
  390. TRegister(twowords(Pai386(p)^.op2).word2)));
  391. hp1^.fileinfo:= p^.fileinfo;
  392. InsertLLItem(AsmL,p^.previous, p^.next, hp1);
  393. Dispose(p, Done);
  394. p := hp1;
  395. End;
  396. 6: Begin
  397. {imul 6, reg1, reg2 to
  398. lea (,reg1,2), reg2
  399. lea (reg2,reg1,4), reg2
  400. imul 6, reg1 to
  401. lea (reg1,reg1,2), reg1
  402. add reg1, reg1}
  403. If (aktoptprocessor <= Class386)
  404. Then
  405. Begin
  406. TmpRef^.Index := TRegister(twowords(Pai386(p)^.op2).Word1);
  407. If (Pai386(p)^.op3t = Top_Reg)
  408. Then
  409. Begin
  410. TmpRef^.base := TRegister(twowords(Pai386(p)^.op2).word2);
  411. TmpRef^.ScaleFactor := 4;
  412. hp1 := New(Pai386, op_ref_reg(A_LEA, S_L, TmpRef,
  413. TRegister(twowords(Pai386(p)^.op2).word2)));
  414. End
  415. Else
  416. Begin
  417. Dispose(TmpRef);
  418. hp1 := New(Pai386, op_reg_reg(A_ADD, S_L,
  419. TRegister(Pai386(p)^.op2),TRegister(Pai386(p)^.op2)));
  420. End;
  421. hp1^.fileinfo := p^.fileinfo;
  422. InsertLLItem(AsmL,p, p^.next, hp1);
  423. New(TmpRef);
  424. TmpRef^.segment := R_DEFAULT_SEG;
  425. TmpRef^.symbol := nil;
  426. TmpRef^.isintvalue := false;
  427. TmpRef^.offset := 0;
  428. TmpRef^.Index := TRegister(twowords(Pai386(p)^.op2).Word1);
  429. TmpRef^.ScaleFactor := 2;
  430. If (Pai386(p)^.op3t = Top_Reg)
  431. Then
  432. Begin
  433. TmpRef^.base := R_NO;
  434. hp1 := New(Pai386, op_ref_reg(A_LEA, S_L, TmpRef,
  435. TRegister(twowords(Pai386(p)^.op2).word2)));
  436. End
  437. Else
  438. Begin
  439. TmpRef^.base := TRegister(Pai386(p)^.op2);
  440. hp1 := New(Pai386, op_ref_reg(A_LEA, S_L, TmpRef, TRegister(Pai386(p)^.op2)));
  441. End;
  442. hp1^.fileinfo := p^.fileinfo;
  443. InsertLLItem(AsmL,p^.previous, p^.next, hp1);
  444. Dispose(p, Done);
  445. p := Pai(hp1^.next);
  446. End
  447. Else Dispose(TmpRef);
  448. End;
  449. 9: Begin
  450. {imul 9, reg1, reg2 to
  451. lea (reg1,reg1,8), reg2
  452. imul 9, reg1 to
  453. lea (reg1,reg1,8), reg1}
  454. TmpRef^.base := TRegister(twowords(Pai386(p)^.op2).Word1);
  455. TmpRef^.Index := TRegister(twowords(Pai386(p)^.op2).Word1);
  456. TmpRef^.ScaleFactor := 8;
  457. If (Pai386(p)^.op3t = Top_None)
  458. Then hp1 := New(Pai386, op_ref_reg(A_LEA, S_L, TmpRef, TRegister(Pai386(p)^.op2)))
  459. Else hp1 := New(Pai386, op_ref_reg(A_LEA, S_L, TmpRef,
  460. TRegister(twowords(Pai386(p)^.op2).word2)));
  461. hp1^.fileinfo := p^.fileinfo;
  462. InsertLLItem(AsmL,p^.previous, p^.next, hp1);
  463. Dispose(p, Done);
  464. p := hp1;
  465. End;
  466. 10: Begin
  467. {imul 10, reg1, reg2 to
  468. lea (reg1,reg1,4), reg2
  469. add reg2, reg2
  470. imul 10, reg1 to
  471. lea (reg1,reg1,4), reg1
  472. add reg1, reg1}
  473. If (aktoptprocessor <= Class386) Then
  474. Begin
  475. If (Pai386(p)^.op3t = Top_Reg)
  476. Then
  477. hp1 := New(Pai386, op_reg_reg(A_ADD, S_L,
  478. Tregister(twowords(Pai386(p)^.op2).word2),
  479. Tregister(twowords(Pai386(p)^.op2).word2)))
  480. Else hp1 := New(Pai386, op_reg_reg(A_ADD, S_L,
  481. TRegister(Pai386(p)^.op2), TRegister(Pai386(p)^.op2)));
  482. hp1^.fileinfo := p^.fileinfo;
  483. InsertLLItem(AsmL,p, p^.next, hp1);
  484. TmpRef^.base := TRegister(twowords(Pai386(p)^.op2).Word1);
  485. TmpRef^.Index := TRegister(twowords(Pai386(p)^.op2).Word1);
  486. TmpRef^.ScaleFactor := 4;
  487. If (Pai386(p)^.op3t = Top_Reg)
  488. Then
  489. hp1 := New(Pai386, op_ref_reg(A_LEA, S_L, TmpRef,
  490. TRegister(twowords(Pai386(p)^.op2).word2)))
  491. Else
  492. hp1 := New(Pai386, op_ref_reg(A_LEA, S_L, TmpRef,
  493. TRegister(Pai386(p)^.op2)));
  494. hp1^.fileinfo := p^.fileinfo;
  495. InsertLLItem(AsmL,p^.previous, p^.next, hp1);
  496. Dispose(p, Done);
  497. p := Pai(hp1^.next);
  498. End
  499. Else Dispose(TmpRef);
  500. End;
  501. 12: Begin
  502. {imul 12, reg1, reg2 to
  503. lea (,reg1,4), reg2
  504. lea (,reg1,8) reg2
  505. imul 12, reg1 to
  506. lea (reg1,reg1,2), reg1
  507. lea (,reg1,4), reg1}
  508. If (aktoptprocessor <= Class386)
  509. Then
  510. Begin
  511. TmpRef^.Index := TRegister(twowords(Pai386(p)^.op2).Word1);
  512. If (Pai386(p)^.op3t = Top_Reg)
  513. Then
  514. Begin
  515. TmpRef^.base := TRegister(twowords(Pai386(p)^.op2).word2);
  516. TmpRef^.ScaleFactor := 8;
  517. hp1 := New(Pai386, op_ref_reg(A_LEA, S_L, TmpRef,
  518. TRegister(twowords(Pai386(p)^.op2).word2)));
  519. End
  520. Else
  521. Begin
  522. TmpRef^.base := R_NO;
  523. TmpRef^.ScaleFactor := 4;
  524. hp1 := New(Pai386, op_ref_reg(A_LEA, S_L, TmpRef,
  525. TRegister(Pai386(p)^.op2)));
  526. End;
  527. hp1^.fileinfo := p^.fileinfo;
  528. InsertLLItem(AsmL,p, p^.next, hp1);
  529. New(TmpRef);
  530. TmpRef^.segment := R_DEFAULT_SEG;
  531. TmpRef^.symbol := nil;
  532. TmpRef^.isintvalue := false;
  533. TmpRef^.offset := 0;
  534. TmpRef^.Index := TRegister(twowords(Pai386(p)^.op2).Word1);
  535. If (Pai386(p)^.op3t = Top_Reg)
  536. Then
  537. Begin
  538. TmpRef^.base := R_NO;
  539. TmpRef^.ScaleFactor := 4;
  540. hp1 := New(Pai386, op_ref_reg(A_LEA, S_L, TmpRef,
  541. TRegister(twowords(Pai386(p)^.op2).word2)));
  542. End
  543. Else
  544. Begin
  545. TmpRef^.base := TRegister(Pai386(p)^.op2);
  546. TmpRef^.ScaleFactor := 2;
  547. hp1 := New(Pai386, op_ref_reg(A_LEA, S_L, TmpRef,
  548. TRegister(Pai386(p)^.op2)));
  549. End;
  550. hp1^.fileinfo := p^.fileinfo;
  551. InsertLLItem(AsmL,p^.previous, p^.next, hp1);
  552. Dispose(p, Done);
  553. p := Pai(hp1^.next);
  554. End
  555. Else Dispose(TmpRef);
  556. End
  557. Else Dispose(TmpRef);
  558. End;
  559. End;
  560. End;
  561. A_LEA:
  562. Begin
  563. {changes "lea (%reg1), %reg2" into "mov %reg1, %reg2"}
  564. If (PReference(Pai386(p)^.op1)^.Base In [R_EAX..R_EDI]) And
  565. (PReference(Pai386(p)^.op1)^.Index = R_NO) And
  566. (PReference(Pai386(p)^.op1)^.Offset = 0) And
  567. (Not(Assigned(PReference(Pai386(p)^.op1)^.Symbol))) Then
  568. If (PReference(Pai386(p)^.op1)^.Base <> TRegister(Pai386(p)^.op2))
  569. Then
  570. Begin
  571. hp1 := New(Pai386, op_reg_reg(A_MOV, S_L,PReference(Pai386(p)^.op1)^.Base,
  572. TRegister(Pai386(p)^.op2)));
  573. hp1^.fileinfo := p^.fileinfo;
  574. InsertLLItem(AsmL,p^.previous,p^.next, hp1);
  575. Dispose(p, Done);
  576. p := hp1;
  577. Continue;
  578. End
  579. Else
  580. Begin
  581. hp1 := Pai(p^.Next);
  582. AsmL^.Remove(p);
  583. Dispose(p, Done);
  584. p := hp1;
  585. Continue;
  586. End;
  587. End;
  588. A_MOV:
  589. Begin
  590. TmpUsedRegs := UsedRegs;
  591. If (Pai386(p)^.op2t = top_reg) And
  592. (TRegister(Pai386(p)^.op2) In [R_EAX, R_EBX, R_EDX, R_EDI]) And
  593. GetNextInstruction(p, hp1) And
  594. (Pai(hp1)^.typ = ait_instruction) And
  595. (Pai386(hp1)^._operator = A_MOV) And
  596. (Pai386(hp1)^.op1t = top_reg) And
  597. (Pai386(hp1)^.op1 = Pai386(p)^.op2)
  598. Then
  599. {we have "mov x, %treg; mov %treg, y}
  600. If (Pai386(hp1)^.op2t <> top_reg) Or
  601. (GetNextInstruction(hp1, hp2) And
  602. (RegUsedAfterInstruction(TRegister(Pai386(hp1)^.op2), hp1, TmpUsedRegs) or
  603. {now TmpUsedRegs contains the regalloc data after hp1}
  604. (RegInInstruction(TRegister(Pai386(hp1)^.op2), hp2))) And
  605. Not(TRegister(Pai386(hp1)^.op1) in TmpUsedRegs))
  606. Then
  607. {we've got "mov x, %treg; mov %treg, y; XXX y" (ie. y is used in
  608. the third instruction)}
  609. Case Pai386(p)^.op1t Of
  610. top_reg:
  611. {change "mov %reg, %treg; mov %treg, y"
  612. to "mov %reg, y"}
  613. Begin
  614. Pai386(hp1)^.op1 := Pai386(p)^.op1;
  615. AsmL^.Remove(p);
  616. Dispose(p, Done);
  617. p := hp1;
  618. continue;
  619. End;
  620. top_ref:
  621. If (Pai386(hp1)^.op2t = top_reg)
  622. Then
  623. {change "mov mem, %treg; mov %treg, %reg"
  624. to "mov mem, %reg"}
  625. Begin
  626. Pai386(p)^.op2 := Pai386(hp1)^.op2;
  627. AsmL^.Remove(hp1);
  628. Dispose(hp1, Done);
  629. continue;
  630. End;
  631. End
  632. Else
  633. {remove an instruction which never makes sense: we've got
  634. "mov mem, %reg1; mov %reg1, %edi" and then EDI isn't used anymore!}
  635. { Begin
  636. If (TRegister(Pai386(hp1)^.op2) = R_EDI) And
  637. Not(GetNextInstruction(hp1, hp2) And
  638. (Pai(hp2)^.typ = ait_instruction) And
  639. (Pai386(hp2)^.op2t = top_reg) And
  640. (Pai386(hp2)^.op2 = Pointer(R_ESI))) Then
  641. Begin
  642. AsmL^.Remove(hp1);
  643. Dispose(hp1, Done);
  644. Continue;
  645. End
  646. End}
  647. Else
  648. {Change "mov %reg1, %reg2; xxx %reg2, ???" to
  649. "mov %reg1, %reg2; xxx %reg1, ???" to avoid a write/read
  650. penalty}
  651. If (Pai386(p)^.op1t = top_reg) And
  652. (Pai386(p)^.op2t = top_reg) And
  653. GetNextInstruction(p,hp1) And
  654. (Pai(hp1)^.typ = ait_instruction) And
  655. (Pai386(hp1)^.op1t = top_reg) And
  656. (Pai386(hp1)^.op1 = Pai386(p)^.op2)
  657. Then
  658. {we have "mov %reg1, %reg2; XXX %reg2, ???"}
  659. Begin
  660. If ((Pai386(hp1)^._operator = A_OR) Or
  661. (Pai386(hp1)^._operator = A_TEST)) And
  662. (Pai386(hp1)^.op2t = top_reg) And
  663. (Pai386(hp1)^.op1 = Pai386(hp1)^.op2)
  664. Then
  665. {we have "mov %reg1, %reg2; test/or %reg2, %reg2"}
  666. Begin
  667. TmpUsedRegs := UsedRegs;
  668. If GetNextInstruction(hp1, hp2) And
  669. (hp2^.typ = ait_labeled_instruction) And
  670. Not(RegUsedAfterInstruction(TRegister(Pai386(hp1)^.op1), hp1, TmpUsedRegs))
  671. Then
  672. {change "mov %reg1, %reg2; test/or %reg2, %reg2; jxx" to
  673. "test %reg1, %reg1; jxx"}
  674. Begin
  675. Pai386(hp1)^.op1 := Pai386(p)^.op1;
  676. Pai386(hp1)^.op2 := Pai386(p)^.op1;
  677. AsmL^.Remove(p);
  678. Dispose(p, done);
  679. p := hp1;
  680. continue
  681. End
  682. Else
  683. {change "mov %reg1, %reg2; test/or %reg2, %reg2" to
  684. "mov %reg1, %reg2; test/or %reg1, %reg1"}
  685. Begin
  686. Pai386(hp1)^.op1 := Pai386(p)^.op1;
  687. Pai386(hp1)^.op2 := Pai386(p)^.op1;
  688. End;
  689. End
  690. { Else
  691. If (Pai386(p^.next)^._operator
  692. In [A_PUSH, A_OR, A_XOR, A_AND, A_TEST])}
  693. {change "mov %reg1, %reg2; push/or/xor/... %reg2, ???" to
  694. "mov %reg1, %reg2; push/or/xor/... %reg1, ???"}
  695. End
  696. Else
  697. {leave out the mov from "mov reg, x(%frame_pointer); leave/ret" (with
  698. x >= RetOffset) as it doesn't do anything (it writes either to a
  699. parameter or to the temporary storage room for the function
  700. result)}
  701. If GetNextInstruction(p, hp1) And
  702. (Pai(hp1)^.typ = ait_instruction)
  703. Then
  704. If ((Pai386(hp1)^._operator = A_LEAVE) Or
  705. (Pai386(hp1)^._operator = A_RET)) And
  706. (Pai386(p)^.op2t = top_ref) And
  707. (TReference(Pai386(p)^.op2^).base = ProcInfo.FramePointer) And
  708. (TReference(Pai386(p)^.op2^).offset >= ProcInfo.RetOffset) And
  709. (TReference(Pai386(p)^.op2^).index = R_NO) And
  710. (Pai386(p)^.op1t = top_reg)
  711. Then
  712. Begin
  713. AsmL^.Remove(p);
  714. Dispose(p, done);
  715. p := hp1;
  716. End
  717. Else
  718. If (Pai386(p)^.op1t = top_reg) And
  719. (Pai386(p)^.op2t = top_ref) And
  720. (Pai386(p)^.Size = Pai386(hp1)^.Size) And
  721. (Pai386(hp1)^._operator = A_CMP) And
  722. (Pai386(hp1)^.op2t = top_ref) And
  723. RefsEqual(TReference(Pai386(p)^.op2^),
  724. TReference(Pai386(hp1)^.op2^))
  725. Then
  726. {change "mov reg, mem1; cmp x, mem1" to "mov reg, mem1; cmp x, reg1"}
  727. Begin
  728. Dispose(PReference(Pai386(hp1)^.op2));
  729. Pai386(hp1)^.opxt := Pai386(hp1)^.op1t + (top_reg shl 4);
  730. Pai386(hp1)^.op2 := Pai386(p)^.op1
  731. End;
  732. { Next instruction is also a MOV ? }
  733. If GetNextInstruction(p, hp1) And
  734. (pai(hp1)^.typ = ait_instruction) and
  735. (Pai386(hp1)^._operator = A_MOV)
  736. Then
  737. Begin
  738. If (Pai386(hp1)^.op1t = Pai386(p)^.op2t) and
  739. (Pai386(hp1)^.op2t = Pai386(p)^.op1t)
  740. Then
  741. {mov reg1, mem1 or mov mem1, reg1
  742. mov mem2, reg2 mov reg2, mem2}
  743. Begin
  744. If (Pai386(hp1)^.op2t = top_ref)
  745. Then
  746. TmpBool1 := RefsEqual(TReference(Pai386(hp1)^.op2^), TReference(Pai386(p)^.op1^))
  747. Else
  748. TmpBool1 := Pai386(hp1)^.op2 = Pai386(p)^.op1;
  749. If TmpBool1
  750. Then
  751. {mov reg1, mem1 or mov mem1, reg1
  752. mov mem2, reg1 mov reg2, mem1}
  753. Begin
  754. If (Pai386(hp1)^.op1t = top_ref)
  755. Then
  756. TmpBool1 := RefsEqual(TReference(Pai386(hp1)^.op1^),
  757. TReference(Pai386(p)^.op2^))
  758. Else TmpBool1 := (Pai386(hp1)^.op1 = Pai386(p)^.op2);
  759. If TmpBool1 Then
  760. { Removes the second statement from
  761. mov reg1, mem1
  762. mov mem1, reg1 }
  763. Begin
  764. AsmL^.remove(hp1);
  765. Dispose(hp1,done);
  766. End;
  767. End
  768. Else
  769. Begin
  770. If GetNextInstruction(hp1, hp2) And
  771. (Pai386(p)^.op1t = top_ref) And
  772. (Pai386(p)^.op2t = top_reg) And
  773. (Pai386(hp1)^.op1t = top_reg) And
  774. (Pai386(hp1)^.op1 = Pai386(p)^.op2) And
  775. (Pai386(hp1)^.op2t = top_ref) And
  776. (Pai(hp2)^.typ = ait_instruction) And
  777. (Pai386(hp2)^._operator = A_MOV) And
  778. (Pai386(hp2)^.op2t = top_reg) And
  779. (Pai386(hp2)^.op1t = top_ref) And
  780. RefsEqual(TReference(Pai386(hp2)^.op1^),
  781. TReference(Pai386(hp1)^.op2^))
  782. Then
  783. If (TRegister(Pai386(p)^.op2) = R_EDI)
  784. Then
  785. { mov mem1, %edi
  786. mov %edi, mem2
  787. mov mem2, reg2
  788. to:
  789. mov mem1, reg2
  790. mov reg2, mem2}
  791. Begin
  792. Pai386(p)^.op2 := Pai386(hp2)^.op2;
  793. Pai386(hp1)^.op1 := Pai386(hp2)^.op2;
  794. AsmL^.Remove(hp2);
  795. Dispose(hp2,Done);
  796. End
  797. Else
  798. { mov mem1, reg1 mov mem1, reg1
  799. mov reg1, mem2 mov reg1, mem2
  800. mov mem2, reg2 mov mem2, reg1
  801. to: to:
  802. mov mem1, reg1 mov mem1, reg1
  803. mov mem1, reg2 mov reg1, mem2
  804. mov reg1, mem2}
  805. Begin
  806. If (Pai386(p)^.op2 <> Pai386(hp2)^.op2) Then
  807. Begin
  808. Pai386(hp1)^.opxt := top_ref + top_reg shl 4;
  809. If Assigned(TReference(Pai386(hp1)^.op2^).Symbol)
  810. Then Freemem(TReference(Pai386(hp1)^.op2^).Symbol,
  811. Length(TReference(Pai386(hp1)^.op2^).Symbol^)+1);
  812. Pai386(hp1)^.op1 := Pai386(hp1)^.op2; {move the treference}
  813. TReference(Pai386(hp1)^.op1^) := TReference(Pai386(p)^.op1^);
  814. If Assigned(TReference(Pai386(p)^.op1^).Symbol) Then
  815. Begin
  816. Getmem(TReference(Pai386(hp1)^.op1^).Symbol,
  817. Length(TReference(Pai386(p)^.op1^).Symbol^)+1);
  818. TReference(Pai386(hp1)^.op1^).Symbol^ :=
  819. TReference(Pai386(p)^.op1^).Symbol^;
  820. End;
  821. Pai386(hp1)^.op2 := Pai386(hp2)^.op2;
  822. End
  823. Else
  824. Begin
  825. AsmL^.Remove(hp1);
  826. Dispose(hp1, Done)
  827. End;
  828. Pai386(hp2)^.opxt := top_reg + top_ref shl 4;
  829. Pai386(hp2)^.op2 := Pai386(hp2)^.op1;
  830. Pai386(hp2)^.op1 := Pai386(p)^.op2;
  831. End;
  832. End;
  833. End
  834. Else
  835. (* {movl [mem1],reg1
  836. movl [mem1],reg2
  837. to:
  838. movl [mem1],reg1
  839. movl reg1,reg2 }
  840. If (Pai386(p)^.op1t = top_ref) and
  841. (Pai386(p)^.op2t = top_reg) and
  842. (Pai386(hp1)^.op1t = top_ref) and
  843. (Pai386(hp1)^.op2t = top_reg) and
  844. (Pai386(p)^.size = Pai386(hp1)^.size) and
  845. RefsEqual(TReference(Pai386(p)^.op1^),TReference(Pai386(hp1)^.op1^)) and
  846. (TRegister(Pai386(p)^.op2)<>TReference(Pai386(hp1)^.op1^).base) and
  847. (TRegister(Pai386(p)^.op2)<>TReference(Pai386(hp1)^.op1^).index) then
  848. Begin
  849. Dispose(PReference(Pai386(hp1)^.op1));
  850. Pai386(hp1)^.op1:=Pai386(p)^.op2;
  851. Pai386(hp1)^.opxt:=Top_reg+Top_reg shl 4;
  852. End
  853. Else*)
  854. { movl const1,[mem1]
  855. movl [mem1],reg1
  856. to:
  857. movl const1,reg1
  858. movl reg1,[mem1] }
  859. If (Pai386(p)^.op1t = top_const) and
  860. (Pai386(p)^.op2t = top_ref) and
  861. (Pai386(hp1)^.op1t = top_ref) and
  862. (Pai386(hp1)^.op2t = top_reg) and
  863. (Pai386(p)^.size = Pai386(hp1)^.size) and
  864. RefsEqual(TReference(Pai386(hp1)^.op1^),TReference(Pai386(p)^.op2^)) then
  865. Begin
  866. Pai386(hp1)^.op1:=Pai386(hp1)^.op2;
  867. Pai386(hp1)^.op2:=Pai386(p)^.op2;
  868. Pai386(hp1)^.opxt:=Top_reg+Top_ref shl 4;
  869. Pai386(p)^.op2:=Pai386(hp1)^.op1;
  870. Pai386(p)^.opxt:=Top_const+(top_reg shl 4);
  871. End
  872. End;
  873. {changes "mov $0, %reg" into "xor %reg, %reg"}
  874. If (Pai386(p)^.op1t = Top_Const) And
  875. (Pai386(p)^.op1 = Pointer(0)) And
  876. (Pai386(p)^.op2t = Top_Reg)
  877. Then
  878. Begin
  879. Pai386(p)^._operator := A_XOR;
  880. Pai386(p)^.opxt := Top_Reg+Top_reg shl 4;
  881. Pai386(p)^.op1 := Pai386(p)^.op2;
  882. End;
  883. End;
  884. A_MOVZX:
  885. Begin
  886. {removes superfluous And's after movzx's}
  887. If (Pai386(p)^.op2t = top_reg) And
  888. GetNextInstruction(p, hp1) And
  889. (Pai(hp1)^.typ = ait_instruction) And
  890. (Pai386(hp1)^._operator = A_AND) And
  891. (Pai386(hp1)^.op1t = top_const) And
  892. (Pai386(hp1)^.op2t = top_reg) And
  893. (Pai386(hp1)^.op2 = Pai386(p)^.op2)
  894. Then
  895. Case Pai386(p)^.Size Of
  896. S_BL, S_BW:
  897. If (Longint(Pai386(hp1)^.op1) = $ff)
  898. Then
  899. Begin
  900. AsmL^.Remove(hp1);
  901. Dispose(hp1, Done);
  902. End;
  903. S_WL:
  904. If (Longint(Pai386(hp1)^.op1) = $ffff)
  905. Then
  906. Begin
  907. AsmL^.Remove(hp1);
  908. Dispose(hp1, Done);
  909. End;
  910. End;
  911. {changes some movzx constructs to faster synonims (all examples
  912. are given with eax/ax, but are also valid for other registers)}
  913. If (Pai386(p)^.op2t = top_reg) Then
  914. If (Pai386(p)^.op1t = top_reg)
  915. Then
  916. Case Pai386(p)^.size of
  917. S_BW:
  918. Begin
  919. If (TRegister(Pai386(p)^.op1) = Reg16ToReg8(TRegister(Pai386(p)^.op2))) And
  920. Not(CS_LittleSize In aktglobalswitches)
  921. Then
  922. {Change "movzbw %al, %ax" to "andw $0x0ffh, %ax"}
  923. Begin
  924. Pai386(p)^._operator := A_AND;
  925. Pai386(p)^.opxt := top_const+Top_reg shl 4;
  926. Longint(Pai386(p)^.op1) := $ff;
  927. Pai386(p)^.Size := S_W
  928. End
  929. Else
  930. If GetNextInstruction(p, hp1) And
  931. (Pai(hp1)^.typ = ait_instruction) And
  932. (Pai386(hp1)^._operator = A_AND) And
  933. (Pai386(hp1)^.op1t = top_const) And
  934. (Pai386(hp1)^.op2t = top_reg) And
  935. (Pai386(hp1)^.op2 = Pai386(p)^.op2)
  936. Then
  937. {Change "movzbw %reg1, %reg2; andw $const, %reg2"
  938. to "movw %reg1, reg2; andw $(const1 and $ff), %reg2"}
  939. Begin
  940. Pai386(p)^._operator := A_MOV;
  941. Pai386(p)^.Size := S_W;
  942. Pai386(p)^.op1 := Pointer(Reg8ToReg16(TRegister(Pai386(p)^.op1)));
  943. Pai386(hp1)^.op1 := Pointer(Longint(Pai386(hp1)^.op1) And $ff);
  944. End;
  945. End;
  946. S_BL:
  947. Begin
  948. If (TRegister(Pai386(p)^.op1) = Reg32ToReg8(TRegister(Pai386(p)^.op2))) And
  949. Not(CS_LittleSize in aktglobalswitches)
  950. Then
  951. {Change "movzbl %al, %eax" to "andl $0x0ffh, %eax"}
  952. Begin
  953. Pai386(p)^._operator := A_AND;
  954. Pai386(p)^.opxt := top_const+Top_reg shl 4;
  955. Longint(Pai386(p)^.op1) := $ff;
  956. Pai386(p)^.Size := S_L;
  957. End
  958. Else
  959. If GetNextInstruction(p, hp1) And
  960. (Pai(hp1)^.typ = ait_instruction) And
  961. (Pai386(hp1)^._operator = A_AND) And
  962. (Pai386(hp1)^.op1t = top_const) And
  963. (Pai386(hp1)^.op2t = top_reg) And
  964. (Pai386(hp1)^.op2 = Pai386(p)^.op2)
  965. Then
  966. {Change "movzbl %reg1, %reg2; andl $const, %reg2"
  967. to "movl %reg1, reg2; andl $(const1 and $ff), %reg2"}
  968. Begin
  969. Pai386(p)^._operator := A_MOV;
  970. Pai386(p)^.Size := S_L;
  971. Pai386(p)^.op1 := Pointer(Reg8ToReg32(TRegister(Pai386(p)^.op1)));
  972. Pai386(hp1)^.op1 := Pointer(Longint(Pai386(hp1)^.op1) And $ff);
  973. End
  974. End;
  975. S_WL:
  976. Begin
  977. If (TRegister(Pai386(p)^.op1) = Reg32ToReg16(TRegister(Pai386(p)^.op2))) And
  978. Not(CS_LittleSize In aktglobalswitches)
  979. Then
  980. {Change "movzwl %ax, %eax" to "andl $0x0ffffh, %eax"}
  981. Begin
  982. Pai386(p)^._operator := A_AND;
  983. Pai386(p)^.opxt := top_const+Top_reg shl 4;
  984. Longint(Pai386(p)^.op1) := $ffff;
  985. Pai386(p)^.Size := S_L
  986. End
  987. Else
  988. If GetNextInstruction(p, hp1) And
  989. (Pai(hp1)^.typ = ait_instruction) And
  990. (Pai386(hp1)^._operator = A_AND) And
  991. (Pai386(hp1)^.op1t = top_const) And
  992. (Pai386(hp1)^.op2t = top_reg) And
  993. (Pai386(hp1)^.op2 = Pai386(p)^.op2)
  994. Then
  995. {Change "movzwl %reg1, %reg2; andl $const, %reg2"
  996. to "movl %reg1, reg2; andl $(const1 and $ffff), %reg2"}
  997. Begin
  998. Pai386(p)^._operator := A_MOV;
  999. Pai386(p)^.Size := S_L;
  1000. Pai386(p)^.op1 := Pointer(Reg16ToReg32(TRegister(Pai386(p)^.op1)));
  1001. Pai386(hp1)^.op1 := Pointer(Longint(Pai386(hp1)^.op1) And $ffff);
  1002. End;
  1003. End;
  1004. End
  1005. Else
  1006. If (Pai386(p)^.op1t = top_ref) Then
  1007. Begin
  1008. If GetNextInstruction(p, hp1) And
  1009. (Pai(hp1)^.typ = ait_instruction) And
  1010. (Pai386(hp1)^._operator = A_AND) And
  1011. (Pai386(hp1)^.op1t = Top_Const) And
  1012. (Pai386(hp1)^.op2t = Top_Reg) And
  1013. (Pai386(hp1)^.op2 = Pai386(p)^.op2) Then
  1014. Begin
  1015. Pai386(p)^._operator := A_MOV;
  1016. Case Pai386(p)^.Size Of
  1017. S_BL:
  1018. Begin
  1019. Pai386(p)^.Size := S_L;
  1020. Pai386(hp1)^.op1 := Pointer(Longint(Pai386(hp1)^.op1)
  1021. And $ff);
  1022. End;
  1023. S_WL:
  1024. Begin
  1025. Pai386(p)^.Size := S_L;
  1026. Pai386(hp1)^.op1 := Pointer(Longint(Pai386(hp1)^.op1)
  1027. And $ffff);
  1028. End;
  1029. S_BW:
  1030. Begin
  1031. Pai386(p)^.Size := S_W;
  1032. Pai386(hp1)^.op1 := Pointer(Longint(Pai386(hp1)^.op1)
  1033. And $ff);
  1034. End;
  1035. End;
  1036. End;
  1037. End;
  1038. End;
  1039. A_POP:
  1040. Begin
  1041. if (Pai386(p)^.op1t = top_reg) And
  1042. GetNextInstruction(p, hp1) And
  1043. (pai(hp1)^.typ=ait_instruction) and
  1044. (Pai386(hp1)^._operator=A_PUSH) and
  1045. (Pai386(hp1)^.op1t = top_reg) And
  1046. (Pai386(hp1)^.op1=Pai386(p)^.op1) then
  1047. If (Not(cs_regalloc in aktglobalswitches)) Then
  1048. Begin
  1049. hp2:=pai(hp1^.next);
  1050. asml^.remove(p);
  1051. asml^.remove(hp1);
  1052. dispose(p,done);
  1053. dispose(hp1,done);
  1054. p:=hp2;
  1055. continue
  1056. End
  1057. Else
  1058. Begin
  1059. Pai386(p)^._operator := A_MOV;
  1060. Pai386(p)^.op2 := Pai386(p)^.op1;
  1061. Pai386(p)^.opxt := top_ref + top_reg shl 4;
  1062. New(TmpRef);
  1063. TmpRef^.segment := R_DEFAULT_SEG;
  1064. TmpRef^.base := R_ESP;
  1065. TmpRef^.index := R_NO;
  1066. TmpRef^.scalefactor := 1;
  1067. TmpRef^.symbol := nil;
  1068. TmpRef^.isintvalue := false;
  1069. TmpRef^.offset := 0;
  1070. Pai386(p)^.op1 := Pointer(TmpRef);
  1071. hp1 := Pai(p^.next);
  1072. AsmL^.Remove(hp1);
  1073. Dispose(hp1, Done)
  1074. End
  1075. end;
  1076. A_PUSH:
  1077. Begin
  1078. If (Pai386(p)^.size = S_W) And
  1079. (Pai386(p)^.op1t = Top_Const) And
  1080. GetNextInstruction(p, hp1) And
  1081. (Pai(hp1)^.typ = ait_instruction) And
  1082. (Pai386(hp1)^._operator = A_PUSH) And
  1083. (Pai386(hp1)^.op1t = Top_Const) And
  1084. (Pai386(hp1)^.size = S_W) Then
  1085. Begin
  1086. Pai386(p)^.Size := S_L;
  1087. Pai386(p)^.op1 := Pointer(Longint(Pai386(p)^.op1) shl 16 + Longint(Pai386(hp1)^.op1));
  1088. AsmL^.Remove(hp1);
  1089. Dispose(hp1, Done)
  1090. End;
  1091. End;
  1092. A_SHL, A_SAL:
  1093. Begin
  1094. If (Pai386(p)^.op1t = Top_Const) And
  1095. (Pai386(p)^.op2t = Top_Reg) And
  1096. (Pai386(p)^.Size = S_L) And
  1097. (Longint(Pai386(p)^.op1) <= 3)
  1098. {Changes "shl const, %reg32; add const/reg, %reg32" to one lea statement}
  1099. Then
  1100. Begin
  1101. TmpBool1 := True; {should we check the next instruction?}
  1102. TmpBool2 := False; {have we found an add/sub which could be
  1103. integrated in the lea?}
  1104. New(TmpRef);
  1105. TmpRef^.segment := R_DEFAULT_SEG;
  1106. TmpRef^.base := R_NO;
  1107. TmpRef^.index := TRegister(Pai386(p)^.op2);
  1108. TmpRef^.scalefactor := 1 shl Longint(Pai386(p)^.op1);
  1109. TmpRef^.symbol := nil;
  1110. TmpRef^.isintvalue := false;
  1111. TmpRef^.offset := 0;
  1112. While TmpBool1 And
  1113. GetNextInstruction(p, hp1) And
  1114. (Pai(hp1)^.typ = ait_instruction) And
  1115. ((Pai386(hp1)^._operator = A_ADD) Or
  1116. (Pai386(hp1)^._operator = A_SUB)) And
  1117. (Pai386(hp1)^.op2t = Top_Reg) And
  1118. (Pai386(hp1)^.op2 = Pai386(p)^.op2) Do
  1119. Begin
  1120. TmpBool1 := False;
  1121. If (Pai386(hp1)^.op1t = Top_Const)
  1122. Then
  1123. Begin
  1124. TmpBool1 := True;
  1125. TmpBool2 := True;
  1126. If Pai386(hp1)^._operator = A_ADD
  1127. Then Inc(TmpRef^.offset, Longint(Pai386(hp1)^.op1))
  1128. Else Dec(TmpRef^.offset, Longint(Pai386(hp1)^.op1));
  1129. AsmL^.Remove(hp1);
  1130. Dispose(hp1, Done);
  1131. End
  1132. Else
  1133. If (Pai386(hp1)^.op1t = Top_Reg) And
  1134. (Pai386(hp1)^._operator = A_ADD) And
  1135. (TmpRef^.base = R_NO) Then
  1136. Begin
  1137. TmpBool1 := True;
  1138. TmpBool2 := True;
  1139. TmpRef^.base := TRegister(Pai386(hp1)^.op1);
  1140. AsmL^.Remove(hp1);
  1141. Dispose(hp1, Done);
  1142. End;
  1143. End;
  1144. If TmpBool2 Or
  1145. ((aktoptprocessor < ClassP6) And
  1146. (Longint(Pai386(p)^.op1) <= 3) And
  1147. Not(CS_LittleSize in aktglobalswitches))
  1148. Then
  1149. Begin
  1150. If Not(TmpBool2) And
  1151. (Longint(Pai386(p)^.op1) = 1)
  1152. Then
  1153. Begin
  1154. Dispose(TmpRef);
  1155. hp1 := new(Pai386,op_reg_reg(A_ADD,Pai386(p)^.Size,
  1156. TRegister(Pai386(p)^.op2), TRegister(Pai386(p)^.op2)))
  1157. End
  1158. Else hp1 := New(Pai386, op_ref_reg(A_LEA, S_L, TmpRef,
  1159. TRegister(Pai386(p)^.op2)));
  1160. hp1^.fileinfo := p^.fileinfo;
  1161. InsertLLItem(AsmL,p^.previous, p^.next, hp1);
  1162. Dispose(p, Done);
  1163. p := hp1;
  1164. End;
  1165. End
  1166. Else
  1167. If (aktoptprocessor < ClassP6) And
  1168. (Pai386(p)^.op1t = top_const) And
  1169. (Pai386(p)^.op2t = top_reg) Then
  1170. If (Longint(Pai386(p)^.op1) = 1)
  1171. Then
  1172. {changes "shl $1, %reg" to "add %reg, %reg", which is the same on a 386,
  1173. but faster on a 486, and pairable in both U and V pipes on the Pentium
  1174. (unlike shl, which is only pairable in the U pipe)}
  1175. Begin
  1176. hp1 := new(Pai386,op_reg_reg(A_ADD,Pai386(p)^.Size,
  1177. TRegister(Pai386(p)^.op2), TRegister(Pai386(p)^.op2)));
  1178. hp1^.fileinfo := p^.fileinfo;
  1179. InsertLLItem(AsmL,p^.previous, p^.next, hp1);
  1180. Dispose(p, done);
  1181. p := hp1;
  1182. End
  1183. Else If (Pai386(p)^.size = S_L) and
  1184. (Longint(Pai386(p)^.op1) <= 3) Then
  1185. {changes "shl $2, %reg" to "lea (,%reg,4), %reg"
  1186. "shl $3, %reg" to "lea (,%reg,8), %reg}
  1187. Begin
  1188. New(TmpRef);
  1189. TmpRef^.segment := R_DEFAULT_SEG;
  1190. TmpRef^.base := R_NO;
  1191. TmpRef^.index := TRegister(Pai386(p)^.op2);
  1192. TmpRef^.scalefactor := 1 shl Longint(Pai386(p)^.op1);
  1193. TmpRef^.symbol := nil;
  1194. TmpRef^.isintvalue := false;
  1195. TmpRef^.offset := 0;
  1196. hp1 := new(Pai386,op_ref_reg(A_LEA,S_L,TmpRef, TRegister(Pai386(p)^.op2)));
  1197. hp1^.fileinfo := p^.fileinfo;
  1198. InsertLLItem(AsmL,p^.previous, p^.next, hp1);
  1199. Dispose(p, done);
  1200. p := hp1;
  1201. End
  1202. End;
  1203. A_SAR, A_SHR:
  1204. {changes the code sequence
  1205. shr/sar const1, %reg
  1206. shl const2, %reg
  1207. to either "sar/and", "shl/and" or just "and" depending on const1 and const2}
  1208. Begin
  1209. If GetNextInstruction(p, hp1) And
  1210. (pai(hp1)^.typ = ait_instruction) and
  1211. (Pai386(hp1)^._operator = A_SHL) and
  1212. (Pai386(p)^.op1t = top_const) and
  1213. (Pai386(hp1)^.op1t = top_const)
  1214. Then
  1215. If (Longint(Pai386(p)^.op1) > Longint(Pai386(hp1)^.op1)) And
  1216. (Pai386(p)^.op2t = Top_reg) And
  1217. Not(CS_LittleSize In aktglobalswitches) And
  1218. ((Pai386(p)^.Size = S_B) Or
  1219. (Pai386(p)^.Size = S_L))
  1220. Then
  1221. Begin
  1222. Dec(Longint(Pai386(p)^.op1), Longint(Pai386(hp1)^.op1));
  1223. Pai386(hp1)^._operator := A_And;
  1224. Pai386(hp1)^.op1 := Pointer(1 shl Longint(Pai386(hp1)^.op1)-1);
  1225. If (Pai386(p)^.Size = S_L)
  1226. Then Pai386(hp1)^.op1 := Pointer(Longint(Pai386(hp1)^.op1) Xor $ffffffff)
  1227. Else Pai386(hp1)^.op1 := Pointer(Longint(Pai386(hp1)^.op1) Xor $ff);
  1228. End
  1229. Else
  1230. If (Longint(Pai386(p)^.op1) < Longint(Pai386(hp1)^.op1)) And
  1231. (Pai386(p)^.op2t = Top_reg) And
  1232. Not(CS_LittleSize In aktglobalswitches) And
  1233. ((Pai386(p)^.Size = S_B) Or
  1234. (Pai386(p)^.Size = S_L))
  1235. Then
  1236. Begin
  1237. Dec(Longint(Pai386(hp1)^.op1), Longint(Pai386(p)^.op1));
  1238. Pai386(p)^._operator := A_And;
  1239. Pai386(p)^.op1 := Pointer(1 shl Longint(Pai386(p)^.op1)-1);
  1240. If (Pai386(p)^.Size = S_L)
  1241. Then Pai386(hp1)^.op1 := Pointer(Longint(Pai386(hp1)^.op1) Xor $ffffffff)
  1242. Else Pai386(hp1)^.op1 := Pointer(Longint(Pai386(hp1)^.op1) Xor $ff);
  1243. End
  1244. Else
  1245. Begin
  1246. Pai386(p)^._operator := A_And;
  1247. Pai386(p)^.op1 := Pointer(1 shl Longint(Pai386(p)^.op1)-1);
  1248. Case Pai386(p)^.Size Of
  1249. S_B: Pai386(hp1)^.op1 := Pointer(Longint(Pai386(hp1)^.op1) Xor $ff);
  1250. S_W: Pai386(hp1)^.op1 := Pointer(Longint(Pai386(hp1)^.op1) Xor $ffff);
  1251. S_L: Pai386(hp1)^.op1 := Pointer(Longint(Pai386(hp1)^.op1) Xor
  1252. $ffffffff);
  1253. End;
  1254. AsmL^.remove(hp1);
  1255. dispose(hp1, done);
  1256. End;
  1257. End;
  1258. A_SUB:
  1259. {change "subl $2, %esp; pushw x" to "pushl x"}
  1260. Begin
  1261. If (Pai386(p)^.op1t = top_const) And
  1262. (Longint(Pai386(p)^.op1) = 2) And
  1263. (Pai386(p)^.op2t = top_reg) And
  1264. (TRegister(Pai386(p)^.op2) = R_ESP)
  1265. Then
  1266. Begin
  1267. hp1 := Pai(p^.next);
  1268. While Assigned(hp1) And
  1269. (Pai(hp1)^.typ In [ait_instruction]+SkipInstr) And
  1270. Not((Pai(hp1)^.typ = ait_instruction) And
  1271. ((Pai386(hp1)^._operator in [A_CALL,A_PUSH]) or
  1272. ((Pai386(hp1)^._operator = A_MOV) And
  1273. (Pai386(hp1)^.op2t = top_ref) And
  1274. (TReference(Pai386(hp1)^.op2^).base = R_ESP)))) do
  1275. hp1 := Pai(hp1^.next);
  1276. If Assigned(hp1) And
  1277. (Pai(hp1)^.typ = ait_instruction) And
  1278. (Pai386(hp1)^._operator = A_PUSH) And
  1279. (Pai386(hp1)^.Size = S_W)
  1280. Then
  1281. Begin
  1282. Pai386(hp1)^.size := S_L;
  1283. If (Pai386(hp1)^.op1t = top_reg) Then
  1284. Pai386(hp1)^.op1 := Pointer(Reg16ToReg32(TRegister(Pai386(hp1)^.op1)));
  1285. hp1 := Pai(p^.next);
  1286. AsmL^.Remove(p);
  1287. Dispose(p, Done);
  1288. p := hp1;
  1289. Continue
  1290. End
  1291. Else
  1292. If GetLastInstruction(p, hp1) And
  1293. (Pai(hp1)^.typ = ait_instruction) And
  1294. (Pai386(hp1)^._operator = A_SUB) And
  1295. (Pai386(hp1)^.op1t = top_const) And
  1296. (Pai386(hp1)^.op2t = top_reg) And
  1297. (TRegister(Pai386(hp1)^.Op2) = R_ESP)
  1298. Then
  1299. Begin
  1300. Inc(Longint(Pai386(p)^.op1), Longint(Pai386(hp1)^.op1));
  1301. AsmL^.Remove(hp1);
  1302. Dispose(hp1, Done);
  1303. End;
  1304. End;
  1305. End;
  1306. A_TEST, A_OR:
  1307. {removes the line marked with (x) from the sequence
  1308. And/or/xor/add/sub/... $x, %y
  1309. test/or %y, %y (x)
  1310. j(n)z _Label
  1311. as the first instruction already adjusts the ZF}
  1312. Begin
  1313. If (Pai386(p)^.op1 = Pai386(p)^.op2) And
  1314. GetLastInstruction(p, hp1) And
  1315. (pai(hp1)^.typ = ait_instruction) Then
  1316. Case Pai386(hp1)^._operator Of
  1317. A_ADD, A_SUB, A_OR, A_XOR, A_AND, A_SHL, A_SHR:
  1318. Begin
  1319. If (Pai386(hp1)^.op2 = Pai386(p)^.op1) Then
  1320. Begin
  1321. hp1 := pai(p^.next);
  1322. asml^.remove(p);
  1323. dispose(p, done);
  1324. p := pai(hp1);
  1325. continue
  1326. End;
  1327. End;
  1328. A_DEC, A_INC, A_NEG:
  1329. Begin
  1330. If (Pai386(hp1)^.op1 = Pai386(p)^.op1) Then
  1331. Begin
  1332. hp1 := pai(p^.next);
  1333. asml^.remove(p);
  1334. dispose(p, done);
  1335. p := pai(hp1);
  1336. continue
  1337. End;
  1338. End
  1339. End;
  1340. End;
  1341. End;
  1342. End;
  1343. { ait_label:
  1344. Begin
  1345. If Not(Pai_Label(p)^.l^.is_used)
  1346. Then
  1347. Begin
  1348. hp1 := Pai(p^.next);
  1349. AsmL^.Remove(p);
  1350. Dispose(p, Done);
  1351. p := hp1;
  1352. Continue
  1353. End;
  1354. End;}
  1355. End;
  1356. p:=pai(p^.next);
  1357. end;
  1358. end;
  1359. Procedure PeepHoleOptPass2(AsmL: PAasmOutput);
  1360. var
  1361. p,hp1 : pai;
  1362. Begin
  1363. P := Pai(AsmL^.First);
  1364. While Assigned(p) Do
  1365. Begin
  1366. Case P^.Typ Of
  1367. Ait_Instruction:
  1368. Begin
  1369. Case Pai386(p)^._operator Of
  1370. A_MOV:
  1371. Begin
  1372. If (Pai386(p)^.op1t = top_reg) And
  1373. (Pai386(p)^.op2t = top_reg) And
  1374. GetNextInstruction(p, hp1) And
  1375. (hp1^.typ = ait_Instruction) And
  1376. (Pai386(hp1)^._operator = A_MOV) And
  1377. (Pai386(hp1)^.op1t = top_ref) And
  1378. (Pai386(hp1)^.op2t = top_reg) And
  1379. ((TReference(Pai386(hp1)^.op1^).Base = TRegister(Pai386(p)^.op2)) Or
  1380. (TReference(Pai386(hp1)^.op1^).Index = TRegister(Pai386(p)^.op2))) And
  1381. (TRegister(Pai386(hp1)^.op2) = TRegister(Pai386(p)^.op2)) Then
  1382. {mov reg1, reg2
  1383. mov (reg2, ..), reg2 to mov (reg1, ..), reg2}
  1384. Begin
  1385. If (TReference(Pai386(hp1)^.op1^).Base = TRegister(Pai386(p)^.op2)) Then
  1386. TReference(Pai386(hp1)^.op1^).Base := TRegister(Pai386(p)^.op1);
  1387. If (TReference(Pai386(hp1)^.op1^).Index = TRegister(Pai386(p)^.op2)) Then
  1388. TReference(Pai386(hp1)^.op1^).Index := TRegister(Pai386(p)^.op1);
  1389. AsmL^.Remove(p);
  1390. Dispose(p, Done);
  1391. p := hp1;
  1392. Continue;
  1393. End;
  1394. End;
  1395. A_MOVZX:
  1396. Begin
  1397. If (Pai386(p)^.op2t = top_reg) Then
  1398. If (Pai386(p)^.op1t = top_reg)
  1399. Then
  1400. Case Pai386(p)^.size of
  1401. S_BL:
  1402. Begin
  1403. If IsGP32Reg(TRegister(Pai386(p)^.op2)) And
  1404. Not(CS_LittleSize in aktglobalswitches) And
  1405. (aktoptprocessor = ClassP5)
  1406. Then
  1407. {Change "movzbl %reg1, %reg2" to
  1408. "xorl %reg2, %reg2; movb %reg1, %reg2" for Pentium and
  1409. PentiumMMX}
  1410. Begin
  1411. hp1 := New(Pai386, op_reg_reg(A_XOR, S_L,
  1412. TRegister(Pai386(p)^.op2), TRegister(Pai386(p)^.op2)));
  1413. hp1^.fileinfo := p^.fileinfo;
  1414. InsertLLItem(AsmL,p^.previous, p, hp1);
  1415. Pai386(p)^._operator := A_MOV;
  1416. Pai386(p)^.size := S_B;
  1417. Pai386(p)^.op2 :=
  1418. Pointer(Reg32ToReg8(TRegister(Pai386(p)^.op2)));
  1419. { Jonas
  1420. InsertLLItem(AsmL,p, p^.next, hp2);
  1421. I think you forgot to delete this line PM
  1422. Indeed, I had forgotten that one (JM) }
  1423. End;
  1424. End;
  1425. End
  1426. Else
  1427. If (Pai386(p)^.op1t = top_ref) And
  1428. (PReference(Pai386(p)^.op1)^.base <> TRegister(Pai386(p)^.op2)) And
  1429. (PReference(Pai386(p)^.op1)^.index <> TRegister(Pai386(p)^.op2)) And
  1430. Not(CS_LittleSize in aktglobalswitches) And
  1431. IsGP32Reg(TRegister(Pai386(p)^.op2)) And
  1432. (aktoptprocessor = ClassP5) And
  1433. (Pai386(p)^.Size = S_BL)
  1434. Then
  1435. {changes "movzbl mem, %reg" to "xorl %reg, %reg; movb mem, %reg8" for
  1436. Pentium and PentiumMMX}
  1437. Begin
  1438. hp1 := New(Pai386,op_reg_reg(A_XOR, S_L, TRegister(Pai386(p)^.op2),
  1439. TRegister(Pai386(p)^.op2)));
  1440. hp1^.fileinfo := p^.fileinfo;
  1441. Pai386(p)^._operator := A_MOV;
  1442. Pai386(p)^.size := S_B;
  1443. Pai386(p)^.op2 := Pointer(Reg32ToReg8(TRegister(Pai386(p)^.op2)));
  1444. InsertLLItem(AsmL,p^.previous, p, hp1);
  1445. End;
  1446. End;
  1447. End;
  1448. End;
  1449. End;
  1450. p := Pai(p^.next)
  1451. End;
  1452. End;
  1453. End.
  1454. {
  1455. $Log$
  1456. Revision 1.19 1998-10-23 15:38:23 jonas
  1457. + some small FPU peephole optimizations (use value in FP regs instead of loading it
  1458. from memory if possible, mostly with var1+var1 and var1*var1)
  1459. Revision 1.18 1998/10/05 14:41:14 jonas
  1460. * fixed small memory leak
  1461. * fixed small inefficiency
  1462. * tested multiple line comments ability of my new MacCVS client :)
  1463. Revision 1.17 1998/10/02 17:29:56 jonas
  1464. + removal of "lea (reg), reg)", "imul $1, reg", change "mov reg1, reg2; mov (reg2), reg2" to "mov (reg1), reg2"
  1465. Revision 1.16 1998/10/01 20:19:57 jonas
  1466. * moved UpdateUsedRegs (+ bugfix) to daopt386
  1467. Revision 1.15 1998/09/30 12:18:29 peter
  1468. * fixed subl $2,esp;psuhw bug
  1469. Revision 1.14 1998/09/20 17:11:51 jonas
  1470. * released REGALLOC
  1471. Revision 1.13 1998/09/16 18:00:00 jonas
  1472. * optimizer now completely dependant on GetNext/GetLast instruction, works again with -dRegAlloc
  1473. Revision 1.12 1998/09/15 14:05:22 jonas
  1474. * fixed optimizer incompatibilities with freelabel code in psub
  1475. Revision 1.11 1998/08/28 10:57:02 peter
  1476. * removed warnings
  1477. Revision 1.10 1998/08/27 15:17:50 florian
  1478. * reinstated Jonas' bugfix
  1479. Revision 1.9 1998/08/25 16:58:59 pierre
  1480. * removed a line that add no sense and
  1481. introduce garbage in the asmlist
  1482. (uninitialized data !)
  1483. Revision 1.7 1998/08/19 16:07:53 jonas
  1484. * changed optimizer switches + cleanup of DestroyRefs in daopt386.pas
  1485. Revision 1.6 1998/08/10 14:50:14 peter
  1486. + localswitches, moduleswitches, globalswitches splitting
  1487. Revision 1.5 1998/08/06 19:40:28 jonas
  1488. * removed $ before and after Log in comment
  1489. Revision 1.4 1998/08/05 16:27:17 jonas
  1490. * fstp/fld bugfix (fstt does not exist)
  1491. Revision 1.3 1998/08/05 16:00:15 florian
  1492. * some fixes for ansi strings
  1493. * log to Log changed
  1494. }