From patchwork Fri Jun 22 20:56:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 10483025 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 66BE660230 for ; Fri, 22 Jun 2018 20:57:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 57DF528F7E for ; Fri, 22 Jun 2018 20:57:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C4F428F87; Fri, 22 Jun 2018 20:57:00 +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=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, 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 E0BC528F7E for ; Fri, 22 Jun 2018 20:56:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932981AbeFVU46 (ORCPT ); Fri, 22 Jun 2018 16:56:58 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:32779 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754337AbeFVU45 (ORCPT ); Fri, 22 Jun 2018 16:56:57 -0400 Received: by mail-ed1-f67.google.com with SMTP id q21-v6so1938845eds.0 for ; Fri, 22 Jun 2018 13:56:57 -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=V7I+fULmrsp7ClwKa9ZjmhIvRN8jLREYuWHGxi61ziY=; b=C9ia5yafQgxkP2BXuLlulqU5jWzfsj2rND/AUi0nq/00AZW4uZ/62uz7LsM7TCoEoj NvB7m53kWTSXC6LonQQb7HMzQSHbuu/Qu6m3cDZRCbb7RsiMBb3aIZJ4fFS5BaGQfn+B NHq3cpejkcYqZ6/gJ8qPeOyVEmoIscSUMK7lQLWONweE6ix65qHinMIeEALrs5UBUQ3P K+F+SOJBrjgrPNLSurJAEJxtW1CqYR37hhzWJHfJRsqHfYCWK8n6nFdrd5ET2yWkbE4W vNwQC2Z8KsrytzNSXY1jPPgQgJk2R9Kz9Ad1fEue+9qNaioMCwmAnn5cwxGtjo7nDenY 6x8w== 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=V7I+fULmrsp7ClwKa9ZjmhIvRN8jLREYuWHGxi61ziY=; b=H2my4QBca8ZfFSNIuI4zlIW87VBWnf3vLj2fhNy9FfBnvscvP7VTJiDCMv0N16fCBS rzWUYUyouu4tHvI1dz9XG5uPIGyyj/nUNEW+FKoso+QkCkF2TCkQY1U/QYHoXjjEiTdM 4NJhR+OxscNyiaWzOVEmcoKT8y6hNkN8Wh9mScn50b+2Fzv82wgquVW5pvO1sf6K+MXi 1iJWBoQOYtJDqgoaQpwzPzin4LTOGjzOyzhfxDkzqU+0nPP0fOI5xdXQBGq4OHxFUXO7 r+h8OG6ZnybTxIHzyH19ZYEAZ/j7eTVVCpG/6ZkyYbaI9/5E5VBzAYeiJpv1zwh6rk1H +eLw== X-Gm-Message-State: APt69E0V8Tg2FA7eEB3EM0B0CK/t4X8oYyGy6OPEiHetk2E/9ab+BTD0 smOzVC9AvQJaxr7u6OLvesNROU7f X-Google-Smtp-Source: ADUXVKKf39xeq91tEhakrS7w3Bdn0J3MOEcRPLOjPyVc2NSawq6nkl8QqtPqUV1cL5+5muaOlyLiBA== X-Received: by 2002:a50:b832:: with SMTP id j47-v6mr3013065ede.272.1529701016333; Fri, 22 Jun 2018 13:56:56 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4030:b100:5921:9b4b:cd6c:8b4b]) by smtp.gmail.com with ESMTPSA id f17-v6sm3791411edm.97.2018.06.22.13.56.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Jun 2018 13:56:55 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 2/3] new helper: replace_pseudo() Date: Fri, 22 Jun 2018 22:56:47 +0200 Message-Id: <20180622205648.20232-3-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180622205648.20232-1-luc.vanoostenryck@gmail.com> References: <20180622205648.20232-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 Replacing the value of an operand is a relatively common operation during simplification. Since this operation currently needs two more primitive operations which must have common arguments, it would be better to have a helper for it. Create the helper: replace_pseudo() and use it when possible. Signed-off-by: Luc Van Oostenryck --- simplify.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/simplify.c b/simplify.c index 77d818e1f..5c3a744f0 100644 --- a/simplify.c +++ b/simplify.c @@ -338,6 +338,20 @@ static inline int constant(pseudo_t pseudo) return pseudo->type == PSEUDO_VAL; } +/// +// replace one operand by a new value +// @insn: the instruction +// @pp: the address of the instruction's operand +// @new: the new value for the operand +// @return: REPEAT_CSE. +static inline int replace_pseudo(struct instruction *insn, pseudo_t *pp, pseudo_t new) +{ + pseudo_t old = *pp; + use_pseudo(insn, new, pp); + remove_usage(old, pp); + return REPEAT_CSE; +} + static int replace_with_pseudo(struct instruction *insn, pseudo_t pseudo) { convert_instruction_target(insn, pseudo); @@ -904,8 +918,7 @@ offset: warning(insn->pos, "crazy programmer"); } insn->offset += off->value; - use_pseudo(insn, new, &insn->src); - remove_usage(addr, &insn->src); + replace_pseudo(insn, &insn->src, new); return REPEAT_CSE | REPEAT_SYMBOL_CLEANUP; } @@ -1077,8 +1090,7 @@ static int simplify_range(struct instruction *insn) */ static int simplify_cond_branch(struct instruction *br, pseudo_t cond, struct instruction *def, pseudo_t newcond) { - use_pseudo(br, newcond, &br->cond); - remove_usage(cond, &br->cond); + replace_pseudo(br, &br->cond, newcond); if (def->opcode == OP_SET_EQ) { struct basic_block *tmp = br->bb_true; br->bb_true = br->bb_false; @@ -1137,18 +1149,13 @@ static int simplify_branch(struct instruction *insn) insn->bb_true = insn->bb_false; insn->bb_false = tmp; } - use_pseudo(insn, def->src1, &insn->cond); - remove_usage(cond, &insn->cond); - return REPEAT_CSE; + return replace_pseudo(insn, &insn->cond, def->src1); } } if (def->opcode == OP_CAST || def->opcode == OP_SCAST) { int orig_size = def->orig_type ? def->orig_type->bit_size : 0; - if (def->size > orig_size) { - use_pseudo(insn, def->src, &insn->cond); - remove_usage(cond, &insn->cond); - return REPEAT_CSE; - } + if (def->size > orig_size) + return replace_pseudo(insn, &insn->cond, def->src); } } return 0;