Skip to content

Commit

Permalink
tcg/optimize: Split out arg_new_constant
Browse files Browse the repository at this point in the history
Fixes a bug wherein raw uses of tcg_constant_internal
do not have their TempOptInfo initialized.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
  • Loading branch information
rth7680 committed Nov 6, 2023
1 parent 3eaadae commit 26aac97
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions tcg/optimize.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,21 @@ static TCGTemp *find_mem_copy_for(OptContext *ctx, TCGType type, intptr_t s)
return NULL;
}

static TCGArg arg_new_constant(OptContext *ctx, uint64_t val)
{
TCGType type = ctx->type;
TCGTemp *ts;

if (type == TCG_TYPE_I32) {
val = (int32_t)val;
}

ts = tcg_constant_internal(type, val);
init_ts_info(ctx, ts);

return temp_arg(ts);
}

static bool tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src)
{
TCGTemp *dst_ts = arg_temp(dst);
Expand Down Expand Up @@ -399,16 +414,8 @@ static bool tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src)
static bool tcg_opt_gen_movi(OptContext *ctx, TCGOp *op,
TCGArg dst, uint64_t val)
{
TCGTemp *tv;

if (ctx->type == TCG_TYPE_I32) {
val = (int32_t)val;
}

/* Convert movi to mov with constant temp. */
tv = tcg_constant_internal(ctx->type, val);
init_ts_info(ctx, tv);
return tcg_opt_gen_mov(ctx, op, dst, temp_arg(tv));
return tcg_opt_gen_mov(ctx, op, dst, arg_new_constant(ctx, val));
}

static uint64_t do_constant_folding_2(TCGOpcode op, uint64_t x, uint64_t y)
Expand Down Expand Up @@ -1431,7 +1438,7 @@ static bool fold_deposit(OptContext *ctx, TCGOp *op)

op->opc = and_opc;
op->args[1] = op->args[2];
op->args[2] = temp_arg(tcg_constant_internal(ctx->type, mask));
op->args[2] = arg_new_constant(ctx, mask);
ctx->z_mask = mask & arg_info(op->args[1])->z_mask;
return false;
}
Expand All @@ -1442,7 +1449,7 @@ static bool fold_deposit(OptContext *ctx, TCGOp *op)
uint64_t mask = deposit64(-1, op->args[3], op->args[4], 0);

op->opc = and_opc;
op->args[2] = temp_arg(tcg_constant_internal(ctx->type, mask));
op->args[2] = arg_new_constant(ctx, mask);
ctx->z_mask = mask & arg_info(op->args[1])->z_mask;
return false;
}
Expand Down

0 comments on commit 26aac97

Please sign in to comment.