From: Richard Henderson <rth@twiddle.net>
To: Kirill Batuzov <batuzovk@ispras.ru>
Cc: qemu-devel@nongnu.org, zhur@ispras.ru
Subject: Re: [Qemu-devel] [PATCH v2 3/6] Do constant folding for basic arithmetic operations.
Date: Fri, 10 Jun 2011 10:57:57 -0700 [thread overview]
Message-ID: <4DF25B25.1020708@twiddle.net> (raw)
In-Reply-To: <1307616344-27161-4-git-send-email-batuzovk@ispras.ru>
On 06/09/2011 03:45 AM, Kirill Batuzov wrote:
> +static int op_to_mov(int op)
> +{
> + if (op_bits(op) == 32) {
> + return INDEX_op_mov_i32;
> + }
> +#if TCG_TARGET_REG_BITS == 64
> + if (op_bits(op) == 64) {
> + return INDEX_op_mov_i64;
> + }
> +#endif
> + tcg_abort();
> +}
Again, switch not two calls.
> +static TCGArg do_constant_folding(int op, TCGArg x, TCGArg y)
> +{
> + TCGArg res = do_constant_folding_2(op, x, y);
> +#if TCG_TARGET_REG_BITS == 64
> + if (op_bits(op) == 32) {
> + res &= 0xffffffff;
Strictly speaking, this isn't required. The top bits of any
constant are considered garbage to the code generators. C.f.
the code in tcg_out_movi for any 64-bit host.
That said, only x86_64 and s390 get this right for the constraints.
x86_64 by being able to use 'i' to accept all constants for 32-bit
operations, and s390 by using 'W' as a modifier to force 32-bit
comparison in tcg_target_const_match.
So it's probably best to keep this for now.
> + /* Simplify expression if possible. */
> + switch (op) {
> + case INDEX_op_add_i32:
> +#if TCG_TARGET_REG_BITS == 64
> + case INDEX_op_add_i64:
> +#endif
> + if (temps[args[1]].state == TCG_TEMP_CONST) {
> + /* 0 + x == x + 0 */
> + tmp = args[1];
> + args[1] = args[2];
> + args[2] = tmp;
> + }
Probably best to break this out into another switch so that
you can handle all of the commutative operations.
> + /* Fallthrough */
> + case INDEX_op_sub_i32:
> +#if TCG_TARGET_REG_BITS == 64
> + case INDEX_op_sub_i64:
> +#endif
> + if (temps[args[1]].state == TCG_TEMP_CONST) {
> + /* Proceed with possible constant folding. */
> + break;
> + }
> + if (temps[args[2]].state == TCG_TEMP_CONST
> + && temps[args[2]].val == 0) {
> + if ((temps[args[0]].state == TCG_TEMP_COPY
> + && temps[args[0]].val == args[1])
> + || args[0] == args[1]) {
> + args += 3;
> + gen_opc_buf[op_index] = INDEX_op_nop;
> + } else {
> + reset_temp(temps, args[0], nb_temps, nb_globals);
> + if (args[1] >= s->nb_globals) {
> + temps[args[0]].state = TCG_TEMP_COPY;
> + temps[args[0]].val = args[1];
> + temps[args[1]].num_copies++;
> + }
> + gen_opc_buf[op_index] = op_to_mov(op);
> + gen_args[0] = args[0];
> + gen_args[1] = args[1];
> + gen_args += 2;
> + args += 3;
> + }
> + continue;
> + }
> + break;
> + case INDEX_op_mul_i32:
> +#if TCG_TARGET_REG_BITS == 64
> + case INDEX_op_mul_i64:
> +#endif
> + if ((temps[args[1]].state == TCG_TEMP_CONST
> + && temps[args[1]].val == 0)
> + || (temps[args[2]].state == TCG_TEMP_CONST
> + && temps[args[2]].val == 0)) {
> + reset_temp(temps, args[0], nb_temps, nb_globals);
> + temps[args[0]].state = TCG_TEMP_CONST;
> + temps[args[0]].val = 0;
> + assert(temps[args[0]].num_copies == 0);
> + gen_opc_buf[op_index] = op_to_movi(op);
> + gen_args[0] = args[0];
> + gen_args[1] = 0;
> + args += 3;
> + gen_args += 2;
> + continue;
> + }
This is *way* too much code duplication, particularly with the
same code sequences already existing for mov and movi and more
to come with the logicals.
r~
next prev parent reply other threads:[~2011-06-10 17:58 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-09 10:45 [Qemu-devel] [PATCH v2 0/6] Implement constant folding and copy propagation in TCG Kirill Batuzov
2011-06-09 10:45 ` [Qemu-devel] [PATCH v2 1/6] Add TCG optimizations stub Kirill Batuzov
2011-06-09 10:45 ` [Qemu-devel] [PATCH v2 2/6] Add copy and constant propagation Kirill Batuzov
2011-06-10 17:44 ` Richard Henderson
2011-07-07 12:36 ` Kirill Batuzov
2011-06-09 10:45 ` [Qemu-devel] [PATCH v2 3/6] Do constant folding for basic arithmetic operations Kirill Batuzov
2011-06-10 17:57 ` Richard Henderson [this message]
2011-06-09 10:45 ` [Qemu-devel] [PATCH v2 4/6] Do constant folding for boolean operations Kirill Batuzov
2011-06-09 10:45 ` [Qemu-devel] [PATCH v2 5/6] Do constant folding for shift operations Kirill Batuzov
2011-06-10 18:02 ` Richard Henderson
2011-06-09 10:45 ` [Qemu-devel] [PATCH v2 6/6] Do constant folding for unary operations Kirill Batuzov
2011-06-10 18:04 ` Richard Henderson
2011-06-10 18:08 ` [Qemu-devel] [PATCH v2 0/6] Implement constant folding and copy propagation in TCG Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4DF25B25.1020708@twiddle.net \
--to=rth@twiddle.net \
--cc=batuzovk@ispras.ru \
--cc=qemu-devel@nongnu.org \
--cc=zhur@ispras.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.