public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "jiangning.liu at amperecomputing dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/109343] New: invalid if conversion optimization for aarch64 Date: Thu, 30 Mar 2023 07:14:28 +0000 [thread overview] Message-ID: <bug-109343-4@http.gcc.gnu.org/bugzilla/> (raw) 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
next reply other threads:[~2023-03-30 7:14 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-03-30 7:14 jiangning.liu at amperecomputing dot com [this message] 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
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=bug-109343-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.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: linkBe 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 read-only IMAP folder(s) and NNTP newsgroup(s).