https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121183
Bug ID: 121183 Summary: extra sign extend in some cases Product: gcc Version: 14.2.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: ``` long long f(long long l){ if(l>1000) return l; if(l<-1000) return l; int t = l; return t + 2; } long long f1(long long l){ if(l>1000) return l; if(l<-1000) return l; long long t = l; return t + 2; } ``` GCC knows that l is [-1000,1000] when there is a cast to int and then there is an addition to 2 since that does not cause an overflow the addition could be done in long long instead. So basically f and f1 should produce the same code. This could in theory happen with induction variables but I have not seen this in real code yet.