[Bug c/126753] New: GCC emitting useless AND instruction when setting a bool from processor flags
contact at ivanchev dot net via Gcc-bugs <[email protected]>
| Newsgroups | gmane.comp.gcc.bugs |
|---|---|
| Message-ID | <[email protected]/bugzilla/> |
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126753
Bug ID: 126753
Summary: GCC emitting useless AND instruction when setting a
bool from processor flags
Product: gcc
Version: 16.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: contact at ivanchev dot net
Target Milestone: ---
See this example https://godbolt.org/z/5nfr1vscn
I am compiling
#include <stdint.h>
#include <stdckdint.h>
#include <stdbool.h>
uint32_t func(uint32_t a, uint32_t b, bool *overflow) {
uint32_t res;
*overflow = ckd_add(&res, a, b);
return res;
}
with `-m32 -O2`.
GCC emits a useless AND after setting the boolean var from the CARRY flag:
setc BYTE PTR [edx]
and BYTE PTR [edx], 1
This seems to happen for all flags and I'm seeing it across a broad range of
cases.