<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/57400>57400</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Any way to disable clang optimizing struct load?
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
xu-xionglong
</td>
</tr>
</table>
<pre>
```
struct A {
A(unsigned long pa, unsigned long pb) {a = pa; b = pb;}
unsigned long a;
unsigned long b;
};
A f(unsigned long a, unsigned long b) {
return A(a, b);
}
```
The above f function is compiled to the blow llvm bitcode
```
; Function Attrs: noinline optnone ssp uwtable
define [2 x i64] @_Z1fmm(i64 %0, i64 %1) #0 {
%3 = alloca %struct.A, align 8
%4 = alloca i64, align 8
%5 = alloca i64, align 8
store i64 %0, i64* %4, align 8
store i64 %1, i64* %5, align 8
%6 = load i64, i64* %4, align 8
%7 = load i64, i64* %5, align 8
%8 = call %struct.A* @_ZN1AC1Emm(%struct.A* %3, i64 %6, i64 %7)
%9 = bitcast %struct.A* %3 to [2 x i64]*
%10 = load [2 x i64], [2 x i64]* %9, align 8
ret [2 x i64] %10
}
```
I guess that clang optimize the struct to an array when returning it so it could be loaded faster. However, loading [2 x i64] seems not supported by llvm interpreter. [see this issue I opened](https://github.com/llvm/llvm-project/issues/57374).
When I try to add some other members to the struct making it not well-aligned, the bitcode function no longer return an array type from the function. So I wonder if there is some ways to force disabling this optimization.
```
struct A {
A(unsigned long pa, unsigned long pb) {a = pa; b = pb;}
unsigned long a;
unsigned long b;
float c;
};
```
```
; Function Attrs: noinline optnone ssp uwtable
define void @_Z1fmm(%struct.A* noalias sret(%struct.A) align 8 %0, i64 %1, i64 %2) #0 {
%4 = alloca i64, align 8
%5 = alloca i64, align 8
store i64 %1, i64* %4, align 8
store i64 %2, i64* %5, align 8
%6 = load i64, i64* %4, align 8
%7 = load i64, i64* %5, align 8
%8 = call %struct.A* @_ZN1AC1Emm(%struct.A* %0, i64 %6, i64 %7)
ret void
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzdVU1v4zYQ_TXSZRBDomzLOuigJA2aSy8tUKCXgpQomy0lCiQVx_31naHl2HKc7BZtgcUGRkxpvt7M8D0L0xzKaJ1Mn-QxSirn7Vh7qCDK749vAP-qiG3G3qltLxvQpt_CwCP2AFfvRMQKCuQQZY_kkt2DOJ4FnqP88ZxyHkquH9nEm40SnM4VtO9A3cB0gnRObqUfbR9aCv7kMatwPMzH8stOAhfmRUIL7djXXpkelIPadIPSWMwb8OgjtNmD1i8dCOVr08ib2WguT6cslffWRVkFvVG9Vr0EM_je4LdzA4x7z4We0jSyJXu0umfwCmq9jFaPEC2T339L267DhvAVRGyVUF_TOQ0DYFlyOQV8n4W9cK1Nzen5uPhFRaFc4wRhc-G9vPSmwje9Vl_2ct5YCVc4I1aFIl_yT-f-q9so1gGFNrw5Yfi8BL7OPwn5oMomhNTY7Hx61XEhP6XVQ_pDWMq1GWd_sZ_1xTmnq3guUYQSdJG48--q0Arx1s0uAxou4tPk3NaV28O7uFDwRqtIl-sLR5k_p8szbEfpHFKCe6g1RyLipVad-ksGmkwqg_B5D9xafoD9TvYTNxW6Kw_O0P_ajLoBIUMbSLQWZyHtAn40e_kiLSEmC8XMYTopO4ekwkTjMBjrMVgcjuRUPeYYsBplwjD0RVzIZ-XcKOEZ0UqUkDCZzc77gQgasSf8bJXfjWKBxMcHSjZ93Q3W_CFrj48hicPDKs9yvEYF1ghj-ZV6fAZvD6H1psEeO-Q7jsRCJzshrTspyTSijv85jYM62Uut78KCEBx2HiTnKDRnWepNkD5MOUnd24z9YUA_a7oQeApYwM8GUe1N32CMaslInHNHdHt-CKBaY2sJjXKoRwQpzGvaKg95bl6Fb_oHhWwtXh-8Zjd_ZK51-z-V8Rejmpl6XzG8N7hpjlvANV5bixNNb8j925l9IP3_j5in_1DM2Xci5slXiDmJKK37I9WMZZmu1-mqYCxZxk2ZNUVW8Ngrr2VZ9QciIXHwyD45l1Qi48QyajrKnuLR6vLfyNYySeJducyZ3IgmSYuG83VdtE2RsLwpRFHkomZtrLmQ2pUooKiUsSpZgvg3LE8KlrFswdMNz1Z5KpM2SbK8wFnKjiu9oMILY7exLQMGMW4dGrVy3p2N3AXSylN-PvqdseXrePeKhNsSleOAuQyA_wZ-RxSG">