From patchwork Mon Aug 7 01:33:38 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: 9884201 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 6B3E860364 for ; Mon, 7 Aug 2017 01:33:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5841026223 for ; Mon, 7 Aug 2017 01:33:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4CA5A28384; Mon, 7 Aug 2017 01:33:53 +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 EA1B928577 for ; Mon, 7 Aug 2017 01:33:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751375AbdHGBdv (ORCPT ); Sun, 6 Aug 2017 21:33:51 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:33217 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751426AbdHGBdv (ORCPT ); Sun, 6 Aug 2017 21:33:51 -0400 Received: by mail-wm0-f65.google.com with SMTP id q189so12145653wmd.0 for ; Sun, 06 Aug 2017 18:33:50 -0700 (PDT) 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=UGccclBLK1b0GL++AlZl6G+FTV0DjYxxPiy1Ozt6otQ=; b=IT3Oz432wlAOpe+C8Gpwfu4TF3+eJyiGF3uRQZwlGaI1G2HKrhAJ/IetG2t0Ppmh8V bTRtVS5qSYcGWf0mPJf7LovUj2xkeGWcoNOP+VD30iuoQn5orKdfJqdCkqAiJ50PO2hx eUfMs1ezQQrMKeoWDJnmKjH9dbFs0IfrBTOcswvXrdZaOv6s/GPpWvV6cR9IR1rWIGyJ jMpPkeK+SYi3pzJQsQ6ma+qp8Ms1GTWNNpkfXg/6OZ8y+dNL+/bcGYVarQegAHBz91O9 bt9K2izLMpoIgrKjIcX5cpsyjf2ZzwRIilCpfuXlnnf/V/SQAjlfx841O/9FcyCQ+NQ6 EBkw== 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=UGccclBLK1b0GL++AlZl6G+FTV0DjYxxPiy1Ozt6otQ=; b=gLCsEXuUSIWcdBnMxFyF7vYOBUHV1LtJe3jGsUD+3MpryQFH/nslLCiLCoW7aOgTKG D6b+eNs2SLAivvOGFrr+TY6ffJrvIJQBVZTQOp9rDNV1xN16swy8qyPQfVQxCEW7RZCG 9bV2LvocPfn4lPsq7LWuf2QlayniuQ7T0itN/S9opwGhJ0s52r3xj+rrf8BYgp6UIm9T aXMsf7+/BX21M/IsIKZCLx4syFPeqSiWdKwZhot9UQatoQdz99uAGIgq6mC8GPxZFZOM /+enMNiLG0I4oMHooRjhafV/oeVbYl700Mvx/wm5AjYw194BSSB/wQ4htfZW28eBYleq YXEA== X-Gm-Message-State: AHYfb5h8suW2cL6tLsmFhlUEPhwRSPO1I9aJ+LAAVAci6Mcyx7BUkHFn CetopiLAPBWx0oCIBxI= X-Received: by 10.80.241.66 with SMTP id z2mr6632356edl.21.1502069630057; Sun, 06 Aug 2017 18:33:50 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4076:600:ac70:e17d:ec67:ee66]) by smtp.gmail.com with ESMTPSA id f29sm5937685edd.23.2017.08.06.18.33.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 06 Aug 2017 18:33:49 -0700 (PDT) From: Luc Van Oostenryck To: Dibyendu Majumdar Cc: linux-sparse@vger.kernel.org, Luc Van Oostenryck Subject: [PATCH 3/3] simplify ((A & M') | B ) & M when M' & M == 0 Date: Mon, 7 Aug 2017 03:33:38 +0200 Message-Id: <20170807013338.46211-4-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170807013338.46211-1-luc.vanoostenryck@gmail.com> References: <20170807013338.46211-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 Reported-by: Dibyendu Majumdar Signed-off-by: Luc Van Oostenryck --- simplify.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/simplify.c b/simplify.c index cfb6b2cda..3fb2c8d8f 100644 --- a/simplify.c +++ b/simplify.c @@ -532,6 +532,46 @@ static int simplify_seteq_setne(struct instruction *insn, long long value) } } +static int simplify_and_or_mask(struct instruction *insn, pseudo_t and, pseudo_t other, unsigned long long mask) +{ + struct instruction *def = and->def; + pseudo_t old; + + if (!constant(def->src2)) + return 0; + if (def->src2->value & mask) + return 0; + old = insn->src1; + use_pseudo(insn, other, &insn->src1); + remove_usage(old, &insn->src1); + return REPEAT_CSE; +} + +static int simplify_constant_mask(struct instruction *insn, unsigned long long mask) +{ + struct instruction *left; + pseudo_t src1, src2; + + switch (def_opcode(insn->src1)) { + case OP_OR: + // Let's handle ((A & M') | B ) & M + // or (B | (A & M')) & M + // when M' & M == 0 + left = insn->src1->def; + src1 = left->src1; + src2 = left->src2; + if (def_opcode(src1) == OP_AND) + return simplify_and_or_mask(insn, src1, src2, mask); + if (def_opcode(src2) == OP_AND) + return simplify_and_or_mask(insn, src2, src1, mask); + break; + + default: + break; + } + return 0; +} + static int simplify_constant_rightside(struct instruction *insn) { long long value = insn->src2->value; @@ -576,7 +616,7 @@ static int simplify_constant_rightside(struct instruction *insn) case OP_AND: if (!value) return replace_with_pseudo(insn, insn->src2); - return 0; + return simplify_constant_mask(insn, value); case OP_SET_NE: case OP_SET_EQ: