<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 - [SimplifyCFG] Failure to flatten and simplify checks"
href="https://bugs.llvm.org/show_bug.cgi?id=43210">43210</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[SimplifyCFG] Failure to flatten and simplify checks
</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>lebedev.ri@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre><a href="https://godbolt.org/z/rokl2m">https://godbolt.org/z/rokl2m</a>
#include <cstdint> // for intptr_t
bool is_ub(char *base, unsigned long offset) {
// Cast pointer to integer, perform usual arithmetic addition,
// and cast to pointer. This is legal.
char *computed = reinterpret_cast<char*>(reinterpret_cast<intptr_t>(base) +
offset);
// If either the pointer becomes non-nullptr, or becomes nullptr, we must use
``computed`` result.
return (((base == nullptr) && (computed != nullptr)) ||
((base != nullptr) && (computed == nullptr)));
}
After -O3 produces:
define dso_local zeroext i1 @_Z5is_ubPcm(i8* %0, i64 %1) local_unnamed_addr #0
{
%3 = ptrtoint i8* %0 to i64
%4 = add i64 %3, %1
%5 = icmp eq i8* %0, null
%6 = icmp ne i64 %4, 0
%7 = and i1 %5, %6
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = icmp ne i8* %0, null
%10 = icmp eq i64 %4, 0
%11 = and i1 %9, %10
br label %12
12: ; preds = %8, %2
%13 = phi i1 [ true, %2 ], [ %11, %8 ]
ret i1 %13
}
But this should just be
define dso_local zeroext i1 @_Z5is_ubPcm(i8* %0, i64 %1) local_unnamed_addr #0
{
%3 = ptrtoint i8* %0 to i64
%4 = icmp ne i8* %0, null
%5 = sub i64 0, %1
%6 = icmp eq i64 %3, %5
%7 = xor i1 %4, %6
ret i1 %7
}</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>