<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/109704>109704</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Freeze causes pessimization of simple code
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
gbaraldi
</td>
</tr>
</table>
<pre>
In julia we have a pass that generates code that looks something like
```llvm
define void @julia_split128_13(ptr noalias nocapture noundef nonnull sret([2 x i64]) align 8 dereferenceable(16) %sret_return, i128 noundef zeroext %0) {
top:
%1 = alloca [16 x i8], align 16
%2 = alloca [16 x i8], align 16
%3 = alloca [2 x i64], align 8
call void @llvm.lifetime.start.p0(i64 16, ptr %1)
store i128 %0, ptr %1, align 16
call void @llvm.lifetime.start.p0(i64 16, ptr %2)
%13 = freeze [16 x i8] undef
store [16 x i8] %13, ptr %2, align 1
call void @llvm.memcpy.p0.p0.i64(ptr align 1 %2, ptr align 1 %1, i64 16, i1 false)
call void @llvm.memcpy.p0.p0.i64(ptr %3, ptr %2, i64 16, i1 false)
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %sret_return, ptr align 8 %3, i64 16, i1 false)
ret void
}
```
As it turns out that freeze we emit there causes a large pessimization.
The code without it optimizes to
```llvm
define void @julia_split128_132(ptr noalias nocapture noundef nonnull writeonly sret([2 x i64]) align 8 dereferenceable(16) %sret_return, i128 noundef zeroext %0) local_unnamed_addr #0 {
store i128 %0, ptr %sret_return, align 8
ret void
}
```
While the code with it expands to
```llvm
define void @julia_split128_13(ptr noalias nocapture noundef nonnull writeonly sret([2 x i64]) align 8 dereferenceable(16) %sret_return, i128 noundef zeroext %0) local_unnamed_addr #0 {
%.sroa.046.0.extract.trunc = trunc i128 %0 to i8
%.sroa.347.0.extract.shift = lshr i128 %0, 8
%.sroa.347.0.extract.trunc = trunc i128 %.sroa.347.0.extract.shift to i8
%.sroa.448.0.extract.shift = lshr i128 %0, 16
%.sroa.448.0.extract.trunc = trunc i128 %.sroa.448.0.extract.shift to i8
%.sroa.549.0.extract.shift = lshr i128 %0, 24
%.sroa.549.0.extract.trunc = trunc i128 %.sroa.549.0.extract.shift to i8
%.sroa.650.0.extract.shift = lshr i128 %0, 32
%.sroa.650.0.extract.trunc = trunc i128 %.sroa.650.0.extract.shift to i8
%.sroa.751.0.extract.shift = lshr i128 %0, 40
%.sroa.751.0.extract.trunc = trunc i128 %.sroa.751.0.extract.shift to i8
%.sroa.852.0.extract.shift = lshr i128 %0, 48
%.sroa.852.0.extract.trunc = trunc i128 %.sroa.852.0.extract.shift to i8
%.sroa.953.0.extract.shift = lshr i128 %0, 56
%.sroa.953.0.extract.trunc = trunc i128 %.sroa.953.0.extract.shift to i8
%.sroa.1054.0.extract.shift = lshr i128 %0, 64
%.sroa.1054.0.extract.trunc = trunc i128 %.sroa.1054.0.extract.shift to i8
%.sroa.1155.0.extract.shift = lshr i128 %0, 72
%.sroa.1155.0.extract.trunc = trunc i128 %.sroa.1155.0.extract.shift to i8
%.sroa.1256.0.extract.shift = lshr i128 %0, 80
%.sroa.1256.0.extract.trunc = trunc i128 %.sroa.1256.0.extract.shift to i8
%.sroa.1357.0.extract.shift = lshr i128 %0, 88
%.sroa.1357.0.extract.trunc = trunc i128 %.sroa.1357.0.extract.shift to i8
%.sroa.1458.0.extract.shift = lshr i128 %0, 96
%.sroa.1458.0.extract.trunc = trunc i128 %.sroa.1458.0.extract.shift to i8
%.sroa.1559.0.extract.shift = lshr i128 %0, 104
%.sroa.1559.0.extract.trunc = trunc i128 %.sroa.1559.0.extract.shift to i8
%.sroa.1660.0.extract.shift = lshr i128 %0, 112
%.sroa.1660.0.extract.trunc = trunc i128 %.sroa.1660.0.extract.shift to i8
%.sroa.1761.0.extract.shift = lshr i128 %0, 120
%.sroa.1761.0.extract.trunc = trunc nuw i128 %.sroa.1761.0.extract.shift to i8
store i8 %.sroa.046.0.extract.trunc, ptr %sret_return, align 8
%.sroa.2.0.sret_return.sroa_idx = getelementptr inbounds i8, ptr %sret_return, i64 1
store i8 %.sroa.347.0.extract.trunc, ptr %.sroa.2.0.sret_return.sroa_idx, align 1
%.sroa.3.0.sret_return.sroa_idx = getelementptr inbounds i8, ptr %sret_return, i64 2
store i8 %.sroa.448.0.extract.trunc, ptr %.sroa.3.0.sret_return.sroa_idx, align 2
%.sroa.433.0.sret_return.sroa_idx = getelementptr inbounds i8, ptr %sret_return, i64 3
store i8 %.sroa.549.0.extract.trunc, ptr %.sroa.433.0.sret_return.sroa_idx, align 1
%.sroa.534.0.sret_return.sroa_idx = getelementptr inbounds i8, ptr %sret_return, i64 4
store i8 %.sroa.650.0.extract.trunc, ptr %.sroa.534.0.sret_return.sroa_idx, align 4
%.sroa.635.0.sret_return.sroa_idx = getelementptr inbounds i8, ptr %sret_return, i64 5
store i8 %.sroa.751.0.extract.trunc, ptr %.sroa.635.0.sret_return.sroa_idx, align 1
%.sroa.736.0.sret_return.sroa_idx = getelementptr inbounds i8, ptr %sret_return, i64 6
store i8 %.sroa.852.0.extract.trunc, ptr %.sroa.736.0.sret_return.sroa_idx, align 2
%.sroa.837.0.sret_return.sroa_idx = getelementptr inbounds i8, ptr %sret_return, i64 7
store i8 %.sroa.953.0.extract.trunc, ptr %.sroa.837.0.sret_return.sroa_idx, align 1
%.sroa.938.0.sret_return.sroa_idx = getelementptr inbounds i8, ptr %sret_return, i64 8
store i8 %.sroa.1054.0.extract.trunc, ptr %.sroa.938.0.sret_return.sroa_idx, align 8
%.sroa.1039.0.sret_return.sroa_idx = getelementptr inbounds i8, ptr %sret_return, i64 9
store i8 %.sroa.1155.0.extract.trunc, ptr %.sroa.1039.0.sret_return.sroa_idx, align 1
%.sroa.1140.0.sret_return.sroa_idx = getelementptr inbounds i8, ptr %sret_return, i64 10
store i8 %.sroa.1256.0.extract.trunc, ptr %.sroa.1140.0.sret_return.sroa_idx, align 2
%.sroa.1241.0.sret_return.sroa_idx = getelementptr inbounds i8, ptr %sret_return, i64 11
store i8 %.sroa.1357.0.extract.trunc, ptr %.sroa.1241.0.sret_return.sroa_idx, align 1
%.sroa.1342.0.sret_return.sroa_idx = getelementptr inbounds i8, ptr %sret_return, i64 12
store i8 %.sroa.1458.0.extract.trunc, ptr %.sroa.1342.0.sret_return.sroa_idx, align 4
%.sroa.1443.0.sret_return.sroa_idx = getelementptr inbounds i8, ptr %sret_return, i64 13
store i8 %.sroa.1559.0.extract.trunc, ptr %.sroa.1443.0.sret_return.sroa_idx, align 1
%.sroa.1544.0.sret_return.sroa_idx = getelementptr inbounds i8, ptr %sret_return, i64 14
store i8 %.sroa.1660.0.extract.trunc, ptr %.sroa.1544.0.sret_return.sroa_idx, align 2
%.sroa.1645.0.sret_return.sroa_idx = getelementptr inbounds i8, ptr %sret_return, i64 15
store i8 %.sroa.1761.0.extract.trunc, ptr %.sroa.1645.0.sret_return.sroa_idx, align 1
ret void
}
```
Is there anything we can do to make this a little better. i.e emit this code differently. Specially because the memcpy there guarantees that this store is always dead.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUmUGPozoSxz-Nc7EGYWMDOeTQPa2W5rwr7bHlQCXxjAPINp3OfPqVIZ1Ogu2wsy9PelJLkwGX6_cvm3JBCWPktgFYIf6M-MtC9HbX6tV2LbRQtVys2_q4-tHgn72SAh8A78Q7YIE7YQy2O2HxFhrQwoLBVVvDeE217S-DTbsHu5PNFiv5CzBKX1D6hPJ0_FPqfT9eqmEjG8DvrawxYung6s10SlpCyzeSIVp2VuOmFUoKg5u2Ep3tNeCm7ZsaNrhpm6ZXChsNFtES8WeKP7DMGeIviC6xUHLb4BLXoGEDGpoKxFoBoiXJ3X1EuTN902B73SD6HUtCy_P0v0G38GHdsHQYXjyP4LbtUPY0_sbuNsEoe8FCqbYSGPFnkjuOcsD4fsIg-YUB_V8NshuDS6GfBuXn-EoodQ6ri3ei5Aas3ENirNA26VJES5kz54N-xy7KTgWiy88pjG01jOEY5V-OmhL-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