https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115240
Bug ID: 115240 Summary: [alias] Does we assume the math function have pure attribute ? Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: zhongyunde at huawei dot com Target Milestone: --- * test: https://gcc.godbolt.org/z/5YbezdW89 ``` float foo (float num[], float r2inv, int n) { float sum = 0.0; for (int i=0; i < 1000; i++) { float a = num[i]; // const float r = a / std::sqrt (r2inv); const float expm2 = std::exp (a); float tmp = expm2 * num[i]; sum += tmp * tmp; } return sum; } ``` * gcc's assemble reuse the num[i], so it assume the function math function expf doesn't clobber the num[i], does we assume the function expf have the pure atrribute ? ``` .L2: ldr s15, [x19], 4 fmov s0, s15 ; backup the num[i], and reuse it after the call expf bl expf fmul s15, s15, s0 fmadd s14, s15, s15, s14 cmp x19, x20 bne .L2 ```