@@ -2118,14 +2118,14 @@ bool MinMaxMatcher::emit() {
2118
2118
2119
2119
// For a given instruction, find the insertion position which is the closest
2120
2120
// to all the similar users to the specified reference user.
2121
- static std::tuple<BasicBlock *, Instruction *>
2121
+ static Instruction *
2122
2122
findOptimalInsertionPos (Instruction *I, Instruction *Ref, DominatorTree *DT,
2123
2123
std::function<bool (Instruction *)> IsSimilar) {
2124
2124
IGC_ASSERT_MESSAGE (!isa<PHINode>(Ref), " PHINode is not expected!" );
2125
2125
2126
2126
// Shortcut case. If it's single-used, insert just before that user.
2127
2127
if (I->hasOneUse ())
2128
- return std::make_tuple ( nullptr , Ref) ;
2128
+ return Ref;
2129
2129
2130
2130
DenseMap<BasicBlock *, Instruction *> BBs;
2131
2131
for (auto U : I->users ()) {
@@ -2150,7 +2150,7 @@ findOptimalInsertionPos(Instruction *I, Instruction *Ref, DominatorTree *DT,
2150
2150
auto MI = BBs.begin ();
2151
2151
// Another shortcut case. If it's only used in a single BB,
2152
2152
if (BBs.size () == 1 )
2153
- return std::make_tuple ( MI->first , MI-> second ) ;
2153
+ return MI->second ;
2154
2154
2155
2155
BasicBlock *BB = MI->first ;
2156
2156
for (++MI; MI != BBs.end (); ++MI)
@@ -2163,7 +2163,9 @@ findOptimalInsertionPos(Instruction *I, Instruction *Ref, DominatorTree *DT,
2163
2163
Pos = MI->second ;
2164
2164
}
2165
2165
IGC_ASSERT (BB);
2166
- return std::make_tuple (BB, Pos);
2166
+ if (!Pos)
2167
+ return BB->getTerminator ();
2168
+ return Pos;
2167
2169
}
2168
2170
2169
2171
// For the specified constant, calculate its reciprocal if it's safe;
@@ -2279,13 +2281,8 @@ void GenXPatternMatch::visitFDiv(BinaryOperator &I) {
2279
2281
return User->getOpcode () == Instruction::FDiv && User->hasAllowReciprocal ();
2280
2282
};
2281
2283
2282
- BasicBlock *BB = nullptr ;
2283
- Instruction *Pos = nullptr ;
2284
- std::tie (BB, Pos) = findOptimalInsertionPos (Divisor, &I, DT, IsSimilar);
2285
- if (Pos)
2286
- IRB.SetInsertPoint (Pos);
2287
- else
2288
- IRB.SetInsertPoint (BB);
2284
+ Instruction *Pos = findOptimalInsertionPos (Divisor, &I, DT, IsSimilar);
2285
+ IRB.SetInsertPoint (Pos);
2289
2286
2290
2287
// (fdiv 1., (sqrt x)) -> (rsqrt x)
2291
2288
// TODO: This can be removed if pattern match is applied
0 commit comments