Commit Graph

242 Commits

Author SHA1 Message Date
florian
de34eab23d + optimize and ...,255/strb ... sequence if possible
git-svn-id: trunk@22323 -
2012-09-05 11:24:03 +00:00
florian
93d0033282 * improve AndAnd2And optimization by checking if the first destination register is allocated after the second and
git-svn-id: trunk@22322 -
2012-09-05 11:23:05 +00:00
florian
8a6c65b008 * fix r22319: hp1 must have the same condition as p
git-svn-id: trunk@22321 -
2012-09-05 09:05:26 +00:00
florian
2f1989c1a6 * hp1 can have any condition in this case so don't access hp1.condition because it
is not guranteed that hp1 is actually a tai_instruction before calling MatchInstruction

git-svn-id: trunk@22319 -
2012-09-04 18:58:28 +00:00
masta
d8af83d252 Introduce a version of MatchInstruction for multiple instructions
It is the same as the normal MatchInstruction function but supports to
be called with a set of TAsmOps instead of a single op.

git-svn-id: trunk@22231 -
2012-08-24 15:54:36 +00:00
florian
6b73bc45c5 * check constant for being a valid offset
git-svn-id: trunk@22230 -
2012-08-24 09:16:47 +00:00
florian
58a85e79ce * set index register correctly * index register might not be changed
git-svn-id: trunk@22229 -
2012-08-24 09:16:38 +00:00
florian
245d8286d5 + LookForPostindexedPattern
git-svn-id: trunk@22228 -
2012-08-24 09:16:26 +00:00
masta
012da673a8 Use MatchInstruction in OpCmp2OpS
MatchInstruction keeps the code a bit more readable and compact.

git-svn-id: trunk@22226 -
2012-08-23 23:08:26 +00:00
florian
a016bc5ced * white space change
git-svn-id: trunk@22224 -
2012-08-23 21:04:31 +00:00
florian
f2ccd6e400 * when doing the AddSubLdr2Ldr optimization check also if the source register of the add is modified before the load
git-svn-id: trunk@22223 -
2012-08-23 21:04:21 +00:00
florian
4e2de05667 * don't apply the AddSubLdr2Ldr optimization if the base register in the reference is used/modified during the ldr/str
git-svn-id: trunk@22222 -
2012-08-23 21:04:11 +00:00
florian
d89b742109 * apply Add/SubLdr2Ldr only if no condition flags are involved
git-svn-id: trunk@22221 -
2012-08-23 21:04:02 +00:00
florian
73d540e7b5 * unsigned byte ldr/str allow also an offset of max. +/-4095
git-svn-id: trunk@22220 -
2012-08-23 21:03:52 +00:00
florian
9d20a73986 * optimize also str/ldrb/h/d
git-svn-id: trunk@22219 -
2012-08-23 21:03:44 +00:00
florian
1b3e03d72d + DEBUG_AOPTCPU to turn off peephole optimizer messages
git-svn-id: trunk@22218 -
2012-08-23 21:03:34 +00:00
florian
8a20ccc5f9 + Add/SubLdr2Ldr optimization
git-svn-id: trunk@22217 -
2012-08-23 21:03:24 +00:00
masta
b9fa9da629 Small fixes to OpCmp2OpS
1.) For UMULL and UMLAL support we would have to make sure the following
code checks RdHi and RdLo, which is currently not supported.
The former code would transform the following

  umull r0, r1, r2, r3
  cmp   r0, #0
  bne   .LSomething

into

  umulls r0,r1,r2,r3
  bne    .LSomething

which is wrong. UMULL has a 64bit result in r1+r0 and checks the full 64bit for 0
before setting the Z flag.

2.) Support MLA.

3.) Support MI/PL/NE/EQ for all instructions. As all of them are setting
the N and Z flags in the same way only based on the result of the
operation not on its input values.

N:=Result[31];
Z:=Result = 0;

Wurst

git-svn-id: trunk@22213 -
2012-08-23 14:22:29 +00:00
florian
3ad32b6e4e * opcode spelling fixed
git-svn-id: trunk@22204 -
2012-08-23 08:55:07 +00:00
florian
935985d0c0 * checked and updated valid opcode for OpCmp2OpS optimization
git-svn-id: trunk@22203 -
2012-08-23 08:55:03 +00:00
florian
70009e8ed1 * move flag allocation item
git-svn-id: trunk@22202 -
2012-08-23 08:54:58 +00:00
florian
2d2c66467c + optimize op ... / cmp .... when possible
git-svn-id: trunk@22200 -
2012-08-23 08:54:47 +00:00
florian
a92ca7c456 * adjust the reg. allocations of the target register in RemoveSuperfluousMove
git-svn-id: trunk@22194 -
2012-08-22 19:52:37 +00:00
florian
3d7b603d11 * get rid or move the allocation of the replaced register if possible
git-svn-id: trunk@22193 -
2012-08-22 19:52:30 +00:00
florian
77e579f59f * RemoveSuperfluousMove uses FindRegDeAlloc to find out if the register used in the move can be removed
* RemoveSuperfluousMove fixes partially the register allocation changes caused by the mov

git-svn-id: trunk@22192 -
2012-08-22 19:52:23 +00:00
florian
5fd457e586 * when determining of a register is used after an instruction, new allocs should not be taken into account
git-svn-id: trunk@22189 -
2012-08-22 19:52:03 +00:00
florian
c0425c48fd * make use of GetNextInstructionUsingReg
git-svn-id: trunk@22186 -
2012-08-22 19:51:40 +00:00
florian
f3f5be2af1 * RemoveSuperfluousMove should not mess with moves targetting lr or pc
git-svn-id: trunk@22185 -
2012-08-22 19:51:31 +00:00
florian
93eb20d407 + GetNextInstructionUsingReg
git-svn-id: trunk@22184 -
2012-08-22 19:51:19 +00:00
florian
2a14394cf5 * cleaned up scheduler code, created own scheduler class to avoid unneeded passes through the assembler
git-svn-id: trunk@22133 -
2012-08-19 19:15:34 +00:00
florian
a3bf956c33 * improved main loop of TCpuPreRegallocScheduler.PeepHoleOptPass1Cpu
* reordered conditions in scheduler main loop so they abort potentially quicker

git-svn-id: trunk@22132 -
2012-08-19 19:13:49 +00:00
florian
54e2b40ab4 * revert the parameter type change of the last commit, it was an overleft from a failed fix attempt
git-svn-id: trunk@22116 -
2012-08-17 19:36:37 +00:00
florian
45eafd3e65 * fix MovMov optimization if the second mov is a mov rX,rX
git-svn-id: trunk@22114 -
2012-08-17 19:36:22 +00:00
florian
4b4e08c28b * fixes copy&paste errors when moving end of live pointers
git-svn-id: trunk@22113 -
2012-08-17 19:36:16 +00:00
florian
53a0d3e3a3 * fixed typo when checking live start of references
git-svn-id: trunk@22112 -
2012-08-17 19:36:10 +00:00
florian
a693fe9fb7 + implemented TCpuPreRegallocScheduler.SwapRegLive and make use of it to be able to reschedule instructions before register allocation
git-svn-id: trunk@22110 -
2012-08-17 19:35:59 +00:00
florian
354cac2bb6 + completed arm architectures
* ldrd/strd and pld collected under the edsp define

git-svn-id: trunk@22104 -
2012-08-17 10:37:27 +00:00
florian
7588896775 * make use of cpuflags in the arm compiler
* armv5te architecture

git-svn-id: trunk@22103 -
2012-08-17 10:37:17 +00:00
florian
371ef7bada * cover more cases in AlignedToQWord
git-svn-id: trunk@22060 -
2012-08-11 15:11:43 +00:00
florian
db7e029574 * strd/ldrd optimization might be only done on dword operations
git-svn-id: trunk@22059 -
2012-08-11 15:11:10 +00:00
florian
8c45a909be + support ldr/ldr -> ldrd and str/str -> strd optimization where appliable
git-svn-id: trunk@22058 -
2012-08-11 11:45:54 +00:00
masta
9e039936bf Support more operators in FoldShiftProcess on ARM
Now we can also fold shifts into teq, tst, cmp, cmn instructions.

git-svn-id: trunk@22023 -
2012-08-07 06:46:32 +00:00
florian
023d632f44 * optimize also lsr/asr, lsl, lsr/asr sequences on arm
git-svn-id: trunk@21981 -
2012-07-28 22:30:11 +00:00
florian
c8435b503f * better folding of consecutive shift operations
git-svn-id: trunk@21978 -
2012-07-28 17:59:45 +00:00
masta
be6bf6e3f7 Fix possible access violation introduces in r21885
r21885 added a new peephole optimizer. The associated code refactoring
missed a check for

  tai(hp1).typ = tai_instruction

Which can lead to an access violation later on, because the rest of the
code expects to find a taicpu in hp1.

git-svn-id: trunk@21949 -
2012-07-22 18:06:08 +00:00
florian
701a5d76bb * remove unneeded movs
git-svn-id: trunk@21885 -
2012-07-11 20:58:52 +00:00
masta
5498456269 Add LsrAndLsr Peephole Optimizer for ARM
Remove the superfluous and in:
mov r0, r0, lsr #24
and r0, r0, #255

Doing this allows for better shift-folding later

git-svn-id: trunk@21659 -
2012-06-20 12:39:19 +00:00
florian
64ac48c815 * patch by Nico Erfurth: Better support for PLD on ARM
git-svn-id: trunk@21572 -
2012-06-09 17:28:05 +00:00
florian
3db61ae52d * patch by Nico Erfurth: Reworked regLoadedWithNewValue
Added better support for A_STR, A_LDR, A_STM, A_LDM.

Reworked the code the use a case statement for better readability.

git-svn-id: trunk@21571 -
2012-06-09 17:27:30 +00:00
florian
03a30ff036 * patch by Nico Erfurth: Remove STRH and STRB from instructionLoadsFromReg
STRH and STRB are not handled as sperate instructions by the code
generator.

git-svn-id: trunk@21570 -
2012-06-09 17:26:06 +00:00
florian
7599de416d * patch by Nico Erfurth: Reworked MatchOperand in ARM Peephole Optimizers
Added top_ref comperator which uses RefsEqual.
Reworked the code for easier readability by using a case statement.

git-svn-id: trunk@21569 -
2012-06-09 17:25:32 +00:00
florian
6e8594a9af * patch by Nico Erfurth: Minor fix for FoldShiftProcess peephole optimizer on ARM
Use UpdateUsedRegs and drop the check for reloading of the register, as
this is done in RegUsedAfterInstruction now.

git-svn-id: trunk@21520 -
2012-06-07 18:21:46 +00:00
florian
5b02a7cb9b * patch by Nico Erfurth: Check for register reloading in RegUsedAfterInstruction on ARM
This slightly changes the semantics of RegUsedAfterInstruction.
We now check if the `current value` of the register will be used later.
It will do `the right thing` for all the normal use cases.

git-svn-id: trunk@21519 -
2012-06-07 18:20:35 +00:00
florian
8cae4c9f23 * patch by Nico Erfurth: Fix for MovStrMov Peephole optimizer on ARM
The loop checked for the wrong instruction for .opcode = A_STR. Making
the whole optimizer non functional but at least not destructive.

git-svn-id: trunk@21508 -
2012-06-06 19:44:20 +00:00
florian
83fb4c289d * patch by Nico Erfurth: Implement FoldShiftProcess Peephole optimizer for ARM
This optimizer folds shift/roll operations into following data
instructions.

It will change code like:

mov r0, r0, lsl #16
add r1, r0, r1

into

add r1, r1, r0, lsl #16

Source registers will be reordered when necessary, also SUB/SBC will be
replaced with RSB/RSC and vice versa when reordering is required.

It could be expanded to support more operations like LDR/STR.

git-svn-id: trunk@21507 -
2012-06-06 19:43:36 +00:00
florian
5393efb128 * patch by Nico Erfurth: Support A_MOV and A_MVN in RedundantMovProcess
This changes the ARM Peephole optimizer RedundantMovProcess to also
recognize and modify something like the following sequence.

mov r0, r1
mov r0, r0, lsl #8

this would be changed into

mov r0, r1, lsl #8

git-svn-id: trunk@21506 -
2012-06-06 19:43:05 +00:00
florian
3ae5fc8c04 * patch by Nico Erfurth: adds a check for SM_ASR to also support removal of unnecessary sign extension before STRH.
git-svn-id: trunk@21446 -
2012-05-31 20:24:48 +00:00
florian
4f273aa08d * patch by Nico Erfurth: Handle STR*/LDR* properly in ARM Peephole optimizers
git-svn-id: trunk@21444 -
2012-05-31 17:00:19 +00:00
florian
fbc77b74c2 * patch by Nico Erfurth to remove superfluouse moves
git-svn-id: trunk@21422 -
2012-05-28 21:58:06 +00:00
florian
c348b6f2cc * patch by Nico Erfurth:
- Support MLA and MUL in DataMov2Data
- SMLAL and UMLAL are also reading from oper[0]
- UMLAL, UMULL, SMLAL and SMULL are writing to oper[1]

git-svn-id: trunk@21421 -
2012-05-28 18:11:31 +00:00
florian
9e180fb318 * remove unneeded zero extensions from 16 to 32 Bit
git-svn-id: trunk@21404 -
2012-05-28 07:21:27 +00:00
florian
05a8783b1e * patch by Nico Erfurth:
Improve ARM-Peephole Optimizers

1.) Introduce a ARM-specific RegUsedAfterInstruction which analyzes
instructions and reg allocation information to see if a register is
really needed afterwards to decide if some special optimizations can be
done.

2.) Introduce "RemoveSuperfluousMove"
This tries to fold mov into a previous Data-Instruction (ADD, ORR, etc)
or LDR-Instruction.

3.) Introduce new Optimizer "DataMov2Data" and modify LdrMov2Ldr to use
RemoveSuperfluousMove

4.) Expand Ldr* and Str* Optimizers to also work on {Ldr,Str}{,b,h}

git-svn-id: trunk@21314 -
2012-05-17 08:31:44 +00:00
florian
748694a325 * fixes some issues with reg. allocation information
git-svn-id: trunk@21303 -
2012-05-15 18:06:41 +00:00
florian
2959d596f9 * patch by Nico Erfurth: Remove superfluous mov from MovStrMov sequences
git-svn-id: trunk@21067 -
2012-04-26 20:31:13 +00:00
florian
aa2a9dbf2e patches by Nico Erfurth to improve the arm peephole optimizer:
* Introduce MatchInstruction and MatchOperand

MatchInstruction allows to match an instruction by condition and
oppostfix. MatchOperand checks if an operand is a register and matches
another operand. In the future this could be overloaded with other
versions not only accepting TRegister.

* Optimize cmp,moveq,movne sequence on ARM

This patch implements an peephole optimizer for the following sequence:

  cmp   reg,const1
  movne reg,const2
  moveq reg,const1

* Small improvements to the ARM peephole optimizer

Most instructions in the ARM ISA have taicpu(p).oper[0]^.typ = top_reg
as the only option, so there is no need to check for it if we're
looking at those instructions.

* Remove redundant mov instructions on ARM

This is an addition to the ARM PeepHole Optimizer.
It folds code like this:

mov reg1, reg2
add reg1, reg1, (const|reg)

git-svn-id: trunk@21024 -
2012-04-24 18:25:19 +00:00
florian
c5445399c6 * take care also of reg. allocation information after the current instruction when moving it
git-svn-id: trunk@20709 -
2012-04-05 14:21:41 +00:00
florian
9867f34398 * the arm rescheduler has not only to move instructions but also associated register allocations
git-svn-id: trunk@20707 -
2012-04-04 21:21:52 +00:00
florian
38d3a081f6 * update of TODOs
git-svn-id: trunk@20513 -
2012-03-11 20:12:46 +00:00
florian
0fe22a358b + first version of ldr instruction scheduler on arm
git-svn-id: trunk@20512 -
2012-03-11 19:10:58 +00:00
florian
9c6e3d317a * reenabled ldr/ldr and ldr/str optimization
git-svn-id: trunk@20497 -
2012-03-10 17:09:42 +00:00
florian
b4907578b0 * temporarily disable LDR/LDR STR/LDR optimizations, let's see if this broke regression testing on fpcarm
git-svn-id: trunk@20473 -
2012-03-04 20:37:06 +00:00
florian
fdfb9a3fba * take care of conditions when doing ldr/str optimizations
git-svn-id: trunk@20428 -
2012-02-25 21:04:28 +00:00
florian
bb2df48aa9 - <op> ....; cmp ...,#0 cmps ... optimization deactivated
* optimize ldr/ldr if possible

git-svn-id: trunk@20416 -
2012-02-23 21:29:22 +00:00
florian
e2c9a8c6a1 * fold <arithmed. op> ...; cmp ...,#0into cmps on arm
* remove unnecessary ldr after str to the same memoy location, however, to do this optimization safely, we should add support for volatile variables

git-svn-id: trunk@20399 -
2012-02-22 20:16:06 +00:00
Jonas Maebe
852ae48cb7 * also use blx instead of bl for direct calls on ARMv5+, since the target
may be thumb(2) (mantis #19896)
  * don't conditionalize "blx <imm target>", because that's not a valid
    encoding

git-svn-id: trunk@18984 -
2011-09-05 20:33:15 +00:00
florian
515774b864 * merged armthum branch
-- Zusammenführen der Unterschiede zwischen Projektarchiv-URLs in ».«:
U    rtl/arm/setjump.inc
A    rtl/arm/thumb2.inc
U    rtl/arm/divide.inc
A    rtl/embedded/arm/stm32f103.pp
U    rtl/inc/system.inc
U    compiler/alpha/cgcpu.pas
U    compiler/sparc/cgcpu.pas
U    compiler/i386/cgcpu.pas
U    compiler/ncgld.pas
U    compiler/powerpc/cgcpu.pas
U    compiler/avr/cgcpu.pas
U    compiler/aggas.pas
U    compiler/powerpc64/cgcpu.pas
U    compiler/x86_64/cgcpu.pas
U    compiler/cgobj.pas
U    compiler/psystem.pas
U    compiler/aasmtai.pas
U    compiler/m68k/cgcpu.pas
U    compiler/ncgutil.pas
U    compiler/rautils.pas
U    compiler/arm/raarmgas.pas
U    compiler/arm/armatts.inc
U    compiler/arm/cgcpu.pas
U    compiler/arm/armins.dat
U    compiler/arm/rgcpu.pas
U    compiler/arm/cpubase.pas
U    compiler/arm/agarmgas.pas
U    compiler/arm/cpuinfo.pas
U    compiler/arm/armop.inc
U    compiler/arm/narmadd.pas
U    compiler/arm/aoptcpu.pas
U    compiler/arm/armatt.inc
U    compiler/arm/aasmcpu.pas
U    compiler/systems/t_embed.pas
U    compiler/psub.pas
U    compiler/options.pas

git-svn-id: trunk@13801 -
2009-10-04 09:03:44 +00:00
florian
91dcb722a2 + optimization of sequential ands
git-svn-id: trunk@12806 -
2009-02-27 12:59:08 +00:00
florian
66e015f48c * avoid shifter constant overflow on arm when optimizing two shifter operations into one
git-svn-id: trunk@11474 -
2008-07-28 15:51:58 +00:00
yury
2829f4e46f * Fixed arm optimizer bug (mantis #9209). No testsuite regressions with -O2.
* Removed unused local vars.
+ test.

git-svn-id: trunk@7970 -
2007-07-06 13:09:28 +00:00
florian
c5d8e53758 * last commit fixed
git-svn-id: trunk@6338 -
2007-02-04 18:50:22 +00:00
florian
3609ddc5dd * more MustBeLast fixes
* const insertation algorithm fixed

git-svn-id: trunk@6337 -
2007-02-04 18:45:43 +00:00
florian
8d33f640d4 * stop conditional optimization at mov pc,...
git-svn-id: trunk@6321 -
2007-02-03 17:40:32 +00:00
florian
d09295b686 * shift folding
git-svn-id: trunk@6312 -
2007-02-02 23:12:08 +00:00
florian
1e1f711663 * instructions being already conditional can't be marked as conditional again
git-svn-id: trunk@5394 -
2006-11-15 22:42:22 +00:00
florian
84f0b62f93 * cond. instruction optimization enabled
git-svn-id: trunk@5393 -
2006-11-15 21:59:29 +00:00
florian
4010d66c2c * arm cond. instruction support
git-svn-id: trunk@5387 -
2006-11-14 22:37:22 +00:00
florian
0308048768 * fixed compilation
git-svn-id: trunk@1418 -
2005-10-16 14:12:30 +00:00
Jonas Maebe
ab3bc45fa4 * cpu-specific overrides of optimizer methods now get called
+ first simple rlwinm optimization for ppc

git-svn-id: trunk@1320 -
2005-10-07 21:44:00 +00:00
fpc
790a4fe2d3 * log and id tags removed
git-svn-id: trunk@42 -
2005-05-21 09:42:41 +00:00
fpc
50778076c3 initial import
git-svn-id: trunk@1 -
2005-05-16 18:37:41 +00:00
florian
2b67164568 * optimizer files fixed 2005-02-20 19:36:03 +00:00
florian
871fd8d2b8 * initial commit 2005-02-20 19:11:04 +00:00