https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70600
Bug ID: 70600 Summary: Missed tree optimization with multiple additions in different types. Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: bernds at gcc dot gnu.org Target Milestone: --- Target: x86_64-pc-linux-gnu The following is a testcase reduced from a Linux kernel file. Compile with -O2 on x86_64-linux. There are two additions, the first in type unsigned long, the second one after casting the first result to unsigned int. Together, they end up as a no-op, but this is not caught during tree optimization. The combiner finally manages to eliminate them, with the help of a note added by fwprop. (I was looking at whether we could eliminate the creation of REG_EQUAL notes from fwprop, and found only three cases out of a set of 4492 source files where they changed code generation; this was one of them.) int p (long mem_map, long page, unsigned int *p, unsigned int *frag) { unsigned int _83 = *p; long _142 = page - mem_map; long _143 = _142 / 56; unsigned long _144 = _143; unsigned long _145 = _144 << 12; unsigned long _146 = _145 + 0xc0000000; unsigned int _147 = _146; unsigned int _190 = _83 + 0x40000000; unsigned int _149 = _147 + _190; return _149; }