From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by sourceware.org (Postfix) with ESMTPS id 785AC3857007 for ; Tue, 9 Jan 2024 14:43:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 785AC3857007 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 785AC3857007 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d32 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704811432; cv=none; b=Rdfbf/LAvxKVR/x0vpiquu72WhrKiMxKvmCJO3+IcArx3ZaD/b3Cm03nnAFos+/z8mPn5wD9wwLaJJRkpaYovx/CxoyPIJAuFtgCRvSfTO2IFl7Zf9XwCBsbGqL3UNuS3fBko3+MLayLztnNejkiEMBQ3sphrtBgTbFrpYYLmJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704811432; c=relaxed/simple; bh=Sq9DbOc1UvloU9i7XOvkjnS+6/l+bbVDEAVNb9ZXTYo=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=prXl29Hvl7BlubKF8Fdusc+5ZYcIZBwRu7lhLnqZL8Mv8lB88/xVgcrY6cGHth0WcWE4OXhxJuNQldyB6QlHx7DDRWEa1b5gRFQPFFW07oCEl91aqGTp6ov1affw626/4yM8zYWKzo2/LasJqdyA7sKDxJmimDgZRFJQ4pPLGz8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-io1-xd32.google.com with SMTP id ca18e2360f4ac-7bade847536so145054239f.0 for ; Tue, 09 Jan 2024 06:43:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704811428; x=1705416228; darn=gcc.gnu.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=CYc6lb/W3PwDg2rSTAYm83ivayEbZ4u5sJeP2fUXCME=; b=OC8a/No+WlvL2ldnQS3sAWQ3hQfSZuL4z2Z/CDOZLJGnmMcGERNuC9PWk9h3sr5hbK ZU50vxKTfFrMDTX27vdTnlfUEBwQqGIFJmnxfi1u0sh11RokmdcvQxxex8OpNRcphbla bBW/JNOeCppHEFDoXYON12OXzkdfvfJK7uErXZ/gYglHAtxfXFVzy2E1nvlEBlkwFXkr 1/lPRq0jkTRymCmMgMRV45J6yNumtx0k5CqsB39alfOvrcHGX4kO/gkkoxXKd/MxO5d2 GcWI88g2bNPIDfDDBwBLIZVAQNgNRWj9IbpKVBpckj0QNygUMQnxsHUzVyIDVc4mc9to jb0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704811428; x=1705416228; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CYc6lb/W3PwDg2rSTAYm83ivayEbZ4u5sJeP2fUXCME=; b=q0/EQCgDiUn2Bvk1K8QqVtNkTA0/jZKRk7CxQyblEOl95XkX20AXrydsSrs6dAS0T/ zW+WcmFuZsWtqiz4c0WwSK94yhulr70oLLyDQTMGvlX8EQ76f4YpjBHcCKoiMsyHS6wi 4RlFGYGma6FcZcEprdd0vXSxBYrMJdq4YQY1KvzMc92JpjsvtyQdMKqrRStLioROJUyI 3DjrXKzWl31rqpZmc601ZGJ8PdlSgEC8l8tpZdDbhdOESSlpCNKTiZ511QH+ytIqO3TF m+FYLq3AHCcMs28XII+V6AdkWWOgB3he5svv420zlpwviqy9TvYDdvScMlOVVyPyhuVh TqVw== X-Gm-Message-State: AOJu0YzA0TVVpVu9HGWc1cT7Kw8n6KemMAH88/K35mTQ5PRTjRtolJyM cJ9J/mKvZf2s9HXGWWpuBs4= X-Google-Smtp-Source: AGHT+IFZJpRm9zNwoLZICBD5BnfetE3KVgKvaDAhbbJvoT6J5j62fOokTetcaSgCwmdwTuzzcqmReg== X-Received: by 2002:a5d:8190:0:b0:7bc:1809:897 with SMTP id u16-20020a5d8190000000b007bc18090897mr6455703ion.13.1704811427855; Tue, 09 Jan 2024 06:43:47 -0800 (PST) Received: from [172.31.0.109] ([136.36.72.243]) by smtp.gmail.com with ESMTPSA id dn9-20020a056638090900b0046e2b07c836sm668703jab.170.2024.01.09.06.43.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 09 Jan 2024 06:43:47 -0800 (PST) Message-ID: <775d6a17-53c8-40d0-93d5-3252ab1b782d@gmail.com> Date: Tue, 9 Jan 2024 07:43:45 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] RISC-V: Also handle sign extension in branch costing Content-Language: en-US To: "Maciej W. Rozycki" , gcc-patches@gcc.gnu.org Cc: Andrew Waterman , Jim Wilson , Kito Cheng , Palmer Dabbelt References: From: Jeff Law In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,KAM_SHORT,LIKELY_SPAM_BODY,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 1/7/24 17:06, Maciej W. Rozycki wrote: > Complement commit c1e8cb3d9f94 ("RISC-V: Rework branch costing model for > if-conversion") and also handle extraneous sign extend operations that > are sometimes produced by `noce_try_cmove_arith' instead of zero extend > operations, making branch costing consistent. It is unclear what the > condition is for the middle end to choose between the zero extend and > sign extend operation, but the test case included uses sign extension > with 64-bit targets, preventing if-conversion from triggering across all > the architectural variants. > > There are further anomalies revealed by the test case, specifically the > exceedingly high branch cost of 6 required for the `-mmovcc' variant > despite that the final branchless sequence only uses 4 instructions, the > missed conversion at -O1 for 32-bit targets even though code is machine > word size agnostic, and the missed conversion at -Os and -Oz for 32-bit > Zicond targets even though the branchless sequence would be shorter than > the branched one. These will have to be handled separately. > > gcc/ > * config/riscv/riscv.cc (riscv_noce_conversion_profitable_p): > Also handle sign extension. > > gcc/testsuite/ > * gcc.target/riscv/cset-sext-sfb.c: New test. > * gcc.target/riscv/cset-sext-thead.c: New test. > * gcc.target/riscv/cset-sext-ventana.c: New test. > * gcc.target/riscv/cset-sext-zicond.c: New test. > * gcc.target/riscv/cset-sext.c: New test. > --- > Hi, > > This is still in regression-testing, but as a branch costing adjustment > only I don't expect any code correctness issues, and the performance > advantage seems very obvious as the sign extend operation applied to the > result of a conditional set instruction is always a no-op, just as with > the zero extension. > > Depending on how you look at it you may qualify this as a bug fix (for > the commit referred; it's surely rare enough a case I missed in original > testing) or a missed optimisation. Either way it's a narrow-scoped very > small change, almost an obviously correct one. I'll be very happy to get > it off my plate now, but if it has to wait for GCC 15, I'll accept the > decision. > > OK to apply then or shall I wait? OK to apply. jeff