public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/114595] New: rtl-expand emit redundant store for bitwise-and expression
@ 2024-04-04 23:33 absoler at smail dot nju.edu.cn
  2024-04-04 23:35 ` [Bug target/114595] " absoler at smail dot nju.edu.cn
  2024-04-05  2:49 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: absoler at smail dot nju.edu.cn @ 2024-04-04 23:33 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114595
           Summary: rtl-expand emit redundant store for bitwise-and
                    expression
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: absoler at smail dot nju.edu.cn
  Target Milestone: ---

Hi, here's a weird case:
```
int g1, g3;
char g2;
void func_1() {
    g3 = (g2 = (1 && 1 & g1)) ;
}

```
one store to `g2` is splted into two since gcc-5 under -O2:
```
func_1():
  401130:       mov    0x2efe(%rip),%eax        # 404034 <g1>
  401136:       mov    %al,0x2ef0(%rip)        # 40402c <g2>
  40113c:       and    $0x1,%eax
  40113f:       andb   $0x1,0x2ee6(%rip)        # 40402c <g2>
  401146:       mov    %eax,0x2ee4(%rip)        # 404030 <g3>
```

RTL-expand choose to do this and no other pass could optimize it.

```
;;
;; Full RTL generated for this function:
;;
    1: NOTE_INSN_DELETED
    3: NOTE_INSN_BASIC_BLOCK 2
    2: NOTE_INSN_FUNCTION_BEG
    5: r82:SI=[`g1']
    6: [`g2']=r82:SI#0
    7: {[`g2']=[`g2']&0x1;clobber flags:CC;}
    8: {r86:SI=r82:SI&0x1;clobber flags:CC;}
    9: [`g3']=r86:SI
```

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug target/114595] rtl-expand emit redundant store for bitwise-and expression
  2024-04-04 23:33 [Bug rtl-optimization/114595] New: rtl-expand emit redundant store for bitwise-and expression absoler at smail dot nju.edu.cn
@ 2024-04-04 23:35 ` absoler at smail dot nju.edu.cn
  2024-04-05  2:49 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: absoler at smail dot nju.edu.cn @ 2024-04-04 23:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from absoler at smail dot nju.edu.cn ---
gcc-4's result:
```
func_1():
        movl    g1(%rip), %eax
        andl    $1, %eax
        movb    %al, g2(%rip)
        movl    %eax, g3(%rip)
        ret
```

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug target/114595] rtl-expand emit redundant store for bitwise-and expression
  2024-04-04 23:33 [Bug rtl-optimization/114595] New: rtl-expand emit redundant store for bitwise-and expression absoler at smail dot nju.edu.cn
  2024-04-04 23:35 ` [Bug target/114595] " absoler at smail dot nju.edu.cn
@ 2024-04-05  2:49 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-05  2:49 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
   Target Milestone|---                         |14.0
         Resolution|---                         |FIXED

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Already fixed on the trunk. Most likely by r14-6420-g85c5efcffed19c .

We get now:
```
func_1:
        movzbl  g1(%rip), %eax
        andl    $1, %eax
        movb    %al, g2(%rip)
        movsbl  %al, %eax
        movl    %eax, g3(%rip)
```

There is a small extra zero extend but the extra load/store is gone

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-05  2:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-04 23:33 [Bug rtl-optimization/114595] New: rtl-expand emit redundant store for bitwise-and expression absoler at smail dot nju.edu.cn
2024-04-04 23:35 ` [Bug target/114595] " absoler at smail dot nju.edu.cn
2024-04-05  2:49 ` pinskia at gcc dot gnu.org

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 read-only IMAP folder(s) and NNTP newsgroup(s).