From patchwork Tue Feb 7 19:00:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 9560903 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5028460434 for ; Tue, 7 Feb 2017 19:00:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4395B2654B for ; Tue, 7 Feb 2017 19:00:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3897D28477; Tue, 7 Feb 2017 19:00:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E90242654B for ; Tue, 7 Feb 2017 19:00:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754472AbdBGTAq (ORCPT ); Tue, 7 Feb 2017 14:00:46 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:35429 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755426AbdBGTAo (ORCPT ); Tue, 7 Feb 2017 14:00:44 -0500 Received: by mail-wm0-f66.google.com with SMTP id u63so30033457wmu.2 for ; Tue, 07 Feb 2017 11:00:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wr4Kq8nw58cKLrLog7Z85yrRyx2JCz8+uxx+JybdpTs=; b=XnEntJyVwYK5UmDhUHFfqx0yQEUtjtEdaZ2J8zhKNVrloaRwiPOBBJJp+z7G0or8kM yALIOs0soctRYjmOwb9wIFjh3E6ei9+SZQrj6G3K88T4DfgdmdHt/zHYRecitNP5jqK7 I/0p/HQ60nX5MQwWasqacImolEDBAfw2tkazaFuyCNZsBHDM9ZRvfvwg1X6W1eF3BcgP RVomWRCLU+U6wfqkc8e67yFUsmPRpV9TM3skTPLafRbkgdV71oLUYeyl6KfM5/eJFpa2 o21o3Cof80LjXFlR1bzVEjAhpLjsErutxVTWeoVr4RQVbCoKnH7a5ioCkjIej0wn1ZL3 0bdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wr4Kq8nw58cKLrLog7Z85yrRyx2JCz8+uxx+JybdpTs=; b=spyCYM8lR+6Y6+DI56OqPF228y+4NEf5YjPeQswfo+mFT1xyjys9XI8o9iO1HNDgkD gg3QqrRslBLFBnNKJmfe1aFxJ6JgC9affha7VYHIsyKoKegoRsJ045xLDbw8TXn8WHrb YQahJpx5tcOn2mXrWg9pSqlhN85S8cMgqrdeEEhzGTuEm48MS7fenSQ2DSrksVz9uanA zmIM/F19GHiOGZMVteBaIcPly3BryTBSVy7uIWQ4r5mXskrmoaEq8PaQqxtk3Ew3d1E4 JiiA75gqVGrfvsMovOQ51RWWdZntuUtIHIOwBayEuLwNLpj6A6TigZKxv+/rMhsvWcKe HxEQ== X-Gm-Message-State: AMke39m7qZLeZaMXsaN2oMJ6ZlF3jp51O/Usn1ZGH1YQ2O51IRkO9hT6mxRd5bo/n37TWg== X-Received: by 10.28.178.16 with SMTP id b16mr15847966wmf.83.1486494038518; Tue, 07 Feb 2017 11:00:38 -0800 (PST) Received: from localhost.localdomain ([91.179.185.46]) by smtp.gmail.com with ESMTPSA id w16sm93056wmd.4.2017.02.07.11.00.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Feb 2017 11:00:38 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Luc Van Oostenryck Subject: [PATCH v2 4/5] simplify '(x / -1)' to '-x' (but only for signed division) Date: Tue, 7 Feb 2017 20:00:27 +0100 Message-Id: <20170207190028.24343-5-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170207190028.24343-1-luc.vanoostenryck@gmail.com> References: <20170207190028.24343-1-luc.vanoostenryck@gmail.com> Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- simplify.c | 2 ++ validation/optim/muldiv-minus-one.c | 2 ++ 2 files changed, 4 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..05a5f915c 100644 --- a/validation/optim/muldiv-minus-one.c +++ b/validation/optim/muldiv-minus-one.c @@ -2,6 +2,7 @@ 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; } /* * check-name: muldiv-minus-one @@ -9,5 +10,6 @@ u32 umulm1(u32 a) { return a * (u32) -1; } * check-output-ignore * * check-output-excludes: mul[us]\\. + * check-output-excludes: divs\\. * check-output-contains: neg\\. */