<html>
<head>
<base href="https://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 - CodeGenPrepare::CombineUAddWithOverflow - improve icmp eq/ne matching"
href="https://bugs.llvm.org/show_bug.cgi?id=40486">40486</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>CodeGenPrepare::CombineUAddWithOverflow - improve icmp eq/ne matching
</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>Windows NT
</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>Common Code Generator Code
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>llvm-dev@redking.me.uk
</td>
</tr>
<tr>
<th>CC</th>
<td>arthur.j.odwyer@gmail.com, llvm-bugs@lists.llvm.org, sanjoy@playingwithpointers.com, spatel+llvm@rotateright.com
</td>
</tr></table>
<p>
<div>
<pre>Reviewing the addcarry cases from [<a class="bz_bug_link
bz_status_CONFIRMED "
title="CONFIRMED - replacing variable by a constant breaks add-with-carry (adc) and subtract-with-borrow (sbb) optimization"
href="show_bug.cgi?id=31754#c3">Bug #31754 Comment #3</a>]:
<a href="https://godbolt.org/z/eZWlsG">https://godbolt.org/z/eZWlsG</a>
The IR demonstrates that much of the problem is that while
CombineUAddWithOverflow can match the ult/ugt cases of the add result, it can't
handle ult/ugt canonicalizations (against 1/-1/signbit/etc) that result in a
icmp eq/ne instead:
define void @_Z4testILy1EEvRyS0_(i64*, i64*) {
%3 = load i64, i64* %0, align 8
%4 = add i64 %3, 1
store i64 %4, i64* %0, align 8
%5 = icmp eq i64 %4, 0 // <---- fails to match uaddo
%6 = zext i1 %5 to i8
%7 = load i64, i64* %1, align 8
%8 = tail call { i8, i64 } @llvm.x86.addcarry.64(i8 %6, i64 %7, i64 0) #2
%9 = extractvalue { i8, i64 } %8, 1
store i64 %9, i64* %1, align 8
ret void
}
define void @_Z4testILy2EEvRyS0_(i64*, i64*) {
%3 = load i64, i64* %0, align 8
%4 = add i64 %3, 2
store i64 %4, i64* %0, align 8
%5 = icmp ult i64 %4, 2 // <---- matches uaddo
%6 = zext i1 %5 to i8
%7 = load i64, i64* %1, align 8
%8 = tail call { i8, i64 } @llvm.x86.addcarry.64(i8 %6, i64 %7, i64 0) #2
%9 = extractvalue { i8, i64 } %8, 1
store i64 %9, i64* %1, align 8
ret void
}
declare { i8, i64 } @llvm.x86.addcarry.64(i8, i64, i64)</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>