aoptcpurv.pas 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. {
  2. Copyright (c) 1998-2002 by Jonas Maebe, member of the Free Pascal
  3. Development Team
  4. This unit implements the common RiscV 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 aoptcpurv;
  19. interface
  20. {$I fpcdefs.inc}
  21. { $define DEBUG_AOPTCPU}
  22. uses
  23. cpubase,
  24. globals, globtype,
  25. cgbase,
  26. aoptobj, aoptcpub, aopt,
  27. aasmtai, aasmcpu;
  28. type
  29. TRVCpuAsmOptimizer = class(TAsmOptimizer)
  30. function InstructionLoadsFromReg(const reg: TRegister; const hp: tai): boolean; override;
  31. function RegLoadedWithNewValue(reg: tregister; hp: tai): boolean; override;
  32. function RegModifiedByInstruction(Reg: TRegister; p1: tai): boolean; override;
  33. Function GetNextInstructionUsingReg(Current: tai; Out Next: tai; reg: TRegister): Boolean;
  34. { outputs a debug message into the assembler file }
  35. procedure DebugMsg(const s: string; p: tai);
  36. function PeepHoleOptPass1Cpu(var p: tai): boolean; override;
  37. function OptPass1OP(var p: tai): boolean;
  38. function OptPass1Add(var p: tai): boolean;
  39. procedure RemoveInstr(var orig: tai; moveback: boolean=true);
  40. end;
  41. implementation
  42. uses
  43. cutils;
  44. function MatchInstruction(const instr: tai; const op: TCommonAsmOps; const AConditions: TAsmConds = []): boolean;
  45. begin
  46. result :=
  47. (instr.typ = ait_instruction) and
  48. (taicpu(instr).opcode in op) and
  49. ((AConditions=[]) or (taicpu(instr).condition in AConditions));
  50. end;
  51. function MatchInstruction(const instr: tai; const op: TAsmOp; const AConditions: TAsmConds = []): boolean;
  52. begin
  53. result :=
  54. (instr.typ = ait_instruction) and
  55. (taicpu(instr).opcode = op) and
  56. ((AConditions=[]) or (taicpu(instr).condition in AConditions));
  57. end;
  58. function MatchOperand(const oper1: TOper; const oper2: TOper): boolean; inline;
  59. begin
  60. result := oper1.typ = oper2.typ;
  61. if result then
  62. case oper1.typ of
  63. top_const:
  64. Result:=oper1.val = oper2.val;
  65. top_reg:
  66. Result:=oper1.reg = oper2.reg;
  67. {top_ref:
  68. Result:=RefsEqual(oper1.ref^, oper2.ref^);}
  69. else Result:=false;
  70. end
  71. end;
  72. function MatchOperand(const oper: TOper; const reg: TRegister): boolean; inline;
  73. begin
  74. result := (oper.typ = top_reg) and (oper.reg = reg);
  75. end;
  76. {$ifdef DEBUG_AOPTCPU}
  77. procedure TRVCpuAsmOptimizer.DebugMsg(const s: string;p : tai);
  78. begin
  79. asml.insertbefore(tai_comment.Create(strpnew(s)), p);
  80. end;
  81. {$else DEBUG_AOPTCPU}
  82. procedure TRVCpuAsmOptimizer.DebugMsg(const s: string;p : tai);inline;
  83. begin
  84. end;
  85. {$endif DEBUG_AOPTCPU}
  86. function TRVCpuAsmOptimizer.InstructionLoadsFromReg(const reg: TRegister; const hp: tai): boolean;
  87. var
  88. p: taicpu;
  89. i: longint;
  90. begin
  91. result:=false;
  92. if not (assigned(hp) and (hp.typ=ait_instruction)) then
  93. exit;
  94. p:=taicpu(hp);
  95. i:=0;
  96. while(i<p.ops) do
  97. begin
  98. case p.oper[I]^.typ of
  99. top_reg:
  100. result:=(p.oper[I]^.reg=reg) and (p.spilling_get_operation_type(i)<>operand_write);
  101. top_ref:
  102. result:=
  103. (p.oper[I]^.ref^.base=reg);
  104. else
  105. ;
  106. end;
  107. if result then exit; {Bailout if we found something}
  108. Inc(I);
  109. end;
  110. end;
  111. function TRVCpuAsmOptimizer.RegLoadedWithNewValue(reg: tregister; hp: tai): boolean;
  112. begin
  113. result:=
  114. (hp.typ=ait_instruction) and
  115. (taicpu(hp).ops>1) and
  116. (taicpu(hp).oper[0]^.typ=top_reg) and
  117. (taicpu(hp).oper[0]^.reg=reg) and
  118. (taicpu(hp).spilling_get_operation_type(0)<>operand_read);
  119. end;
  120. function TRVCpuAsmOptimizer.RegModifiedByInstruction(Reg: TRegister; p1: tai): boolean;
  121. var
  122. i : Longint;
  123. begin
  124. result:=false;
  125. for i:=0 to taicpu(p1).ops-1 do
  126. case taicpu(p1).oper[i]^.typ of
  127. top_reg:
  128. if (taicpu(p1).oper[i]^.reg=Reg) and (taicpu(p1).spilling_get_operation_type(i) in [operand_write,operand_readwrite]) then
  129. exit(true);
  130. else
  131. ;
  132. end;
  133. end;
  134. function TRVCpuAsmOptimizer.GetNextInstructionUsingReg(Current: tai; out Next: tai; reg: TRegister): Boolean;
  135. begin
  136. Next:=Current;
  137. repeat
  138. Result:=GetNextInstruction(Next,Next);
  139. until not (Result) or
  140. not(cs_opt_level3 in current_settings.optimizerswitches) or
  141. (Next.typ<>ait_instruction) or
  142. RegInInstruction(reg,Next) or
  143. is_calljmp(taicpu(Next).opcode);
  144. end;
  145. function TRVCpuAsmOptimizer.OptPass1OP(var p : tai) : boolean;
  146. var
  147. hp1 : tai;
  148. begin
  149. result:=false;
  150. { replace
  151. <Op> %reg3,%reg2,%reg1
  152. addi %reg4,%reg3,0
  153. dealloc %reg3
  154. by
  155. <Op> %reg4,%reg2,%reg1
  156. ?
  157. }
  158. if GetNextInstruction(p,hp1) and
  159. MatchInstruction(hp1,A_ADDI) and
  160. (taicpu(hp1).oper[2]^.val=0) and
  161. MatchOperand(taicpu(p).oper[0]^,taicpu(hp1).oper[1]^) then
  162. begin
  163. TransferUsedRegs(TmpUsedRegs);
  164. UpdateUsedRegs(TmpUsedRegs, tai(p.next));
  165. if not(RegUsedAfterInstruction(taicpu(hp1).oper[1]^.reg,hp1,TmpUsedRegs)) then
  166. begin
  167. taicpu(p).loadoper(0,taicpu(hp1).oper[0]^);
  168. DebugMsg('Peephole OpAddi02Op done',p);
  169. RemoveInstruction(hp1);
  170. result:=true;
  171. end;
  172. end;
  173. end;
  174. procedure TRVCpuAsmOptimizer.RemoveInstr(var orig: tai; moveback: boolean = true);
  175. var
  176. n: tai;
  177. begin
  178. if moveback and (not GetLastInstruction(orig,n)) then
  179. GetNextInstruction(orig,n);
  180. AsmL.Remove(orig);
  181. orig.Free;
  182. orig:=n;
  183. end;
  184. function TRVCpuAsmOptimizer.OptPass1Add(var p: tai): boolean;
  185. var
  186. hp1: tai;
  187. begin
  188. result:=false;
  189. {
  190. Changes
  191. addi x, y, #
  192. addi/addiw z, x, #
  193. dealloc x
  194. To
  195. addi z, y, #+#
  196. }
  197. if (taicpu(p).ops=3) and
  198. (taicpu(p).oper[2]^.typ=top_const) and
  199. GetNextInstructionUsingReg(p, hp1, taicpu(p).oper[0]^.reg) and
  200. MatchInstruction(hp1,[A_ADDI{$ifdef riscv64},A_ADDIW{$endif}]) and
  201. (taicpu(hp1).ops=3) and
  202. MatchOperand(taicpu(p).oper[0]^,taicpu(hp1).oper[1]^) and
  203. (taicpu(hp1).oper[2]^.typ=top_const) and
  204. is_imm12(taicpu(p).oper[2]^.val+taicpu(hp1).oper[2]^.val) and
  205. (not RegModifiedBetween(taicpu(p).oper[1]^.reg, p,hp1)) and
  206. RegEndOfLife(taicpu(p).oper[0]^.reg, taicpu(hp1)) then
  207. begin
  208. taicpu(hp1).loadreg(1,taicpu(p).oper[1]^.reg);
  209. taicpu(hp1).loadconst(2, taicpu(p).oper[2]^.val+taicpu(hp1).oper[2]^.val);
  210. DebugMsg('Peephole AddiAddi2Addi performed', hp1);
  211. RemoveInstr(p);
  212. result:=true;
  213. end
  214. {
  215. Changes
  216. addi x, z, (ref)
  217. ld/sd y, 0(x)
  218. dealloc x
  219. To
  220. ld/sd y, 0(ref)(x)
  221. }
  222. else if (taicpu(p).ops=3) and
  223. (taicpu(p).oper[2]^.typ=top_ref) and
  224. MatchOperand(taicpu(p).oper[0]^,taicpu(p).oper[1]^) and
  225. GetNextInstructionUsingReg(p, hp1, taicpu(p).oper[0]^.reg) and
  226. MatchInstruction(hp1, [A_LB,A_LBU,A_LH,A_LHU,A_LW,
  227. A_SB,A_SH,A_SW{$ifdef riscv64},A_LD,A_LWU,A_SD{$endif}]) and
  228. (taicpu(hp1).ops=2) and
  229. (taicpu(hp1).oper[1]^.typ=top_ref) and
  230. (taicpu(hp1).oper[1]^.ref^.base=taicpu(p).oper[0]^.reg) and
  231. (taicpu(hp1).oper[1]^.ref^.offset=0) and
  232. (not RegModifiedBetween(taicpu(p).oper[1]^.reg, p,hp1)) and
  233. RegEndOfLife(taicpu(p).oper[0]^.reg, taicpu(hp1)) then
  234. begin
  235. taicpu(hp1).loadref(1,taicpu(p).oper[2]^.ref^);
  236. taicpu(hp1).oper[1]^.ref^.base:=taicpu(p).oper[1]^.reg;
  237. DebugMsg('Peephole AddiMem2Mem performed', hp1);
  238. RemoveInstr(p);
  239. result:=true;
  240. end
  241. {
  242. Changes
  243. addi x, z, #w
  244. ld/sd y, 0(x)
  245. dealloc x
  246. To
  247. ld/sd y, #w(z)
  248. }
  249. else if (taicpu(p).ops=3) and
  250. (taicpu(p).oper[2]^.typ=top_const) and
  251. //MatchOperand(taicpu(p).oper[0]^,taicpu(p).oper[1]^) and
  252. GetNextInstructionUsingReg(p, hp1, taicpu(p).oper[0]^.reg) and
  253. MatchInstruction(hp1, [A_LB,A_LBU,A_LH,A_LHU,A_LW,
  254. A_SB,A_SH,A_SW{$ifdef riscv64},A_LWU,A_LD,A_SD{$endif}]) and
  255. (taicpu(hp1).ops=2) and
  256. (taicpu(hp1).oper[1]^.typ=top_ref) and
  257. (taicpu(hp1).oper[1]^.ref^.base=taicpu(p).oper[0]^.reg) and
  258. (taicpu(hp1).oper[1]^.ref^.offset=0) and
  259. (not RegModifiedBetween(taicpu(p).oper[1]^.reg, p,hp1)) and
  260. RegEndOfLife(taicpu(p).oper[0]^.reg, taicpu(hp1)) then
  261. begin
  262. //taicpu(hp1).loadconst(1,taicpu(p).oper[2]^.ref^);
  263. taicpu(hp1).oper[1]^.ref^.offset:=taicpu(p).oper[2]^.val;
  264. taicpu(hp1).oper[1]^.ref^.base:=taicpu(p).oper[1]^.reg;
  265. DebugMsg('Peephole AddiMem2Mem performed', hp1);
  266. RemoveInstr(p);
  267. result:=true;
  268. end
  269. else
  270. result:=OptPass1OP(p);
  271. end;
  272. function TRVCpuAsmOptimizer.PeepHoleOptPass1Cpu(var p: tai): boolean;
  273. var
  274. hp1: tai;
  275. begin
  276. result:=false;
  277. case p.typ of
  278. ait_instruction:
  279. begin
  280. case taicpu(p).opcode of
  281. A_ADDI:
  282. result:=OptPass1Add(p);
  283. A_SUB:
  284. begin
  285. {
  286. Turn
  287. sub x,y,z
  288. bgeu X0,x,...
  289. dealloc x
  290. Into
  291. bne y,x,...
  292. }
  293. if (taicpu(p).ops=3) and
  294. GetNextInstructionUsingReg(p, hp1, taicpu(p).oper[0]^.reg) and
  295. MatchInstruction(hp1,A_Bxx,[C_GEU,C_EQ]) and
  296. (taicpu(hp1).ops=3) and
  297. MatchOperand(taicpu(hp1).oper[0]^,NR_X0) and
  298. MatchOperand(taicpu(hp1).oper[1]^,taicpu(p).oper[0]^) and
  299. (not RegModifiedBetween(taicpu(p).oper[1]^.reg, p,hp1)) and
  300. (not RegModifiedBetween(taicpu(p).oper[2]^.reg, p,hp1)) and
  301. RegEndOfLife(taicpu(p).oper[0]^.reg, taicpu(hp1)) then
  302. begin
  303. taicpu(hp1).loadreg(0,taicpu(p).oper[1]^.reg);
  304. taicpu(hp1).loadreg(1,taicpu(p).oper[2]^.reg);
  305. taicpu(hp1).condition:=C_EQ;
  306. DebugMsg('Peephole SubBxx2Beq performed', hp1);
  307. RemoveInstr(p);
  308. result:=true;
  309. end
  310. else
  311. result:=OptPass1OP(p);
  312. end;
  313. A_ANDI:
  314. begin
  315. {
  316. Changes
  317. andi x, y, #
  318. andi z, x, #
  319. dealloc x
  320. To
  321. andi z, y, # and #
  322. }
  323. if (taicpu(p).ops=3) and
  324. (taicpu(p).oper[2]^.typ=top_const) and
  325. GetNextInstructionUsingReg(p, hp1, taicpu(p).oper[0]^.reg) and
  326. MatchInstruction(hp1,A_ANDI) and
  327. (taicpu(hp1).ops=3) and
  328. MatchOperand(taicpu(p).oper[0]^,taicpu(hp1).oper[1]^) and
  329. (taicpu(hp1).oper[2]^.typ=top_const) and
  330. is_imm12(taicpu(p).oper[2]^.val+taicpu(hp1).oper[2]^.val) and
  331. (not RegModifiedBetween(taicpu(p).oper[1]^.reg, p,hp1)) and
  332. RegEndOfLife(taicpu(p).oper[0]^.reg, taicpu(hp1)) then
  333. begin
  334. taicpu(hp1).loadreg(1,taicpu(p).oper[1]^.reg);
  335. taicpu(hp1).loadconst(2, taicpu(p).oper[2]^.val and taicpu(hp1).oper[2]^.val);
  336. DebugMsg('Peephole AndiAndi2Andi performed', hp1);
  337. RemoveInstr(p);
  338. result:=true;
  339. end
  340. else
  341. result:=OptPass1OP(p);
  342. end;
  343. A_SLT,
  344. A_SLTU:
  345. begin
  346. {
  347. Turn
  348. sltu x,X0,y
  349. beq/bne x, X0, ...
  350. dealloc x
  351. Into
  352. bltu/geu X0, y, ...
  353. }
  354. if (taicpu(p).ops=3) and
  355. MatchOperand(taicpu(p).oper[1]^,NR_X0) and
  356. GetNextInstructionUsingReg(p, hp1, taicpu(p).oper[0]^.reg) and
  357. MatchInstruction(hp1,A_Bxx,[C_NE,C_EQ]) and
  358. (taicpu(hp1).ops=3) and
  359. MatchOperand(taicpu(hp1).oper[0]^,taicpu(p).oper[0]^) and
  360. MatchOperand(taicpu(hp1).oper[1]^,NR_X0) and
  361. (not RegModifiedBetween(taicpu(p).oper[2]^.reg, p,hp1)) and
  362. RegEndOfLife(taicpu(p).oper[0]^.reg, taicpu(hp1)) then
  363. begin
  364. taicpu(hp1).loadreg(0,NR_X0);
  365. taicpu(hp1).loadreg(1,taicpu(p).oper[2]^.reg);
  366. if taicpu(p).opcode=A_SLTU then
  367. begin
  368. if taicpu(hp1).condition=C_NE then
  369. taicpu(hp1).condition:=C_LTU
  370. else
  371. taicpu(hp1).condition:=C_GEU;
  372. end
  373. else
  374. begin
  375. if taicpu(hp1).condition=C_NE then
  376. taicpu(hp1).condition:=C_LT
  377. else
  378. taicpu(hp1).condition:=C_GE;
  379. end;
  380. DebugMsg('Peephole SltuB2B performed', hp1);
  381. RemoveInstr(p);
  382. result:=true;
  383. end
  384. {
  385. Turn
  386. sltu x,y,z
  387. beq/bne x, X0, ...
  388. dealloc x
  389. Into
  390. bltu/geu y, z, ...
  391. }
  392. else if (taicpu(p).ops=3) and
  393. GetNextInstructionUsingReg(p, hp1, taicpu(p).oper[0]^.reg) and
  394. MatchInstruction(hp1,A_Bxx,[C_NE,C_EQ]) and
  395. (taicpu(hp1).ops=3) and
  396. MatchOperand(taicpu(hp1).oper[0]^,taicpu(p).oper[0]^) and
  397. MatchOperand(taicpu(hp1).oper[1]^,NR_X0) and
  398. (not RegModifiedBetween(taicpu(p).oper[1]^.reg, p,hp1)) and
  399. (not RegModifiedBetween(taicpu(p).oper[2]^.reg, p,hp1)) and
  400. RegEndOfLife(taicpu(p).oper[0]^.reg, taicpu(hp1)) then
  401. begin
  402. taicpu(hp1).loadreg(0,taicpu(p).oper[1]^.reg);
  403. taicpu(hp1).loadreg(1,taicpu(p).oper[2]^.reg);
  404. if taicpu(p).opcode=A_SLTU then
  405. begin
  406. if taicpu(hp1).condition=C_NE then
  407. taicpu(hp1).condition:=C_LTU
  408. else
  409. taicpu(hp1).condition:=C_GEU;
  410. end
  411. else
  412. begin
  413. if taicpu(hp1).condition=C_NE then
  414. taicpu(hp1).condition:=C_LT
  415. else
  416. taicpu(hp1).condition:=C_GE;
  417. end;
  418. DebugMsg('Peephole SltuB2B performed', hp1);
  419. RemoveInstr(p);
  420. result:=true;
  421. end;
  422. end;
  423. A_SLTIU:
  424. begin
  425. {
  426. Turn
  427. sltiu x,y,1
  428. beq/ne x,x0,...
  429. dealloc x
  430. Into
  431. bne y,x0,...
  432. }
  433. if (taicpu(p).ops=3) and
  434. (taicpu(p).oper[2]^.typ=top_const) and
  435. (taicpu(p).oper[2]^.val=1) and
  436. GetNextInstructionUsingReg(p, hp1, taicpu(p).oper[0]^.reg) and
  437. MatchInstruction(hp1,A_Bxx,[C_NE,C_EQ]) and
  438. (taicpu(hp1).ops=3) and
  439. MatchOperand(taicpu(hp1).oper[0]^,taicpu(p).oper[0]^) and
  440. MatchOperand(taicpu(hp1).oper[1]^,NR_X0) and
  441. (not RegModifiedBetween(taicpu(p).oper[1]^.reg, p,hp1)) and
  442. RegEndOfLife(taicpu(p).oper[0]^.reg, taicpu(hp1)) then
  443. begin
  444. taicpu(hp1).loadreg(0,taicpu(p).oper[1]^.reg);
  445. taicpu(hp1).condition:=inverse_cond(taicpu(hp1).condition);
  446. DebugMsg('Peephole Sltiu0B2B performed', hp1);
  447. RemoveInstr(p);
  448. result:=true;
  449. end;
  450. end;
  451. A_LUI,
  452. A_LB,
  453. A_LBU,
  454. A_LH,
  455. A_LHU,
  456. A_LW,
  457. {$ifdef riscv64}
  458. A_LWU,
  459. A_LD,
  460. {$endif riscv64}
  461. A_ADD,
  462. A_DIV,
  463. A_DIVU,
  464. {$ifdef riscv64}
  465. A_DIVW,
  466. A_DIVUW,
  467. {$endif riscv64}
  468. A_REM,
  469. A_REMU,
  470. {$ifdef riscv64}
  471. A_REMW,
  472. A_REMUW,
  473. {$endif riscv64}
  474. A_MUL,
  475. A_MULH,
  476. A_MULHSU,
  477. A_MULHU,
  478. A_XORI,
  479. A_ORI,
  480. A_AND,
  481. A_OR,
  482. A_XOR,
  483. A_SLL,
  484. A_SRL,
  485. A_SRA,
  486. A_NEG,
  487. A_NOT:
  488. result:=OptPass1OP(p);
  489. A_SRAI,
  490. A_SRLI,
  491. A_SLLI:
  492. begin
  493. if (taicpu(p).oper[2]^.val=0) and
  494. MatchOperand(taicpu(p).oper[0]^,taicpu(p).oper[1]^) then
  495. begin
  496. DebugMsg('Peephole S*LI x,x,0 to nop performed', p);
  497. RemoveInstr(p);
  498. result:=true;
  499. end
  500. else
  501. result:=OptPass1OP(p);
  502. end;
  503. A_SLTI:
  504. begin
  505. {
  506. Turn
  507. slti x,y,0
  508. beq/ne x,x0,...
  509. dealloc x
  510. Into
  511. bge/lt y,x0,...
  512. }
  513. if (taicpu(p).ops=3) and
  514. (taicpu(p).oper[2]^.typ=top_const) and
  515. (taicpu(p).oper[2]^.val=0) and
  516. GetNextInstructionUsingReg(p, hp1, taicpu(p).oper[0]^.reg) and
  517. (hp1.typ=ait_instruction) and
  518. (taicpu(hp1).opcode=A_Bxx) and
  519. (taicpu(hp1).ops=3) and
  520. (taicpu(hp1).oper[0]^.typ=top_reg) and
  521. (taicpu(hp1).oper[0]^.reg=taicpu(p).oper[0]^.reg) and
  522. (taicpu(hp1).oper[1]^.typ=top_reg) and
  523. (taicpu(hp1).oper[1]^.reg=NR_X0) and
  524. (taicpu(hp1).condition in [C_NE,C_EQ]) and
  525. (not RegModifiedBetween(taicpu(p).oper[1]^.reg, p,hp1)) and
  526. RegEndOfLife(taicpu(p).oper[0]^.reg, taicpu(hp1)) then
  527. begin
  528. taicpu(hp1).loadreg(0,taicpu(p).oper[1]^.reg);
  529. taicpu(hp1).loadreg(1,NR_X0);
  530. if taicpu(hp1).condition=C_NE then
  531. taicpu(hp1).condition:=C_LT
  532. else
  533. taicpu(hp1).condition:=C_GE;
  534. DebugMsg('Peephole Slti0B2B performed', hp1);
  535. RemoveInstr(p);
  536. result:=true;
  537. end;
  538. end;
  539. else
  540. ;
  541. end;
  542. end;
  543. else
  544. ;
  545. end;
  546. end;
  547. end.