|
| 1 | +/*========================== begin_copyright_notice ============================ |
| 2 | + |
| 3 | +Copyright (C) 2025 Intel Corporation |
| 4 | + |
| 5 | +SPDX-License-Identifier: MIT |
| 6 | + |
| 7 | +============================= end_copyright_notice ===========================*/ |
| 8 | + |
| 9 | +/*========================== begin_copyright_notice ============================ |
| 10 | + |
| 11 | +Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 12 | +See https://llvm.org/LICENSE.txt for license information. |
| 13 | +SPDX-License-Identifier: Apache-2.0 with LLVM-exception |
| 14 | + |
| 15 | +============================= end_copyright_notice ===========================*/ |
| 16 | + |
| 17 | +# Description: |
| 18 | +# The thread through two basic blocks functionality leads to extra basic block construction |
| 19 | +# that is suboptimal from the performance point of view. |
| 20 | +# Adding `jump-threading-through-two-bbs` option to control it. |
| 21 | +diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp |
| 22 | +index b31eab50c..87e9e4ddd 100644 |
| 23 | +--- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp |
| 24 | ++++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp |
| 25 | +@@ -109,6 +109,10 @@ static cl::opt<bool> ThreadAcrossLoopHeaders( |
| 26 | + cl::desc("Allow JumpThreading to thread across loop headers, for testing"), |
| 27 | + cl::init(false), cl::Hidden); |
| 28 | + |
| 29 | ++static cl::opt<bool> ThreadThroughTwoBBs( |
| 30 | ++ "jump-threading-through-two-bbs", |
| 31 | ++ cl::desc("Allow JumpThreading to thread through two basic blocks"), |
| 32 | ++ cl::init(false), cl::Hidden); |
| 33 | + |
| 34 | + namespace { |
| 35 | + |
| 36 | +@@ -2119,6 +2123,10 @@ bool JumpThreadingPass::maybethreadThroughTwoBasicBlocks(BasicBlock *BB, |
| 37 | + // edges (say, PredBB1 and PredBB2), we know the value of %var in each copy of |
| 38 | + // PredBB. Then we can thread edges PredBB1->BB and PredBB2->BB through BB. |
| 39 | + |
| 40 | ++ // Check that threading through two BBs is allowed |
| 41 | ++ if (!ThreadThroughTwoBBs) |
| 42 | ++ return false; |
| 43 | ++ |
| 44 | + // Require that BB end with a Branch for simplicity. |
| 45 | + BranchInst *CondBr = dyn_cast<BranchInst>(BB->getTerminator()); |
| 46 | + if (!CondBr) |
0 commit comments