From patchwork Thu Oct 21 21:05:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 516105 Delivered-To: patch@linaro.org Received: by 2002:ac0:bf50:0:0:0:0:0 with SMTP id o16csp349435imj; Thu, 21 Oct 2021 14:36:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyr0uhef8OQucyCJX5b6Y5BSyvuZeezC6rN0W+X8cuosGGGGqCXrDh9cZjhGhIxgzx40sbe X-Received: by 2002:a9d:4f13:: with SMTP id d19mr6945094otl.335.1634852215516; Thu, 21 Oct 2021 14:36:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634852215; cv=none; d=google.com; s=arc-20160816; b=umKjHJoFI5lxrHhM7F6xUGrUEX975GTfQa20+iZbrAgc5+MRwdxMTofiimkHHxBR/o McwqAIOhvFA7P4Ben+0UHpeaIf7iKW/TEyN+Hfjhz9Jpzbi3TpfPSZV/Owyyfjbd++E1 gqPDWk6gJjDy9KT2Lzd41xxMEz0zRAj5UVBS+kl/6ruoBBhPtcWVvNw5AxE2HebZgp2a n1uANghoQum/ott/KaDCwfL8ZYkxgPDCH3XINqiCp4U1KhKaMzIgPBzuwiq0QLysxDCJ 1EkmOmWgS8nfSI3EaamIJKupxG3hj2vcZgvPHvrLno9aGvF1stgOgSdSJTg+NBGFX+tR RQFQ== 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:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=qthI0mJdOZrwCwUsWYFpWG7bovv63gF1yFHDwod2Ae8=; b=0st0tR9vVCU8kzYXdZlucyYybJBWsUdUzOtItfpyQSk7s96EBKetwD9AHIMqGVctGw cfLCvIFYUpyFPQJB4+JoU4Gtlq8f3YPJbYnJ4BOp2lqR4idIRGH6T8+1i7RU52n0rWSi Kq0Obqd5g59iAJvTi99+GcAwk+NmoiBOhHqOkzENa2IQhe/YOUf9C7qQp2pzUujW8SPg +YpBWbkd7hplz+tju+hQ3ip8hIacuS3yK5IgaHkF4jDqg6nc0EhBoFC80WJBkhzQg8Va BehlCxw5l5aTVb54MOTRvOriZGQ37g/hESJICfVFdkB7dL9MCAAhlXJPPgtVZKnCbjG9 /EFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=i4wkrtZA; 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=fail (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 l7si9700321otv.258.2021.10.21.14.36.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Oct 2021 14:36:55 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=i4wkrtZA; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37564 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mdfk6-0001C0-Rz for patch@linaro.org; Thu, 21 Oct 2021 17:36:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48588) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdfGJ-0007eH-6p for qemu-devel@nongnu.org; Thu, 21 Oct 2021 17:06:07 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]:39661) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mdfGE-0004O1-1b for qemu-devel@nongnu.org; Thu, 21 Oct 2021 17:06:06 -0400 Received: by mail-pl1-x632.google.com with SMTP id t21so1283731plr.6 for ; Thu, 21 Oct 2021 14:06:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qthI0mJdOZrwCwUsWYFpWG7bovv63gF1yFHDwod2Ae8=; b=i4wkrtZASFecXM8a3p330s82JYZQfUoJQ5yFxGdYlY/BK22e94tOfh3KbSCN8EpQl5 zyUDAHuBo5it9q8t9aVlqMPLDLw62CgWitGls7gsFrvZBOvM61qyrnIEMz5m+u0juPFB ghmbE7MzPNg4SzPtkpK6q6JPfbXIVFlPF0lDN5Rnn5ZU1fiOn9ruDODCqBUH91qxhbBJ Ure16ABzuqo+xSgIlxph60kk44uwYzcGvtvGeIpj7YNPhBoDC1V8pTmF7/Hx9j4f0+wb BVdWGr9HGzUepGUCdzEQ10vvNyGg+/8WdhY/2MK1UJap8IgiNN5dd3Dceg//wa6Dg5sa 93Uw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=qthI0mJdOZrwCwUsWYFpWG7bovv63gF1yFHDwod2Ae8=; b=qfLlmbbXt9XmPwn7Jymvv/xj/vwUAeN2Gw/W2heJ4YgJ9vRinp9NyWuDKTp+VyNFxw g3dYXqp1ZqdRBwHTACm5hzBEH0oDBWSzxdJQZEzzb1vZtihvN6P3rmvz6Dk4K0mHk//S t79fMUOhoIlscjV7A37Zvc3d24oOfmsxu88BpLN4W8H9cN4jPqs1u49TQTNZ/API4jbK gIVMU39y2el7BBJYV3A5YlwYx4D9/graW2JO9CuU3dCeCnppoIGxKf2BZXUCZlE7B4Xc zb0/VW1f4UX8gngf2DBXx6W/DP3Hht3X1Kq49K7001+jqu7oSYA5k1JtE/kHQBP/o4My oyEQ== X-Gm-Message-State: AOAM531TIaqpMoZMAVawJuhe7f+cWEXChq3tt4r4WJUGP+qkjjmaD12h dWZi4tbJdLQ4YaJptV/b1yi4h/utPMrXLg== X-Received: by 2002:a17:903:246:b0:13f:75bb:cabd with SMTP id j6-20020a170903024600b0013f75bbcabdmr7461093plh.30.1634850359742; Thu, 21 Oct 2021 14:05:59 -0700 (PDT) Received: from localhost.localdomain ([71.212.134.125]) by smtp.gmail.com with ESMTPSA id g7sm5981670pgp.17.2021.10.21.14.05.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Oct 2021 14:05:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 26/48] tcg/optimize: Split out fold_count_zeros Date: Thu, 21 Oct 2021 14:05:17 -0700 Message-Id: <20211021210539.825582-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211021210539.825582-1-richard.henderson@linaro.org> References: <20211021210539.825582-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x632.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: luis.pires@eldorado.org.br, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Richard Henderson --- tcg/optimize.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) -- 2.25.1 Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Luis Pires diff --git a/tcg/optimize.c b/tcg/optimize.c index 9758d83e3e..c54f839434 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -873,6 +873,20 @@ static bool fold_call(OptContext *ctx, TCGOp *op) return true; } +static bool fold_count_zeros(OptContext *ctx, TCGOp *op) +{ + if (arg_is_const(op->args[1])) { + uint64_t t = arg_info(op->args[1])->val; + + if (t != 0) { + t = do_constant_folding(op->opc, t, 0); + return tcg_opt_gen_movi(ctx, op, op->args[0], t); + } + return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[2]); + } + return false; +} + static bool fold_ctpop(OptContext *ctx, TCGOp *op) { return fold_const1(ctx, op); @@ -1724,20 +1738,6 @@ void tcg_optimize(TCGContext *s) } break; - CASE_OP_32_64(clz): - CASE_OP_32_64(ctz): - if (arg_is_const(op->args[1])) { - TCGArg v = arg_info(op->args[1])->val; - if (v != 0) { - tmp = do_constant_folding(opc, v, 0); - tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); - } else { - tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[2]); - } - continue; - } - break; - default: break; @@ -1762,6 +1762,10 @@ void tcg_optimize(TCGContext *s) case INDEX_op_brcond2_i32: done = fold_brcond2(&ctx, op); break; + CASE_OP_32_64(clz): + CASE_OP_32_64(ctz): + done = fold_count_zeros(&ctx, op); + break; CASE_OP_32_64(ctpop): done = fold_ctpop(&ctx, op); break;