<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/102845>102845</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
`xor r8d, r8d` followed by `setne r8b` is redundant
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Validark
</td>
</tr>
</table>
<pre>
```zig
export fn foo(unescaped_quotes: u64, unescaped_apostrophes: u64, newlines: u64, comment_starts: u64, line_string_starts: u64) extern struct { a: u64, b: u8 } {
const all_ored = unescaped_quotes | unescaped_apostrophes | comment_starts | line_string_starts;
const lsb = all_ored & (~all_ored +% 1);
var bitstr: u64 = newlines;
var id: u8 = 0;
if ((unescaped_apostrophes & lsb) != 0) {
bitstr = unescaped_apostrophes;
bitstr &= bitstr -% 1;
id = 1;
}
if ((unescaped_quotes & lsb) != 0) {
bitstr = unescaped_quotes;
bitstr &= bitstr -% 1;
id = 2;
}
return .{ .a = @ctz(bitstr), .b = id };
}
```
Compiled for Zen 4, generates: ([Godbolt link](https://godbolt.org/z/51d9hfP5a)) (Ctrl+F in the assembly window for 'r8')
```asm
foo:
mov rax, rdi
or rcx, r8
or rax, rsi
xor r8d, r8d
or rax, rcx
blsr rcx, rsi
neg rax
test rax, rsi
cmove rcx, rdx
setne r8b
blsr rsi, rdi
test rax, rdi
mov edx, 2
cmove rsi, rcx
cmove rdx, r8
tzcnt rax, rsi
ret
```
I believe the highlighted line should be removed.
```diff
foo:
mov rax, rdi
or rcx, r8
or rax, rsi
- xor r8d, r8d
or rax, rcx
blsr rcx, rsi
neg rax
test rax, rsi
cmove rcx, rdx
setne r8b
blsr rsi, rdi
test rax, rdi
mov edx, 2
cmove rsi, rcx
cmove rdx, r8
tzcnt rax, rsi
ret
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsVk1v4zYQ_TX0ZRBDpvV50CGO4aK3nn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