Message ID | 20161207154655.98109-3-luc.vanoostenryck@gmail.com (mailing list archive) |
---|---|
State | Superseded, archived |
Headers | show |
On Wed, Dec 7, 2016 at 11:46 PM, Luc Van Oostenryck <luc.vanoostenryck@gmail.com> wrote: > Currently we simplify multiplication by 1 but nothing > for the similar divide by 1. > > --- a/simplify.c > +++ b/simplify.c > @@ -320,6 +320,10 @@ 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: > + case OP_DIVU: > + break; This patch has already applied to sparse-next. Just one minor comment that if the fall through is just a break. It is better just break there. If the later code need to use the fall though, just add the fall through part with the later code. I think the later patch change this code any way. Chris -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Tue, Feb 07, 2017 at 10:53:16AM +0800, Christopher Li wrote: > On Wed, Dec 7, 2016 at 11:46 PM, Luc Van Oostenryck > <luc.vanoostenryck@gmail.com> wrote: > > Currently we simplify multiplication by 1 but nothing > > for the similar divide by 1. > > > > --- a/simplify.c > > +++ b/simplify.c > > @@ -320,6 +320,10 @@ 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: > > + case OP_DIVU: > > + break; > > This patch has already applied to sparse-next. Just one minor comment that > if the fall through is just a break. It is better just break there. If > the later code > need to use the fall though, just add the fall through part with the later code. Mmmh yes. In fact here these 4 lines are not needed at all. It's most probably leftover of some code restructuration. Do you want that I send a new version of this patch? Luc -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Tue, Feb 7, 2017 at 10:52 PM, Luc Van Oostenryck <luc.vanoostenryck@gmail.com> wrote: > > Mmmh yes. In fact here these 4 lines are not needed at all. > It's most probably leftover of some code restructuration. > > Do you want that I send a new version of this patch? If you have a new version of this patch or series. I am happy to replace the old version and apply the new one. I can rebase sparse-next. Chris -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
This serie add a few more simplification of multiplicative operators (multiplication, division & modulo) with constants 1 or -1. Only simplifications that doesn't depend on undefined behavior are done. Changes since v1: - no functional changes - remove unneeded case + break in patch 2 Luc Van Oostenryck (5): move OP_MUL simplification in a separate function simplify '(x / 1)' to 'x' simplify '(x * -1)' to '-x' simplify '(x / -1)' to '-x' (but only for signed division) simplify '(x % 1)' into '0' simplify.c | 36 ++++++++++++++++++++++++++++++++++++ validation/optim/muldiv-by-one.c | 19 +++++++++++++++++++ validation/optim/muldiv-by-zero.c | 13 +++++++++++++ validation/optim/muldiv-minus-one.c | 15 +++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 validation/optim/muldiv-by-one.c create mode 100644 validation/optim/muldiv-by-zero.c create mode 100644 validation/optim/muldiv-minus-one.c
On Wed, Feb 8, 2017 at 3:00 AM, Luc Van Oostenryck <luc.vanoostenryck@gmail.com> wrote: > This serie add a few more simplification of multiplicative operators > (multiplication, division & modulo) with constants 1 or -1. > Only simplifications that doesn't depend on undefined behavior are done. > > Changes since v1: Just double checking. I suppose to take out the old version of the patch already applied in spase-next then apply this series, right? Chris -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/simplify.c b/simplify.c index b242b64d..5541fc4c 100644 --- a/simplify.c +++ b/simplify.c @@ -320,6 +320,10 @@ 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: + case OP_DIVU: + break; } return 0; @@ -348,6 +352,7 @@ static int simplify_constant_rightside(struct instruction *insn) case OP_ASR: return simplify_asr(insn, insn->src1, value); + case OP_DIVU: case OP_DIVS: case OP_MULU: case OP_MULS: return simplify_mul_div(insn, value); diff --git a/validation/optim/muldiv-by-one.c b/validation/optim/muldiv-by-one.c index ac8ac95b..f6dd7cb2 100644 --- a/validation/optim/muldiv-by-one.c +++ b/validation/optim/muldiv-by-one.c @@ -3,6 +3,8 @@ typedef int si; si smul1(si a) { return a * 1; } ui umul1(ui a) { return a * 1; } +si sdiv1(si a) { return a / 1; } +ui udiv1(ui a) { return a / 1; } /* * check-name: muldiv-by-one @@ -10,4 +12,5 @@ ui umul1(ui a) { return a * 1; } * check-output-ignore * * check-output-excludes: mul[us]\\. + * check-output-excludes: div[us]\\. */
Currently we simplify multiplication by 1 but nothing for the similar divide by 1. This patch add the missing simplification together with its test cases. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> --- simplify.c | 5 +++++ validation/optim/muldiv-by-one.c | 3 +++ 2 files changed, 8 insertions(+)