A previous patch added the simplification for multiply by -1 but we can do the same for the signed divide. This patch add this simplification Also add the corresponding test cases. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- simplify.c | 2 ++ validation/optim/muldiv-minus-one.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/simplify.c b/simplify.c index 363cc5ad7..86d2f5da9 100644 --- a/simplify.c +++ b/simplify.c @@ -323,6 +323,8 @@ static int simplify_mul_div(struct instruction *insn, long long value) case OP_MULU: if (value == 0) return replace_with_pseudo(insn, insn->src2); + /* Fall through */ + case OP_DIVS: if (!(value & sbit)) // positive break; diff --git a/validation/optim/muldiv-minus-one.c b/validation/optim/muldiv-minus-one.c index 729b73443..42b086afd 100644 --- a/validation/optim/muldiv-minus-one.c +++ b/validation/optim/muldiv-minus-one.c @@ -2,6 +2,8 @@ typedef unsigned int u32; int smulm1(int a) { return a * -1; } u32 umulm1(u32 a) { return a * (u32) -1; } +int sdivm1(int a) { return a / -1; } +u32 udivm1(u32 a) { return a / (u32) -1; } /* * check-name: muldiv-minus-one @@ -9,5 +11,8 @@ u32 umulm1(u32 a) { return a * (u32) -1; } * check-output-ignore * * check-output-excludes: mul[us]\\. + * check-output-excludes: divs\\. * check-output-contains: neg\\. + * check-output-contains: divu\\. + * check-output-pattern-3-times: neg\\. */ -- 2.11.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