From patchwork Wed Feb 9 11:21:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 541093 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp1250484imo; Wed, 9 Feb 2022 03:24:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJytMrkRZ0fqYWgaOmYpZokOrWIu7+IQGzlbg0IXDTwKQ72M4HUtZaI+AJU95yCcWMMxz12G X-Received: by 2002:a81:7e06:: with SMTP id o6mr1548665ywn.13.1644405848466; Wed, 09 Feb 2022 03:24:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644405848; cv=none; d=google.com; s=arc-20160816; b=bRqFpz5S5OjrfuO/H3UL4xg5ambq8N52mxI7bBnK4hAtEBJ5V6nkvmPKqBgdnzPL16 r0jn6OZwQL1ffuRM0awHfIAyLX/y7/SnJYasHFubq9LWv/zNLY2BaXjNWph5t7rASeLA Lu6X/WMImYJYGTU0rSKsJz65EnreJ8zM3gr4LHg9GjKbP7nWQnqyZyR7pgp+zOvrGGTs Yh7nOdYmucfPa6/n33yz+HpxiVJrizPjOhxRveGtHNhQ/VkFADnS53YcTXhOF+tTTAFe IYIucXUVJ2LTAtZ/+UH2bpRjWeUhaWSA29OCxeWVXrBgmYl9qHTjii1O4CHezmufR3P8 pvUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature; bh=cJkq9Ju39KsUpL747ow6W8ArRJVwDxPgiiAhCRO0pww=; b=hQD/drQwUpTL58ipvKHyjTicrJ7AqE3/oteMPNYc3/trBSKIhqu0LT1Gkd/1dLnIYn pFYDO6tuRlWzymOmw3KV7nVc4bK/8S65vGz/wCyttb8GGPdgI4kSQcgDWSAwVKZ/WC/t /0+G+z+fx1sbGe6gj7j2toLwX47viXG7N7dM2Rpr8PNv9wDKyUQIa0jWnL9MFvSnwEib Nv8zHjvPL5o+d3C1Y790o1w4FhL1+8moMd+qR3t3w0D7qiWQ5u5uDcgvU6QX15LMGAw5 +b5mljRPrbfSUdqCz4ugjMsoCOZ1WaSNGhJRjRIBMCxg18z1muJoNxi696fffUKPS8Zf 6LTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vErm5g1Z; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b186si7326267ywa.17.2022.02.09.03.24.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 09 Feb 2022 03:24:08 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vErm5g1Z; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49462 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHl4y-0003yG-0U for patch@linaro.org; Wed, 09 Feb 2022 06:24:08 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50112) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHl2x-0003v5-Ja for qemu-devel@nongnu.org; Wed, 09 Feb 2022 06:22:03 -0500 Received: from [2a00:1450:4864:20::535] (port=46831 helo=mail-ed1-x535.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHl2l-00034v-Ko for qemu-devel@nongnu.org; Wed, 09 Feb 2022 06:22:03 -0500 Received: by mail-ed1-x535.google.com with SMTP id m11so4269515edi.13 for ; Wed, 09 Feb 2022 03:21:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=cJkq9Ju39KsUpL747ow6W8ArRJVwDxPgiiAhCRO0pww=; b=vErm5g1Z7PqaJKLisDl1RtbII74yK/ycMjY/qHZnKDLI3VK4M27s0FkgtxABYF8s3j k8uQUScKg6gyWyGRLTgad8vf9mqcJOk6yHl67fQQCePzABf3YoH7QIueWKYAc97mN0T6 D0J4Fj/3AdSsaxZUAC9pA9eac6Mgt0EQZIAXHlI7DWiKlKm2WerVfBz4qoyDp3qxWaWU FDZRiE1xgf6fLkurpQs8v+Zxb12nIh5v5CaFrUINEU9LhRS5peLzxoO64l6or1PfIxAr A4T+gqDWrmtHDRWJlrhSi2BUubBGJDHWX8EEQk4QQjyF4FYOjUXgWceX3G0Hzvyfppci x7yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=cJkq9Ju39KsUpL747ow6W8ArRJVwDxPgiiAhCRO0pww=; b=RoDqyXJql6Rt6+m/hSRHI0MGNw89mMYX3pvbmomhoSiXq4lbSkg4Kbm2RriMQN8hfi cz4xtE5mesDJhc4TqPSo6NUQmRZ/yCVgIOFwL4Tl2sEWiqWayddfFBeqY6RG+NA40Tzh simyqPfVYBuL2c4KmNhp5cJxi5cphTXzHhGgCv7Gfc4g0vUqT1RiK9Lw79/tISHCvPI2 NrFpO+mJdxzSucNAmgUDl8r6zYPpMvts23qWZeDqpLqEPGUlGpSlzHO5yQe2Wqj7AEff Orwn34Y6/ZSctKofIjHOM098G4f2GnqA6jAyRIYJ77HmkPeBBt+1QJxwE4ukcJj5me9n wmAA== X-Gm-Message-State: AOAM533DuUzYyaNgMNnu3YJrtbwia1xARdCFo2YjfP6C3g5XiiDppFZ4 r7d0S6njdyOrafDoHtAoJ3RUgA== X-Received: by 2002:a05:6402:4414:: with SMTP id y20mr1892224eda.219.1644405708756; Wed, 09 Feb 2022 03:21:48 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id k7sm5865948eje.162.2022.02.09.03.21.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 03:21:47 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 67BF81FFB7; Wed, 9 Feb 2022 11:21:47 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org, richard.henderson@linaro.org Subject: [RFC PATCH] tcg/optimize: only read val after const check Date: Wed, 9 Feb 2022 11:21:42 +0000 Message-Id: <20220209112142.3367525-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::535 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::535; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x535.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" valgrind pointed out that arg_info()->val can be undefined which will be the case if the arguments are not constant. The ordering of the checks will have ensured we never relied on an undefined value but for the sake of completeness re-order the code to be clear. Signed-off-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé --- tcg/optimize.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tcg/optimize.c b/tcg/optimize.c index e573000951..06213fd434 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -552,10 +552,10 @@ static bool do_constant_folding_cond_eq(TCGCond c) static int do_constant_folding_cond(TCGType type, TCGArg x, TCGArg y, TCGCond c) { - uint64_t xv = arg_info(x)->val; - uint64_t yv = arg_info(y)->val; - if (arg_is_const(x) && arg_is_const(y)) { + uint64_t xv = arg_info(x)->val; + uint64_t yv = arg_info(y)->val; + switch (type) { case TCG_TYPE_I32: return do_constant_folding_cond_32(xv, yv, c); @@ -567,7 +567,7 @@ static int do_constant_folding_cond(TCGType type, TCGArg x, } } else if (args_are_copies(x, y)) { return do_constant_folding_cond_eq(c); - } else if (arg_is_const(y) && yv == 0) { + } else if (arg_is_const(y) && arg_info(y)->val == 0) { switch (c) { case TCG_COND_LTU: return 0;