Commit Graph

189 Commits

Author SHA1 Message Date
florian
af107ca8fe o patch by J. Gareth Moreton, resolves #36355
+ This patch serves to extend the JMP -> RET optimisation in OptPass2JMP by also doing the same
      for JMP -> MOV/RET, since there are often cases where the result (e.g. EAX) is set just
      prior to the function exiting.
    * RemoveDeadCodeAfterJump will now drop out if it detects SEH information -
      this stops exception information from being stripped if it is called on the final RET instruction.

git-svn-id: trunk@43592 -
2019-11-25 21:15:41 +00:00
florian
c6116258fd o patch by J. Gareth Moreton:
* adds an extra optimisation to "PostPeepholeOptMov" in compiler/x86/aoptx86.pas:
      If the instruction "MOV REG, -1" (Intel notation) is found, where REG is either
      a 32- or 64-bit register, it is changed to "OR REG, -1" instead.
      The effect is the same and takes exactly the same speed to execute, but the encoding is much smaller.
      As it cause false data dependencies, it is only applied in -Os mode

      For 16-bit registers, only AX is optimised this way because it has its own encoding for OR that takes fewer bytes.

git-svn-id: trunk@43579 -
2019-11-24 20:26:02 +00:00
florian
94b728005d * more RemoveCurrentP usage
git-svn-id: trunk@43576 -
2019-11-24 19:51:04 +00:00
florian
d444f750f9 * factored out TX86AsmOptimizer.OptPass1Cmp
* fixed it
  * activated it for x86-64

git-svn-id: trunk@43574 -
2019-11-24 16:33:50 +00:00
florian
f5caa9940b * make use of RemoveCurrentP
git-svn-id: trunk@43532 -
2019-11-21 20:19:49 +00:00
pierre
ff415ba39c Fixes by Gareth Moreton for problems exposed by use of -CriotR option
git-svn-id: trunk@43529 -
2019-11-21 10:00:20 +00:00
florian
40c54e9d37 * do not generate conditional jump with full references
+ more assembler optimizer output

git-svn-id: trunk@43520 -
2019-11-20 22:12:27 +00:00
florian
6bed497c7c * be carefully with references using RIP when doing LeaOp2Op optimizations
git-svn-id: trunk@43460 -
2019-11-13 20:47:40 +00:00
florian
ae6b204c94 + added comments for LeaOp2Op
git-svn-id: trunk@43457 -
2019-11-12 22:10:01 +00:00
florian
7ee0ad4d63 + LeaOp2Op optimization
* replaced some manual removels of p by RemoveCurrentP calls

git-svn-id: trunk@43456 -
2019-11-12 22:04:23 +00:00
florian
5c0a5b73c7 * patch by J. Gareth Moreton: fix compilation with debug info after r43441 and friends, resolves #36299
git-svn-id: trunk@43455 -
2019-11-12 20:03:19 +00:00
florian
1d6e719e38 * improve ShlAddLeaSubIncDec2Lea to take care of foldable LEAs
git-svn-id: trunk@43453 -
2019-11-11 22:08:17 +00:00
florian
83a11c2a7d * patch by J. Gareth Moreton to clean up TX86AsmOptimizer.OptPass2Jcc, resolves #36295
git-svn-id: trunk@43452 -
2019-11-11 21:29:13 +00:00
florian
7464c88003 * fix and improve MovImul2Imul: we cannot insert the move target into imul if the imul is 64 bit and the mov 32 bit as
we cannot ensure that the upper 32 bits of the move target are really clear

git-svn-id: trunk@43447 -
2019-11-10 21:09:06 +00:00
florian
4b455600b8 * swapped decrefs and StripLabelFast as proposed by Gareth on the mailing list
git-svn-id: trunk@43445 -
2019-11-10 18:23:50 +00:00
florian
2d295a3816 * patch by J. Gareth Moreton, issue #36271, part 2: x86 specific rework of the jump optimizer
git-svn-id: trunk@43440 -
2019-11-10 16:11:39 +00:00
florian
20a47afe13 * more aggressive LeaCallLeaRet2Jmp
git-svn-id: trunk@43373 -
2019-11-02 22:37:31 +00:00
florian
1fc7667b3b + LeaCallLeaRet2Jmp
git-svn-id: trunk@43372 -
2019-11-02 22:37:30 +00:00
florian
6842c5784d * CallRet2Jmp works with PIC
git-svn-id: trunk@43371 -
2019-11-02 22:37:29 +00:00
florian
3487c34ed9 * unified TX86AsmOptimizer.OptPass1MOVAP and TX86AsmOptimizer.OptPass1VMOVAP
git-svn-id: trunk@43370 -
2019-11-02 18:48:23 +00:00
florian
f9530437c2 * fix i386 building
git-svn-id: trunk@43369 -
2019-11-02 18:34:53 +00:00
florian
c3ef42b164 * allow cmov with memory reference if it is a pure symbol or a rip relative symbol: as the symbol is
allocated within the image of the program, this should never cause a seg. fault, so it is save
    to use cmov with it

git-svn-id: trunk@43368 -
2019-11-02 18:09:11 +00:00
florian
172a4a999b + MovMov2Mov 6 and MovMov2Mov 7 optimization
git-svn-id: trunk@43339 -
2019-10-30 22:39:13 +00:00
florian
cfec725195 * clean up TX86AsmOptimizer.OptPass1MOV
git-svn-id: trunk@43336 -
2019-10-30 20:07:26 +00:00
florian
533a113885 + LeaCallLeaRet2Jmp optimization
git-svn-id: trunk@43178 -
2019-10-12 21:51:15 +00:00
florian
00c2fd4005 + x86: LeaLea2Lea optimization
git-svn-id: trunk@43177 -
2019-10-12 21:51:14 +00:00
pierre
af03c0208b Use tcgint typecast instead of aint, as it is the type of the second parameter of loadconst taicpu method
git-svn-id: trunk@42281 -
2019-06-25 04:24:56 +00:00
Jonas Maebe
281b3ad276 * fix case completeness and unreachable code warnings in compiler that would
be introduced by the next commit

git-svn-id: trunk@42046 -
2019-05-12 14:29:03 +00:00
florian
d657373933 * patch by J. Gareth Moreton which avoids that the optimizer causes reads of invalid memory, resolves #35187
git-svn-id: trunk@41667 -
2019-03-10 10:48:50 +00:00
florian
c7bb028d35 * factored out OptPass1FLD, used bx x86-64 now as well
- removed unused function

git-svn-id: trunk@41061 -
2019-01-24 20:10:29 +00:00
florian
6cb6517411 * better recognization of procedure exit code
git-svn-id: trunk@41060 -
2019-01-24 19:53:51 +00:00
florian
24f6cc0da5 * factored out OptPass1FSTP, used by x86-64 now as well
git-svn-id: trunk@41059 -
2019-01-24 19:38:32 +00:00
florian
cfd0790f89 * avoid assembler errors for the MovOpMov2MovOp optimziation in case the size of the instruction
gets changed and the first one contains a constant, resolves #34933

git-svn-id: trunk@41021 -
2019-01-23 21:02:14 +00:00
florian
4fb7b5d3ff * fix MovOpMov2MovOp optimization if no -Cpcoreavx2 is used
git-svn-id: trunk@40979 -
2019-01-21 21:57:07 +00:00
florian
75a89d2115 * fix and enable MovOpMov2MovOp optimization on x86-64
git-svn-id: trunk@40941 -
2019-01-20 17:00:43 +00:00
florian
94d7a02fae * modified patch by Gareth Moreton to pool TmpUsedRegs in the assembler optimizers, resolves #34679
git-svn-id: trunk@40938 -
2019-01-20 14:16:38 +00:00
Jonas Maebe
122d0d36d6 + volatile() expression that marks an expression as volatile
* disable matching volatile references in the assembler optimisers, so they
    can't be removed (more conservative than needed, but better than removing
    too many)
   o the CSE optimiser will ignore them by default, because they're an unknown
     inline node for it
  * also removed no longer used fpc_in_move_x and fpc_in_fillchar_x inline node
    identifiers from rtl/inc/innr.inc, and placed fpc_in_unaligned_x at the
    right place

git-svn-id: trunk@40465 -
2018-12-04 19:53:20 +00:00
florian
c43cae9231 * disable MovOpMov2MovOp optimization on x86-64 for now as it seems to break
git-svn-id: trunk@40361 -
2018-11-21 21:22:54 +00:00
florian
477d7be651 * building on i386-linux fixed
git-svn-id: trunk@40360 -
2018-11-21 19:19:24 +00:00
florian
ac37a54d79 + MovOpMov2MovOp optimization
git-svn-id: trunk@40359 -
2018-11-20 22:20:43 +00:00
yury
30d64cec68 * Removed unused local vars.
git-svn-id: trunk@40185 -
2018-11-02 18:51:19 +00:00
yury
4357caaad8 * Removed unused local vars.
git-svn-id: trunk@40183 -
2018-11-02 18:44:29 +00:00
florian
59d5d6ec95 + factored out TX86AsmOptimizer.PrePeepholeOptIMUL, used now by x86-64 and i386
* generalized and simplified the code

git-svn-id: trunk@40162 -
2018-11-01 20:49:20 +00:00
pierre
e5dffebdc7 Avoid range check error in MaskLength evaluation
git-svn-id: trunk@40110 -
2018-10-31 14:51:23 +00:00
florian
9805214d34 * properly take care of register allocations between the first and second instruction for the FoldLea optimization
* check for ait_instruction after a GetNextInstruction function call
* cosmetics

git-svn-id: trunk@39983 -
2018-10-18 18:28:03 +00:00
florian
5782acc32d * patch by J. Gareth Moreton to fix 33909
git-svn-id: trunk@39353 -
2018-07-01 12:54:30 +00:00
florian
78943ea843 + patch by J. Gareth Moreton: x86 optimisations for Jcc and SETcc, resolves #33899
* optimization also added for i386

git-svn-id: trunk@39307 -
2018-06-25 20:40:05 +00:00
florian
1472a81768 * patch by J. Gareth Moreton to unify the x86 assembler optimizer method headers, resolves #33908
git-svn-id: trunk@39305 -
2018-06-25 20:13:34 +00:00
florian
0d168796d7 * patch by J. Gareth Moreton: More Peephole optimizations for AND and MOV
git-svn-id: trunk@39242 -
2018-06-18 20:50:08 +00:00
florian
a0b343a787 * patch by J. Gareth Moreton for less invasive DEBUG_AOPTCPU
git-svn-id: trunk@39239 -
2018-06-17 14:56:19 +00:00
florian
9b18e39c81 * enable Lea2AddBase and Lea2AddIndex in TX86AsmOptimizer.PostPeepholeOptLea as we have flag tracking now
* some flag allocations fixed

git-svn-id: trunk@38501 -
2018-03-11 20:30:09 +00:00
florian
5fbecc5501 + use TX86AsmOptimizer.OptPass1SHLSAL on x86-64
git-svn-id: trunk@38499 -
2018-03-11 14:35:22 +00:00
florian
47927f053a * factored out TX86AsmOptimizer.OptPass1SHLSAL
git-svn-id: trunk@38498 -
2018-03-11 14:35:19 +00:00
florian
78878f59b1 + generic TAOptObj.AllocRegBetween
- removed x86 specific AllocRegBetween

git-svn-id: trunk@38445 -
2018-03-07 22:17:35 +00:00
florian
c5f8567ed7 * getsubreg => getsupreg
git-svn-id: trunk@38344 -
2018-02-25 15:34:14 +00:00
florian
fc6c0e8ef4 + AndShlToShl optimization
* moved topsize2memsize to cpubase

git-svn-id: trunk@38343 -
2018-02-25 15:34:12 +00:00
florian
6e811d057c * MovOpMov2Op cannot be applied for L, Q, Q as operand sizes
+ test

git-svn-id: trunk@38337 -
2018-02-25 10:19:52 +00:00
florian
e92422383a * compilation fixed
git-svn-id: trunk@38280 -
2018-02-18 09:29:36 +00:00
florian
91514da267 * factored out TX86AsmOptimizer.PostPeepholeOptCall
+ use TX86AsmOptimizer.PostPeepholeOptCall on x86-64

git-svn-id: trunk@38278 -
2018-02-17 23:25:01 +00:00
florian
1b3627add1 + peephole optimization MovMov2Mov 5
git-svn-id: trunk@38273 -
2018-02-17 21:10:51 +00:00
florian
5eb59196d5 * remove sequential moves to the same register
+ test

git-svn-id: trunk@38267 -
2018-02-17 12:45:17 +00:00
florian
99f1fe54af * check for registers removed which is not needed anymore
git-svn-id: trunk@38265 -
2018-02-17 12:45:13 +00:00
florian
810acd82b2 * patch by J. Gareth Moreton that makes some improvements to the Peephole Optimizer for x86 and x86-64 code, as well as some cleanup with formatting, code syntax consistency, and debug messages.
- xorq %reg,%reg (identical registers) is now changed to xorl %reg,%reg if doing so removes the REX prefix.
  - movw %bx,%ax; andl $0xffff,%eax, for example, is now changed to movzwl %bx,%eax as long as a conditional operation doesn't follow 'and' (checks to see if the CPU flags are in use).
  - movzbq and movzwq get optimised to movzbl and movzwl respectively if doing so removes the REX prefix.
  - Removal of optimisation code that zero-extends from 32-bit to 64-bit, because there isn't actually a valid combination of opcodes for MOVZX that allows that (for registers,
    just use  MOV). This is not the case with MOVSX.
  - movq is now optimised to movl even if the CPU flags are in use (this stops mov %reg,0 from being optimised to xor %reg,%reg if doing so breaks an algorithm that relies on them).
  - Fixed typo in peephole message regarding movq to movl (it said movd instead).
  - Made the peephole debug messages more consistent in formatting, some of which now have more detail.
* small fixes of the patch

git-svn-id: trunk@38070 -
2018-01-28 14:41:54 +00:00
florian
10ea652493 * fix for #32576
+ test case

git-svn-id: trunk@38069 -
2018-01-28 13:26:49 +00:00
florian
93353d8d79 * typo
git-svn-id: trunk@38068 -
2018-01-28 13:26:47 +00:00
florian
674398c5a5 * i8086 compilation fixed after r37572
git-svn-id: trunk@37573 -
2017-11-11 13:25:02 +00:00
florian
73fda1ccb6 * factored out OptPass1Sub
+ make use of OptPass1Sub on x86_64 and i8086 as well

git-svn-id: trunk@37572 -
2017-11-10 20:55:22 +00:00
florian
4da4b768ec * factored out PostPeepholeOptTest
+ use PostPeepholeOptTest on x86-64

git-svn-id: trunk@37551 -
2017-11-04 19:10:14 +00:00
florian
3097eaf8ee * made PostPeepholeOptMov a function
git-svn-id: trunk@37550 -
2017-11-04 19:10:12 +00:00
florian
a7ea7fb569 * factored out PostPeepholeOptCmp
+ use PostPeepholeOptCmp for x86_64

git-svn-id: trunk@37549 -
2017-11-04 19:10:09 +00:00
nickysn
80226e3af4 + added an optimization pass, that optimizes x86 references
git-svn-id: trunk@37494 -
2017-10-20 15:55:55 +00:00
florian
ce7487b7de o patch by J. Gareth "Kit" Moreton, resolves partially issue #32037
o improves readibility of TX86AsmOptimizer.OptPass1MOV and fixes some spelling mistakes
  + Optimization MovAnd2Mov 2
  + extended Optimization MovTestJxx2TestMov and MovTestJxx2ovTestJxx to take care of and as well
  + Peephole Optimization: movq x,%reg -> movd x,%reg

git-svn-id: trunk@37377 -
2017-10-01 18:40:11 +00:00
florian
15b617546e + call TX86AsmOptimizer.OptPass1VOP for logical operations as well
git-svn-id: trunk@37367 -
2017-10-01 14:40:21 +00:00
florian
05ecd784f2 * factored out OptPass1LEA and use it for x86-64 as well
+ LEAMov2LEA optimization

git-svn-id: trunk@37199 -
2017-09-13 20:40:32 +00:00
florian
22956c4393 + TX86AsmOptimizer.OptPass1OP
git-svn-id: trunk@36365 -
2017-05-28 13:49:43 +00:00
florian
c83e6991d5 * properly check number of operands
git-svn-id: trunk@36322 -
2017-05-25 12:44:30 +00:00
yury
884cb758e7 * Ensure the number of operands is 2 for MOVXX instructions in OptPass1MOVXX. Otherwise the classic MOVSD/W/B no-operand instructions (REP MOVSX) cause AV during checks of operands. The AV is thrown when trying to compile ucomplex.pp with -Cfsse3.
* Also fixed generation of debug comments in OptPass1MOVXX.

git-svn-id: trunk@36295 -
2017-05-22 15:20:18 +00:00
florian
3c5ec4e76c * allocate register correctly for "MovMov2Mov 2"
+ more debug messages
* debug message naming fixed

git-svn-id: trunk@36284 -
2017-05-21 15:06:22 +00:00
florian
1ffdf02b94 + Ch_*Op4
+ op_const_reg_reg_reg

git-svn-id: trunk@36279 -
2017-05-21 11:12:55 +00:00
florian
0f16f6d94d + OptPass1MOVXX
git-svn-id: trunk@36209 -
2017-05-14 20:59:10 +00:00
florian
535c990233 + OptPass1MOVAP
git-svn-id: trunk@36203 -
2017-05-13 21:48:44 +00:00
florian
3ade6ae9b8 + Mov2Nop optimization
git-svn-id: trunk@36201 -
2017-05-13 09:58:27 +00:00
florian
f4a29bb75d * moved InstructionLoadsFromReg and RegReadByInstruction from TCpuAsmOptimizer (i386) to TX86AsmOptimizer
git-svn-id: trunk@36200 -
2017-05-13 09:58:25 +00:00
florian
f93b784895 * make fullcycle for i8086 fixed
git-svn-id: trunk@36164 -
2017-05-09 19:53:06 +00:00
florian
52d3756c26 * factored out OptPass1Movx and merged i386 and x86-64 version
git-svn-id: trunk@36159 -
2017-05-08 20:44:27 +00:00
florian
06c4c651fd * factored out PrePeepholeOptSxx
+ x86-64 uses PrePeepholeOptSxx now as well

git-svn-id: trunk@36158 -
2017-05-08 20:44:24 +00:00
florian
74b338266d * ifdef cmov optimization, as i8086 has no cpu_capabilities
git-svn-id: trunk@36150 -
2017-05-07 16:18:44 +00:00
florian
f8d517be70 * make TX86AsmOptimizer.IsExitCode usable for x86-64 as well
git-svn-id: trunk@36148 -
2017-05-07 16:18:40 +00:00
florian
4a43d992f5 * unified usage of MatchOpType
* fixed generic MatchOpType

git-svn-id: trunk@36145 -
2017-05-07 16:18:33 +00:00
florian
7afe762d22 * factored out OptPass2Jcc assembler optimization
* OptPass2Jcc now used by x86-64 as well
* remove orphaned alignments if the label is not used anymore after cmov is used

git-svn-id: trunk@36143 -
2017-05-07 12:45:48 +00:00
florian
e3f0b338d4 * SkipLabels moved to aoptutils
* factored out OptPass2Jmp assembler optimization
* OptPass2Jmp now used by x86-64 as well

git-svn-id: trunk@36141 -
2017-05-06 21:07:02 +00:00
florian
f985971a62 * apply mov reg1, mem1; cmp x, mem1 to mov reg1, mem1; cmp x, reg1 also for test
git-svn-id: trunk@36138 -
2017-05-06 18:47:47 +00:00
nickysn
b882ba5fd2 + also recognize sbb reg,reg as writing a new value in the register in TX86AsmOptimizer.RegLoadedWithNewValue
git-svn-id: trunk@36119 -
2017-05-05 14:24:13 +00:00
nickysn
0e0e5c0caf + support the flags register and its subregisters in TX86AsmOptimizer.RegLoadedWithNewValue
git-svn-id: trunk@36114 -
2017-05-05 12:17:50 +00:00
nickysn
85fbbec319 + recognize xor reg,reg (same register twice) and sub reg,reg as writing a new
value to reg in TX86AsmOptimizer.RegLoadedWithNewValue

git-svn-id: trunk@36112 -
2017-05-05 11:01:34 +00:00
nickysn
aa93259463 + support the lahf,fstsw and fnstsw instructions in
TX86AsmOptimizer.RegLoadedWithNewValue

git-svn-id: trunk@36087 -
2017-05-04 16:02:01 +00:00
nickysn
92cc447326 + support the aam instruction in TX86AsmOptimizer.RegLoadedWithNewValue
git-svn-id: trunk@36083 -
2017-05-04 15:34:48 +00:00
nickysn
2431b1fa19 + support the lodsb,lodsw,lodsd and lodsq instructions in
TX86AsmOptimizer.RegLoadedWithNewValue

git-svn-id: trunk@36082 -
2017-05-04 15:12:37 +00:00
nickysn
6b7593d7d0 + support the SETcc instructions in TX86AsmOptimizer.RegLoadedWithNewValue
git-svn-id: trunk@36081 -
2017-05-04 14:43:18 +00:00
nickysn
e10f184b74 + support lds,les,lfs,lgs and lss in TX86AsmOptimizer.RegLoadedWithNewValue
git-svn-id: trunk@36079 -
2017-05-04 14:08:36 +00:00