public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/109343] New: invalid if conversion optimization for aarch64
@ 2023-03-30  7:14 jiangning.liu at amperecomputing dot com
  2023-03-30  7:28 ` [Bug rtl-optimization/109343] " rguenth at gcc dot gnu.org
  2023-03-30 12:45 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: jiangning.liu at amperecomputing dot com @ 2023-03-30  7:14 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109343
           Summary: invalid if conversion optimization for aarch64
           Product: gcc
           Version: rust/master
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jiangning.liu at amperecomputing dot com
  Target Milestone: ---

For this small case, if-conversion optimization in back-end generated csel
instruction for aarch64, which is unsafe. The address of variable sga_var could
be invalid if sga_mapped is false.

$ cat ttt2.c
extern int sga_mapped, sga_var;
int func(int j){
        int i=0;
        if(sga_mapped)
                i=i+sga_var;
        return i;
}
$ gcc -O3 -S ttt2.c
$ cat ttt2.s
        .arch armv8-a
        .file   "ttt2.c"
        .text
        .align  2
        .p2align 4,,11
        .global func
        .type   func, %function
func:
.LFB0:
        .cfi_startproc
        adrp    x0, sga_mapped
        adrp    x1, sga_var
        ldr     w0, [x0, #:lo12:sga_mapped]
        ldr     w1, [x1, #:lo12:sga_var]
        cmp     w0, 0
        csel    w0, w1, w0, ne
        ret
        .cfi_endproc
.LFE0:
        .size   func, .-func
        .ident  "GCC: (GNU) 12.2.1 20221121 (Red Hat 12.2.1-4)"
        .section        .note.GNU-stack,"",@progbits

For x86, the following code is generated. It is safe because the memory access
to sga_var(%rip) won't be really triggered if %eax is not set. Here x86 and
aarch64 are different.

$ cat ttt2.s
        .file   "ttt2.c"
        .text
        .p2align 4
        .globl  func
        .type   func, @function
func:
.LFB0:
        .cfi_startproc
        endbr64
        movl    sga_mapped(%rip), %eax
        testl   %eax, %eax
        cmovne  sga_var(%rip), %eax
        ret

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

* [Bug rtl-optimization/109343] invalid if conversion optimization for aarch64
  2023-03-30  7:14 [Bug rtl-optimization/109343] New: invalid if conversion optimization for aarch64 jiangning.liu at amperecomputing dot com
@ 2023-03-30  7:28 ` rguenth at gcc dot gnu.org
  2023-03-30 12:45 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-03-30  7:28 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
             Status|UNCONFIRMED                 |WAITING
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-03-30
             Target|                            |aarch64

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
How can sga_var be unmapped if you don't declare it 'weak'?

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

* [Bug rtl-optimization/109343] invalid if conversion optimization for aarch64
  2023-03-30  7:14 [Bug rtl-optimization/109343] New: invalid if conversion optimization for aarch64 jiangning.liu at amperecomputing dot com
  2023-03-30  7:28 ` [Bug rtl-optimization/109343] " rguenth at gcc dot gnu.org
@ 2023-03-30 12:45 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-03-30 12:45 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|---                         |INVALID

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
If we mark sga_var as weak then there is no ifcvt.


extern int sga_mapped;
extern int sga_var __attribute__((weak));
int func(int j){
        int i=0;
        if(sga_mapped)
                i=i+sga_var;
        return i;
}

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

end of thread, other threads:[~2023-03-30 12:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-30  7:14 [Bug rtl-optimization/109343] New: invalid if conversion optimization for aarch64 jiangning.liu at amperecomputing dot com
2023-03-30  7:28 ` [Bug rtl-optimization/109343] " rguenth at gcc dot gnu.org
2023-03-30 12:45 ` 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).