<html>
<head>
<base href="https://llvm.org/bugs/" />
</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 --- - [llvm.expect] no metadata created if intrinsic is not used by an 'icmp ne'"
href="https://llvm.org/bugs/show_bug.cgi?id=27542">27542</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[llvm.expect] no metadata created if intrinsic is not used by an 'icmp ne'
</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>normal
</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>spatel+llvm@rotateright.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>int foo(int x) {
if (__builtin_expect(x, 20) > 10)
return 234;
return 0;
}
$ ./clang -O1 expect.c -S -o - -emit-llvm | grep weights
$
----------------------------------------------------------------------------
The problem is in the LowerExpectIntrinsic pass. It discards llvm.expect
intrinsics without adding metadata if the expect isn't used by a compare
not-equal:
define i32 @foo(i32 %x) {
entry:
%conv = sext i32 %x to i64
%expval = call i64 @llvm.expect.i64(i64 %conv, i64 20)
%cmp = icmp sgt i64 %expval, 10
br i1 %cmp, label %if.then, label %if.end
if.then:
br label %return
if.end:
br label %return
return:
%retval.0 = phi i32 [ 234, %if.then ], [ 0, %if.end ]
ret i32 %retval.0
}
declare i64 @llvm.expect.i64(i64, i64)
----------------------------------------------------------------------------
$ ./opt -lower-expect exp.ll -S
; ModuleID = 'exp.ll'
source_filename = "exp.ll"
define i32 @foo(i32 %x) #0 {
entry:
%conv = sext i32 %x to i64
%cmp = icmp sgt i64 %conv, 10
br i1 %cmp, label %if.then, label %if.end
if.then: ; preds = %entry
br label %return
if.end: ; preds = %entry
br label %return
return: ; preds = %if.end, %if.then
%retval.0 = phi i32 [ 234, %if.then ], [ 0, %if.end ]
ret i32 %retval.0
}
declare i64 @llvm.expect.i64(i64, i64) #1</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>