<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 - Optimizer ignores __builtin_unreachable"
href="https://bugs.llvm.org/show_bug.cgi?id=41688">41688</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Optimizer ignores __builtin_unreachable
</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>Linux
</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>david.bolvansky@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>int foo(int p)
{
if (p <= 0) __builtin_unreachable();
return abs(p);
}
Clang sadly ignores this hint and produces:
foo(int):
mov eax, edi
neg eax
cmovl eax, edi
ret
** IR Dump After Instrument function entry/exit with calls to e.g. mcount()
(pre inlining) ***
; Function Attrs: nounwind uwtable
define dso_local i32 @foo(i32 %p) #0 {
entry:
%p.addr = alloca i32, align 4
store i32 %p, i32* %p.addr, align 4, !tbaa !2
%0 = load i32, i32* %p.addr, align 4, !tbaa !2
%cmp = icmp sle i32 %0, 0
br i1 %cmp, label %if.then, label %if.end
if.then: ; preds = %entry
unreachable
if.end: ; preds = %entry
%1 = load i32, i32* %p.addr, align 4, !tbaa !2
%call = call i32 @abs(i32 %1) #2
ret i32 %call
}
*** IR Dump After Simplify the CFG ***
; Function Attrs: nounwind uwtable
define dso_local i32 @foo(i32 %p) #0 {
entry:
%p.addr = alloca i32, align 4
store i32 %p, i32* %p.addr, align 4, !tbaa !2
%0 = load i32, i32* %p.addr, align 4, !tbaa !2
%call = call i32 @abs(i32 %0) #2
ret i32 %call
}
*** IR Dump After SROA ***
; Function Attrs: nounwind uwtable
define dso_local i32 @foo(i32 %p) #0 {
entry:
%call = call i32 @abs(i32 %p) #2
ret i32 %call
}
When Simplify CFG removes unreachable branch, maybe it should also add
llvm.assume on branch condition, no?</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>