<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64221>64221</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
redundant `continue` in `if`-chain leads to different code
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
firewave
</td>
</tr>
</table>
<pre>
```cpp
extern int multiComparePercent(const char *tok, const char*& haystack, int varid);
int multiCompare(const char *tok, const char *haystack, int varid)
{
const char *needle = tok;
const char *needlePointer = needle;
for (;;) {
if (needlePointer == needle && haystack[0] == '%' && haystack[1] != '|' && haystack[1] != '\0' && haystack[1] != ' ') {
const int ret = multiComparePercent(tok, haystack, varid);
if (ret < 2)
return ret;
} else if (*haystack == '|') {
if (*needlePointer == 0) {
// If needle is at the end, we have a match.
return 1;
}
needlePointer = needle;
++haystack;
} else if (*needlePointer == *haystack) {
if (*needlePointer == '\0')
return 1;
++needlePointer;
++haystack;
} else if (*haystack == ' ' || *haystack == '\0') {
if (needlePointer == needle)
return 0;
break;
}
// If haystack and needle don't share the same character,
// find next '|' character.
else {
needlePointer = needle;
do {
++haystack;
if (*haystack == ' ' || *haystack == '\0') {
return -1;
}
if (*haystack == '|') {
break;
}
} while (true);
++haystack;
}
}
if (*needlePointer == '\0')
return 1;
return -1;
}
```
https://godbolt.org/z/qWK69n7fo
If you add a `continue` in the first `if`-block the code will change profoundly and it also appears to be worse (based on `llvm-mca`).
Adding `continue` to the other blocks also affect the code generation but only slightly.
https://godbolt.org/z/ovcn753z3
GCC is only slightly affected by adding those but it seems to regress a bit when they are used inconsistently.
Strangely if you remove the contents of the first `if`-block it has the reverse effect. With `continue` it seems to generate better code (also based on `llvm-mca`). GCC does not seem to be affected at all.
https://godbolt.org/z/feejKMGx8
https://godbolt.org/z/ahrbKfrde
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0V1GP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