Issue 55464
Summary Missed optimization - suspect escape analysis
Labels new issue
Assignees
Reporter OfekShilon
    [godbolt link](https://godbolt.org/z/fM5W96YjG)

In the following toy code:
```cpp
struct Arr { double* data; };

struct Scalar {
    Scalar();
    double val;
};

void func( const Arr* __restrict__ input, Arr* __restrict__ result ) {
    const double* b = input->data;

    Scalar sc;
    for(int j = 0; j < 2; ++j ) {
        sc.val += b[j];
        result->data[j] += sc.val;
    }
}
```
An optimization remark is visible in the line ` sc1.val += b[j];`, reading: 

> Load of type double not eliminated because it is clobbered by call

The only suspected clobbering call (the only call for that matter) is the `Scalar` ctor. Indeed, adding a visible implementation like `Scalar() : val(0) {}` produces much better code.  The godbolt link demonstrates both.

Not sure what the compiler is guarding against - it seems no address can escape through a ctor (or any) call with no arguments. The same remark is shown for a ctor taking an argument by value, and is equally surprising.


_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to