Skip to content

Commit 180d4fe

Browse files
paigealesys_zuul
authored andcommitted
Fix hoistCongruentPhi function to use a local variable for InstMap in so it is automatically cleared. This will prevent future bugs from happening when returning.
Change-Id: Id2c428cb95e9cead43f566131191dee5cd8d0c76
1 parent 06f7987 commit 180d4fe

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

IGC/Compiler/CISACodeGen/CodeSinking.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ namespace IGC {
730730
}
731731

732732
///////////////////////////////////////////////////////////////////////////
733-
bool CodeSinking::checkCongruent(const InstPair& values, InstVec& leaves, unsigned depth)
733+
bool CodeSinking::checkCongruent(std::vector<InstPair> &instMap, const InstPair& values, InstVec& leaves, unsigned depth)
734734
{
735735
Instruction* src0 = values.first;
736736
Instruction* src1 = values.second;
@@ -829,7 +829,7 @@ namespace IGC {
829829
if (iv0 && iv0->getParent() == src0->getParent() &&
830830
iv1 && iv1->getParent() == src1->getParent())
831831
{
832-
if (!checkCongruent(std::make_pair(iv0, iv1), tmpVec, depth + 1))
832+
if (!checkCongruent(instMap, std::make_pair(iv0, iv1), tmpVec, depth + 1))
833833
{
834834
equals = false;
835835
break;
@@ -843,7 +843,7 @@ namespace IGC {
843843
}
844844
if (equals)
845845
{
846-
appendIfNotExist(std::make_pair(src0, src1));
846+
appendIfNotExist(std::make_pair(src0, src1), instMap);
847847
appendIfNotExist(leaves, tmpVec);
848848
return equals;
849849
}
@@ -889,7 +889,7 @@ namespace IGC {
889889
if (iv0 && iv0->getParent() == src0->getParent() &&
890890
iv1 && iv1->getParent() == src1->getParent())
891891
{
892-
if (!checkCongruent(std::make_pair(iv0, iv1), leaves, depth + 1))
892+
if (!checkCongruent(instMap, std::make_pair(iv0, iv1), leaves, depth + 1))
893893
{
894894
equals = false;
895895
break;
@@ -903,7 +903,7 @@ namespace IGC {
903903
}
904904
if (equals)
905905
{
906-
appendIfNotExist(std::make_pair(src0, src1));
906+
appendIfNotExist(std::make_pair(src0, src1), instMap);
907907
appendIfNotExist(leaves, tmpVec);
908908
}
909909
return equals;
@@ -922,7 +922,11 @@ namespace IGC {
922922
src1 = dyn_cast<Instruction>(phi->getIncomingValue(1));
923923
if (src0 && src1 && src0 != src1)
924924
{
925-
if (checkCongruent(std::make_pair(src0, src1), leaves, 0))
925+
// this vector maps all instructions leading to source0 of phi instruction to
926+
// the corresponding instructions of source1
927+
std::vector<InstPair> instMap;
928+
929+
if (checkCongruent(instMap, std::make_pair(src0, src1), leaves, 0))
926930
{
927931
BasicBlock* predBB = nullptr;
928932
Instruction* insertPos = nullptr;
@@ -1008,7 +1012,6 @@ namespace IGC {
10081012
}
10091013
}
10101014
}
1011-
instMap.clear();
10121015
return changed;
10131016
}
10141017

IGC/Compiler/CISACodeGen/CodeSinking.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,7 @@ namespace IGC {
108108
typedef std::pair<llvm::Instruction*, llvm::Instruction*> InstPair;
109109
typedef smallvector<llvm::Instruction*, 4> InstVec;
110110

111-
// this vector maps all instructions leading to source0 of phi instruction to
112-
// the corresponding instructions of source1
113-
std::vector<InstPair> instMap;
114-
115-
void appendIfNotExist(InstPair src)
111+
void appendIfNotExist(InstPair src, std::vector<InstPair> &instMap)
116112
{
117113
if (std::find(instMap.begin(), instMap.end(), src) == instMap.end())
118114
{
@@ -136,7 +132,7 @@ namespace IGC {
136132

137133
// check if two values are congruent (derived from same values), and
138134
// record all intermediate results in vector.
139-
bool checkCongruent(const InstPair& values, InstVec& leaves, unsigned depth);
135+
bool checkCongruent(std::vector<InstPair> &instMap, const InstPair& values, InstVec& leaves, unsigned depth);
140136

141137
/**
142138
* Detech phi with congruent incoming values, and try to hoist them to

0 commit comments

Comments
 (0)