public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "wilson at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/97747] New: missed combine opt with logical ops after zero extended load Date: Fri, 06 Nov 2020 21:07:21 +0000 [thread overview] Message-ID: <bug-97747-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97747 Bug ID: 97747 Summary: missed combine opt with logical ops after zero extended load Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: wilson at gcc dot gnu.org Target Milestone: --- Consider this testcase struct { unsigned int a : 1; unsigned int b : 1; unsigned int c : 1; unsigned int d : 1; unsigned int pad1 : 28; } s; void sub (void) { s.a = 1; s.c = 1; } Compiling with -O2 -S for ARM I get sub: @ args = 0, pretend = 0, frame = 0 @ frame_needed = 0, uses_anonymous_args = 0 @ link register save eliminated. movw r2, #:lower16:.LANCHOR0 movt r2, #:upper16:.LANCHOR0 ldrb r3, [r2] @ zero_extendqisi2 bic r3, r3, #5 orr r3, r3, #5 strb r3, [r2] bx lr The bic bit-clear instruction is obviously unnecessary. In the combine dump file I see that we have (insn 9 7 11 2 (set (reg:SI 120) (and:SI (reg:SI 119 [ MEM <unsigned char> [(struct *)&sD.5619] ]) (const_int -6 [0xfffffffffffffffa]))) "tmp.c":13:7 90 {*arm_andsi3_insn} (expr_list:REG_DEAD (reg:SI 119 [ MEM <unsigned char> [(struct *)&sD.5619] ]) (nil))) (insn 11 9 13 2 (set (reg:SI 122) (ior:SI (reg:SI 120) (const_int 5 [0x5]))) "tmp.c":13:7 106 {*iorsi3_insn} (expr_list:REG_DEAD (reg:SI 120) (nil))) And the combiner does: Trying 9 -> 11: 9: r120:SI=r119:SI&0xfffffffffffffffa REG_DEAD r119:SI 11: r122:SI=r120:SI|0x5 REG_DEAD r120:SI Failed to match this instruction: (set (reg:SI 122) (ior:SI (and:SI (reg:SI 119 [ MEM <unsigned char> [(struct *)&sD.5619] ]) (const_int 250 [0xfa])) (const_int 5 [0x5]))) The problem here is that the ARM port generated a zero_extend for the load byte, so combine knows that r120 has only 8 nonzero bits, it modified the -6 to 250 and then fails to notice that the and operation can be folded away because in SImode the operation is no longer redundant with the modified constant. On targets that do not generate the zero_extend, the and -6 operation gets optimized away in combine. For instance, with the current RISC-V port I get sub: lui a4,%hi(s) lbu a5,%lo(s)(a4) ori a5,a5,5 sb a5,%lo(s)(a4) ret This likely fails on any target where movqi generates a zero extended load.
next reply other threads:[~2020-11-06 21:07 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-11-06 21:07 wilson at gcc dot gnu.org [this message] 2022-02-04 21:17 ` [Bug tree-optimization/97747] [9/10/11/12 Regression] " pinskia at gcc dot gnu.org 2022-02-04 21:18 ` pinskia at gcc dot gnu.org 2022-10-19 9:23 ` [Bug tree-optimization/97747] [10/11/12/13 " rguenth at gcc dot gnu.org 2023-04-26 6:55 ` [Bug tree-optimization/97747] [10/11/12/13/14 " rguenth at gcc dot gnu.org 2023-07-27 9:22 ` [Bug tree-optimization/97747] [11/12/13/14 " rguenth at gcc dot gnu.org 2024-05-21 9:10 ` [Bug tree-optimization/97747] [11/12/13/14/15 " jakub 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-97747-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).