From patchwork Mon Aug 7 01:33:36 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: 9884195 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 7266260364 for ; Mon, 7 Aug 2017 01:33:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 646D528578 for ; Mon, 7 Aug 2017 01:33:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 592CB2857F; Mon, 7 Aug 2017 01:33:47 +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 08E0028578 for ; Mon, 7 Aug 2017 01:33:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751422AbdHGBdq (ORCPT ); Sun, 6 Aug 2017 21:33:46 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:37231 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751375AbdHGBdq (ORCPT ); Sun, 6 Aug 2017 21:33:46 -0400 Received: by mail-wm0-f67.google.com with SMTP id t138so12076864wmt.4 for ; Sun, 06 Aug 2017 18:33:45 -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=m4ezQ4CpeOz1QhIf0+qbbDVp2/QQ+KnFoiGAZitXQZU=; b=DIz4eMLKQ+DaHUBWfk1Uf096E+UVwBa/c+vDvutwm6pngUoQ5Mg3y5iWu7jQ18W8q8 zMDjqMPuUrq+AOqLP05W79LBbLViYfl/Eog+OuiSq830sSlyBzh62NUkbNgNxpn5T5I4 sUqF76oK+tptxFp4EMSUgV7B3kvKBz25Kugp5n5m/M7kpLKnT+zRN4Zl197M1NEfiOB9 c1732QOusC+CAt8FBKOWRNyhsGwBsoA+eNq5VPMsINam0kuWBpx2V+7nPipyPOIVynlV 87HVGc3IIkSEhHq0VNLlywevLiPzaVRJknJug8r6cSQ89O3v8mlGJb88iMv+CX5Cvaax PMwA== 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=m4ezQ4CpeOz1QhIf0+qbbDVp2/QQ+KnFoiGAZitXQZU=; b=Ynt0YA960v4jgsNojUKWfhyYkn6jf7wUoLLElUj+ePvFmSsT3e0FEWQ7Z9KXmRBktg s7HRMkSPzzh/IElZXLuTo8jVnjmCh3DkL8MEEXKdskXAPhYoW2Qk0dDJ/1247ZeKKPTQ KtzQh8BZRkI3YTYEQ22zV2iyskwToMS/4THgdNHVqS8n8cBzQ0SbhpjUZzdDFSEN6eho c9JMh6NHn5RE26PgjPcGY8+v8+gkbqdjHw4lhz67rrViiwgZ/+yiju9ZL6bRWErsQEQ2 4emQBxoyk/hEI+fCWne5subsno/qvzoP9hY5n8WWSqrHoIMM5x8bQu43EEkcyCgYKIuQ bUkQ== X-Gm-Message-State: AIVw112b8XhM0JkK+/z0xBWKFHosCrrzICd1TCnmYwUMrjwGIhuKKpyl EsR1uODbjGfi1g== X-Received: by 10.80.132.36 with SMTP id 33mr9825268edp.15.1502069625104; Sun, 06 Aug 2017 18:33:45 -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.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 06 Aug 2017 18:33:44 -0700 (PDT) From: Luc Van Oostenryck To: Dibyendu Majumdar Cc: linux-sparse@vger.kernel.org, Luc Van Oostenryck Subject: [PATCH 1/3] new helper: def_opcode() Date: Mon, 7 Aug 2017 03:33:36 +0200 Message-Id: <20170807013338.46211-2-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 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 f292fd5b6..cfb6b2cda 100644 --- a/simplify.c +++ b/simplify.c @@ -380,6 +380,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; @@ -404,9 +411,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; @@ -822,13 +829,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) @@ -993,9 +998,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;