<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/93152>93152</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
LLVM ERROR: Broken function found after pass "LowerSwitchPass", compilation aborted!
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
mikaelholmen
</td>
</tr>
</table>
<pre>
llvm commit: 4cc6d0f4dfb26d
Reproduce with:
```opt -passes="lower-switch" -verify-each bbi-95731.ll -o /dev/null```
Result:
```
PHINode should have one entry for each predecessor of its parent basic block!
%tmp = phi i3 [ 0, %LeafBlock ], [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ]
LLVM ERROR: Broken function found after pass "LowerSwitchPass", compilation aborted!
```
If we look at what lower-switch actually produces (-print-after-all) we see
```
; *** IR Dump After LowerSwitchPass on v_257_0 ***
define void @v_257_0(i3 %0) {
bb.0:
br label %LeafBlock
LeafBlock: ; preds = %bb.0
%.off = add i3 %0, 2
%SwitchLeaf = icmp ule i3 %.off, -4
br i1 %SwitchLeaf, label %bb.1, label %bb.2
bb.1: ; preds = %LeafBlock
%tmp = phi i3 [ 0, %LeafBlock ], [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ]
br label %bb.2
bb.2: ; preds = %LeafBlock, %bb.1
ret void
}
PHINode should have one entry for each predecessor of its parent basic block!
%tmp = phi i3 [ 0, %LeafBlock ], [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ]
```
So it has removed the switch instruction but it only updated one of the five phi operands for %bb.0.
The input looked like
```
define void @v_257_0(i3 %0) {
bb.0:
switch i3 %0, label %bb.2 [
i3 -1, label %bb.1
i3 -2, label %bb.1
i3 2, label %bb.1
i3 1, label %bb.1
i3 0, label %bb.1
]
bb.1: ; preds = %bb.0, %bb.0, %bb.0, %bb.0, %bb.0
%tmp = phi i3 [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ]
br label %bb.2
bb.2: ; preds = %bb.1, %bb.0
ret void
}
```
So there is one phi operand for each of the values that makes it jump from %bb.0 to %bb.1 and lower-switch only updated one of them when it changed things.
[bbi-95731.ll.gz](https://github.com/llvm/llvm-project/files/15414163/bbi-95731.ll.gz)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkVktv4zYQ_jX0ZSBDoiQ_DjrY6xoNkLaLbNHrghJHFtcUKZCUjfTXF6QUP7NJF02BAjUE2OY8v5lvRmTWip1CLEi-JvlmwnrXaFO0Ys9QNlq2qCal5s-FlIcWKt22wpF0BVlVzXhcZ7wu6YyTeEPi1RN2RvO-QjgK15B0NRyTWTw8unMQdcxatCTdEEqlPqKJ7FG4qiGUQnRAI-rnCFnVQFmKaJnP02QqJUQaCN1yPBC6Vb2UJ58vkW0v3X3E4e_nnx9-1RzBNrqXHBp2QNAKAZUzz1BrAyFgZ5BjhdZqA7oG4Sx0zKByUDIrKiilrvaEJoNTAEJz13ZA0g10jQCRAsnXEBP6yYsekdVrbwEk34SzC2FZTuMPPQ8pPT7-8Qv89PT025Pv0NroPSqoe1U5oRXUulccWO3QgG8CEEoffQO-hPp_ZtYSSr3jSredkCxYsVIbh_wE-6a0DzUcEaTWe2AOjg1zcNlUYJXrmZTPMDLDR11EnRHKRSGViElJ6NJ7sYivxiDpGghdDQ88PMGmbztYBSA3AEArOHyl-fxrfDYZvHCshUI4aMGBZPGoRejC943msU-CzNeDsq_riU0ApQHJSpRXfR2TGyp_OkxX8Dc_HpannA0MGpt5wa2prusgYpzDKclPQC90BuQ-etAUVdtBL3FU9x68RZSNJqUBkVzbefkJW1lOk9sDeokzKKSr-9xvqvIfHI7rLr4CjP5A715v4LkIpwROy8KgC9wbg843_6_VdDPSXzQIBw2zYLDVB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