<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 - delete dead CFG edges based on __builtin_assume"
href="https://bugs.llvm.org/show_bug.cgi?id=41606">41606</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>delete dead CFG edges based on __builtin_assume
</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>Testcase:
struct pair { int first; bool second; };
bool mode;
int arr[8];
inline pair do_some_work() {
if (mode) {
int k = 0;
for (int n = 0; n != 8; ++n)
k += arr[n];
return {k, mode};
} else {
int k = 1;
for (int n = 0; n != 8; ++n)
k *= arr[n];
return {k, mode};
}
}
int f() {
auto res = do_some_work();
__builtin_assume(res.second);
return res.first;
}
Produces:
; Function Attrs: nounwind uwtable
define dso_local i32 @_Z1fv() local_unnamed_addr #0 {
%1 = load i8, i8* @mode, align 1, !tbaa !2, !range !6
%2 = icmp eq i8 %1, 0
%3 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 0), align 16, !tbaa !7
%4 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 1), align 4, !tbaa !7
br i1 %2, label %19, label %5
5: ; preds = %0
%6 = add nsw i32 %4, %3
%7 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 2), align 8, !tbaa !7
%8 = add nsw i32 %6, %7
%9 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 3), align 4, !tbaa !7
%10 = add nsw i32 %8, %9
%11 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 4), align 16, !tbaa !7
%12 = add nsw i32 %10, %11
%13 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 5), align 4, !tbaa !7
%14 = add nsw i32 %12, %13
%15 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 6), align 8, !tbaa !7
%16 = add nsw i32 %14, %15
%17 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 7), align 4, !tbaa !7
%18 = add nsw i32 %16, %17
br label %33
19: ; preds = %0
%20 = mul nsw i32 %4, %3
%21 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 2), align 8, !tbaa !7
%22 = mul nsw i32 %20, %21
%23 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 3), align 4, !tbaa !7
%24 = mul nsw i32 %22, %23
%25 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 4), align 16, !tbaa !7
%26 = mul nsw i32 %24, %25
%27 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 5), align 4, !tbaa !7
%28 = mul nsw i32 %26, %27
%29 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 6), align 8, !tbaa !7
%30 = mul nsw i32 %28, %29
%31 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 7), align 4, !tbaa !7
%32 = mul nsw i32 %30, %31
br label %33
33: ; preds = %5, %19
%34 = phi i32 [ %32, %19 ], [ %18, %5 ]
%35 = icmp ne i8 %1, 0
tail call void @llvm.assume(i1 %35)
ret i32 %34
}
We could simplify this significantly by taking advantage of the assumption from
the llvm.assume.</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>