<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/133059>133059</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[InstCombine][FuncAttrs] InstCombine breaks `initializes` attribute
</td>
</tr>
<tr>
<th>Labels</th>
<td>
miscompilation,
llvm:instcombine,
miscompilation:undef,
generated by fuzzer
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dtcxzyw
</td>
</tr>
</table>
<pre>
Reproducer: https://alive2.llvm.org/ce/z/rx6rJk
```
; bin/opt -passes=instcombine test.ll -S
define fastcc void @src(ptr initializes((0, 48)) %0) {
%2 = alloca [24 x i8], align 8
store i8 0, ptr %0, align 16
%3 = getelementptr i8, ptr %0, i64 1
store i8 0, ptr %3, align 1
%4 = getelementptr i8, ptr %0, i64 2
store i16 0, ptr %4, align 2
%5 = getelementptr i8, ptr %0, i64 4
store i32 0, ptr %5, align 4
%6 = getelementptr i8, ptr %0, i64 8
store i16 0, ptr %6, align 8
%7 = getelementptr i8, ptr %0, i64 10
store i16 0, ptr %7, align 2
%8 = getelementptr i8, ptr %0, i64 12
store i32 0, ptr %8, align 4
%9 = getelementptr i8, ptr %0, i64 16
store double 0.000000e+00, ptr %9, align 16
%10 = getelementptr i8, ptr %0, i64 24
call void @llvm.memcpy.p0.p0.i64(ptr %10, ptr %2, i64 24, i1 false)
ret void
}
```
After InstCombine, the last memcpy is dropped as the source buffer is uninitialized (filled with undef (in llvm)/poison (in alive2)).
Should we adjust `initializes` to only account for writing with well-defined values?
Generated with rustlantis + llubi.
Original rust mir program: https://gist.github.com/dtcxzyw/78250ce921833ea20c5cb040d29f1a3f
cc @haopliu @nikic
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMld1uozgUx5_GuTlqZI6BwAUXZCJWuzcr7TyBMQfiGYORbdppn35laFqm260SIUF87J-Pz8ff0ns9TEQVy84suxzkEq7WVV1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