<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 - LLVM misses conversion of load of select between pointers-to-constants into select between constants"
href="https://bugs.llvm.org/show_bug.cgi?id=45084">45084</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>LLVM misses conversion of load of select between pointers-to-constants into select between constants
</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>richard-llvm@metafoo.co.uk
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Similar bug in GCC (including motivation):
<a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94006">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94006</a>
Testcase:
struct f { int t; };
static const struct f g0 = {0};
static const struct f g1 = {-1};
struct f f1(int a, int b) {
return a == b ? g0 : g1;
}
IR:
%struct.f = type { i32 }
@_ZL2g0 = internal unnamed_addr constant %struct.f zeroinitializer, align 4
@_ZL2g1 = internal unnamed_addr constant %struct.f { i32 -1 }, align 4
define dso_local i32 @_Z2f1ii(i32 %0, i32 %1) local_unnamed_addr #0 {
%3 = icmp eq i32 %0, %1
%4 = select i1 %3, %struct.f* @_ZL2g0, %struct.f* @_ZL2g1
%5 = getelementptr inbounds %struct.f, %struct.f* %4, i64 0, i32 0
%6 = load i32, i32* %5, align 4, !tbaa.struct !2
ret i32 %6
}
LLVM doesn't appear to notice this can be simplified to:
%struct.f = type { i32 }
@_ZL2g0 = internal unnamed_addr constant %struct.f zeroinitializer, align 4
@_ZL2g1 = internal unnamed_addr constant %struct.f { i32 -1 }, align 4
define dso_local i32 @_Z2f1ii(i32 %0, i32 %1) local_unnamed_addr #0 {
%3 = icmp eq i32 %0, %1
%4 = select i1 %3, i32 0, i32 -1
ret i32 %4
}
(and then to
%struct.f = type { i32 }
@_ZL2g0 = internal unnamed_addr constant %struct.f zeroinitializer, align 4
@_ZL2g1 = internal unnamed_addr constant %struct.f { i32 -1 }, align 4
define dso_local i32 @_Z2f1ii(i32 %0, i32 %1) local_unnamed_addr #0 {
%3 = icmp eq i32 %0, %1
%4 = sext i1 %3 to i32
ret i32 %4
}
or similar).</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>