https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81357
--- Comment #11 from Wilco <wilco at gcc dot gnu.org> --- (In reply to Qing Zhao from comment #10) > the following is my conclusion on this bug based on previous discussion and > study, for this testing case: > > 1. due to the fact that "mov" and "uxtw" are the same instruction, the > assembly generated by -O1 and -O2 are exactly the same except > A. the order of the instructions (this is due to the instruction > scheduling applied in -O2). > B. the registers used in difference instructions. > > 2. I agree with Wilco's comments in comment 7: > "The compiler believes there are 2 distinct values so it uses 2 registers > irrespectively of the order" > > i.e, for the testing case: > > 1 unsigned long long d; > 2 unsigned int test1(unsigned int fParm) > 3 { > 4 d = fParm + 1; > 5 return fParm + 1; > 6 } > > at line 4 and 5, the result of fparm + 1 has two different usages: > * one is at line 4, convert to unsigned long long first, and then > assign > to the global d; > * the other is at line 5, directly return as the return result of the > routine. > > the compiler has to use 2 different registers for these two different > values. > > So, I think that the compiler does NOT do anything wrong for this testing > case. > the additional "mov" or "uxtw" instruction that is claimed in comment 1 > actually is necessary and should NOT be deleted. > > I think that this bug could be closed as not a bug. Well it is not wrong, just non-optimal. It is possible to use a single register here but it means teaching GCC that these values are identical, which is non-trivial as it likely affects various places in the mid-end (this issue is target-independent).