Skip to content

Commit d96fdf6

Browse files
Gang Y Chenigcbot
authored andcommitted
WIA without LCSSA
This is the solution when we do WIAnalysis without requiring LCSSA form. I have added detailed comment to explain what we do in this situation
1 parent da2c561 commit d96fdf6

File tree

5 files changed

+21
-38
lines changed

5 files changed

+21
-38
lines changed

IGC/Compiler/CISACodeGen/ConstantCoalescing.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ SPDX-License-Identifier: MIT
1919
#include <llvm/IR/PassManager.h>
2020
#include <llvm/IR/IRBuilder.h>
2121
#include <llvm/ADT/SmallBitVector.h>
22+
#include <llvmWrapper/Transforms/Utils.h>
2223
#include "common/LLVMWarningsPop.hpp"
2324
#include "common/IGCIRBuilder.h"
2425

IGC/Compiler/CISACodeGen/ShaderCodeGen.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ static void AddAnalysisPasses(CodeGenContext& ctx, IGCPassManager& mpm)
266266
mpm.add(new Legalizer::PeepholeTypeLegalizer());
267267

268268
// need this before WIAnalysis:
269+
// insert phi to prevent changing of WIAnalysis result by later code-motion
269270
mpm.add(llvm::createLCSSAPass());
270271
// Fixup extract value pairs.
271272
mpm.add(createExtractValuePairFixupPass());
@@ -308,8 +309,6 @@ static void AddAnalysisPasses(CodeGenContext& ctx, IGCPassManager& mpm)
308309
mpm.add(createPromoteMemoryToRegisterPass());
309310
// Resolving private memory allocas
310311
mpm.add(CreatePrivateMemoryResolution());
311-
// need this before WIAnalysis:
312-
mpm.add(llvm::createLCSSAPass());
313312
}
314313

315314
// This is for dumping register pressure info
@@ -535,8 +534,6 @@ static void AddLegalizationPasses(CodeGenContext& ctx, IGCPassManager& mpm, PSSi
535534
IGC_IS_FLAG_ENABLED(LateInlineUnmaskedFunc)))
536535
{
537536
mpm.add(createBreakCriticalEdgesPass());
538-
// need this before WIAnalysis:
539-
mpm.add(llvm::createLCSSAPass());
540537
mpm.add(createAnnotateUniformAllocasPass());
541538

542539
if (IGC_IS_FLAG_DISABLED(DisablePromotePrivMem) &&
@@ -604,8 +601,7 @@ static void AddLegalizationPasses(CodeGenContext& ctx, IGCPassManager& mpm, PSSi
604601
if (!isOptDisabled &&
605602
ctx.m_instrTypes.hasLoadStore && IGC_IS_FLAG_DISABLED(DisableMemOpt)) {
606603
// run AdvMemOpt and MemOPt back-to-back so that we only
607-
// need to run WIAnalysis once, also need LCSSA before WIAnalysis:
608-
mpm.add(llvm::createLCSSAPass());
604+
// need to run WIAnalysis once
609605
if (IGC_IS_FLAG_ENABLED(EnableAdvMemOpt))
610606
mpm.add(createAdvMemOptPass());
611607
bool AllowNegativeSymPtrsForLoad =
@@ -772,8 +768,6 @@ static void AddLegalizationPasses(CodeGenContext& ctx, IGCPassManager& mpm, PSSi
772768
if (IGC_IS_FLAG_DISABLED(DisableConstantCoalescing))
773769
{
774770
mpm.add(createBreakCriticalEdgesPass());
775-
// need this before WIAnalysis:
776-
mpm.add(llvm::createLCSSAPass());
777771
mpm.add(new ConstantCoalescing());
778772
}
779773

IGC/Compiler/CISACodeGen/WIAnalysis.cpp

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -946,18 +946,23 @@ void WIAnalysisRunner::update_cf_dep(const IGCLLVM::TerminatorInst* inst)
946946
m_pChangedNew->push_back(it->second);
947947
}
948948

949-
// Experiment to see when the code after this test is needed
950-
if (IGC_IS_FLAG_ENABLED(WIAExperimental))
951-
continue;
952-
949+
// This is an optimization that tries to detect instruction
950+
// not really affected by control-flow divergency because
951+
// all the sources are outside the region.
952+
// However this is only as good as we can get because we
953+
// only search limited depth
953954
if (isRegionInvariant(defi, &br_info, 0))
954955
{
955956
continue;
956957
}
957-
// look at the uses
958+
// We need to look at where the use is in order to decide
959+
// we should make def to be "random" when loop is not in
960+
// LCSSA form because we do not have LCSSA phi-nodes.
961+
// 1) if use is in the full-join
962+
// 2) if use is even outside the full-join
963+
// 3) if use is in partial-join but def is not in partial-join
958964
Value::use_iterator use_it = defi->use_begin();
959965
Value::use_iterator use_e = defi->use_end();
960-
961966
for (; use_it != use_e; ++use_it)
962967
{
963968
Instruction* user = dyn_cast<Instruction>((*use_it).getUser());
@@ -966,32 +971,20 @@ void WIAnalysisRunner::update_cf_dep(const IGCLLVM::TerminatorInst* inst)
966971
PHINode* phi = dyn_cast<PHINode>(user);
967972
if (phi)
968973
{
969-
// another place we assume all critical edges have been split and
970-
// phi-move will be placed on the blocks created on those
974+
// another place we assume all critical edges have been
975+
// split and phi-move will be placed on those splitters
971976
user_blk = phi->getIncomingBlock(*use_it);
972977
}
973-
auto canUserBeHoistedToDefBlock = [](Instruction* UI, Instruction* DI)->bool {
974-
for (auto& uo : UI->operands())
975-
{
976-
Value* V = uo.get();
977-
if (V == DI)
978-
continue;
979-
else if (dyn_cast<Constant>(V))
980-
continue;
981-
else
982-
return false;
983-
}
984-
return true;
985-
};
986-
if ((user_blk == def_blk) ||
987-
(canUserBeHoistedToDefBlock(user, defi) && !phi))
978+
if (user_blk == def_blk)
988979
{
989980
// local def-use, not related to control-dependence
990981
continue; // skip
991982
}
992983
if (user_blk == br_info.full_join ||
993-
br_info.partial_joins.count(user_blk) ||
994-
!br_info.influence_region.count(user_blk))
984+
!br_info.influence_region.count(user_blk) ||
985+
(br_info.partial_joins.count(user_blk) &&
986+
!br_info.partial_joins.count(def_blk))
987+
)
995988
{
996989
updateDepMap(defi, instDep);
997990
// break out of the use loop

IGC/Compiler/CISACodeGen/WIAnalysis.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ SPDX-License-Identifier: MIT
2828
#include <llvm/IR/InstIterator.h>
2929
#include <llvm/IR/Dominators.h>
3030
#include <llvm/Analysis/PostDominators.h>
31-
#include <llvmWrapper/Transforms/Utils.h>
3231
#include "common/LLVMWarningsPop.hpp"
3332

3433

@@ -327,8 +326,6 @@ namespace IGC
327326
AU.addRequired<MetaDataUtilsWrapper>();
328327
AU.addRequired<CodeGenContextWrapper>();
329328
AU.addRequired<TranslationTable>();
330-
AU.addRequiredID(llvm::LCSSAID);
331-
AU.addPreservedID(llvm::LCSSAID);
332329
}
333330

334331
/// @brief LLVM llvm::Function pass entry

IGC/common/igc_flags.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,6 @@ DECLARE_IGC_REGKEY(bool, EnablerReadSuppressionWA, true, "Enable read suppres
241241
DECLARE_IGC_REGKEY(bool, DPASReadSuppressionWA, true, "Enable read suppression WA for the send and indirect access", false)
242242
DECLARE_IGC_REGKEY(DWORD, RSWARegNum, 0, "dummy register used for EnablerReadSuppressionWA", false)
243243
DECLARE_IGC_REGKEY(bool, EnableDivergentBarrierCheck, false, "Uses WIAnalysis to find barriers in divergent flow control. May have false positives.", false)
244-
DECLARE_IGC_REGKEY(bool, WIAExperimental, false, "Experimental flag to find certain check in WIA is really needed or not", false)
245-
246244
DECLARE_IGC_GROUP("Shader dumping")
247245
DECLARE_IGC_REGKEY(bool, EnableCosDump, false, "Enable cos dump", true)
248246
DECLARE_IGC_REGKEY(bool, EnableCisDump, false, "Enable cis dump", true)

0 commit comments

Comments
 (0)