Github messages for voidlinux
 help / color / mirror / Atom feed
From: riddicc <riddicc@users.noreply.github.com>
To: ml@inbox.vuxu.org
Subject: [ISSUE] [cross-arm-none-eabi-gcc] /  suboptimal optimization: superfluous stack write
Date: Thu, 26 Oct 2023 08:18:12 +0200	[thread overview]
Message-ID: <gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-46899@inbox.vuxu.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 2398 bytes --]

New issue by riddicc on void-packages repository

https://github.com/void-linux/void-packages/issues/46899

Description:
### Is this a new report?

Yes

### System Info

Void 6.5.5_2 x86_64 GenuineIntel uptodate hold rrrmFFF

### Package(s) Affected

cross-arm-none-eabi-gcc-9.3.0_1

### Does a report exist for this bug with the project's home (upstream) and/or another distro?

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111582

somehow my related issue #46239 gets no attention... dunno why... am i doing something wrong?

### Expected behaviour

the code should be easier/faster to execute...
there are possibly much more issues, that could be fixed in the current version 13.2.0 of gcc...

### Actual behaviour

it adds instructions like this:
```
sub     sp, sp, #16
mov     r2, sp
add     sp, sp, #16
```
without ever using something on the stack...

### Steps to reproduce

1. install cross-arm-none-eabi-gcc
2. compile source code containing bitfield operations [[1]]
3. u will get [2]

[[1]]: source:
```
# 1 "a.c"
# 1 "/tmp//"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "a.c"

typedef unsigned char u8;
typedef unsigned int u32;
extern int fatal();
__attribute__((always_inline)) inline u32 lsb(const u8 l) { return (1U<<l)-1U; }

typedef struct { u32 a; u32 msk; u32 v; u8 rs:1; u8 aw:7; } Reg;
__attribute__((always_inline)) inline Reg GI(u32 A, u32 N, u32 RS, u8 AW) { Reg R={A+4*N,lsb(32),0,RS?1:0,AW}; return R; }
__attribute__((always_inline)) inline u32 GS(Reg R) {
   for (u32 i=0, msk=lsb(8); R.aw==1 && msk; i++, msk<<=8)
      if ( !~(R.msk | msk) ) {
         const u8 v = R.v >> (i*8);
         if (R.rs || msk==~R.msk) return (((volatile u8*)R.a)[i] = v) << (i*8);
         else if (R.v==~R.msk) return (((volatile u8*)R.a)[i] |= v) << (i*8);
         return (((volatile u8*)R.a)[i] = (((volatile u8*)R.a)[i] & (R.msk>>(i*8))) | v) << (i*8);
      }
 return 0;
}
__attribute__((always_inline)) inline Reg GU(Reg R, u32 A, u32 N, u8 o, u8 w, u32 v) {
   const u32 msk=~(lsb(w)<<o); R.msk&=msk; R.v&=msk;
   R.v |= (v<<o);
   return R;
}
u32 artiSP() { return GS(GU(GI(0xE0000000,42,0,1),0xE0000000,42,17,3,2)); }
```
[2]: resulting assembly code:
```
artiSP:
        sub     sp, sp, #16
        mov     r2, sp
        movs    r3, #2
        strb    r3, [r2, #12]
...
        add     sp, sp, #16
        bx      lr
```

             reply	other threads:[~2023-10-26  6:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-26  6:18 riddicc [this message]
2023-10-26 10:48 ` ahesford
2023-10-26 10:48 ` [ISSUE] [CLOSED] " ahesford
2023-10-26 15:27 ` riddicc
2023-10-26 15:28 ` riddicc
2023-10-26 15:30 ` ahesford

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-46899@inbox.vuxu.org \
    --to=riddicc@users.noreply.github.com \
    --cc=ml@inbox.vuxu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).