Issue 93152
Summary LLVM ERROR: Broken function found after pass "LowerSwitchPass", compilation aborted!
Labels new issue
Assignees
Reporter mikaelholmen
    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)

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to