<html>
<head>
<base href="http://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - XORing of all bytes of a multi-word integer can be simplified"
href="http://bugs.llvm.org/show_bug.cgi?id=32119">32119</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>XORing of all bytes of a multi-word integer can be simplified
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Scalar Optimizations
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>andreybokhanko@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>$ cat test2.c
#include <inttypes.h>
uint8_t foo1(uint32_t val) {
return ((val >> 24) & 0xFF) ^ ((val >> 16) & 0xFF) ^ ((val >> 8) & 0xFF) ^
(val & 0xFF);
}
uint8_t foo2(uint32_t val) {
uint32_t t = ((val >> 16) & 0xFFFF) ^ (val & 0xFFFF);
uint8_t res = ((t >> 8) & 0xFF) ^ (t & 0xFF);
return res;
}
$ mrk3-cc test2.c -S -emit-llvm -Os
$ cat test2.ll
...
; Function Attrs: norecurse nounwind optsize readnone
define zeroext i8 @foo1(i32 %val) #0 {
entry:
%shr = lshr i32 %val, 24
%shr1 = lshr i32 %val, 16
%shr3 = lshr i32 %val, 8
%xor = xor i32 %shr1, %val
%xor5 = xor i32 %xor, %shr
%xor7 = xor i32 %xor5, %shr3
%conv = trunc i32 %xor7 to i8
ret i8 %conv
}
; Function Attrs: norecurse nounwind optsize readnone
define zeroext i8 @foo2(i32 %val) #0 {
entry:
%shr = lshr i32 %val, 16
%and1 = and i32 %val, 65535
%xor = xor i32 %shr, %and1
%shr2 = lshr i32 %xor, 8
%xor5 = xor i32 %shr2, %xor
%conv = trunc i32 %xor5 to i8
ret i8 %conv
}
foo1 and foo2 are equivalent -- foo2 just implements XORing of all bytes of a
multi-word integer more efficiently.
Resulting number of instructions: 7 for foo1 (3 shr, 3 xor, 1 trunc); 6 for
foo2 (2 shr, 1 and, 2 xor). foo2 can be optimized further by removing "and"
instruction, which is not really required.
This probably belongs to InstCombiner? (Sorry, can't find specific category for
InstCombiner.)
Andrey</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>