After an OP_ZEXT, it is guaranted that the sign bit is zero. So, an arithmetic right-shift following an OP_ZEXT gives the same result as an logical right-shift which is simpler to handle and further optimize. So, when preceded by an OP_ZEXT, replace OP_ASR by OP_LSR. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- simplify.c | 12 ++++++++++++ validation/optim/zext-asr.c | 13 +++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 validation/optim/zext-asr.c diff --git a/simplify.c b/simplify.c index 65ea87d94..513652d2b 100644 --- a/simplify.c +++ b/simplify.c @@ -549,6 +549,7 @@ undef: static int simplify_shift(struct instruction *insn, pseudo_t pseudo, long long value) { + struct instruction *def; unsigned int size; if (!value) @@ -562,6 +563,17 @@ static int simplify_shift(struct instruction *insn, pseudo_t pseudo, long long v } switch (insn->opcode) { case OP_ASR: + switch(DEF_OPCODE(def, pseudo)) { + case OP_ZEXT: + // transform: + // zext.N %t <- (O) %a + // asr.N %r <- %t, C + // into + // zext.N %t <- (O) %a + // lsr.N %r <- %t, C + insn->opcode = OP_LSR; + return REPEAT_CSE; + } break; case OP_LSR: size = operand_size(insn, pseudo); diff --git a/validation/optim/zext-asr.c b/validation/optim/zext-asr.c new file mode 100644 index 000000000..5f235ad80 --- /dev/null +++ b/validation/optim/zext-asr.c @@ -0,0 +1,13 @@ +unsigned short foo(unsigned short a) +{ + return a >> 16; +} + +/* + * check-name: zext-asr + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-contains: ret\\..*\\$0 + * check-output-excludes: asr\\. + */ -- 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