Skip to content

Commit 5519219

Browse files
krystian-andrzejewskiigcbot
authored andcommitted
Patch for LowerSwitchPass
This change is to address a crash in findNearestCommonDominator called in the CodeSinking pass. The reason for removing unreachable blocks is this change in the LLVM repo: llvm/llvm-project@1065f34 LowerSwitchPass can leave phi instructions with nodes from unreachable basic blocks which is a disallowed state for DomTree.
1 parent 2463b4c commit 5519219

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*========================== begin_copyright_notice ============================
2+
3+
Copyright (C) 2024 Intel Corporation
4+
5+
SPDX-License-Identifier: MIT
6+
7+
============================= end_copyright_notice ===========================*/
8+
/*========================== begin_copyright_notice ============================
9+
10+
Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
11+
See https://llvm.org/LICENSE.txt for license information.
12+
SPDX-License-Identifier: Apache-2.0 with LLVM-exception
13+
14+
============================= end_copyright_notice ===========================*/
15+
The reason for removing unreachable blocks is this change in the LLVM repo:
16+
https://github.com/llvm/llvm-project/commit/1065f3439bad59323f16e7c8ee568c7d94dcd952
17+
LowerSwitchPass can leave phi instructions with nodes from unreachable basic blocks
18+
which is a disallowed state for DomTree.
19+
20+
diff --git a/llvm/lib/Transforms/Utils/LowerSwitch.cpp b/llvm/lib/Transforms/Utils/LowerSwitch.cpp
21+
index aff9d1311..b38de0a7a 100644
22+
--- a/llvm/lib/Transforms/Utils/LowerSwitch.cpp
23+
+++ b/llvm/lib/Transforms/Utils/LowerSwitch.cpp
24+
@@ -38,6 +38,7 @@
25+
#include "llvm/Support/raw_ostream.h"
26+
#include "llvm/Transforms/Utils.h"
27+
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
28+
+#include "llvm/Transforms/Utils/Local.h"
29+
#include <algorithm>
30+
#include <cassert>
31+
#include <cstdint>
32+
@@ -542,6 +543,10 @@ bool LowerSwitch(Function &F, LazyValueInfo *LVI, AssumptionCache *AC) {
33+
DeleteDeadBlock(BB);
34+
}
35+
36+
+ if (!DeleteList.empty()) {
37+
+ removeUnreachableBlocks(F);
38+
+ }
39+
+
40+
return Changed;
41+
}
42+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*========================== begin_copyright_notice ============================
2+
3+
Copyright (C) 2024 Intel Corporation
4+
5+
SPDX-License-Identifier: MIT
6+
7+
============================= end_copyright_notice ===========================*/
8+
/*========================== begin_copyright_notice ============================
9+
10+
Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
11+
See https://llvm.org/LICENSE.txt for license information.
12+
SPDX-License-Identifier: Apache-2.0 with LLVM-exception
13+
14+
============================= end_copyright_notice ===========================*/
15+
The reason for removing unreachable blocks is this change in the LLVM repo:
16+
https://github.com/llvm/llvm-project/commit/1065f3439bad59323f16e7c8ee568c7d94dcd952
17+
LowerSwitchPass can leave phi instructions with nodes from unreachable basic blocks
18+
which is a disallowed state for DomTree.
19+
20+
diff --git a/llvm/lib/Transforms/Utils/LowerSwitch.cpp b/llvm/lib/Transforms/Utils/LowerSwitch.cpp
21+
index aff9d1311..b38de0a7a 100644
22+
--- a/llvm/lib/Transforms/Utils/LowerSwitch.cpp
23+
+++ b/llvm/lib/Transforms/Utils/LowerSwitch.cpp
24+
@@ -38,6 +38,7 @@
25+
#include "llvm/Support/raw_ostream.h"
26+
#include "llvm/Transforms/Utils.h"
27+
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
28+
+#include "llvm/Transforms/Utils/Local.h"
29+
#include <algorithm>
30+
#include <cassert>
31+
#include <cstdint>
32+
@@ -542,6 +543,10 @@ bool LowerSwitch(Function &F, LazyValueInfo *LVI, AssumptionCache *AC) {
33+
DeleteDeadBlock(BB);
34+
}
35+
36+
+ if (!DeleteList.empty()) {
37+
+ removeUnreachableBlocks(F);
38+
+ }
39+
+
40+
return Changed;
41+
}
42+

0 commit comments

Comments
 (0)