https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86554
Bug ID: 86554 Summary: Incorrect code generation with signed/unsigned comparison Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: anton at samba dot org Target Milestone: --- The test case below fails on both ppc64le and x86_64 when built with -O2, I see: ret is 1017 ret is < 1 Looking at the code, the < 1 comparison is removed completely. -- #include <stdio.h> #include <stdint.h> struct foo { uint32_t x; }; typedef struct foo foo; static inline int zot(foo *f) { int ret; if (f->x > 0x7FFFFFFF) ret = (int)(f->x - 0x7FFFFFFF); else ret = (int)f->x - 0x7FFFFFFF; return ret; } void bar(foo *f) { int ret = zot(f); printf("ret is %d\n", ret); if (ret < 1) printf("ret is < 1\n"); } int main(void) { foo f; f.x = 0x800003f8; bar(&f); }