History | View | Annotate | Download (34.3 kB)
tcg/optimize: fix setcond2 optimization
When setcond2 is rewritten into setcond, the state of the destinationtemp should be reset, so that a copy of the previous value is notused instead of the result.
Reported-by: Michael Tokarev <mjt@tls.msk.ru>Reviewed-by: Richard Henderson <rth@twiddle.net>...
tcg-optimize: Fold sub r,0,x to neg r,x
Cc: Blue Swirl <blauwirbel@gmail.com>Signed-off-by: Richard Henderson <rth@twiddle.net>Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
tcg: Add 64-bit multiword arithmetic operations
Matching the 32-bit multiword arithmetic that we already have.
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
tcg: Add signed multiword multiplication operations
Signed-off-by: Richard Henderson <rth@twiddle.net>Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
optimize: optimize using nonzero bits
This adds two optimizations using the non-zero bit mask. In some casesinvolving shifts or ANDs the value can become zero, and can thus beoptimized to a move of zero. Second, useless zero-extension or anAND with constant can be detected that would only zero bits that are...
optimize: track nonzero bits of registers
Add a "mask" field to the tcg_temp_info struct. A bit that is zeroin "mask" will always be zero in the corresponding temporary.Zero bits in the mask can be produced from moves of immediates,zero-extensions, ANDs with constants, shifts; they can then be...
optimize: only write to state when clearing optimizer data
The next patch will add to the TCG optimizer a field that should benon-zero in the default case. Thus, replace the memset of thetemps array with a loop. Only the state field has to be up-to-date,...
TCG: Use gen_opc_buf from context instead of global variable.
Signed-off-by: Evgeny Voevodin <e.voevodin@samsung.com>Reviewed-by: Richard Henderson <rth@twiddle.net>Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
tcg: rework TCG helper flags
The current helper flags, TCG_CALL_CONST and TCG_CALL_PURE might beconfusing and doesn't provide enough granularity for some helpers (FPhelpers for example).
This patch changes them into the following helpers flags:- TCG_CALL_NO_READ_GLOBALS means that the helper does not read globals,...
tcg: Optimize mulu2
Like add2, do operand ordering, constant folding, and dead operandelimination. The latter happens about 15% of all mulu2 during anx86_64 bios boot.
Signed-off-by: Richard Henderson <rth@twiddle.net>Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
tcg: Constant fold add2 and sub2
tcg: Do constant folding on double-word comparisons
tcg: Split out subroutines from do_constant_folding_cond
We can re-use these for implementing double-word folding.
tcg: Optimize double-word comparisons against zero
tcg: Use common code when failing to optimize
This saves a whole lot of repetitive code sequences.
tcg: Swap commutative double-word comparisons
tcg: Canonicalize add2 operand ordering
tcg: Split out swap_commutative as a subroutine
Reduces code duplication and prefers
movcond d, c1, c2, const, sto movcond d, c1, c2, s, const
It also prefers
add r, r, cover add r, c, r
when both inputs are known constants. This doesn't matter for true add, as...
tcg: Add TCG_COND_NEVER, TCG_COND_ALWAYS
There are several cases that can be handled easier inside bothtranslators and code generators if we have out-of-band valuesfor conditions. It's easy enough to handle ALWAYS and NEVER inthe natural way inside the tcg middle-end....
tcg/optimize: rework copy progagation
The copy propagation pass tries to keep track what is a copy of whatand what has copy of what, and in addition it keep a circular list ofof all the copies. Unfortunately this doesn't fully work: a mov froma temp which has a state "COPY" changed it into a state "HAS_COPY"....
tcg/optimize: do copy propagation for all operations
It is possible to due copy propagation for all operations, even the onethat have side effects or clobber arguments (it only concerns inputarguments). That said, the call operation should be handled differently...
tcg/optimize: optimize "op r, a, a => mov r, a"
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: optimize "op r, a, a => movi r, 0"
Now that it's possible to detect copies, we can optimize the casethe "op r, a, a => movi r, 0". This helps in the computation ofoverflow flags when one of the two args is 0.
Reviewed-by: Richard Henderson <rth@twiddle.net>...
tcg/optimize: further optimize brcond/movcond/setcond
When both argument of brcond/movcond/setcond are the same or when oneof the two values is a constant equal to zero, it's possible to dofurther optimizations.
tcg/optimize: prefer the "op a, a, b" form for commutative ops
The "op a, a, b" form is better handled on non-RISC host than the "opa, b, a" form, so swap the arguments to this form when possible, andwhen b is not a constant.
This reduces the number of generated instructions by a tiny bit....
tcg/optimize: add constant folding for deposit
tcg/optimize: remove TCG_TEMP_ANY
TCG_TEMP_ANY has no different meaning than TCG_TEMP_UNDEF, so usethe later instead.
tcg/optimize: check types in copy propagation
The copy propagation doesn't check the types of the temps during copypropagation. However TCG is using the mov_i32 for the i64 to i32conversion and thus the two are not equivalent.
With this patch tcg_opt_gen_mov() doesn't consider two temps of...
tcg: Optimize movcond for constant comparisons
tcg: Optimize two-address commutative operations
While swapping constants to the second operand, swapsources matching destinations to the first operand.
tcg/optimize: fix end of basic block detection
Commit e31b0a7c050711884ad570fe73df806520953618 fixed copy propagation on32-bit host by restricting the copy between different types. This was thewrong fix.
The real problem is that the all temps states should be reset at the end...
revert "TCG: fix copy propagation"
Given the copy propagation breakage on 32-bit hosts has been fixedcommit 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 style
optimizer.c contains some cases were the break is appearing in both theif and the else parts. Fix that by moving it to the outer part. Alsomove some common code there.
tcg/optimize: add constant folding for brcond
tcg/optimize: add constant folding for setcond
tcg/optimize: swap brcond/setcond arguments when possible
brcond and setcond ops are not commutative, but it's easy to compute thenew condition after swapping the arguments. Try to always put the constantargument in second position like for commutative ops, to help backends to...
tcg/optimize: simplify shift/rot r, 0, a => movi r, 0 cases
shift/rot r, 0, a is equivalent to movi r, 0.
tcg/optimize: simplify and r, a, 0 cases
and r, a, 0 is equivalent to a movi r, 0.
tcg/optimize: simplify or/xor r, a, 0 cases
or/xor r, a, 0 is equivalent to a mov r, a.
tcg/optimize: split expression simplification
Split expression simplification in multiple parts so that a given opcan appear multiple times. This patch should not change anything.
TCG: improve optimizer debugging
Use enum TCGOpcode instead of plain old int so that the name ofcurrent op can be seen in GDB. Add a default case to switchso that GCC does not complain about unhandled enum cases.
tcg: Constant fold neg, andc, orc, eqv, nand, nor.
tcg: Always define all of the TCGOpcode enum members.
By always defining these symbols, we can eliminate a lot of ifdefs.
To allow this to be checked reliably, the semantics of theTCG_TARGET_HAS_* macros must be changed from def/undef to true/false.This allows even more ifdefs to be removed, converting them into...
tcg: Add and use TCG_OPF_64BIT.
This allows the simplification of the op_bits function fromtcg/optimize.c.
TCG: fix copy propagation
Copy propagation introduced in 22613af4a6d9602001e6d0e7b6d98aa40aa018dcconsidered only global registers. However, register temps and stackallocated locals must be handled differently because register tempsdon't survive across brcond....
TCG: fix breakage by previous patch
Fix incorrect logic and typos in previous commit1bfd07bdfe56cea43dbe258dcb161e46b0ee29b7.
TCG: fix breakage on some RISC hosts
Fix breakage by a640f03178c22355a158fa9378e4f8bfa4f517a6and 55c0975c5b358e948b9ae7bd7b07eff92508e756.
Some TCG targets don't implement all TCG ops, so makeoptimizing those conditional.
Do constant folding for unary operations.
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 boolean operations.
Perform constant folding for AND, OR, XOR operations.
Do constant folding for shift operations.
Perform constant forlding for SHR, SHL, SAR, ROTR, ROTL operations.
Do constant folding for basic arithmetic operations.
Perform actual constant folding for ADD, SUB and MUL operations.
Add copy and constant propagation.
Make tcg_constant_folding do copy and constant propagation. It is apreparational work before actual constant folding.
Add TCG optimizations stub
Added file tcg/optimize.c to hold TCG optimizations. Function tcg_optimizeis called from tcg_gen_code_common. It calls other functions performingspecific optimizations. Stub for constant folding was added.
Signed-off-by: Kirill Batuzov <batuzovk@ispras.ru>...