https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109601
Bug ID: 109601 Summary: Useless branch not eliminated when writing to a union Product: gcc Version: 12.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: 67 at mniip dot com Target Milestone: --- Created attachment 54909 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54909&action=edit Minimal testcase On x86_64-pc-linux-gnu the attached code compiles (with -O3) to rather unsatisfying assembly with a branch that does the same thing whether taken or not: > 10: 85 c0 test %eax,%eax > 12: 74 04 je 18 > 14: c3 ret > 15: 0f 1f 00 nopl (%rax) > 18: c3 ret I've tested on my machine in GCC 12.2.1, but Compiler Explorer ( https://godbolt.org/z/cW69rfrPc ) shows the same thing happens in a lot of other versions, including trunk (6ab856aa49bef7c04efa6144a5048e129b3a058b). Notably, this doesn't happen in GCC 4.5.3. This seems to happen for a few other targets as well, e.g: arm, riscv32; but not on some others, e.g. aarch64, mips.