This repository has been archived by the owner on Jan 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mlir][llvm] Drop unreachable basic block during import (#78467)
This revision updates the LLVM IR import to support unreachable basic blocks. An unreachable block may dominate itself and a value defined inside the block may thus be used before its definition. The import does not support such dependencies. We thus delete the unreachable basic blocks before the import. This is possible since MLIR does not have basic block labels that can be reached using an indirect call and unreachable blocks can indeed be deleted safely. Additionally, add a small poison constant import test.
- Loading branch information
Showing
4 changed files
with
97 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
; RUN: mlir-translate -import-llvm %s | FileCheck %s | ||
|
||
; Test unreachable blocks are dropped. | ||
|
||
; CHECK-LABEL: llvm.func @unreachable_block | ||
define void @unreachable_block(float %0) { | ||
.entry: | ||
; CHECK: llvm.return | ||
ret void | ||
|
||
unreachable: | ||
; CHECK-NOT: llvm.fadd | ||
%1 = fadd float %0, %1 | ||
br label %unreachable | ||
} | ||
|
||
; Test unreachable blocks with back edges are supported. | ||
|
||
; CHECK-LABEL: llvm.func @back_edge | ||
define i32 @back_edge(i32 %0) { | ||
.entry: | ||
; CHECK: llvm.br ^[[RET:.*]](%{{.*}}) | ||
br label %ret | ||
ret: | ||
; CHECK: ^[[RET]](%{{.*}}: i32) | ||
%1 = phi i32 [ %0, %.entry ], [ %2, %unreachable ] | ||
; CHECK: llvm.return %{{.*}} : i32 | ||
ret i32 %1 | ||
|
||
unreachable: | ||
; CHECK-NOT: add | ||
%2 = add i32 %0, %2 | ||
%3 = icmp eq i32 %2, 42 | ||
br i1 %3, label %ret, label %unreachable | ||
} |