Some casts, the ones which doesn't change the size or the resulting 'machine type', are no-op. Directly simplify away such casts. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- linearize.c | 8 ++++++++ validation/linear/cast-kinds.c | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/linearize.c b/linearize.c index c6c377b2e..0258a82a5 100644 --- a/linearize.c +++ b/linearize.c @@ -1206,6 +1206,8 @@ static int get_cast_opcode(struct symbol *dst, struct symbol *src) case MTYPE_FLOAT: switch (stype) { case MTYPE_FLOAT: + if (dst->bit_size == src->bit_size) + return OP_NOP; return OP_FCVTF; case MTYPE_UINT: return OP_UCVTF; @@ -1243,6 +1245,12 @@ static pseudo_t cast_pseudo(struct entrypoint *ep, pseudo_t src, struct symbol * if (from->bit_size < 0 || to->bit_size < 0) return VOID; opcode = get_cast_opcode(to, from); + switch (opcode) { + case OP_NOP: + return src; + default: + break; + } insn = alloc_typed_instruction(opcode, to); result = alloc_pseudo(insn); insn->target = result; diff --git a/validation/linear/cast-kinds.c b/validation/linear/cast-kinds.c index d8ac5d34f..5944610c6 100644 --- a/validation/linear/cast-kinds.c +++ b/validation/linear/cast-kinds.c @@ -50,6 +50,9 @@ static double long_2_double(long a) { return (double)a; } static double ulong_2_double(ulong a) { return (double)a; } static double float_2_double(float a) { return (double)a; } +static float float_2_float(float a) { return a; } +static double double_2_double(double a) { return a; } + /* * check-name: cast-kinds * check-command: test-linearize -m64 $file @@ -387,5 +390,17 @@ float_2_double: ret.64 %r143 +float_2_float: +.L96: + <entry-point> + ret.32 %arg1 + + +double_2_double: +.L98: + <entry-point> + ret.64 %arg1 + + * check-output-end */ -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html