From patchwork Thu Feb 29 17:45:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georg-Johann Lay X-Patchwork-Id: 208449 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp568763dyb; Thu, 29 Feb 2024 09:46:38 -0800 (PST) X-Forwarded-Encrypted: i=4; AJvYcCXIb4mtoeI5Tp+wGaxULG+o/paVIoJ+uaF/BfvgQZgLCYbgmkcfkyPQ4R60UaqFvqxwfpJWJ4IjCXerqIrUbKudiYXyrw== X-Google-Smtp-Source: AGHT+IFE1zO88D8Q6sMjKBXhqHnjXSxJF9n6Rjjx84oNGBO6qz+Mfj6osPsDJuGOvQzY3RcFsuCr X-Received: by 2002:a05:620a:5605:b0:787:d4b1:92da with SMTP id vu5-20020a05620a560500b00787d4b192damr3187595qkn.34.1709228798379; Thu, 29 Feb 2024 09:46:38 -0800 (PST) ARC-Seal: i=3; a=rsa-sha256; t=1709228798; cv=pass; d=google.com; s=arc-20160816; b=xTd9ErzKiedwR124ob8WnrMG3dWPCqhmhm5YPKOVCmnA9pjtgMmkEoEvzh4maGUBFB A1dv2dkwG6UZb6BVm8mbdx+mZQ7Lv2IBXb8N9OaTahrVPSt/LZwa+zg/5UYxVTsYHwtG E6dnk66aueBViQ+uryk9A4yDHqwNXSqcc8uJ3xLC7IWbTV8DG8gSX+6zmxgYVtfT+jU3 lFBFg9FLxlkf53bUqObMJfJ4H/QP6BnhTAfcxQ8h4ohKQgWYLG9jM46R/tIezxtW5K0a Z9MgVyli1RLH7z8gxff2vH/9zS+m0li02y/IQd0qJQJHc/v26tdtTrb8nWfF/owimqZE GsTA== ARC-Message-Signature: i=3; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :subject:to:from:content-language:user-agent:mime-version:date :message-id:dkim-signature:dkim-signature:arc-filter:dmarc-filter :delivered-to; bh=R98RTYoi3BhVQKo4d/TZTxXxV2uNVnSE1LVmHvS5Y+E=; fh=XNn3asQvIblazGK92GBt13dVv+YmGV3pBS0JC29ZQco=; b=xNTtDohj4Wpw7E3Yo86ZG0uslLI+mE3OQC4Qw0BPwOMw8+NGm6rMxFxvspUd5I7MEW Vu0QWq1E1UzqOtZEreXIVi2nbp9ToIawMSmTmleZ8CWG4R9NjGTAM+b8Guu4BrMV15Hr 2GSAEjc4tl9fozWPJUTaij7ONjQso19ybRcH3Wu8fxB64A+HOU87Twk813/Jk236rJHp 3MP1L+Nu6sFxpDXmnO8hBHqjxAWTLBxUZcGteZ6acHZ+nIe0YMj5WI+0Ssll6yKAPd3i ha0XrWzA5iDeLapjBRDqlKxKeipqCpPVM1PQ0+puC5M+mmzwwTbVw3CqL1D3KEhy9dMM qc0A==; dara=google.com ARC-Authentication-Results: i=3; mx.google.com; dkim=pass header.i=@gjlay.de header.s=strato-dkim-0002 header.b="tRRwr/z5"; dkim=neutral (no key) header.i=@gjlay.de header.s=strato-dkim-0003; arc=pass (i=2); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id wa26-20020a05620a4d1a00b007877956ddcbsi1770249qkn.430.2024.02.29.09.46.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 09:46:38 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gjlay.de header.s=strato-dkim-0002 header.b="tRRwr/z5"; dkim=neutral (no key) header.i=@gjlay.de header.s=strato-dkim-0003; arc=pass (i=2); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1644F3858408 for ; Thu, 29 Feb 2024 17:46:38 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [85.215.255.22]) by sourceware.org (Postfix) with ESMTPS id 983533858414 for ; Thu, 29 Feb 2024 17:45:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 983533858414 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gjlay.de Authentication-Results: sourceware.org; spf=none smtp.mailfrom=gjlay.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 983533858414 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=85.215.255.22 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1709228749; cv=pass; b=pnjo+P1PUsGiPRa0NPfmvqkK1oAM6Qae5H+OgXnwrXjKIAhSz1q4NFZFcsDtsmAwe0dmMt6ZTgNTq3h6Jz0NMV37iyB5zHpqw5k2SXvUf6H5c8f1gwyXhQkM2BO5EnQYJAZxyNfpnA7BiLahqmYusIWOnSWAwmNQ1isexjQIyWY= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1709228749; c=relaxed/simple; bh=75MDCv54x00uXbMCm4tRSwxMixEelDU8yD7kQ/nL+DU=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:MIME-Version:From: To:Subject; b=q8CPqXaKmGRokzbQ3cYkgDK53JMsAEwkCZ8dFZZf5ok+OOdU9aXyXqKiuFCHilFfA7ZQO6+ll2pVNAcresIGTC8Eft0OWu8o+xutK6BE+JBc4KnmUW/IuJ6Dn8zlB15k3qNCPk7kw4GLDid58AgYZz8VdUYOA7i43CYYaKag+Bo= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; t=1709228746; cv=none; d=strato.com; s=strato-dkim-0002; b=aH7l76t/LSrf/LhdrtX0OY95HClKLROeEEN3zqbsUJD3VCY0UNRW7JVsNA6z+3Gcxg U0XCaazoe+C5Fra1+TndmQK9Up2IycBD42mMv0jw5v40+eYAD8ljRfGVFTvV+1q8jPfv 0oDkd6PqXiSGXwYdx3fGrBUNBrmYvwpSXYaMbOZFSQXYDP81B1NSIqyJoK0m8wpxOUlc lIMd8CWBh/Vz7RP7fvhvwDILHPNrMoQa73K7kt+JeG7yfqckgkLkN/8sWLPYw19c1z3Y Kxpv30IRBUCxfFLoEUuBXEv0vv5dEXgIYjjXez7hkKpv/2e2IyfTLRQDQc0Gm7jnSz8j XQJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1709228746; s=strato-dkim-0002; d=strato.com; h=Subject:To:From:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=R98RTYoi3BhVQKo4d/TZTxXxV2uNVnSE1LVmHvS5Y+E=; b=MXalj7NEWndwgfdlAptqx/bKszVAEeAEypn+RpZ0SAHsOH9OwI2tIu3COK0mhu1yRP 1+DFQjcuZFoFTSrrgcm7EwtJdAY3M6/BTrz7vDacnKX1BVsUEvp6LsLg9rqvsG0YRhJf hdIARPWSBTn03lShrxJRttf9JcF7Oxhtcg+k6aNIY7XjWXUyr4ZjfQrfJqzPoS0xnej9 rzjrRFPGnaw4/4OF4TGDnmAeT3Ijnj4dw+wes8ckz9lskhYqaYDz5wpbvHuCzjxOVOtU DSMwnYCjwGpLGWFA0FWSNGfIsWVCsxcDuiTNdBTaZxbAPslMXriL4CcrI2mTuuypbZLD Dt9A== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1709228746; s=strato-dkim-0002; d=gjlay.de; h=Subject:To:From:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=R98RTYoi3BhVQKo4d/TZTxXxV2uNVnSE1LVmHvS5Y+E=; b=tRRwr/z5fz/jA6Pr7f+P+u62BdAtYdwnwBUf7CYwdhAZC2zputmOhaEPj9vjpyKpuL poRYK96Wu1eTVz7myfADqYMiVgBJ2xql+EiM7VcVh7VvhWgw+cDx6Yf6Kct+2dFaVqfS TRuGrYrY/d4t5zRNhkv+cFQMmRtPXjQn00FRO+Sq9GEgbZ2zUism4wRgBJD667yYrsX4 3PeJ8OGSCTFVETAHJoV7RcwXMP6RzY3WBEUJW7I7TuZKRpAKyhP1SVTXTtJva0bFwDTS AWBXnRGzKsHCySGwPXk6Tl0OeX2KimLd4v2GT5pNjHYehsB9T3JlywC8miTIWo8AMuNr 8zkg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1709228746; s=strato-dkim-0003; d=gjlay.de; h=Subject:To:From:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=R98RTYoi3BhVQKo4d/TZTxXxV2uNVnSE1LVmHvS5Y+E=; b=I+3cn+rTsNjFWZO2UbNAbJK2bETVHwxx4uzQycxU2aC+VNLLUs51m4hLvZRsV7bNUJ gnTa4gFPAZH+olKpkUDw== X-RZG-AUTH: ":LXoWVUeid/7A29J/hMvvT3koxZnKT7Qq0xotTetVnKkSgcSjpmy9KwoMJ/K0VA==" Received: from [192.168.2.102] by smtp.strato.de (RZmta 50.2.0 DYNA|AUTH) with ESMTPSA id d8d71d01THjj0V0 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate) for ; Thu, 29 Feb 2024 18:45:45 +0100 (CET) Message-ID: <48d68127-9fe7-4d37-8274-32a753636033@gjlay.de> Date: Thu, 29 Feb 2024 18:45:45 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US From: Georg-Johann Lay To: "gcc-patches@gcc.gnu.org" Subject: [patch,avr,applied] PR target/114132: Sets up a frame without need X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_NONE, 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 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792256296397584020 X-GMAIL-MSGID: 1792256296397584020 The condition when a frame pointer is required because arguments are passe on the stack was not exact, and there were situations when a frame was set up without a need for it. Johann --- AVR: target/114132 - Code sets up a frame pointer without need. The condition CUMULATIVE_ARGS.nregs == 0 in avr_frame_pointer_required_p() means that no more argument registers are left, but that's not the same condition that tells whether an argument pointer is required. PR target/114132 gcc/ * config/avr/avr.h (CUMULATIVE_ARGS) : New field. * config/avr/avr.cc (avr_init_cumulative_args): Initialize it. (avr_function_arg): Set it. (avr_frame_pointer_required_p): Use it instead of .nregs. gcc/testsuite/ * gcc.target/avr/pr114132-1.c: New test. * gcc.target/avr/torture/pr114132-2.c: New test. AVR: target/114132 - Code sets up a frame pointer without need. The condition CUMULATIVE_ARGS.nregs == 0 in avr_frame_pointer_required_p() means that no more argument registers are left, but that's not the same condition that tells whether an argument pointer is required. PR target/114132 gcc/ * config/avr/avr.h (CUMULATIVE_ARGS) : New field. * config/avr/avr.cc (avr_init_cumulative_args): Initialize it. (avr_function_arg): Set it. (avr_frame_pointer_required_p): Use it instead of .nregs. gcc/testsuite/ * gcc.target/avr/pr114132-1.c: New test. * gcc.target/avr/torture/pr114132-2.c: New test. diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc index 655a8e89fdc..478463b237a 100644 --- a/gcc/config/avr/avr.cc +++ b/gcc/config/avr/avr.cc @@ -3565,6 +3565,7 @@ avr_init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype, rtx libname, { cum->nregs = AVR_TINY ? 6 : 18; cum->regno = FIRST_CUM_REG; + cum->has_stack_args = 0; if (!libname && stdarg_p (fntype)) cum->nregs = 0; @@ -3605,6 +3606,8 @@ avr_function_arg (cumulative_args_t cum_v, const function_arg_info &arg) if (cum->nregs && bytes <= cum->nregs) return gen_rtx_REG (arg.mode, cum->regno - bytes); + cum->has_stack_args = 1; + return NULL_RTX; } @@ -6014,6 +6017,8 @@ out_movhi_mr_r (rtx_insn *insn, rtx op[], int *plen) return ""; } + +/* Implement `TARGET_FRAME_POINTER_REQUIRED'. */ /* Return 1 if frame pointer for current function required. */ static bool @@ -6022,7 +6027,7 @@ avr_frame_pointer_required_p (void) return (cfun->calls_alloca || cfun->calls_setjmp || cfun->has_nonlocal_label - || crtl->args.info.nregs == 0 + || crtl->args.info.has_stack_args || get_frame_size () > 0); } diff --git a/gcc/config/avr/avr.h b/gcc/config/avr/avr.h index ff2738df78c..56211fa9cd0 100644 --- a/gcc/config/avr/avr.h +++ b/gcc/config/avr/avr.h @@ -333,6 +333,10 @@ typedef struct avr_args /* Next available register number */ int regno; + + /* Whether some of the arguments are passed on the stack, + and hence an arg pointer is needed. */ + int has_stack_args; } CUMULATIVE_ARGS; #define INIT_CUMULATIVE_ARGS(CUM, FNTYPE, LIBNAME, FNDECL, N_NAMED_ARGS) \ diff --git a/gcc/testsuite/gcc.target/avr/pr114132-1.c b/gcc/testsuite/gcc.target/avr/pr114132-1.c new file mode 100644 index 00000000000..209eca823bd --- /dev/null +++ b/gcc/testsuite/gcc.target/avr/pr114132-1.c @@ -0,0 +1,15 @@ +/* { dg-additional-options "-Os -std=c99" } */ + +#ifdef __AVR_TINY__ +int func (int a, int b, char c) +#else +int func (long long a, long long b, char c) +#endif +{ + (void) a; + (void) b; + + return c; +} + +/* { dg-final { scan-assembler-not "push r28" } } */ diff --git a/gcc/testsuite/gcc.target/avr/torture/pr114132-2.c b/gcc/testsuite/gcc.target/avr/torture/pr114132-2.c new file mode 100644 index 00000000000..c2bcbacec37 --- /dev/null +++ b/gcc/testsuite/gcc.target/avr/torture/pr114132-2.c @@ -0,0 +1,22 @@ +/* { dg-do run } */ +/* { dg-additional-options "-std=c99" } */ + +__attribute__((noinline,noclone)) +#ifdef __AVR_TINY__ +int func (int a, int b, char c) +#else +int func (long long a, long long b, char c) +#endif +{ + (void) a; + (void) b; + return 10 + c; +} + +int main (void) +{ + if (func (0, 0, 91) != 101) + __builtin_abort(); + return 0; +} +