An OP_SEXT or a OP_ZEXT followed by a truncate to a size smaller than the original size is unneeded, the same result can be obtained by doing the truncate directly on the original value. Dualy, an OP_SEXT or a OP_ZEXT followed by a truncate to a size smaller than the original size deosn't need the truncate, the same result can be obtained by doing the extend directly on the original value. Rearrange the inputs (src & orig_type) to bypass the unneeded operation. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- simplify.c | 5 ++++- validation/optim/ext-trunc-greater.c | 1 - validation/optim/ext-trunc-smaller.c | 1 - 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/simplify.c b/simplify.c index 2549860e3..996b3672e 100644 --- a/simplify.c +++ b/simplify.c @@ -1015,7 +1015,10 @@ static int simplify_cast(struct instruction *insn) osize = def->orig_type->bit_size; if (size == osize) return replace_with_pseudo(insn, def->src); - break; + if (size > osize) + insn->opcode = def->opcode; + insn->orig_type = def->orig_type; + return replace_pseudo(insn, &insn->src, def->src); } break; } diff --git a/validation/optim/ext-trunc-greater.c b/validation/optim/ext-trunc-greater.c index bb19e17b0..b682fc5de 100644 --- a/validation/optim/ext-trunc-greater.c +++ b/validation/optim/ext-trunc-greater.c @@ -11,7 +11,6 @@ short ugt(unsigned char x) /* * check-name: ext-trunc-greater * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-excludes: trunc\\. diff --git a/validation/optim/ext-trunc-smaller.c b/validation/optim/ext-trunc-smaller.c index a757a3adc..194c98d7b 100644 --- a/validation/optim/ext-trunc-smaller.c +++ b/validation/optim/ext-trunc-smaller.c @@ -11,7 +11,6 @@ char ult(unsigned short x) /* * check-name: ext-trunc-smaller * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-excludes: sext\\. -- 2.18.0 -- 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