<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/136838>136838</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Auto-vectorizer generates different code for the main loop and for the trailing section
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dmenendez-gruposantander
</td>
</tr>
</table>
<pre>
Repro and code available in godbolt: https://godbolt.org/z/c936s31hn
Function `g()` in the example is expected to be auto-vectorized, and produce the same results as function f`()`, which is not vectorized. This is true for the code generated for the "main" part of the loop: I can see it in the generated assembly and in the test results.
However, the code generated for the **trailing** part of the loop does not match the code generated for the "main" part of the loop: the trailing section fails to fuse a multiplication and an addition.
The example program shows this effect:
- it compares output of `f()` and `g()` for 1 element
- it compares the output of `g()` for 5 equal input elements, showing that the 5-th result (coming out of the trailing part of the loop) is different than the rest.
For reference, the godbolt link compares against gcc, which generates the expected result.
```
$ clang --version
Ubuntu clang version 19.1.7 (++20250114103320+cd708029e0b2-1~exp1~20250114103432.75)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-19/bin
```
Source of installation: https://apt.llvm.org/jammy/dists/llvm-toolchain-jammy-19/main/
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykVUuPqzgT_TXOpkRkDHmwYEF_V-i725k765GxK-A7xmb8SKd7cX_7yIZ0-iHNZqQoEi5Tdc6pUwX3Xo0GsSWHJ3L4tuMxTNa1ckaDRuJrMbq4WM9N4Eai2w1WvrS_4eIscCNBWInAr1xpPmgEZWC0crA6kKqDKYTFk6ojrCes3wJ760bC-lfCetFUR1-VkyG0I7TroxFBWQPkSEfCzoQ15EhTzjAh4I3PSyrhAW8LioASgoUBgcdgiyuKYJ16RUnY_zK0xVkZBeaXPZ8RHPqogwfu4XIvdSFH-lYqvfk8KTGlIsYGeCTdw49J-XQeXES4W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