From patchwork Thu Jul 13 08:57:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 107640 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp1939439qge; Thu, 13 Jul 2017 01:59:32 -0700 (PDT) X-Received: by 10.99.121.75 with SMTP id u72mr8163884pgc.53.1499936372335; Thu, 13 Jul 2017 01:59:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499936372; cv=none; d=google.com; s=arc-20160816; b=mCk+0zxUHkqgOvp2WebtMM6UuUnuEn7x1vptaswy5JMz1KBk7erA+EyreoWb/IK0BI phoj0R0ezS1jzcBWCimwC/DfPyk9oarvQFc1G1/XLEcot1TJGoj6w4z6tk+zQ4GWHgf9 dmEaKTCGfKWGGW6e4vapMtQYmKNnPlzq8vb6l674zZHt9owA93vC6M3VUAsk3ukYkSu6 0Y4He8/FwKRxvPe2M2LrqYSCXrAP68tXPgClzfmWa+7/GqNRbY61YdFdk6ivNP1aS6Tf kcNM4fHYXo1rqTkOz7RnBz5zuUQTlfm/uihSHTvSB31/V8A6WhaUIJ6jy7vipnzVr4hq 6Uzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:mail-followup-to:to:from:delivered-to:sender:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=Icc/VBe6gl1TqrOemeZKLs4vsEVMxOrtLFW9iLOk3us=; b=gifNO9kmGvRDdW5DWPqp2Xgn3xaKi4KP6DX0sEAkpFidKsTnVDFcorbDZ80CT3tRn4 Ij5eEMZEIkigX6BMrCsPQhzAT8Q8HrXHxPGQ5zd8cHzRntEJNVnF6gZ7LYcgY43ABMHi rLs2i+4lbvTg1TFjYqF36P/3tPxwJL+oWPLnyEA6NJVEAkFI5rTj1tL8KN8eOouG3rDc MJYvvdpvyylFX6lOHe/dgRV26YqTo1yNOwCG5DMnVbmrHy8VC0b5aISmsZa/vWgSEsum O0UlcNvNVV0ZF6N70Eim6UkhpguQ2rZJH2IHAmTC7NcHMsezpHmAXhRPU9pM2BvqizIu ggVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.b=ra9k9prx; spf=pass (google.com: domain of gcc-patches-return-458045-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-458045-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id e5si3787970pgk.350.2017.07.13.01.59.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jul 2017 01:59:32 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-458045-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.b=ra9k9prx; spf=pass (google.com: domain of gcc-patches-return-458045-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-458045-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=default; b=pttj0a/84Ld5lBAOWiZBs38stfTLr FDhWYkSA/vhQsLGBtygOYBOPLaEU0tA1UA43WSVXJMWYveIxW4AyBTTy8hHEVyZs VhaMKQw7QCiH4eG2zHmE/oMcqcX+IWWO6WPqLcp1gd9wtejPUmd4r10/FVF62TEC p9M+ZvYUmxdSVc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:references:date:in-reply-to:message-id:mime-version :content-type; s=default; bh=9/aRbVV2K4dzOCcj1yC1mP9z0gw=; b=ra9 k9prx1RfOigzui8Xs1aIOQXAdTGPqaODMZOtr8NOykCXO94u/InuC7Bdf7HEAmbk tv2yUohzvB+J+gtf3WdRMRS17TQNuciLp/hVWDz7oQkgjbTrFsv9sObSwvQeT4H2 n+3Xp8jB6Fg0zMOXs+r9T/KhEQneYPGyZIV+NJkY= Received: (qmail 92183 invoked by alias); 13 Jul 2017 08:57:55 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 91689 invoked by uid 89); 13 Jul 2017 08:57:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm0-f44.google.com Received: from mail-wm0-f44.google.com (HELO mail-wm0-f44.google.com) (74.125.82.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 13 Jul 2017 08:57:51 +0000 Received: by mail-wm0-f44.google.com with SMTP id 70so2199474wmo.1 for ; Thu, 13 Jul 2017 01:57:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=Icc/VBe6gl1TqrOemeZKLs4vsEVMxOrtLFW9iLOk3us=; b=c9MdzUKYDPGtlMBOKiyTPCgcUnZtDcgXPh1p89f6C6ZT/xJjWiK+kbLMuQY0+WBQKt DuF7bMA/jow6H/MB4Z5LNa7YLGLmc1oRMfG9aggFLRB81fnRsfG4wOXOWPPVOvG+gDIv +/iAr//zjU8EKoBph5hH67PuE1vhhEiI5LSYrA9ZyGABaGPK/WWsXnoEY9Rux0Yxl7pg 7KF9FDKL4Bx+iHjhSsP9WqSKVD4QhNr+8AVMOFuvuNULMzDbQZa4OkJ+pA/H17u329Cd V1crctJBq2BmEkggLNqgdlKmYkdE31BCQyiJdgvkinSzHcZy8tS6VKdOwRPaQ62EXt0k 2vJg== X-Gm-Message-State: AIVw110uf4hl1O56G9PuytQrdrc+NDk7pzJJCiK8JLD/7CTidUf+LHp5 yJRCUuS5hTuFYf143U859Q== X-Received: by 10.28.144.6 with SMTP id s6mr1179400wmd.16.1499936268626; Thu, 13 Jul 2017 01:57:48 -0700 (PDT) Received: from localhost (92.40.249.184.threembb.co.uk. [92.40.249.184]) by smtp.gmail.com with ESMTPSA id j190sm6170328wmd.22.2017.07.13.01.57.47 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Jul 2017 01:57:47 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: [54/77] Add explicit int checks for alternative optab implementations References: <8760ewohsv.fsf@linaro.org> Date: Thu, 13 Jul 2017 09:57:46 +0100 In-Reply-To: <8760ewohsv.fsf@linaro.org> (Richard Sandiford's message of "Thu, 13 Jul 2017 09:35:44 +0100") Message-ID: <87o9soemt1.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 expand_unop can expand narrow clz, clrsb, ctz, bswap, parity and ffs operations using optabs for wider modes. These expansions apply only to scalar integer modes (and not for example to vectors), so the patch adds explicit checks for that. 2017-07-13 Richard Sandiford Alan Hayward David Sherwood gcc/ * optabs.c (widen_leading): Change the type of the mode argument to scalar_int_mode. Use opt_scalar_int_mode for the mode iterator. (widen_bswap): Likewise. (expand_parity): Likewise. (expand_ctz): Change the type of the mode argument to scalar_int_mode. (expand_ffs): Likewise. (epand_unop): Check for scalar integer modes before calling the above routines. Index: gcc/optabs.c =================================================================== --- gcc/optabs.c 2017-07-13 09:18:46.703152916 +0100 +++ gcc/optabs.c 2017-07-13 09:18:48.024049315 +0100 @@ -2128,39 +2128,36 @@ expand_simple_unop (machine_mode mode, e A similar operation can be used for clrsb. UNOPTAB says which operation we are trying to expand. */ static rtx -widen_leading (machine_mode mode, rtx op0, rtx target, optab unoptab) +widen_leading (scalar_int_mode mode, rtx op0, rtx target, optab unoptab) { - enum mode_class mclass = GET_MODE_CLASS (mode); - if (CLASS_HAS_WIDER_MODES_P (mclass)) + opt_scalar_int_mode wider_mode_iter; + FOR_EACH_WIDER_MODE (wider_mode_iter, mode) { - machine_mode wider_mode; - FOR_EACH_WIDER_MODE (wider_mode, mode) + scalar_int_mode wider_mode = *wider_mode_iter; + if (optab_handler (unoptab, wider_mode) != CODE_FOR_nothing) { - if (optab_handler (unoptab, wider_mode) != CODE_FOR_nothing) - { - rtx xop0, temp; - rtx_insn *last; + rtx xop0, temp; + rtx_insn *last; - last = get_last_insn (); + last = get_last_insn (); - if (target == 0) - target = gen_reg_rtx (mode); - xop0 = widen_operand (op0, wider_mode, mode, - unoptab != clrsb_optab, false); - temp = expand_unop (wider_mode, unoptab, xop0, NULL_RTX, - unoptab != clrsb_optab); - if (temp != 0) - temp = expand_binop - (wider_mode, sub_optab, temp, - gen_int_mode (GET_MODE_PRECISION (wider_mode) - - GET_MODE_PRECISION (mode), - wider_mode), - target, true, OPTAB_DIRECT); - if (temp == 0) - delete_insns_since (last); + if (target == 0) + target = gen_reg_rtx (mode); + xop0 = widen_operand (op0, wider_mode, mode, + unoptab != clrsb_optab, false); + temp = expand_unop (wider_mode, unoptab, xop0, NULL_RTX, + unoptab != clrsb_optab); + if (temp != 0) + temp = expand_binop + (wider_mode, sub_optab, temp, + gen_int_mode (GET_MODE_PRECISION (wider_mode) + - GET_MODE_PRECISION (mode), + wider_mode), + target, true, OPTAB_DIRECT); + if (temp == 0) + delete_insns_since (last); - return temp; - } + return temp; } } return 0; @@ -2294,22 +2291,20 @@ expand_doubleword_parity (machine_mode m as (lshiftrt:wide (bswap:wide x) ((width wide) - (width narrow))). */ static rtx -widen_bswap (machine_mode mode, rtx op0, rtx target) +widen_bswap (scalar_int_mode mode, rtx op0, rtx target) { - enum mode_class mclass = GET_MODE_CLASS (mode); - machine_mode wider_mode; rtx x; rtx_insn *last; + opt_scalar_int_mode wider_mode_iter; - if (!CLASS_HAS_WIDER_MODES_P (mclass)) - return NULL_RTX; + FOR_EACH_WIDER_MODE (wider_mode_iter, mode) + if (optab_handler (bswap_optab, *wider_mode_iter) != CODE_FOR_nothing) + break; - FOR_EACH_WIDER_MODE (wider_mode, mode) - if (optab_handler (bswap_optab, wider_mode) != CODE_FOR_nothing) - goto found; - return NULL_RTX; + if (!wider_mode_iter.exists ()) + return NULL_RTX; - found: + scalar_int_mode wider_mode = *wider_mode_iter; last = get_last_insn (); x = widen_operand (op0, wider_mode, mode, true, true); @@ -2360,42 +2355,40 @@ expand_doubleword_bswap (machine_mode mo /* Try calculating (parity x) as (and (popcount x) 1), where popcount can also be done in a wider mode. */ static rtx -expand_parity (machine_mode mode, rtx op0, rtx target) +expand_parity (scalar_int_mode mode, rtx op0, rtx target) { enum mode_class mclass = GET_MODE_CLASS (mode); - if (CLASS_HAS_WIDER_MODES_P (mclass)) + opt_scalar_int_mode wider_mode_iter; + FOR_EACH_MODE_FROM (wider_mode_iter, mode) { - machine_mode wider_mode; - FOR_EACH_MODE_FROM (wider_mode, mode) + scalar_int_mode wider_mode = *wider_mode_iter; + if (optab_handler (popcount_optab, wider_mode) != CODE_FOR_nothing) { - if (optab_handler (popcount_optab, wider_mode) != CODE_FOR_nothing) - { - rtx xop0, temp; - rtx_insn *last; + rtx xop0, temp; + rtx_insn *last; - last = get_last_insn (); + last = get_last_insn (); - if (target == 0 || GET_MODE (target) != wider_mode) - target = gen_reg_rtx (wider_mode); + if (target == 0 || GET_MODE (target) != wider_mode) + target = gen_reg_rtx (wider_mode); - xop0 = widen_operand (op0, wider_mode, mode, true, false); - temp = expand_unop (wider_mode, popcount_optab, xop0, NULL_RTX, - true); - if (temp != 0) - temp = expand_binop (wider_mode, and_optab, temp, const1_rtx, - target, true, OPTAB_DIRECT); + xop0 = widen_operand (op0, wider_mode, mode, true, false); + temp = expand_unop (wider_mode, popcount_optab, xop0, NULL_RTX, + true); + if (temp != 0) + temp = expand_binop (wider_mode, and_optab, temp, const1_rtx, + target, true, OPTAB_DIRECT); - if (temp) - { - if (mclass != MODE_INT - || !TRULY_NOOP_TRUNCATION_MODES_P (mode, wider_mode)) - return convert_to_mode (mode, temp, 0); - else - return gen_lowpart (mode, temp); - } + if (temp) + { + if (mclass != MODE_INT + || !TRULY_NOOP_TRUNCATION_MODES_P (mode, wider_mode)) + return convert_to_mode (mode, temp, 0); else - delete_insns_since (last); + return gen_lowpart (mode, temp); } + else + delete_insns_since (last); } } return 0; @@ -2414,7 +2407,7 @@ expand_parity (machine_mode mode, rtx op less convenient for expand_ffs anyway. */ static rtx -expand_ctz (machine_mode mode, rtx op0, rtx target) +expand_ctz (scalar_int_mode mode, rtx op0, rtx target) { rtx_insn *seq; rtx temp; @@ -2457,7 +2450,7 @@ expand_ctz (machine_mode mode, rtx op0, may have an undefined value in that case. If they do not give us a convenient value, we have to generate a test and branch. */ static rtx -expand_ffs (machine_mode mode, rtx op0, rtx target) +expand_ffs (scalar_int_mode mode, rtx op0, rtx target) { HOST_WIDE_INT val = 0; bool defined_at_zero = false; @@ -2714,16 +2707,19 @@ expand_unop (machine_mode mode, optab un /* Widening (or narrowing) clz needs special treatment. */ if (unoptab == clz_optab) { - temp = widen_leading (mode, op0, target, unoptab); - if (temp) - return temp; - - if (GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD - && optab_handler (unoptab, word_mode) != CODE_FOR_nothing) + if (is_a (mode, &int_mode)) { - temp = expand_doubleword_clz (mode, op0, target); + temp = widen_leading (int_mode, op0, target, unoptab); if (temp) return temp; + + if (GET_MODE_SIZE (int_mode) == 2 * UNITS_PER_WORD + && optab_handler (unoptab, word_mode) != CODE_FOR_nothing) + { + temp = expand_doubleword_clz (int_mode, op0, target); + if (temp) + return temp; + } } goto try_libcall; @@ -2731,9 +2727,12 @@ expand_unop (machine_mode mode, optab un if (unoptab == clrsb_optab) { - temp = widen_leading (mode, op0, target, unoptab); - if (temp) - return temp; + if (is_a (mode, &int_mode)) + { + temp = widen_leading (int_mode, op0, target, unoptab); + if (temp) + return temp; + } goto try_libcall; } @@ -2805,16 +2804,19 @@ expand_unop (machine_mode mode, optab un delete_insns_since (last); } - temp = widen_bswap (mode, op0, target); - if (temp) - return temp; - - if (GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD - && optab_handler (unoptab, word_mode) != CODE_FOR_nothing) + if (is_a (mode, &int_mode)) { - temp = expand_doubleword_bswap (mode, op0, target); + temp = widen_bswap (int_mode, op0, target); if (temp) return temp; + + if (GET_MODE_SIZE (int_mode) == 2 * UNITS_PER_WORD + && optab_handler (unoptab, word_mode) != CODE_FOR_nothing) + { + temp = expand_doubleword_bswap (mode, op0, target); + if (temp) + return temp; + } } goto try_libcall; @@ -2915,25 +2917,25 @@ expand_unop (machine_mode mode, optab un } /* Try calculating parity (x) as popcount (x) % 2. */ - if (unoptab == parity_optab) + if (unoptab == parity_optab && is_a (mode, &int_mode)) { - temp = expand_parity (mode, op0, target); + temp = expand_parity (int_mode, op0, target); if (temp) return temp; } /* Try implementing ffs (x) in terms of clz (x). */ - if (unoptab == ffs_optab) + if (unoptab == ffs_optab && is_a (mode, &int_mode)) { - temp = expand_ffs (mode, op0, target); + temp = expand_ffs (int_mode, op0, target); if (temp) return temp; } /* Try implementing ctz (x) in terms of clz (x). */ - if (unoptab == ctz_optab) + if (unoptab == ctz_optab && is_a (mode, &int_mode)) { - temp = expand_ctz (mode, op0, target); + temp = expand_ctz (int_mode, op0, target); if (temp) return temp; }