https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90122
Bug ID: 90122 Summary: inequality of addresses of distinct objects not folded Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- In the test case below GCC folds the second test (as expected, on the assumption that distinct declarations refer to distinct objects) but fails to fold the first. Clang folds both (into false and true, respectively). GCC will only do that if a and b are static or local. Same with extern arrays of known size. $ cat x.c && gcc -O2 -S -Wall -Wextra -fdump-tree-optimized=/dev/stdout -fno-common x.c extern int a, b; void foo (); void bar (); void f (void) { if (&a == &b) foo (); int i = a; b = 0; if (i != a) bar (); } ;; Function f (f, funcdef_no=0, decl_uid=1910, cgraph_uid=1, symbol_order=2) Removing basic block 5 f () { <bb 2> [local count: 1073741824]: if (&a == &b) goto <bb 3>; [17.43%] else goto <bb 4>; [82.57%] <bb 3> [local count: 187153200]: foo (); <bb 4> [local count: 1073741824]: b = 0; return; }