https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114511
Bug ID: 114511 Summary: [Regression] Missed optimization: x = -y; x = c + x + y; ==> x=c; Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: 652023330028 at smail dot nju.edu.cn Target Milestone: --- Hello, we noticed that y can be eliminated from the calculation of x in the following code. (x = c) https://godbolt.org/z/716814Eh5 int x, y; void func(int a, int b, int c, int d){ y = d / a + (-b + a); x = -y; x = c + x + y; } But GCC -O3 -fwrapv: <bb 2> [local count: 1073741824]: # DEBUG BEGIN_STMT _1 = d_7(D) / a_8(D); _2 = a_8(D) - b_9(D); _3 = _1 + _2; y = _3; # DEBUG BEGIN_STMT _18 = b_9(D) + c_12(D); _19 = _18 - a_8(D); # DEBUG BEGIN_STMT _20 = _3 + _19; _6 = _20 - _1; x = _6; return; Expected code: GCC-7.5 -O3 -fwrapv <bb 2> [100.00%]: _1 = d_7(D) / a_8(D); _2 = a_8(D) - b_9(D); _3 = _1 + _2; y = _3; x = c_12(D); return; Thank you very much for your time and effort! We look forward to hearing from you.