From patchwork Sat Sep 5 12:13:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11759047 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5167313B1 for ; Sat, 5 Sep 2020 12:14:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3437920760 for ; Sat, 5 Sep 2020 12:14:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FNZ1Opfm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728473AbgIEMOH (ORCPT ); Sat, 5 Sep 2020 08:14:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726597AbgIEMOG (ORCPT ); Sat, 5 Sep 2020 08:14:06 -0400 Received: from mail-ej1-x643.google.com (mail-ej1-x643.google.com [IPv6:2a00:1450:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60FF0C061244 for ; Sat, 5 Sep 2020 05:14:05 -0700 (PDT) Received: by mail-ej1-x643.google.com with SMTP id e23so12003227eja.3 for ; Sat, 05 Sep 2020 05:14:05 -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 :mime-version:content-transfer-encoding; bh=ufM7TOvsBmOIJKVEbKKr+BAcE1XH3xTVq/JYds7a6ek=; b=FNZ1Opfm8Kv4KnRq6p+ioAwDZ4nwTOejp0tBrOScx+/z/yDIEp/Bms1UrIkJwCebo9 fIUIWViUE8WDEc4hEOuCK3k3GHWakFqJfs3xZ2te7UY4eXDjbojLSx2J9ugYXtjAyZo6 Ji/nO89L5xpQaYQQ15Pi+cCM5YhKWe9KB/1qsxfXJtBijNitdbH7uOHAFWdndUGv3zYz 24nh8w8ao+ypaGFc5cTWxK+49eC3WS0uOyZu9ALERFzsKWMIEsvzVFktt7VWSSJuxNfb pdzosusGoIx/nM5NaSSvPyfdBJyPRKZAlQCVWRdTXs6vGm8APj93BHmKQ1AY8k/2Ho93 I5Xg== 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:mime-version:content-transfer-encoding; bh=ufM7TOvsBmOIJKVEbKKr+BAcE1XH3xTVq/JYds7a6ek=; b=mJn6F3X0awwMzYkzJsa6sVEI/RNaghzuRoRspxZONiVFLulve3ph/Z7dHgXxY9RUjf +nljy0CB4eelw4MSrTLVLre15iBmwUujRivE9Zn3dJnJsy4Dp3kLNj1WHNM6za4gPxPo RM5CKhMPja8y/N3sitmowc2w+OYDXp49vw8f6IlbS0aXrxiRdrgoLcnFGPxtqLOw/OV1 F3rzokriTtl6bMai1x+jLt0BxxP+abkkt5+exb2EW9u7Fh/++ppe+AzzJ0XT0/Yz8USr d/B7MRLMXyavL95E1+lmQj89vTRx+Emz2AoaCBklK3LXofLtdsa0WtYUsOZO6I3rSKfJ PEbA== X-Gm-Message-State: AOAM533D7dwdCfgHyAvUujOD+pBS7mM6SBEwj4mgtTIYIWyQnk6YrvX8 duynQpdy9hfM2yjq3ZyTR5CXnIa5JZg= X-Google-Smtp-Source: ABdhPJz1IzsDBDwQwhtHHVszDCK3pmMgxIMN5vPOUaQdAfequXX+xu6jBp+KftKx/vhs3y9ODDqCbg== X-Received: by 2002:a17:906:ecf1:: with SMTP id qt17mr9293274ejb.158.1599308043383; Sat, 05 Sep 2020 05:14:03 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:a7fb:e200:e1b1:2430:dffc:e425]) by smtp.gmail.com with ESMTPSA id k14sm8577412edo.89.2020.09.05.05.14.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Sep 2020 05:14:02 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 1/3] add helper replace_with_value() Date: Sat, 5 Sep 2020 14:13:56 +0200 Message-Id: <20200905121358.83080-2-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200905121358.83080-1-luc.vanoostenryck@gmail.com> References: <20200905121358.83080-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org During simplification, it's relatively common to have to replace an instruction with pseudo corresponding to a known value. The pseudo can be created with value_pseudo() and the replacement can be made via replace_with_pseudo() but the combination of the two is a bit long. So, create an helper doing both sat once: replace_with_value(). Signed-off-by: Luc Van Oostenryck --- simplify.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/simplify.c b/simplify.c index f6b79685f439..0c75b3fadcab 100644 --- a/simplify.c +++ b/simplify.c @@ -465,6 +465,11 @@ static int replace_with_pseudo(struct instruction *insn, pseudo_t pseudo) return REPEAT_CSE; } +static inline int replace_with_value(struct instruction *insn, long long val) +{ + return replace_with_pseudo(insn, value_pseudo(val)); +} + static inline int def_opcode(pseudo_t p) { if (p->type != PSEUDO_REG) From patchwork Sat Sep 5 12:13:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11759049 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 545F113B1 for ; Sat, 5 Sep 2020 12:14:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 395E320760 for ; Sat, 5 Sep 2020 12:14:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HS1dHczi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728490AbgIEMOJ (ORCPT ); Sat, 5 Sep 2020 08:14:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726597AbgIEMOH (ORCPT ); Sat, 5 Sep 2020 08:14:07 -0400 Received: from mail-ej1-x643.google.com (mail-ej1-x643.google.com [IPv6:2a00:1450:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0B5AC061245 for ; Sat, 5 Sep 2020 05:14:06 -0700 (PDT) Received: by mail-ej1-x643.google.com with SMTP id z23so11915883ejr.13 for ; Sat, 05 Sep 2020 05:14:06 -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 :mime-version:content-transfer-encoding; bh=AZY10VfsIy0J98QGDqghhWbMA+gvKEGSsKayEjX4SHE=; b=HS1dHcziO5PYqa/iVIWS4ilP+TbHenGoTXmvVW/zR7mSPubuDuKhEfztSUFz2bR7Jr j4ohGnOeimdCDNZTNI86F3RiGEyZZg38O0mp18EdJFv8kkr7wvhhtOsQ1qCcHTUlXTms jAMGJG0AWXkDuJ54tzZlvHfEasKa0jX8EHgYko0GuUIseJsalBtNzd1fTDXqsezPSndo dC8QVkVE9ItCV0d+QCCMfLAZb31xVeYqHM3Mcr5D+ZA7Xgna1ve5aKDY5nUIiz8oGNdu EpOPPWnmKR8xiEa2fNuZN0h1rXKE/dloiCmAKn7FNLGK9AXSBSqXsKam5oM7nkk1KBvy z6eA== 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:mime-version:content-transfer-encoding; bh=AZY10VfsIy0J98QGDqghhWbMA+gvKEGSsKayEjX4SHE=; b=Gqj+O9VRhG7OgZytkyYwZXE90vWVTbsbBYIyKkk338lI8VDun92DQ3DwqPl+wTi8PP DQFhxbPGOrDNsB6+WoT6fih7YhJScmofGnGxW1pcPavT6juvRn3CH/V+rEuQaMJrZ7IR kXyjehCIspUhn7sbLcIJVwBNdXSbSwDsDpY9TzaS8cJ8NX9Kl4hB+j/D3MBLVJZ+A31i 807Xo4pf9+BO6fWM9lLqNcT3KuYlbHQtyuDleob4/IX29igcjJevn/zFrQaaGy1+Sdoa 7E8HP7L3Qx6NZsxVILQjpcawXDxRLYR6412pcxp4zn7xt5QXhaZ2rkDDXJ+7ryClHdsy +ayw== X-Gm-Message-State: AOAM532dv+GhR4qK0Ta1ui0DykiolXHPjET0g5FcsDdF5pbKx9t+66dz BJTSS4EtJWKgYQlTdV8PGpXJVsmELck= X-Google-Smtp-Source: ABdhPJwZaGg80+ERwcBrXaN0BGujTHDzaCyoSsP3MNrRJUOcibjnl/yLUonDE7Z9/tGcTxlHvHvCdw== X-Received: by 2002:a17:906:914b:: with SMTP id y11mr12747285ejw.145.1599308044488; Sat, 05 Sep 2020 05:14:04 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:a7fb:e200:e1b1:2430:dffc:e425]) by smtp.gmail.com with ESMTPSA id k14sm8577412edo.89.2020.09.05.05.14.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Sep 2020 05:14:04 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 2/3] use replace_with_value() Date: Sat, 5 Sep 2020 14:13:57 +0200 Message-Id: <20200905121358.83080-3-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200905121358.83080-1-luc.vanoostenryck@gmail.com> References: <20200905121358.83080-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Replace existing 'replace_with_pseudo(insn, value_pseudo($N))' by 'replace_with_value($N)'. Signed-off-by: Luc Van Oostenryck --- simplify.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/simplify.c b/simplify.c index 0c75b3fadcab..3c4b972ce607 100644 --- a/simplify.c +++ b/simplify.c @@ -838,7 +838,7 @@ static int simplify_shift(struct instruction *insn, pseudo_t pseudo, long long v omask = def->src2->value; nmask = omask & mask; if (nmask == 0) - return replace_with_pseudo(insn, value_pseudo(0)); + return replace_with_value(insn, 0); if (nmask == mask) return replace_pseudo(insn, &insn->src1, def->src1); if (nbr_users(pseudo) > 1) @@ -874,7 +874,7 @@ static int simplify_shift(struct instruction *insn, pseudo_t pseudo, long long v omask = def->src2->value; nmask = omask & mask; if (nmask == 0) - return replace_with_pseudo(insn, value_pseudo(0)); + return replace_with_value(insn, 0); if (nmask == mask) return replace_pseudo(insn, &insn->src1, def->src1); // do not simplify into ((A << S) & (M << S)) @@ -912,7 +912,7 @@ new_value: return replace_pseudo(insn, &insn->src1, pseudo->def->src1); } zero: - return replace_with_pseudo(insn, value_pseudo(0)); + return replace_with_value(insn, 0); replace_mask: insn->opcode = OP_AND; insn->src2 = value_pseudo(mask); @@ -1104,7 +1104,7 @@ static int simplify_constant_rightside(struct instruction *insn) case OP_MODU: case OP_MODS: if (value == 1) - return replace_with_pseudo(insn, value_pseudo(0)); + return replace_with_value(insn, 0); return 0; case OP_DIVU: case OP_DIVS: @@ -1167,14 +1167,14 @@ static int simplify_binop_same_args(struct instruction *insn, pseudo_t arg) warning(insn->pos, "self-comparison always evaluates to false"); case OP_SUB: case OP_XOR: - return replace_with_pseudo(insn, value_pseudo(0)); + return replace_with_value(insn, 0); case OP_SET_EQ: case OP_SET_LE: case OP_SET_GE: case OP_SET_BE: case OP_SET_AE: if (Wtautological_compare) warning(insn->pos, "self-comparison always evaluates to true"); - return replace_with_pseudo(insn, value_pseudo(1)); + return replace_with_value(insn, 1); case OP_AND: case OP_OR: @@ -1298,7 +1298,7 @@ static int simplify_constant_unop(struct instruction *insn) mask = 1ULL << (insn->size-1); res &= mask | (mask-1); - replace_with_pseudo(insn, value_pseudo(res)); + replace_with_value(insn, res); return REPEAT_CSE; } @@ -1577,7 +1577,7 @@ static int simplify_select(struct instruction *insn) if (cond == src2 && is_zero(src1)) { kill_use(&insn->src1); kill_use(&insn->src3); - replace_with_pseudo(insn, value_pseudo(0)); + replace_with_value(insn, 0); return REPEAT_CSE; } return 0; From patchwork Sat Sep 5 12:13:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11759051 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 79555618 for ; Sat, 5 Sep 2020 12:14:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5F26E20757 for ; Sat, 5 Sep 2020 12:14:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LSoe1MnC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726597AbgIEMOK (ORCPT ); Sat, 5 Sep 2020 08:14:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728482AbgIEMOI (ORCPT ); Sat, 5 Sep 2020 08:14:08 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1195C061244 for ; Sat, 5 Sep 2020 05:14:06 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id q13so11940409ejo.9 for ; Sat, 05 Sep 2020 05:14:06 -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 :mime-version:content-transfer-encoding; bh=zxGzZnbNeC6bQNhTQk6zKpvF00KuZK2z23uwMDDI1no=; b=LSoe1MnC0BP6aQ1/52b/rltK/dixwIojGn4/WJztW/S5Dv07cPWx6indqPI5gdTyf5 Q2JgOYQjxwbm3f7ftUEaa17BhWzYXhotvZSGSkBxFg1b9Jj0PtIkCjXcz7edEBe76klO IVP/ekFHKSP3R1njpJr8Akz8yOg0Tq6iTNJwXtgS1AZWR+pT7bz3CghRvFf3q4TJ+rU3 OUnkv2ojI4H2cy4FWc/qAwboI61d5OOBb+Q1uCesczaj2qLN4SCgl/dKoh0S45rk8uw7 TR/cn0dRdoxhFf4Jq/FoyPzw7o5/d6tIxoTzzh1goGDPqr7k8l1KP9f8IxV/FlfsLp5X smzw== 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:mime-version:content-transfer-encoding; bh=zxGzZnbNeC6bQNhTQk6zKpvF00KuZK2z23uwMDDI1no=; b=ofweuC6A+qJjS4LoXtfNLmFrd7/30fOqLXvKZGgE9wR2GVruun0+gcRYXovNZWNtRI MGVgLW5s155xoJKJJMFnxSMqK/M/XEyQG0GJWB5gN8mFUREXb9vbWWqd7UNZ5rNk2EG+ v4QHR/ui0ERhN1a0n/AdbiLYJydyjewV6ZwGYj2b0JF461wcZGbJoOvD2lUCCo5/NgQL r4QxMpAlxoTPxX94Mb13ozN72ZTOLWQ/x6Xhn4qpsakojVmIQdJ0bzPtKaG51JDTbVYo JsiitqT9C21ky7TuV/MgJOrtpcGu98zjqHbSVlnDbWXtXf2+Nef8NZUEiHzkWsqJ3gXp M4uA== X-Gm-Message-State: AOAM530U3OxL3skM1W3kJKSZRHlW2D+2GYOhdDrDCqbQZ/4/h+50T+Jf SyztGUWVrSxjMg9PfNr0BQq6talCpwI= X-Google-Smtp-Source: ABdhPJx+AO7tg9rvQCEEh6X30C48kHBGko9FXuT45kjlR2XBI8gGwPKmNcfai468+JeVlf8zUtuARg== X-Received: by 2002:a17:906:59b:: with SMTP id 27mr12871477ejn.56.1599308045268; Sat, 05 Sep 2020 05:14:05 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:a7fb:e200:e1b1:2430:dffc:e425]) by smtp.gmail.com with ESMTPSA id k14sm8577412edo.89.2020.09.05.05.14.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Sep 2020 05:14:04 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 3/3] replace_with_{pseudo,value}() can be tail-calls Date: Sat, 5 Sep 2020 14:13:58 +0200 Message-Id: <20200905121358.83080-4-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200905121358.83080-1-luc.vanoostenryck@gmail.com> References: <20200905121358.83080-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org This avoids the need to have a separate 'return REPEAT_CSE' and thus make the code slightly more compact and fast to read. Signed-off-by: Luc Van Oostenryck --- simplify.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/simplify.c b/simplify.c index 3c4b972ce607..76c0558855a2 100644 --- a/simplify.c +++ b/simplify.c @@ -1153,8 +1153,7 @@ static int simplify_constant_binop(struct instruction *insn) if (!res) return 0; - replace_with_pseudo(insn, res); - return REPEAT_CSE; + return replace_with_pseudo(insn, res); } static int simplify_binop_same_args(struct instruction *insn, pseudo_t arg) @@ -1298,8 +1297,7 @@ static int simplify_constant_unop(struct instruction *insn) mask = 1ULL << (insn->size-1); res &= mask | (mask-1); - replace_with_value(insn, res); - return REPEAT_CSE; + return replace_with_value(insn, res); } static int simplify_unop(struct instruction *insn) @@ -1554,8 +1552,7 @@ static int simplify_select(struct instruction *insn) take = cond->value ? src1 : src2; kill = cond->value ? &insn->src3 : &insn->src2; kill_use(kill); - replace_with_pseudo(insn, take); - return REPEAT_CSE; + return replace_with_pseudo(insn, take); } if (constant(src1) && constant(src2)) { long long val1 = src1->value; @@ -1577,8 +1574,7 @@ static int simplify_select(struct instruction *insn) if (cond == src2 && is_zero(src1)) { kill_use(&insn->src1); kill_use(&insn->src3); - replace_with_value(insn, 0); - return REPEAT_CSE; + return replace_with_value(insn, 0); } return 0; }