From patchwork Mon May 20 23:32:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vineet Gupta X-Patchwork-Id: 90501 X-Patchwork-Delegate: jlaw@ventanamicro.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8A1E73858C31 for ; Mon, 20 May 2024 23:33:20 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id 23AEA3858D1E for ; Mon, 20 May 2024 23:32:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 23AEA3858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 23AEA3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::634 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716247971; cv=none; b=ZQoLJ7BQxZoVlFPz4cn5k9AcpPt8khrQyzgJBHE69jdAyZ3/eCrn24Cj/h0E+GpcvHnA5p+aigfBRfnYfEIcZ7vGI5H9sGCOMzmwD1+zw8JVrhZjJSJDJe79MCx/D/ikv1HZkdARpwbUQq2OJHdEZhT2v+xU6ye9T9ogE1UFvyw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716247971; c=relaxed/simple; bh=00aVM+9N9EfNFg9U/lNHmk5YkqgLWglPjE7BF1xoAVo=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=EQleacNiHg+jLk5nwialtY1ZlRlWgytNlyLlSy3q2+rl0EXfaz5ZvRhqwqXdgrZhiZnAEfKe5/a5XqOU2BDQ2TkcExxjelNnJjwlmuFIBRyNyuIT9VYgQBHycroAnMepeTYJ7OYP6OzwfGGdtFPNS1x0bW1YwT4GcEmi9/8aQlM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1edfc57ac0cso92371265ad.3 for ; Mon, 20 May 2024 16:32:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1716247967; x=1716852767; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=lZr0pC4ejQBBuQy+gLFLxGkcjeAh5p/oaY+MOs3Jn3o=; b=u3PMuWTdKlmClIBY95k1VG0BDs721PKJSAsxe/wLTZHZp3tIprAxXcU8+yIPj4iv4m 5Oah7CA1XB7p+95slKTqfQw9/w8UDMIvsCR2b0QKoM2jHWm8pR3cFgXNicowLEKQLKJ8 rl22/XooxMstVDwB9A9sdP1Tym4iBBJi8qes/l4Ojj2IgbtaQ26mTfEiXKWFPXeswbjX NHZvGwJr6k+jssTEhQhDU4E+u7wOmyaL5C2bgbmVZqSyU7UROpwv6rxxuUMMJJ625O/V TQ3tTy6KWnjlKXMSaPgkJdr+MRQVnGxZuiSFPXSCfALUGGRGxHq5ORRj0/Z14X+janFQ bMrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716247967; x=1716852767; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lZr0pC4ejQBBuQy+gLFLxGkcjeAh5p/oaY+MOs3Jn3o=; b=PYNiWH8udUj67WNJWZZ7tEOCEa9o5jT8YB+GlKuEM9xJvstvHNrA0rndtIxVy5UxCS XwQntIKVDIXrq+oSkoiKEFB3A/yCiEoemUsuBA0IofqeuXDPODbvrIqBhI4JS6kDX4Fb sDGV7E/aK604IO2OGHKLVM8CPmZDXngnS1JaEzWPwulMW1O4QLwnQhSRlrnJ1CYtcncR qcCKIlGf9PwzOx+hjRyifrP/ut8zuZvoSBYZ/spmHf62M3XRYxzZbRIqOBANVoxYxpzP lTKU0CBoZqf+Yeinz5MT0beYOnMaU3GG4zoDvWcH59W2mDvfRKQ1ztDVVmi2l/IJ76ck NSPQ== X-Gm-Message-State: AOJu0Yx3QjQJej67kchcyelPGrQjI3X/onP/LWyj2Fud7Zrr+gprGKYu FQr0T3aWErrZak8siLZAFga1qsoxdMYqnwiSePtVFAC1CHOHcc3hxN3+E/OstdqeA5vCFRmodXr HHG8= X-Google-Smtp-Source: AGHT+IFSMSrtdkAEKr75wAWmtrV7a6tde3A0wgAkAZ1iOHWzh6fAHUiyIXQ7+guaqRDQja8vT2M9EQ== X-Received: by 2002:a17:90a:5508:b0:2b6:ab87:59c8 with SMTP id 98e67ed59e1d1-2b6cc7745a4mr24652024a91.13.1716247966440; Mon, 20 May 2024 16:32:46 -0700 (PDT) Received: from vineet-framework.hq.rivosinc.com ([50.145.13.30]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b628966cdesm22524912a91.34.2024.05.20.16.32.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 16:32:46 -0700 (PDT) From: Vineet Gupta To: gcc-patches@gcc.gnu.org Cc: Jeff Law , kito.cheng@gmail.com, Palmer Dabbelt , gnu-toolchain@rivosinc.com, Vineet Gupta Subject: [PATCH v3 1/2] RISC-V: avoid LUI based const mat in prologue/epilogue expansion [PR/105733] Date: Mon, 20 May 2024 16:32:36 -0700 Message-Id: <20240520233237.109269-1-vineetg@rivosinc.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_ASCII_DIVIDERS, KAM_SHORT, LIKELY_SPAM_BODY, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Changes since v2: - Broke out the hunk corresponding to alloca in epilogue expansion in a seperate patch. --- If the constant used for stack offset can be expressed as sum of two S12 values, the constant need not be materialized (in a reg) and instead the two S12 bits can be added to instructions involved with frame pointer. This avoids burning a register and more importantly can often get down to be 2 insn vs. 3. The prev patches to generally avoid LUI based const materialization didn't fix this PR and need this directed fix in funcion prologue/epilogue expansion. This fix doesn't move the neddle for SPEC, at all, but it is still a win considering gcc generates one insn fewer than llvm for the test ;-) gcc-13.1 release | gcc 230823 | | | g6619b3d4c15c | This patch | clang/llvm --------------------------------------------------------------------------------- li t0,-4096 | li t0,-4096 | addi sp,sp,-2048 | addi sp,sp,-2048 addi t0,t0,2016 | addi t0,t0,2032 | add sp,sp,-16 | addi sp,sp,-32 li a4,4096 | add sp,sp,t0 | add a5,sp,a0 | add a1,sp,16 add sp,sp,t0 | addi a5,sp,-2032 | sb zero,0(a5) | add a0,a0,a1 li a5,-4096 | add a0,a5,a0 | addi sp,sp,2032 | sb zero,0(a0) addi a4,a4,-2032 | li t0, 4096 | addi sp,sp,32 | addi sp,sp,2032 add a4,a4,a5 | sb zero,2032(a0) | ret | addi sp,sp,48 addi a5,sp,16 | addi t0,t0,-2032 | | ret add a5,a4,a5 | add sp,sp,t0 | add a0,a5,a0 | ret | li t0,4096 | sd a5,8(sp) | sb zero,2032(a0)| addi t0,t0,-2016 | add sp,sp,t0 | ret | gcc/ChangeLog: PR target/105733 * config/riscv/riscv.h: New macros for with aligned offsets. * config/riscv/riscv.cc (riscv_split_sum_of_two_s12): New function to split a sum of two s12 values into constituents. (riscv_expand_prologue): Handle offset being sum of two S12. (riscv_expand_epilogue): Ditto. * config/riscv/riscv-protos.h (riscv_split_sum_of_two_s12): New. gcc/testsuite/ChangeLog: * gcc.target/riscv/pr105733.c: New Test. * gcc.target/riscv/rvv/autovec/vls/spill-1.c: Adjust to not expect LUI 4096. * gcc.target/riscv/rvv/autovec/vls/spill-2.c: Ditto. * gcc.target/riscv/rvv/autovec/vls/spill-3.c: Ditto. * gcc.target/riscv/rvv/autovec/vls/spill-4.c: Ditto. * gcc.target/riscv/rvv/autovec/vls/spill-5.c: Ditto. * gcc.target/riscv/rvv/autovec/vls/spill-6.c: Ditto. * gcc.target/riscv/rvv/autovec/vls/spill-7.c: Ditto. Signed-off-by: Vineet Gupta --- gcc/config/riscv/riscv-protos.h | 2 + gcc/config/riscv/riscv.cc | 54 +++++++++++++++++-- gcc/config/riscv/riscv.h | 7 +++ gcc/testsuite/gcc.target/riscv/pr105733.c | 15 ++++++ .../riscv/rvv/autovec/vls/spill-1.c | 4 +- .../riscv/rvv/autovec/vls/spill-2.c | 4 +- .../riscv/rvv/autovec/vls/spill-3.c | 4 +- .../riscv/rvv/autovec/vls/spill-4.c | 4 +- .../riscv/rvv/autovec/vls/spill-5.c | 4 +- .../riscv/rvv/autovec/vls/spill-6.c | 4 +- .../riscv/rvv/autovec/vls/spill-7.c | 4 +- 11 files changed, 89 insertions(+), 17 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/pr105733.c diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h index c64aae18deb9..0704968561bb 100644 --- a/gcc/config/riscv/riscv-protos.h +++ b/gcc/config/riscv/riscv-protos.h @@ -167,6 +167,8 @@ extern void riscv_subword_address (rtx, rtx *, rtx *, rtx *, rtx *); extern void riscv_lshift_subword (machine_mode, rtx, rtx, rtx *); extern enum memmodel riscv_union_memmodels (enum memmodel, enum memmodel); extern bool riscv_reg_frame_related (rtx); +extern void riscv_split_sum_of_two_s12 (HOST_WIDE_INT, HOST_WIDE_INT *, + HOST_WIDE_INT *); /* Routines implemented in riscv-c.cc. */ void riscv_cpu_cpp_builtins (cpp_reader *); diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index d0c22058b8c3..2ecbcf1d0af8 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -4075,6 +4075,32 @@ riscv_split_doubleword_move (rtx dest, rtx src) riscv_emit_move (riscv_subword (dest, true), riscv_subword (src, true)); } } + +/* Constant VAL is known to be sum of two S12 constants. Break it into + comprising BASE and OFF. + Numerically S12 is -2048 to 2047, however it uses the more conservative + range -2048 to 2032 as offsets pertain to stack related registers. */ + +void +riscv_split_sum_of_two_s12 (HOST_WIDE_INT val, HOST_WIDE_INT *base, + HOST_WIDE_INT *off) +{ + if (SUM_OF_TWO_S12_N (val)) + { + *base = -2048; + *off = val - (-2048); + } + else if (SUM_OF_TWO_S12_P_ALGN (val)) + { + *base = 2032; + *off = val - 2032; + } + else + { + gcc_unreachable (); + } +} + /* Return the appropriate instructions to move SRC into DEST. Assume that SRC is operand 1 and DEST is operand 0. */ @@ -7864,6 +7890,17 @@ riscv_expand_prologue (void) GEN_INT (-constant_frame)); RTX_FRAME_RELATED_P (emit_insn (insn)) = 1; } + else if (SUM_OF_TWO_S12_ALGN (-constant_frame)) + { + HOST_WIDE_INT one, two; + riscv_split_sum_of_two_s12 (-constant_frame, &one, &two); + insn = gen_add3_insn (stack_pointer_rtx, stack_pointer_rtx, + GEN_INT (one)); + RTX_FRAME_RELATED_P (emit_insn (insn)) = 1; + insn = gen_add3_insn (stack_pointer_rtx, stack_pointer_rtx, + GEN_INT (two)); + RTX_FRAME_RELATED_P (emit_insn (insn)) = 1; + } else { riscv_emit_move (RISCV_PROLOGUE_TEMP (Pmode), GEN_INT (-constant_frame)); @@ -8160,10 +8197,21 @@ riscv_expand_epilogue (int style) /* Get an rtx for STEP1 that we can add to BASE. Skip if adjust equal to zero. */ - if (step1.to_constant () != 0) + HOST_WIDE_INT step1_value = step1.to_constant (); + if (step1_value != 0) { - rtx adjust = GEN_INT (step1.to_constant ()); - if (!SMALL_OPERAND (step1.to_constant ())) + rtx adjust = GEN_INT (step1_value); + if (SUM_OF_TWO_S12_ALGN (step1_value)) + { + HOST_WIDE_INT one, two; + riscv_split_sum_of_two_s12 (step1_value, &one, &two); + insn = emit_insn (gen_add3_insn (stack_pointer_rtx, + stack_pointer_rtx, + GEN_INT (one))); + RTX_FRAME_RELATED_P (insn) = 1; + adjust = GEN_INT (two); + } + else if (!SMALL_OPERAND (step1_value)) { riscv_emit_move (RISCV_PROLOGUE_TEMP (Pmode), adjust); adjust = RISCV_PROLOGUE_TEMP (Pmode); diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h index 0d27c0d378df..d6b14c4d6205 100644 --- a/gcc/config/riscv/riscv.h +++ b/gcc/config/riscv/riscv.h @@ -641,6 +641,13 @@ enum reg_class #define SUM_OF_TWO_S12(VALUE) \ (SUM_OF_TWO_S12_N (VALUE) || SUM_OF_TWO_S12_P (VALUE)) +/* Variant with first value 8 byte aligned if involving stack regs. */ +#define SUM_OF_TWO_S12_P_ALGN(VALUE) \ + (((VALUE) >= (2032 + 1)) && ((VALUE) <= (2032 * 2))) + +#define SUM_OF_TWO_S12_ALGN(VALUE) \ + (SUM_OF_TWO_S12_N (VALUE) || SUM_OF_TWO_S12_P_ALGN (VALUE)) + /* If this is a single bit mask, then we can load it with bseti. Special handling of SImode 0x80000000 on RV64 is done in riscv_build_integer_1. */ #define SINGLE_BIT_MASK_OPERAND(VALUE) \ diff --git a/gcc/testsuite/gcc.target/riscv/pr105733.c b/gcc/testsuite/gcc.target/riscv/pr105733.c new file mode 100644 index 000000000000..6156c36dc7ef --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/pr105733.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options { -march=rv64gcv -mabi=lp64d } } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" "-Os" "-Oz" } } */ + +#define BUF_SIZE 2064 + +void +foo(unsigned long i) +{ + volatile char buf[BUF_SIZE]; + + buf[i] = 0; +} + +/* { dg-final { scan-assembler-not {li\t[a-x0-9]+,4096} } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-1.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-1.c index b64c73f34f13..6afcf1db593b 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-1.c +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-1.c @@ -129,5 +129,5 @@ spill_12 (int8_t *in, int8_t *out) /* { dg-final { scan-assembler-times {addi\tsp,sp,-256} 1 } } */ /* { dg-final { scan-assembler-times {addi\tsp,sp,-512} 1 } } */ /* { dg-final { scan-assembler-times {addi\tsp,sp,-1024} 1 } } */ -/* { dg-final { scan-assembler-times {addi\tsp,sp,-2048} 1 } } */ -/* { dg-final { scan-assembler-times {li\t[a-x0-9]+,-4096\s+add\tsp,sp,[a-x0-9]+} 1 } } */ +/* { dg-final { scan-assembler-times {addi\tsp,sp,-2048} 3 } } */ +/* { dg-final { scan-assembler-times {addi\tsp,sp,2032} 1 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-2.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-2.c index 8fcdca705384..544e8628a27b 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-2.c +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-2.c @@ -120,5 +120,5 @@ spill_11 (int16_t *in, int16_t *out) /* { dg-final { scan-assembler-times {addi\tsp,sp,-256} 1 } } */ /* { dg-final { scan-assembler-times {addi\tsp,sp,-512} 1 } } */ /* { dg-final { scan-assembler-times {addi\tsp,sp,-1024} 1 } } */ -/* { dg-final { scan-assembler-times {addi\tsp,sp,-2048} 1 } } */ -/* { dg-final { scan-assembler-times {li\t[a-x0-9]+,-4096\s+add\tsp,sp,[a-x0-9]+} 1 } } */ +/* { dg-final { scan-assembler-times {addi\tsp,sp,-2048} 3 } } */ +/* { dg-final { scan-assembler-times {addi\tsp,sp,2032} 1 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-3.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-3.c index ca296ce02d66..4bfeb07e9aca 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-3.c +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-3.c @@ -111,5 +111,5 @@ spill_10 (int32_t *in, int32_t *out) /* { dg-final { scan-assembler-times {addi\tsp,sp,-256} 1 } } */ /* { dg-final { scan-assembler-times {addi\tsp,sp,-512} 1 } } */ /* { dg-final { scan-assembler-times {addi\tsp,sp,-1024} 1 } } */ -/* { dg-final { scan-assembler-times {addi\tsp,sp,-2048} 1 } } */ -/* { dg-final { scan-assembler-times {li\t[a-x0-9]+,-4096\s+add\tsp,sp,[a-x0-9]+} 1 } } */ +/* { dg-final { scan-assembler-times {addi\tsp,sp,-2048} 3 } } */ +/* { dg-final { scan-assembler-times {addi\tsp,sp,2032} 1 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-4.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-4.c index ef61d9a2c0c3..1faf31ffd8e0 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-4.c +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-4.c @@ -102,5 +102,5 @@ spill_9 (int64_t *in, int64_t *out) /* { dg-final { scan-assembler-times {addi\tsp,sp,-256} 1 } } */ /* { dg-final { scan-assembler-times {addi\tsp,sp,-512} 1 } } */ /* { dg-final { scan-assembler-times {addi\tsp,sp,-1024} 1 } } */ -/* { dg-final { scan-assembler-times {addi\tsp,sp,-2048} 1 } } */ -/* { dg-final { scan-assembler-times {li\t[a-x0-9]+,-4096\s+add\tsp,sp,[a-x0-9]+} 1 } } */ +/* { dg-final { scan-assembler-times {addi\tsp,sp,-2048} 3 } } */ +/* { dg-final { scan-assembler-times {addi\tsp,sp,2032} 1 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-5.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-5.c index 150135a91103..0c8dccc518e3 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-5.c +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-5.c @@ -120,5 +120,5 @@ spill_11 (_Float16 *in, _Float16 *out) /* { dg-final { scan-assembler-times {addi\tsp,sp,-256} 1 } } */ /* { dg-final { scan-assembler-times {addi\tsp,sp,-512} 1 } } */ /* { dg-final { scan-assembler-times {addi\tsp,sp,-1024} 1 } } */ -/* { dg-final { scan-assembler-times {addi\tsp,sp,-2048} 1 } } */ -/* { dg-final { scan-assembler-times {li\t[a-x0-9]+,-4096\s+add\tsp,sp,[a-x0-9]+} 1 } } */ +/* { dg-final { scan-assembler-times {addi\tsp,sp,-2048} 3 } } */ +/* { dg-final { scan-assembler-times {addi\tsp,sp,2032} 1 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-6.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-6.c index c5d2d0194348..8bf53b84d1cd 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-6.c +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-6.c @@ -111,5 +111,5 @@ spill_10 (float *in, float *out) /* { dg-final { scan-assembler-times {addi\tsp,sp,-256} 1 } } */ /* { dg-final { scan-assembler-times {addi\tsp,sp,-512} 1 } } */ /* { dg-final { scan-assembler-times {addi\tsp,sp,-1024} 1 } } */ -/* { dg-final { scan-assembler-times {addi\tsp,sp,-2048} 1 } } */ -/* { dg-final { scan-assembler-times {li\t[a-x0-9]+,-4096\s+add\tsp,sp,[a-x0-9]+} 1 } } */ +/* { dg-final { scan-assembler-times {addi\tsp,sp,-2048} 3 } } */ +/* { dg-final { scan-assembler-times {addi\tsp,sp,2032} 1 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-7.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-7.c index 70ca683908db..e3980a295406 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-7.c +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/spill-7.c @@ -102,5 +102,5 @@ spill_9 (int64_t *in, int64_t *out) /* { dg-final { scan-assembler-times {addi\tsp,sp,-256} 1 } } */ /* { dg-final { scan-assembler-times {addi\tsp,sp,-512} 1 } } */ /* { dg-final { scan-assembler-times {addi\tsp,sp,-1024} 1 } } */ -/* { dg-final { scan-assembler-times {addi\tsp,sp,-2048} 1 } } */ -/* { dg-final { scan-assembler-times {li\t[a-x0-9]+,-4096\s+add\tsp,sp,[a-x0-9]+} 1 } } */ +/* { dg-final { scan-assembler-times {addi\tsp,sp,-2048} 3 } } */ +/* { dg-final { scan-assembler-times {addi\tsp,sp,2032} 1 } } */ From patchwork Mon May 20 23:32:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vineet Gupta X-Patchwork-Id: 90500 X-Patchwork-Delegate: jlaw@ventanamicro.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3772C3858C32 for ; Mon, 20 May 2024 23:33:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by sourceware.org (Postfix) with ESMTPS id E387E3858D28 for ; Mon, 20 May 2024 23:32:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E387E3858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E387E3858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716247971; cv=none; b=VsPLldpJXkTf41KeF+chLdDK8o2FQDnbl9/xcsa+yet5Vaea2soRivyK05s/h7ZSWFIoNgvOl8O6y3Zf2j6N4d2d3fhMnFk5QyILNWKxMzHfGqxMbsgtwsNCjxTpzl7ipa8B3eHsXzFS9Xv2jnsva4ImhstIVagP1WpEdTlsYGA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716247971; c=relaxed/simple; bh=00NMJLjxkD0nUaSYoQi7UM71MkvXaasNWlu8mFRJGeg=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=IAJxcFVQZhgzjWy646n2YgVcwYZC96uPF/2TSmp9vAD/Z+QgV9EZcn/ofk3lrdVLV0eXxDYYNRmNk3/KIs9Ds38fr9YAIj3De39ZFMiIiilbpB7tfou6uv78wyyKaDLtr9tdyl1eEqfVbV3VrAbQTWGPkOjcupCYQgqquR0RUK0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1f0537e39b3so88359835ad.3 for ; Mon, 20 May 2024 16:32:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1716247967; x=1716852767; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fUIoaqsv1aaMw5eHLWIK5N8/AFHRusxP91Vx+X85yu0=; b=Sz9n4QRe0t1pIKG1o3rW0tjmCfDjp0Qmj3+KdSO9rGcgjbxjYVLRXqJiDsNvEoYgSi z9YEYrBRGLTEmGKFLAzfr4V3CI6XFYf0+0GOLCafYIiCuFkRJI6FyaIP/gPojc8PwsAR /TWZzUcVK250KAYjVr97r0zkNl9OwjcB1Bvop1NP4r2rdaWG7zXBh6PHBhfWUZzZETvb fnEXs29B4y4hqbgglt3lwSpbZHeuwRj4EsPsIL5OVMD9Jx+vsuSRMqolsO/DFfVNfeG1 OxeuQpovthLYLdKwMn483MNbeSLr+BfiWY35CfFjUxOl6uLl6bTP3ra42wt9K/uSQGpa X4wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716247967; x=1716852767; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fUIoaqsv1aaMw5eHLWIK5N8/AFHRusxP91Vx+X85yu0=; b=ULoLmn/91zSzy4us887nOACHQIK5EK0umkczhD1QVW1kRsBDeNvXRL4rvnUMwHXIgI tup+eyG8bADPbDl83afRqyeg6cskXvCkvw/5fAlZJ1vWJjeGfmEsMk45W5EIUfN0W5PX 1qegl3ghSFBlt/YjRWGlUhu/fl1P0yb50/kInV2VpVjlim7Xdi5w56nECt4ga0d5jAQY IUEQbNJVwiriprEXt7n/uDyxTE2wIPt6BHc+seRm+I6pBmptTanooCxcvaC+nAyRb8XH Dw32jBwDQAGfdWHf7G6v2v1KI+XPxqF52ARimPUa+Urij+J1NgDO3lff7FR5LSb2Ztx+ jY4Q== X-Gm-Message-State: AOJu0Yy7riSfwXOY8xmTPq2+X/pOdmLCwdGk+a983J+DkoeJR3YD5qYc 7+g7VdKfAxyNj9W7mMaKMhA/dhqi0nSGIuSprGZeM93GPqLA10JiJUi54QqHD4WsKZ2TnA4KnO1 oAfA= X-Google-Smtp-Source: AGHT+IHpKwsFa3Joqm1O5JgGVcAYAEEAqpt0FzC994YTp7nQxAN/ENcoiX8UQu3wQ8mxPg7k2KZvbw== X-Received: by 2002:a17:90b:386:b0:2ae:c590:b06f with SMTP id 98e67ed59e1d1-2b6cc758fc1mr25433600a91.18.1716247967631; Mon, 20 May 2024 16:32:47 -0700 (PDT) Received: from vineet-framework.hq.rivosinc.com ([50.145.13.30]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b628966cdesm22524912a91.34.2024.05.20.16.32.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 16:32:47 -0700 (PDT) From: Vineet Gupta To: gcc-patches@gcc.gnu.org Cc: Jeff Law , kito.cheng@gmail.com, Palmer Dabbelt , gnu-toolchain@rivosinc.com, Vineet Gupta Subject: [PATCH v3 2/2] RISC-V: avoid LUI based const mat in alloca epilogue expansion Date: Mon, 20 May 2024 16:32:37 -0700 Message-Id: <20240520233237.109269-2-vineetg@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240520233237.109269-1-vineetg@rivosinc.com> References: <20240520233237.109269-1-vineetg@rivosinc.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org This is testsuite clean however there's a dwarf quirk which I want to run by the experts. The test that was tripping CI has following fragment: Before patch | After Patch ------------------------------------------------------ li t0,-4096 | addi sp,s0,-2048 addi t0,t0,560 | .cfi_def_cfa 2, 2048 <- #1 add sp,s0,t0 | addi sp,sp,-1488 .cfi_def_cfa 2, 3536 | .cfi_def_cfa_offset 3536 <- #2 addi sp,sp,1504 | addi sp,sp,1504 .cfi_def_cfa_offset 2032 | .cfi_def_cfa_offset 2032 <- #3 The dwarf insn #1 and #3 seem ok, however #2 seems dubious to me. --- This is continuing on the prev patch in function epilogue expansion. gcc/ChangeLog: * config/riscv/riscv.cc (riscv_expand_epilogue): Handle offset being sum of two S12. Signed-off-by: Vineet Gupta --- gcc/config/riscv/riscv.cc | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 2ecbcf1d0af8..85df5b7ab498 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -8111,7 +8111,10 @@ riscv_expand_epilogue (int style) need_barrier_p = false; poly_int64 adjust_offset = -frame->hard_frame_pointer_offset; + rtx dwarf_adj = gen_int_mode (adjust_offset, Pmode); rtx adjust = NULL_RTX; + bool sum_of_two_s12 = false; + HOST_WIDE_INT one, two; if (!adjust_offset.is_constant ()) { @@ -8123,14 +8126,23 @@ riscv_expand_epilogue (int style) } else { - if (!SMALL_OPERAND (adjust_offset.to_constant ())) + HOST_WIDE_INT adj_off_value = adjust_offset.to_constant (); + if (SMALL_OPERAND (adj_off_value)) + { + adjust = GEN_INT (adj_off_value); + } + else if (SUM_OF_TWO_S12_ALGN (adj_off_value)) + { + riscv_split_sum_of_two_s12 (adj_off_value, &one, &two); + dwarf_adj = adjust = GEN_INT (one); + sum_of_two_s12 = true; + } + else { riscv_emit_move (RISCV_PROLOGUE_TEMP (Pmode), - GEN_INT (adjust_offset.to_constant ())); + GEN_INT (adj_off_value)); adjust = RISCV_PROLOGUE_TEMP (Pmode); } - else - adjust = GEN_INT (adjust_offset.to_constant ()); } insn = emit_insn ( @@ -8138,14 +8150,21 @@ riscv_expand_epilogue (int style) adjust)); rtx dwarf = NULL_RTX; - rtx cfa_adjust_value = gen_rtx_PLUS ( - Pmode, hard_frame_pointer_rtx, - gen_int_mode (-frame->hard_frame_pointer_offset, Pmode)); + rtx cfa_adjust_value = gen_rtx_PLUS (Pmode, hard_frame_pointer_rtx, + dwarf_adj); rtx cfa_adjust_rtx = gen_rtx_SET (stack_pointer_rtx, cfa_adjust_value); dwarf = alloc_reg_note (REG_CFA_ADJUST_CFA, cfa_adjust_rtx, dwarf); + RTX_FRAME_RELATED_P (insn) = 1; REG_NOTES (insn) = dwarf; + + if (sum_of_two_s12) + { + insn = emit_insn (gen_add3_insn (stack_pointer_rtx, stack_pointer_rtx, + GEN_INT (two))); + RTX_FRAME_RELATED_P (insn) = 1; + } } if (use_restore_libcall || use_multi_pop)