<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 - opt -simplifycfg -lowerswitch makes code worse"
href="https://bugs.llvm.org/show_bug.cgi?id=46039">46039</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>opt -simplifycfg -lowerswitch makes code worse
</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>Transformation Utilities
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>jay.foad@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>This example starts out as "if (x==1) ... else if (x==2) ...". First
-simplifycfg converts the ifs to a switch. Then -lowerswitch converts the
switch back to ifs, but it comes up with worse code than we started with: "if
(x<2) { if (x==1) ... } else { if (x==2) ... }". This seems like a missed
optimization in -lowerswitch.
$ cat a.ll
define void @f(i32 %x, i32* %p) {
bb0:
%c1 = icmp eq i32 %x, 1
br i1 %c1, label %bb1, label %bb2
bb1:
store i32 33, i32* %p
br label %bb4
bb2:
%c2 = icmp eq i32 %x, 2
br i1 %c2, label %bb3, label %bb4
bb3:
store i32 66, i32* %p
br label %bb4
bb4:
ret void
}
$ opt -simplifycfg -lowerswitch a.ll -S -o -
; ModuleID = 'a.ll'
source_filename = "a.ll"
define void @f(i32 %x, i32* %p) {
bb0:
br label %NodeBlock
NodeBlock: ; preds = %bb0
%Pivot = icmp slt i32 %x, 2
br i1 %Pivot, label %LeafBlock, label %LeafBlock1
LeafBlock1: ; preds = %NodeBlock
%SwitchLeaf2 = icmp eq i32 %x, 2
br i1 %SwitchLeaf2, label %bb3, label %NewDefault
LeafBlock: ; preds = %NodeBlock
%SwitchLeaf = icmp eq i32 %x, 1
br i1 %SwitchLeaf, label %bb1, label %NewDefault
bb1: ; preds = %LeafBlock
store i32 33, i32* %p, align 4
br label %bb4
bb3: ; preds = %LeafBlock1
store i32 66, i32* %p, align 4
br label %bb4
NewDefault: ; preds = %LeafBlock1,
%LeafBlock
br label %bb4
bb4: ; preds = %NewDefault, %bb3,
%bb1
ret void
}</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>