Statistics
| Branch: | Revision:

root / tcg / optimize.c @ feature-archipelago

History | View | Annotate | Download (39.5 kB)

# Date Author Comment
23ec69ed 02/17/2014 06:12 pm Richard Henderson

tcg/optimize: Handle known-zeros masks for ANDC

Reviewed-by: Paolo Bonzini <>
Reviewed-by: Aurelien Jarno <>
Signed-off-by: Richard Henderson <>

e201b564 02/17/2014 06:12 pm Richard Henderson

tcg/optimize: Simply some logical ops to NOT

Given, of course, an appropriate constant. These could be generated
from the "canonical" operation for inversion on the guest, or via
other optimizations.

Reviewed-by: Paolo Bonzini <>
Reviewed-by: Aurelien Jarno <>...

e64e958e 02/17/2014 06:12 pm Richard Henderson

tcg/optimize: Optmize ANDC X,Y,Y to MOV X,0

Like we already do for SUB and XOR.

Reviewed-by: Paolo Bonzini <>
Reviewed-by: Aurelien Jarno <>
Signed-off-by: Richard Henderson <>

464a1441 02/17/2014 06:12 pm Richard Henderson

tcg/optimize: Add more identity simplifications

Recognize 0 operand to andc, and -1 operands to and, orc, eqv.

Reviewed-by: Paolo Bonzini <>
Reviewed-by: Aurelien Jarno <>
Signed-off-by: Richard Henderson <>

e46b225a 02/17/2014 06:12 pm Aurelien Jarno

tcg/optimize: fix known-zero bits for right shift ops

32-bit versions of sar and shr ops should not propagate known-zero bits
from the unused 32 high bits. For sar it could even lead to wrong code
being generated.

Cc:
Reviewed-by: Paolo Bonzini <>...

3031244b 02/17/2014 06:12 pm Aurelien Jarno

tcg/optimize: fix known-zero bits optimization

Known-zero bits optimization is a great idea that helps to generate more
optimized code. However the current implementation only works in very few
cases as the computed mask is not saved.

Fix this to make it really working....

f096dc96 02/17/2014 06:12 pm Aurelien Jarno

tcg/optimize: improve known-zero bits for 32-bit ops

The shl_i32 op might set some bits of the unused 32 high bits of the
mask. Fix that by clearing the unused 32 high bits for all 32-bit ops
except load/store which operate on tl values.

Reviewed-by: Paolo Bonzini <>...

c8d70272 02/17/2014 06:12 pm Aurelien Jarno

tcg/optimize: add known-zero bits compute for load ops

Reviewed-by: Paolo Bonzini <>
Signed-off-by: Aurelien Jarno <>
Signed-off-by: Richard Henderson <>

3df2b8fd 09/25/2013 10:23 pm Stefan Weil

misc: Use new rotate functions

Signed-off-by: Stefan Weil <>

03271524 09/02/2013 07:08 pm Richard Henderson

tcg: Add muluh and mulsh opcodes

Use them in places where mulu2 and muls2 are used.
Optimize mulx2 with dead low part to mulxh.

Reviewed-by: Aurelien Jarno <>
Signed-off-by: Richard Henderson <>

01547f7f 09/02/2013 07:08 pm Richard Henderson

tcg: Constant fold div, rem

Reviewed-by: Aurelien Jarno <>
Signed-off-by: Richard Henderson <>

66e61b55 05/09/2013 05:14 pm Aurelien Jarno

tcg/optimize: fix setcond2 optimization

When setcond2 is rewritten into setcond, the state of the destination
temp should be reset, so that a copy of the previous value is not
used instead of the result.

Reported-by: Michael Tokarev <>
Reviewed-by: Richard Henderson <>...

2d497542 03/23/2013 04:31 pm Richard Henderson

tcg-optimize: Fold sub r,0,x to neg r,x

Cc: Blue Swirl <>
Signed-off-by: Richard Henderson <>
Signed-off-by: Blue Swirl <>

d7156f7c 02/23/2013 07:25 pm Richard Henderson

tcg: Add 64-bit multiword arithmetic operations

Matching the 32-bit multiword arithmetic that we already have.

Signed-off-by: Blue Swirl <>

4d3203fd 02/23/2013 07:25 pm Richard Henderson

tcg: Add signed multiword multiplication operations

Signed-off-by: Richard Henderson <>
Signed-off-by: Blue Swirl <>

633f6502 01/19/2013 12:13 pm Paolo Bonzini

optimize: optimize using nonzero bits

This adds two optimizations using the non-zero bit mask. In some cases
involving shifts or ANDs the value can become zero, and can thus be
optimized to a move of zero. Second, useless zero-extension or an
AND with constant can be detected that would only zero bits that are...

3a9d8b17 01/19/2013 12:13 pm Paolo Bonzini

optimize: track nonzero bits of registers

Add a "mask" field to the tcg_temp_info struct. A bit that is zero
in "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...

d193a14a 01/19/2013 12:13 pm Paolo Bonzini

optimize: only write to state when clearing optimizer data

The next patch will add to the TCG optimizer a field that should be
non-zero in the default case. Thus, replace the memset of the
temps array with a loop. Only the state field has to be up-to-date,...

92414b31 11/17/2012 03:53 pm Evgeny Voevodin

TCG: Use gen_opc_buf from context instead of global variable.

Signed-off-by: Evgeny Voevodin <>
Reviewed-by: Richard Henderson <>
Signed-off-by: Blue Swirl <>

78505279 10/28/2012 03:54 pm Aurelien Jarno

tcg: rework TCG helper flags

The current helper flags, TCG_CALL_CONST and TCG_CALL_PURE might be
confusing and doesn't provide enough granularity for some helpers (FP
helpers for example).

This patch changes them into the following helpers flags:
- TCG_CALL_NO_READ_GLOBALS means that the helper does not read globals,...

1414968a 10/17/2012 06:51 pm Richard Henderson

tcg: Optimize mulu2

Like add2, do operand ordering, constant folding, and dead operand
elimination. The latter happens about 15% of all mulu2 during an
x86_64 bios boot.

Signed-off-by: Richard Henderson <>
Signed-off-by: Aurelien Jarno <>

212c328d 10/17/2012 06:51 pm Richard Henderson

tcg: Constant fold add2 and sub2

Signed-off-by: Richard Henderson <>
Signed-off-by: Aurelien Jarno <>

6c4382f8 10/17/2012 06:51 pm Richard Henderson

tcg: Do constant folding on double-word comparisons

Signed-off-by: Richard Henderson <>
Signed-off-by: Aurelien Jarno <>

9519da7e 10/17/2012 06:51 pm Richard Henderson

tcg: Split out subroutines from do_constant_folding_cond

We can re-use these for implementing double-word folding.

Signed-off-by: Richard Henderson <>
Signed-off-by: Aurelien Jarno <>

bc1473ef 10/17/2012 06:32 pm Richard Henderson

tcg: Optimize double-word comparisons against zero

Signed-off-by: Richard Henderson <>
Signed-off-by: Aurelien Jarno <>

6e14e91b 10/17/2012 06:32 pm Richard Henderson

tcg: Use common code when failing to optimize

This saves a whole lot of repetitive code sequences.

Signed-off-by: Richard Henderson <>
Signed-off-by: Aurelien Jarno <>

0bfcb865 10/17/2012 06:31 pm Richard Henderson

tcg: Swap commutative double-word comparisons

Signed-off-by: Richard Henderson <>
Signed-off-by: Aurelien Jarno <>

1e484e61 10/17/2012 06:31 pm Richard Henderson

tcg: Canonicalize add2 operand ordering

Signed-off-by: Richard Henderson <>
Signed-off-by: Aurelien Jarno <>

24c9ae4e 10/17/2012 06:30 pm Richard Henderson

tcg: Split out swap_commutative as a subroutine

Reduces code duplication and prefers

movcond d, c1, c2, const, s
to
movcond d, c1, c2, s, const

It also prefers

add r, r, c
over
add r, c, r

when both inputs are known constants. This doesn't matter for true add, as...

0aed257f 10/06/2012 07:48 pm Richard Henderson

tcg: Add TCG_COND_NEVER, TCG_COND_ALWAYS

There are several cases that can be handled easier inside both
translators and code generators if we have out-of-band values
for conditions. It's easy enough to handle ALWAYS and NEVER in
the natural way inside the tcg middle-end....

e590d4e6 09/22/2012 04:10 pm Aurelien Jarno

tcg/optimize: rework copy progagation

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"....

1ff8c541 09/22/2012 04:10 pm Aurelien Jarno

tcg/optimize: do copy propagation for all operations

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...

0aba1c73 09/22/2012 04:10 pm Aurelien Jarno

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 <>
Signed-off-by: Aurelien Jarno <>

3c94193e 09/22/2012 04:10 pm Aurelien Jarno

tcg/optimize: optimize "op r, a, a => movi r, 0"

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 <>...

b336ceb6 09/22/2012 04:10 pm Aurelien Jarno

tcg/optimize: further optimize brcond/movcond/setcond

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 <>...

c2b0e2fe 09/22/2012 04:10 pm Aurelien Jarno

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 "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....

7ef55fc9 09/22/2012 04:10 pm Aurelien Jarno

tcg/optimize: add constant folding for deposit

Reviewed-by: Richard Henderson <>
Signed-off-by: Aurelien Jarno <>

48b56ce1 09/22/2012 04:10 pm Aurelien Jarno

tcg/optimize: remove TCG_TEMP_ANY

TCG_TEMP_ANY has no different meaning than TCG_TEMP_UNDEF, so use
the later instead.

Reviewed-by: Richard Henderson <>
Signed-off-by: Aurelien Jarno <>

b80bb016 09/22/2012 04:10 pm Aurelien Jarno

tcg/optimize: check types in copy propagation

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...

fa01a208 09/21/2012 08:53 pm Richard Henderson

tcg: Optimize movcond for constant comparisons

Signed-off-by: Richard Henderson <>
Signed-off-by: Aurelien Jarno <>

5d8f5363 09/21/2012 08:53 pm Richard Henderson

tcg: Optimize two-address commutative operations

While swapping constants to the second operand, swap
sources matching destinations to the first operand.

Signed-off-by: Richard Henderson <>
Signed-off-by: Aurelien Jarno <>

a2550660 09/19/2012 10:53 pm Aurelien Jarno

tcg/optimize: fix end of basic block detection

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...

d104bebd 09/19/2012 10:40 pm Aurelien Jarno

revert "TCG: fix copy propagation"

Given the copy propagation breakage on 32-bit hosts has been fixed
commit e31b0a7c050711884ad570fe73df806520953618 can be reverted.

Cc: Blue Swirl <>
Signed-off-by: Aurelien Jarno <>

fedc0da2 09/11/2012 07:06 pm Aurelien Jarno

tcg/optimize: fix if/else/break coding style

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 <>...

fbeaa26c 09/11/2012 07:06 pm Aurelien Jarno

tcg/optimize: add constant folding for brcond

Reviewed-by: Richard Henderson <>
Signed-off-by: Aurelien Jarno <>

f8dd19e5 09/11/2012 07:06 pm Aurelien Jarno

tcg/optimize: add constant folding for setcond

Reviewed-by: Richard Henderson <>
Signed-off-by: Aurelien Jarno <>

65a7cce1 09/11/2012 07:05 pm Aurelien Jarno

tcg/optimize: swap brcond/setcond arguments when possible

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...

01ee5282 09/11/2012 07:05 pm Aurelien Jarno

tcg/optimize: simplify shift/rot r, 0, a => movi r, 0 cases

shift/rot r, 0, a is equivalent to movi r, 0.

Reviewed-by: Richard Henderson <>
Signed-off-by: Aurelien Jarno <>

61251c0c 09/11/2012 07:05 pm Aurelien Jarno

tcg/optimize: simplify and r, a, 0 cases

and r, a, 0 is equivalent to a movi r, 0.

Reviewed-by: Richard Henderson <>
Signed-off-by: Aurelien Jarno <>

38ee188b 09/11/2012 07:05 pm Aurelien Jarno

tcg/optimize: simplify or/xor r, a, 0 cases

or/xor r, a, 0 is equivalent to a mov r, a.

Reviewed-by: Richard Henderson <>
Signed-off-by: Aurelien Jarno <>

56e49438 09/11/2012 07:05 pm Aurelien Jarno

tcg/optimize: split expression simplification

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 <>
Signed-off-by: Aurelien Jarno <>

fe0de7aa 08/28/2011 10:17 am Blue Swirl

TCG: improve optimizer debugging

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 <>

cb25c80a 08/21/2011 09:52 pm Richard Henderson

tcg: Constant fold neg, andc, orc, eqv, nand, nor.

Signed-off-by: Richard Henderson <>
Signed-off-by: Blue Swirl <>

25c4d9cc 08/21/2011 09:52 pm Richard Henderson

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 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...

8399ad59 08/21/2011 09:52 pm Richard Henderson

tcg: Add and use TCG_OPF_64BIT.

This allows the simplification of the op_bits function from
tcg/optimize.c.

Signed-off-by: Richard Henderson <>
Signed-off-by: Blue Swirl <>

e31b0a7c 08/07/2011 12:33 pm Blue Swirl

TCG: fix copy propagation

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....

2ec00650 07/30/2011 09:54 pm Blue Swirl

TCG: fix breakage by previous patch

Fix incorrect logic and typos in previous commit
1bfd07bdfe56cea43dbe258dcb161e46b0ee29b7.

Signed-off-by: Blue Swirl <>

1bfd07bd 07/30/2011 03:21 pm Blue Swirl

TCG: fix breakage on some RISC hosts

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 <>

a640f031 07/30/2011 01:51 pm Kirill Batuzov

Do constant folding for unary operations.

Perform constant folding for NOT and EXT{8,16,32}{S,U} operations.

Signed-off-by: Kirill Batuzov <>
Signed-off-by: Blue Swirl <>

9a81090b 07/30/2011 01:51 pm Kirill Batuzov

Do constant folding for boolean operations.

Perform constant folding for AND, OR, XOR operations.

Signed-off-by: Kirill Batuzov <>
Signed-off-by: Blue Swirl <>

55c0975c 07/30/2011 01:51 pm Kirill Batuzov

Do constant folding for shift operations.

Perform constant forlding for SHR, SHL, SAR, ROTR, ROTL operations.

Signed-off-by: Kirill Batuzov <>
Signed-off-by: Blue Swirl <>

53108fb5 07/30/2011 01:51 pm Kirill Batuzov

Do constant folding for basic arithmetic operations.

Perform actual constant folding for ADD, SUB and MUL operations.

Signed-off-by: Kirill Batuzov <>
Signed-off-by: Blue Swirl <>

22613af4 07/30/2011 01:51 pm Kirill Batuzov

Add copy and constant propagation.

Make tcg_constant_folding do copy and constant propagation. It is a
preparational work before actual constant folding.

Signed-off-by: Kirill Batuzov <>
Signed-off-by: Blue Swirl <>

8f2e8c07 07/30/2011 01:51 pm Kirill Batuzov

Add TCG optimizations stub

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 <>...