summaryrefslogtreecommitdiffstats
path: root/tcg/optimize.c
Commit message (Collapse)AuthorAgeFilesLines
* tcg/optimize: add constant folding for depositAurelien Jarno2012-09-221-0/+20
| | | | | Reviewed-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* tcg/optimize: prefer the "op a, a, b" form for commutative opsAurelien Jarno2012-09-221-1/+4
| | | | | | | | | | | The "op a, a, b" form is better handled on non-RISC host than the "op a, b, a" form, so swap the arguments to this form when possible, and when b is not a constant. This reduces the number of generated instructions by a tiny bit. Reviewed-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* tcg/optimize: further optimize brcond/movcond/setcondAurelien Jarno2012-09-221-51/+76
| | | | | | | | | When both argument of brcond/movcond/setcond are the same or when one of the two values is a constant equal to zero, it's possible to do further optimizations. Reviewed-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* tcg/optimize: optimize "op r, a, a => movi r, 0"Aurelien Jarno2012-09-221-0/+16
| | | | | | | | | Now that it's possible to detect copies, we can optimize the case the "op r, a, a => movi r, 0". This helps in the computation of overflow flags when one of the two args is 0. Reviewed-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* tcg/optimize: optimize "op r, a, a => mov r, a"Aurelien Jarno2012-09-221-1/+1
| | | | | | | | Now that we can easily detect all copies, we can optimize the "op r, a, a => mov r, a" case a bit more. Reviewed-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* tcg/optimize: do copy propagation for all operationsAurelien Jarno2012-09-221-2/+9
| | | | | | | | | | It is possible to due copy propagation for all operations, even the one that have side effects or clobber arguments (it only concerns input arguments). That said, the call operation should be handled differently due to the variable number of arguments. Reviewed-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* tcg/optimize: rework copy progagationAurelien Jarno2012-09-221-75/+92
| | | | | | | | | | | | | | | | | | | | | | | | | The copy propagation pass tries to keep track what is a copy of what and what has copy of what, and in addition it keep a circular list of of all the copies. Unfortunately this doesn't fully work: a mov from a temp which has a state "COPY" changed it into a state "HAS_COPY". Later when this temp is used again, it is considered has not having copy and thus no propagation is done. This patch fixes that by removing the hiearchy between copies, and thus only keeping a "COPY" state both meaning "is a copy" and "has a copy". The decision of which copy to use is deferred to the actual temp replacement. At this stage there is not one best choice to do, but only better choices than others. For doing the best choice the operation would have to be parsed in reversed to know if a temp is going to be used later or not. That what is done by the liveness analysis. At this stage it is known that globals will be always live, that local temps will be dead at the end of the translation block, and that the temps will be dead at the end of the basic block. This means that this stage should try to replace temps by local temps or globals and local temps by globals. Reviewed-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* tcg/optimize: check types in copy propagationAurelien Jarno2012-09-221-10/+8
| | | | | | | | | | | | | | | | The copy propagation doesn't check the types of the temps during copy propagation. However TCG is using the mov_i32 for the i64 to i32 conversion and thus the two are not equivalent. With this patch tcg_opt_gen_mov() doesn't consider two temps of different type as copies anymore. So far it seems the optimization was not aggressive enough to trigger this bug, but it will be triggered later in this series once the copy propagation is improved. Reviewed-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* tcg/optimize: remove TCG_TEMP_ANYAurelien Jarno2012-09-221-6/+5
| | | | | | | | TCG_TEMP_ANY has no different meaning than TCG_TEMP_UNDEF, so use the later instead. Reviewed-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* tcg: Optimize two-address commutative operationsRichard Henderson2012-09-211-1/+14
| | | | | | | | While swapping constants to the second operand, swap sources matching destinations to the first operand. Signed-off-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* tcg: Optimize movcond for constant comparisonsRichard Henderson2012-09-211-0/+40
| | | | | Signed-off-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* tcg/optimize: fix end of basic block detectionAurelien Jarno2012-09-191-13/+9
| | | | | | | | | | | | | | | | | Commit e31b0a7c050711884ad570fe73df806520953618 fixed copy propagation on 32-bit host by restricting the copy between different types. This was the wrong fix. The real problem is that the all temps states should be reset at the end of a basic block. This was done by adding such operations in the switch, but brcond2 was forgotten (that's why the crash was only observed on 32-bit hosts). Fix that by looking at the TCG_OPF_BB_END instead. We need to keep the case for op_set_label as temps might be modified through another path. Cc: Blue Swirl <blauwirbel@gmail.com> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* revert "TCG: fix copy propagation"Aurelien Jarno2012-09-191-9/+6
| | | | | | | | Given the copy propagation breakage on 32-bit hosts has been fixed commit e31b0a7c050711884ad570fe73df806520953618 can be reverted. Cc: Blue Swirl <blauwirbel@gmail.com> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* tcg/optimize: fix if/else/break coding styleAurelien Jarno2012-09-111-23/+11
| | | | | | | | | optimizer.c contains some cases were the break is appearing in both the if and the else parts. Fix that by moving it to the outer part. Also move some common code there. Reviewed-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* tcg/optimize: add constant folding for brcondAurelien Jarno2012-09-111-1/+26
| | | | | Reviewed-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* tcg/optimize: add constant folding for setcondAurelien Jarno2012-09-111-0/+81
| | | | | Reviewed-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* tcg/optimize: swap brcond/setcond arguments when possibleAurelien Jarno2012-09-111-0/+18
| | | | | | | | | | brcond and setcond ops are not commutative, but it's easy to compute the new condition after swapping the arguments. Try to always put the constant argument in second position like for commutative ops, to help backends to generate better code. Reviewed-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* tcg/optimize: simplify shift/rot r, 0, a => movi r, 0 casesAurelien Jarno2012-09-111-0/+20
| | | | | | | shift/rot r, 0, a is equivalent to movi r, 0. Reviewed-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* tcg/optimize: simplify and r, a, 0 casesAurelien Jarno2012-09-111-0/+1
| | | | | | | and r, a, 0 is equivalent to a movi r, 0. Reviewed-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* tcg/optimize: simplify or/xor r, a, 0 casesAurelien Jarno2012-09-111-0/+2
| | | | | | | or/xor r, a, 0 is equivalent to a mov r, a. Reviewed-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* tcg/optimize: split expression simplificationAurelien Jarno2012-09-111-1/+13
| | | | | | | | Split expression simplification in multiple parts so that a given op can appear multiple times. This patch should not change anything. Reviewed-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* TCG: improve optimizer debuggingBlue Swirl2011-08-281-6/+9
| | | | | | | | Use enum TCGOpcode instead of plain old int so that the name of current op can be seen in GDB. Add a default case to switch so that GCC does not complain about unhandled enum cases. Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* tcg: Constant fold neg, andc, orc, eqv, nand, nor.Richard Henderson2011-08-211-0/+27
| | | | | Signed-off-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* tcg: Always define all of the TCGOpcode enum members.Richard Henderson2011-08-211-134/+22
| | | | | | | | | | | | By always defining these symbols, we can eliminate a lot of ifdefs. To allow this to be checked reliably, the semantics of the TCG_TARGET_HAS_* macros must be changed from def/undef to true/false. This allows even more ifdefs to be removed, converting them into C if statements. Signed-off-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* tcg: Add and use TCG_OPF_64BIT.Richard Henderson2011-08-211-74/+3
| | | | | | | | This allows the simplification of the op_bits function from tcg/optimize.c. Signed-off-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* TCG: fix copy propagationBlue Swirl2011-08-071-6/+9
| | | | | | | | | | | | Copy propagation introduced in 22613af4a6d9602001e6d0e7b6d98aa40aa018dc considered only global registers. However, register temps and stack allocated locals must be handled differently because register temps don't survive across brcond. Fix by propagating only within same class of temps. Tested-by: Stefan Weil <weil@mail.berlios.de> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* TCG: fix breakage by previous patchBlue Swirl2011-07-301-7/+12
| | | | | | | Fix incorrect logic and typos in previous commit 1bfd07bdfe56cea43dbe258dcb161e46b0ee29b7. Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* TCG: fix breakage on some RISC hostsBlue Swirl2011-07-301-13/+115
| | | | | | | | | | Fix breakage by a640f03178c22355a158fa9378e4f8bfa4f517a6 and 55c0975c5b358e948b9ae7bd7b07eff92508e756. Some TCG targets don't implement all TCG ops, so make optimizing those conditional. Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Do constant folding for unary operations.Kirill Batuzov2011-07-301-0/+59
| | | | | | | Perform constant folding for NOT and EXT{8,16,32}{S,U} operations. Signed-off-by: Kirill Batuzov <batuzovk@ispras.ru> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Do constant folding for shift operations.Kirill Batuzov2011-07-301-0/+72
| | | | | | | Perform constant forlding for SHR, SHL, SAR, ROTR, ROTL operations. Signed-off-by: Kirill Batuzov <batuzovk@ispras.ru> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Do constant folding for boolean operations.Kirill Batuzov2011-07-301-0/+37
| | | | | | | Perform constant folding for AND, OR, XOR operations. Signed-off-by: Kirill Batuzov <batuzovk@ispras.ru> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Do constant folding for basic arithmetic operations.Kirill Batuzov2011-07-301-0/+125
| | | | | | | Perform actual constant folding for ADD, SUB and MUL operations. Signed-off-by: Kirill Batuzov <batuzovk@ispras.ru> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Add copy and constant propagation.Kirill Batuzov2011-07-301-2/+180
| | | | | | | | Make tcg_constant_folding do copy and constant propagation. It is a preparational work before actual constant folding. Signed-off-by: Kirill Batuzov <batuzovk@ispras.ru> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Add TCG optimizations stubKirill Batuzov2011-07-301-0/+97
Added file tcg/optimize.c to hold TCG optimizations. Function tcg_optimize is called from tcg_gen_code_common. It calls other functions performing specific optimizations. Stub for constant folding was added. Signed-off-by: Kirill Batuzov <batuzovk@ispras.ru> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
OpenPOWER on IntegriCloud