From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id D02953858D32 for ; Mon, 12 Jun 2023 19:26:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D02953858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-653f9c7b3e4so3629068b3a.2 for ; Mon, 12 Jun 2023 12:26:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686598011; x=1689190011; 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=biU3oxRf0g9hfS1KdvQ5cWrZnGq/wrPIt70lakNYqyg=; b=ObB82m/mqRdnNR1hAq4phfAdTN9ZDDG85UzO2M2Dh5Qhk0UB+N16hZmsGXbNc004ww b9g7QkeAZcKsyD/iRJ/iBXW6E3khYpAjyqrQKVIO43MUJ8Xb0JLi1YPe5mGmPAZNwC3c V3cxnvwtrXdZ7JJfzkyOMHKS+J3sl0XmzMi49Lcfk7ngB4BQPFXoWwolw9AFAhnUAc9G NpWxUsJwEDbZlJ79MvtdBqwOfJo9XpkgMOlvFLKVyzNVJXE1XNi9Xr5V+etFhpHfileN Fu9NIWoisZLAfVs+elLz3GUMRjzdXewI8W+9qBh+p5RZspgnn1Ko1Cf2WxEDTmikpids jHDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686598011; x=1689190011; 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=biU3oxRf0g9hfS1KdvQ5cWrZnGq/wrPIt70lakNYqyg=; b=PCe7v5zK3XNWEEPIwmPmcglmiGFQiGn1ZhXxaBtHluaI1z1IuIb+zRCsyBcmfMRtT+ wivNm+6CmqI6IbVghIzMGwKQL9T+h9QEr/nLkx//NVrpWaV2NcXEG3PPf/5htWbtYWup cD9bs60aq9mfhpcxooDOFn/e4iEorRIyc7IpzHKG7ztxg/N424eEJPThZ64pETZarY5o ndQNb+r/iEbWEnoBb80WGCUUVDs+GdCNc/94K9FtNO+4eZthFs5o+S7mps0B7i5w3ZGO YVrp2jBG2XCmZTe/AjYoon2Z1FmSZxfST4TTKDjPzAShbLNKGXBkasXcbjs4MlyWSK/T s3vw== X-Gm-Message-State: AC+VfDxtS3T8AOUVrWQkFjJ1R4m0e8fCV0mqJnQzyb86/9yBRgRnCfJk Hi78pU5qhdSRP6fat7vyUJg= X-Google-Smtp-Source: ACHHUZ6mMP/b0fRbOPDbMTlzmIXOb8hjuGh/FUrlEd5YyGgqhbvvPPo9rz6lfq+HDgkzHL2AX/3qMA== X-Received: by 2002:a17:902:c389:b0:1af:a2a4:8379 with SMTP id g9-20020a170902c38900b001afa2a48379mr6093622plg.17.1686598010349; Mon, 12 Jun 2023 12:26:50 -0700 (PDT) Received: from [172.31.0.109] ([136.36.130.248]) by smtp.gmail.com with ESMTPSA id h3-20020a170902680300b001ab12ccc2a7sm8682752plk.98.2023.06.12.12.26.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 12 Jun 2023 12:26:49 -0700 (PDT) Message-ID: Date: Mon, 12 Jun 2023 13:26:48 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: Re: [PATCH 3/4] [RISC-V] resolve confilct between zcmp multi push/pop and shrink-wrap-separate Content-Language: en-US To: Fei Gao , gcc-patches@gcc.gnu.org Cc: kito.cheng@gmail.com, palmer@dabbelt.com, sinan.lin@linux.alibaba.com, jiawei@iscas.ac.cn References: <20230607055215.29332-1-gaofei@eswincomputing.com> <20230607055215.29332-4-gaofei@eswincomputing.com> From: Jeff Law In-Reply-To: <20230607055215.29332-4-gaofei@eswincomputing.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,KAM_SHORT,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham 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 6/6/23 23:52, Fei Gao wrote: > Disable zcmp multi push/pop if shrink-wrap-separate is active. > > So in -Os that prefers smaller code size, by default shrink-wrap-separate > is disabled while zcmp multi push/pop is enabled. > > And in -O2 and others that prefers speed, by default shrink-wrap-separate > is enabled while zcmp multi push/pop is disabled. To force enabling zcmp multi > push/pop in this case, -fno-shrink-wrap-separate has to be explictly given. > > The following TC shows the issues in -O2 before this patch with both > shrink-wrap-separate and zcmp multi push/pop active. > 1. duplicated store of s regs. > 2. cm.push pushes ra, s0-s11 in reverse order than what normal > prologue does, causing stack corruption and failure to resotre s regs. > > TC: zcmp_shrink_wrap_separate.c included in this patch. > > output asm before this patch: > calc_func: > cm.push {ra, s0-s3}, -32 > ... > beq a5,zero,.L2 > ... > .L2: > ... > sw s1,20(sp) //issue here > sw s3,12(sp) //issue here > ... > sw s2,16(sp) //issue here > > output asm after this patch: > calc_func: > addi sp,sp,-32 > sw s0,24(sp) > ... > beq a5,zero,.L2 > ... > .L2: > ... > sw s1,20(sp) > sw s3,12(sp) > ... > sw s2,16(sp) > gcc/ChangeLog: > > * config/riscv/riscv.cc > (riscv_avoid_shrink_wrapping_separate): wrap the condition check in > riscv_avoid_shrink_wrapping_separate. > (riscv_avoid_multi_push): avoid multi push if shrink_wrapping_separate > is active. > (riscv_get_separate_components): call riscv_avoid_shrink_wrapping_separate > * shrink-wrap.cc (try_shrink_wrapping_separate): call > use_shrink_wrapping_separate. > (use_shrink_wrapping_separate):wrap the condition > check in use_shrink_wrapping_separate > * shrink-wrap.h (use_shrink_wrapping_separate): add to extern > > gcc/testsuite/ChangeLog: > > * gcc.target/riscv/zcmp_shrink_wrap_separate.c: New test. > * gcc.target/riscv/zcmp_shrink_wrap_separate2.c: New test. I know Kito asked for this to be broken up into target dependent vs target independent changes, that's a good ask. Can't we utilize the get_separate_components hook to accomplish what you're trying to do? ie, put the logic to avoid shrink wrapping for this case within the existing risc-v hook? jeff