From patchwork Mon Aug 7 19:11:59 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: 9886043 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 D047F602CC for ; Mon, 7 Aug 2017 19:12:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C07722860A for ; Mon, 7 Aug 2017 19:12:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B5721286BF; Mon, 7 Aug 2017 19:12:15 +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 62D1F2860A for ; Mon, 7 Aug 2017 19:12:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751926AbdHGTMP (ORCPT ); Mon, 7 Aug 2017 15:12:15 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:34620 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751919AbdHGTMN (ORCPT ); Mon, 7 Aug 2017 15:12:13 -0400 Received: by mail-wm0-f67.google.com with SMTP id x64so2066441wmg.1 for ; Mon, 07 Aug 2017 12:12:12 -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=vowpRKWp9kZpDzkr7pWbzbd34sNxFehOkJSDQYveB2U=; b=CMatFwXDwq++sqS3urbAlxw66wLdKd02eiOAJbAmPpEOwBpEWFfoQjklRL9ld2IISf Kf2jXpaCXZxz0CoJxqg/2ZIhuqQI8/xLk7AdIiGi7uiyP6OZwleoskUY23KfrOo+wvJd EiF28UG1MdCChwJuDk2g8Ah+t24a/wigGhZBRk1m4bY7y886vTKQH9lnHJdcmYi8eA9Z uP09d3PeGqkkYFJ4c8Sh5FScVukB6wVaFf67QKO5HpZPhR8MOOuHPINqWZarLFexRkYK sR6vZYBlrWn3UR8o6q26CXttoU5BwrEQzkLM9Q6jNBiywoUgxPtZkK0CVr7afnRyBJ7F ObjA== 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=vowpRKWp9kZpDzkr7pWbzbd34sNxFehOkJSDQYveB2U=; b=jEiGRl0OyKxOJ+/1FGBNBLZxN+kjnsuanIrUy2z9m12saoHGUCLHpygUv3AZgcAldz pZsSUmnTf6lYxl+SwQkzRlDSJb2f6ddevqyfmdjSmL66KVDDVX4a9KiHohyjzqISzGTI 1hnoD9WsB1OaMEfqy7lOsOPx1f2/Prv0Tc0Y0MZsSSXiVRllKGJKPpgyLebZs+w3IH0t U/q2dSTl4hfgKYmLi673Nzz/BcRQy40eKHwMigsOXsOinFjK1oLF+Kp1Gg+c4BkkxQfG bg6YV2j32UCtLzWgNED1ebvdunQJrGbXRYW5oIRGsHqC4pFmx9Nhx7XqZO/ARqSPqEb0 98NA== X-Gm-Message-State: AHYfb5iu+HCNU49dywAF3ZBJW9aZ+D8Q+qsq0HIhUbpG8GR1RYNmy/7N Dv582eWopINDZA== X-Received: by 10.80.158.163 with SMTP id a32mr1895319edf.169.1502133132234; Mon, 07 Aug 2017 12:12:12 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4076:600:29ff:6bdc:a0fa:4163]) by smtp.gmail.com with ESMTPSA id g52sm7742064edg.34.2017.08.07.12.12.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Aug 2017 12:12:11 -0700 (PDT) From: Luc Van Oostenryck To: Dibyendu Majumdar Cc: linux-sparse@vger.kernel.org, Luc Van Oostenryck Subject: [PATCH v2 2/8] new helper: def_opcode() Date: Mon, 7 Aug 2017 21:11:59 +0200 Message-Id: <20170807191205.86590-3-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170807191205.86590-1-luc.vanoostenryck@gmail.com> References: <20170807191205.86590-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 Getting the opcode corresponding to the instruction defining a pseudo if the psedudo has such and instruction (PSEUDO_REG) is an common operation in the simplification phase. Use an helper to make the code a bit easier to read. Signed-off-by: Luc Van Oostenryck --- simplify.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/simplify.c b/simplify.c index 2bc86f53e..d9528de43 100644 --- a/simplify.c +++ b/simplify.c @@ -352,6 +352,13 @@ static int replace_with_pseudo(struct instruction *insn, pseudo_t pseudo) return REPEAT_CSE; } +static inline int def_opcode(pseudo_t p) +{ + if (p->type != PSEUDO_REG) + return -1; + return p->def->opcode; +} + static unsigned int value_size(long long value) { value >>= 8; @@ -376,9 +383,9 @@ static unsigned int operand_size(struct instruction *insn, pseudo_t pseudo) { unsigned int size = insn->size; - if (pseudo->type == PSEUDO_REG) { + if (def_opcode(pseudo) == OP_CAST) { struct instruction *src = pseudo->def; - if (src && src->opcode == OP_CAST && src->orig_type) { + if (src->orig_type) { unsigned int orig_size = src->orig_type->bit_size; if (orig_size < size) size = orig_size; @@ -786,13 +793,11 @@ static int simplify_associative_binop(struct instruction *insn) if (!simple_pseudo(insn->src2)) return 0; - if (pseudo->type != PSEUDO_REG) + if (def_opcode(pseudo) != insn->opcode) return 0; def = pseudo->def; if (def == insn) return 0; - if (def->opcode != insn->opcode) - return 0; if (!simple_pseudo(def->src2)) return 0; if (ptr_list_size((struct ptr_list *)def->target->users) != 1) @@ -957,9 +962,9 @@ static int simplify_cast(struct instruction *insn) } /* A cast of a "and" might be a no-op.. */ - if (src->type == PSEUDO_REG) { + if (def_opcode(src) == OP_AND) { struct instruction *def = src->def; - if (def->opcode == OP_AND && def->size >= size) { + if (def->size >= size) { pseudo_t val = def->src2; if (val->type == PSEUDO_VAL) { unsigned long long value = val->value;