From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by sourceware.org (Postfix) with ESMTPS id 08AC93857C59 for ; Mon, 21 Sep 2020 23:54:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 08AC93857C59 Received: by mail-pf1-x443.google.com with SMTP id l126so10748587pfd.5 for ; Mon, 21 Sep 2020 16:54:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=xdQ9uTQmd8z7vRudQxtxXShm5ENvalSmqda3NU5UK/E=; b=pxn0ZF7CgCjePMDCeKx4gUaWbslmqbRuDIAP+D/kLe6auLsP1jgmeCv4pJQBxHhZJc QQGqWESE/tmbvLgfeitALE4FMJbz34dqjTULkUvRsH+J+lULYsWQTKaSKXkDLhETHthU mTtU+D4nIVuk2fcl61wNAZ/55zju3GQe3/7yDkB6galTrPOlDLb8+zU66FCwlJua6O/c 1EObd7aMAkh5D5Hk3ACUFezT9Pi0rsX2GilhWLwIRe4RZbXAkmK/YuYyPXNy9iDUsZLY J282avSLMMPqUwV80MstpXCiF5Qd/TwAyxZdgwVDv8BmIOh9mXmRxVG293ci1Vy4jcM1 qkzA== X-Gm-Message-State: AOAM531agdqM0/a8d6LxSqF/CqrzVTDfKvuTdbS2e5Wx8rlpjcc/OtFS gWzLfLC1Ws8WOsis52q+GmHKDYe8quU= X-Google-Smtp-Source: ABdhPJxgme3zDI9zzFVd8L3fZIMb3o3PLHmoSoDuU6RaREQDfO/0Od1ZJnAPHKzgiEX2osKJdN0Rog== X-Received: by 2002:aa7:948d:0:b029:13e:cb8d:60e0 with SMTP id z13-20020aa7948d0000b029013ecb8d60e0mr1944947pfk.9.1600732491112; Mon, 21 Sep 2020 16:54:51 -0700 (PDT) Received: from bubble.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id a18sm12238609pgw.50.2020.09.21.16.54.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 16:54:50 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 3E9E180BD3; Tue, 22 Sep 2020 09:24:46 +0930 (ACST) Date: Tue, 22 Sep 2020 09:24:46 +0930 From: Alan Modra To: Segher Boessenkool Cc: gcc-patches@sourceware.org Subject: Re: [RS6000] rs6000_rtx_costs cost IOR Message-ID: <20200921235446.GZ5452@bubble.grove.modra.org> References: <20200915011946.3395-1-amodra@gmail.com> <20200915011946.3395-7-amodra@gmail.com> <20200917000206.GI28786@gate.crashing.org> <20200917034219.GP5452@bubble.grove.modra.org> <20200921154917.GA28786@gate.crashing.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200921154917.GA28786@gate.crashing.org> User-Agent: Mutt/1.9.4 (2018-02-28) X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Sep 2020 23:54:53 -0000 On Mon, Sep 21, 2020 at 10:49:17AM -0500, Segher Boessenkool wrote: > Hi! > > On Thu, Sep 17, 2020 at 01:12:19PM +0930, Alan Modra wrote: > > On Wed, Sep 16, 2020 at 07:02:06PM -0500, Segher Boessenkool wrote: > > > > + /* Test both regs even though the one in the mask is > > > > + constrained to be equal to the output. Increasing > > > > + cost may well result in rejecting an invalid insn > > > > + earlier. */ > > > > > > Is that ever actually useful? > > > > Possibly not in this particular case, but I did see cases where > > invalid insns were rejected early by costing non-reg sub-expressions. > > But does that ever change generated code? > > This makes the compiler a lot harder to read and understand. To the > point that such micro-optimisations makes worthwhile optimisations hard > or impossible to do. Fair enough, here's a revised patch. * config/rs6000/rs6000.c (rotate_insert_cost): New function. (rs6000_rtx_costs): Cost IOR. Tidy break/return. Tidy AND. diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 5025e3c30c0..78c33cc8cba 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -21118,6 +21118,91 @@ rs6000_cannot_copy_insn_p (rtx_insn *insn) && get_attr_cannot_copy (insn); } +/* Handle rtx_costs for scalar integer rotate and insert insns. */ + +static bool +rotate_insert_cost (rtx left, rtx right, machine_mode mode, bool speed, + int *total) +{ + if (GET_CODE (right) == AND + && CONST_INT_P (XEXP (right, 1)) + && UINTVAL (XEXP (left, 1)) + UINTVAL (XEXP (right, 1)) + 1 == 0) + { + rtx leftop = XEXP (left, 0); + rtx rightop = XEXP (right, 0); + + /* rotlsi3_insert_5. */ + if (REG_P (leftop) + && REG_P (rightop) + && mode == SImode + && UINTVAL (XEXP (left, 1)) != 0 + && UINTVAL (XEXP (right, 1)) != 0 + && rs6000_is_valid_mask (XEXP (left, 1), NULL, NULL, mode)) + return true; + /* rotldi3_insert_6. */ + if (REG_P (leftop) + && REG_P (rightop) + && mode == DImode + && exact_log2 (-UINTVAL (XEXP (left, 1))) > 0) + return true; + /* rotldi3_insert_7. */ + if (REG_P (leftop) + && REG_P (rightop) + && mode == DImode + && exact_log2 (-UINTVAL (XEXP (right, 1))) > 0) + return true; + + rtx mask = 0; + rtx shift = leftop; + rtx_code shift_code = GET_CODE (shift); + /* rotl3_insert. */ + if (shift_code == ROTATE + || shift_code == ASHIFT + || shift_code == LSHIFTRT) + mask = right; + else + { + shift = rightop; + shift_code = GET_CODE (shift); + /* rotl3_insert_2. */ + if (shift_code == ROTATE + || shift_code == ASHIFT + || shift_code == LSHIFTRT) + mask = left; + } + if (mask + && CONST_INT_P (XEXP (shift, 1)) + && rs6000_is_valid_insert_mask (XEXP (mask, 1), shift, mode)) + { + *total += rtx_cost (XEXP (shift, 0), mode, shift_code, 0, speed); + *total += rtx_cost (XEXP (mask, 0), mode, AND, 0, speed); + return true; + } + } + /* rotl3_insert_3. */ + if (GET_CODE (right) == ASHIFT + && CONST_INT_P (XEXP (right, 1)) + && (INTVAL (XEXP (right, 1)) + == exact_log2 (UINTVAL (XEXP (left, 1)) + 1))) + { + *total += rtx_cost (XEXP (left, 0), mode, AND, 0, speed); + *total += rtx_cost (XEXP (right, 0), mode, ASHIFT, 0, speed); + return true; + } + /* rotl3_insert_4. */ + if (GET_CODE (right) == LSHIFTRT + && CONST_INT_P (XEXP (right, 1)) + && mode == SImode + && (INTVAL (XEXP (right, 1)) + + exact_log2 (-UINTVAL (XEXP (left, 1)))) == 32) + { + *total += rtx_cost (XEXP (left, 0), mode, AND, 0, speed); + *total += rtx_cost (XEXP (right, 0), mode, LSHIFTRT, 0, speed); + return true; + } + return false; +} + /* Compute a (partial) cost for rtx X. Return true if the complete cost has been computed, and false if subexpressions should be scanned. In either case, *TOTAL contains the cost result. @@ -21165,6 +21250,7 @@ static bool rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code, int opno ATTRIBUTE_UNUSED, int *total, bool speed) { + rtx left, right; int code = GET_CODE (x); switch (code) @@ -21295,7 +21381,7 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code, *total = rs6000_cost->fp; else *total = rs6000_cost->dmul; - break; + return false; case DIV: case MOD: @@ -21355,32 +21441,37 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code, return false; case AND: - if (CONST_INT_P (XEXP (x, 1))) + *total = COSTS_N_INSNS (1); + right = XEXP (x, 1); + if (CONST_INT_P (right)) { - rtx left = XEXP (x, 0); + left = XEXP (x, 0); rtx_code left_code = GET_CODE (left); /* rotate-and-mask: 1 insn. */ if ((left_code == ROTATE || left_code == ASHIFT || left_code == LSHIFTRT) - && rs6000_is_valid_shift_mask (XEXP (x, 1), left, mode)) + && rs6000_is_valid_shift_mask (right, left, mode)) { - *total = rtx_cost (XEXP (left, 0), mode, left_code, 0, speed); - if (!CONST_INT_P (XEXP (left, 1))) - *total += rtx_cost (XEXP (left, 1), SImode, left_code, 1, speed); - *total += COSTS_N_INSNS (1); + *total += rtx_cost (XEXP (left, 0), mode, left_code, 0, speed); + *total += rtx_cost (XEXP (left, 1), mode, left_code, 1, speed); return true; } } - - *total = COSTS_N_INSNS (1); return false; case IOR: - /* FIXME */ *total = COSTS_N_INSNS (1); - return true; + left = XEXP (x, 0); + if (GET_CODE (left) == AND + && CONST_INT_P (XEXP (left, 1))) + { + right = XEXP (x, 1); + if (rotate_insert_cost (left, right, mode, speed, total)) + return true; + } + return false; case CLZ: case XOR: @@ -21465,7 +21556,7 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code, *total = rs6000_cost->fp; return false; } - break; + return false; case NE: case EQ: @@ -21503,13 +21594,11 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code, *total = 0; return true; } - break; + return false; default: - break; + return false; } - - return false; } /* Debug form of r6000_rtx_costs that is selected if -mdebug=cost. */ -- Alan Modra Australia Development Lab, IBM