From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc31.google.com (mail-oo1-xc31.google.com [IPv6:2607:f8b0:4864:20::c31]) by sourceware.org (Postfix) with ESMTPS id 945DD3858C50 for ; Sat, 16 Mar 2024 20:21:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 945DD3858C50 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 945DD3858C50 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c31 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710620472; cv=none; b=IZABZTO1YLug812Yc98FkqOkvM/pStnplhCSAnEb2ROXaUcphJym9UXiaVbkRkYynZVJHck8dmz+1Po54Ph/0ECRzr5ipBnBU2mC3/+uiiBg7WXnLJoKNKPT4ullzu/3+sE7LZTBc/JpE+H+ZMT8G4WsFVGn/TDaOK1Z6AYyQMI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710620472; c=relaxed/simple; bh=4RBr8ltC/MnPrI94QiOo8OupkbLO5WdWM0sXAHH+S3I=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=BBpr3MpkAq3MnL+wjoJLWlwMCb9kK0IdohYFINKaFBcJQVPm4WuuyATR5czuHVckNbKcQrOXF9kzRE43Bk8r9j1gRlMrFRdqDwqNKVtOD2Dt+jHxzlhmAUciHH/Yh9ghicgAGrTuxS9MfcpVHo4pjN3BVSdw370Q7a2OJMvbx7M= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-xc31.google.com with SMTP id 006d021491bc7-5a4789684abso1209040eaf.0 for ; Sat, 16 Mar 2024 13:21:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710620470; x=1711225270; 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=aLqsfBw12yzJKMM6I1/SL66yiu50GSCwvOwj3gofzx8=; b=U0enhe5c/ULdwhUzqV0R7oMvI/HDtASTOuDQkzABug5qGXbQUQ4YnDOevU6klcnXjs Cw6jXyndpkd+SYLsldd90UhZdPvfPLI/d6dKOLpkqwsDfPU3pXv6xFMbijgatdIeeUuA 1yFNT88o0w1UjCq4VZ6nSpKte+Gshy6aVT8XqtynX0sxV/ong/ZhoEpuw3dgnF5GI224 pR4WEHIp347UhpxO8dnzkLUzXOl92Hi+Q2X77UGsnVtmNqyB2q7IRWbmKF05tPDvc11R ACMXd+ooqTFGwzzNrqNsUzuBeqSUY/03pnEil6ywgOq075RIBhov0FGKsZ4ueyEofyZ+ /yQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710620470; x=1711225270; 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=aLqsfBw12yzJKMM6I1/SL66yiu50GSCwvOwj3gofzx8=; b=AnEuVM9FfZCh243Fsaswl2CliGcZMVnWTgCJzcc5eAut0ahRM2PGUI+2Mj1P7szNXy ch4hjvdgfTyI07DXpmuKpw9EQAr94pspj6TRk6ij269VSYtyUOBvauDMUPRh5QsSX4aK vU1EE0x8gmy52Pmd/MyB9WuSsfNZjuKxIKAGE89cwElolDl8lLjM5P7U/1P4nQqPUjDe mblYReMczAEQo89/GROtoMZpXGBHvayumMW3PZ6PiSfIXTEDHA5ZuLYmCSOutqEV74jz NW1CHfmIDE4RLv1VGmxeEGPGdmFnltAvbIpOl4lQminWLZyV9iT0b8i0swb1+d3c518e ScIw== X-Forwarded-Encrypted: i=1; AJvYcCURBzeuv3/ALenWXotSvUadh4sfSt+18ffFFzo26vNyCRHLEBWCNPuXUdZEfnSliYXVFL6UvzQMKVbefsxPhqHqr7tdVmiNmQ== X-Gm-Message-State: AOJu0YyNo1QqZQeST4VTNrDdO0JFvUD+2dVakgBLWgV9qsrFveMbWRap 16PoTrRJ9NhzXHCw0h5YeKBX9lIMIJyy1OWbg1MYFPqhhTbfCwmT X-Google-Smtp-Source: AGHT+IFm2CtR/wVHWlb1cWEPKxeBEKqCjdvHHa/XN/4Ddgq1V/sCbJ6qAVN18lH8KUo5pdZMTa9mIg== X-Received: by 2002:a05:6820:3085:b0:5a4:97f0:ca44 with SMTP id eu5-20020a056820308500b005a497f0ca44mr1224107oob.5.1710620469664; Sat, 16 Mar 2024 13:21:09 -0700 (PDT) Received: from [172.31.0.109] ([136.36.72.243]) by smtp.gmail.com with ESMTPSA id z7-20020a4ad587000000b005a0859a4a01sm1239809oos.36.2024.03.16.13.21.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 16 Mar 2024 13:21:09 -0700 (PDT) Message-ID: Date: Sat, 16 Mar 2024 14:21:07 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Subject: Re: [gcc-15 2/3] RISC-V: avoid LUI based const mat: keep stack offsets aligned Content-Language: en-US To: Vineet Gupta , gcc-patches@gcc.gnu.org Cc: kito.cheng@gmail.com, Palmer Dabbelt , gnu-toolchain@rivosinc.com, Robin Dapp References: <20240316173524.1147760-1-vineetg@rivosinc.com> <20240316173524.1147760-3-vineetg@rivosinc.com> From: Jeff Law In-Reply-To: <20240316173524.1147760-3-vineetg@rivosinc.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,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 3/16/24 11:35 AM, Vineet Gupta wrote: > Noticed that new sum of two s12 splitter was generating following: > > | 059930 : > | 59930: add sp,sp,-16 > | 59934: lui t0,0xfffff > | 59938: sd s0,0(sp) > | 5993c: sd ra,8(sp) > | 59940: add sp,sp,t0 > | 59944: add s0,sp,2047 <---- > | 59948: mv a2,a0 > | 5994c: mv a3,a1 > | 59950: mv a0,sp > | 59954: li a4,1 > | 59958: lui a1,0x1 > | 5995c: add s0,s0,1 <--- > | 59960: jal 59a3c > > SP here becomes unaligned, even if transitively which is undesirable as > well as incorrect: > - ABI requires stack to be 8 byte aligned > - asm code looks weird and unexpected > - to the user it might falsely seem like a compiler bug even when not, > specially when staring at asm for debugging unrelated issue. It's not ideal, but I think it's still ABI compliant as-is. If it wasn't, then I suspect things like virtual origins in Ada couldn't be made ABI compliant. > > Fix this by using 2032+addend idiom when handling register operands > related to stack. This only affects positive S12 values, negative values > are already -2048 based. > > Unfortunately implementation requires making a copy of splitter, since > it needs different varaints of predicate and constraint which cant be > done conditionally in the same MD pattern (constraint with restricted > range prevents LRA from allowing such insn despite new predicate) > > With the patch, we get following correct code instead: > > | .. > | 59944: add s0,sp,2032 > | .. > | 5995c: add s0,s0,16 Alternately you could tighten the positive side of the range of the splitter from patch 1/3 so that you could always use 2032 rather than 2047 on the first addi. ie instead of allowing 2048..4094, allow 2048..4064. I don't have a strong opinion on that vs the direction you've gone here. Jeff