@@ -159,15 +159,15 @@ void AMDGPUConditionalDiscard::optimizeBlock(BasicBlock &BB, bool ConvertToDemot
159
159
160
160
bool FirstPred = true ;
161
161
for (auto PredBlock : make_early_inc_range (predecessors (&BB))) {
162
- auto *PredTerminator = PredBlock->getTerminator ();
163
- auto *PredBranchInst = cast<BranchInst>(PredTerminator);
162
+ auto *PredBranchInst = cast<BranchInst>(PredBlock->getTerminator ());
164
163
165
164
BasicBlock *LiveBlock = nullptr ;
166
165
auto *Cond = PredBranchInst->getCondition ();
167
166
if (PredBranchInst->getSuccessor (0 ) == &BB) {
168
167
// The old kill block could only be reached if
169
168
// the condition was true - negate the condition.
170
- Cond = BinaryOperator::CreateNot (Cond, " " , PredTerminator);
169
+ Cond =
170
+ BinaryOperator::CreateNot (Cond, " " , PredBranchInst->getIterator ());
171
171
LiveBlock = PredBranchInst->getSuccessor (1 );
172
172
} else {
173
173
LiveBlock = PredBranchInst->getSuccessor (0 );
@@ -176,7 +176,7 @@ void AMDGPUConditionalDiscard::optimizeBlock(BasicBlock &BB, bool ConvertToDemot
176
176
auto *NewKill = cast<CallInst>(KillCand->clone ());
177
177
178
178
NewKill->setArgOperand (0 , Cond);
179
- NewKill->insertBefore (PredTerminator );
179
+ NewKill->insertBefore (PredBranchInst );
180
180
181
181
if (ConvertToDemote) {
182
182
NewKill->setCalledFunction (Intrinsic::getDeclaration (
@@ -187,7 +187,8 @@ void AMDGPUConditionalDiscard::optimizeBlock(BasicBlock &BB, bool ConvertToDemot
187
187
KillBlocksToRemove.push_back (&BB);
188
188
189
189
// Change the branch to an unconditional one, targeting the live block.
190
- auto *NewBranchInst = BranchInst::Create (LiveBlock, PredBranchInst);
190
+ auto *NewBranchInst =
191
+ BranchInst::Create (LiveBlock, PredBranchInst->getIterator ());
191
192
NewBranchInst->copyMetadata (*PredBranchInst);
192
193
PredBranchInst->eraseFromParent ();
193
194
} else {
@@ -214,8 +215,8 @@ void AMDGPUConditionalDiscard::optimizeBlock(BasicBlock &BB, bool ConvertToDemot
214
215
// It's possible that the branch became unconditional.
215
216
if (PredBranchInst->getSuccessor (0 ) ==
216
217
PredBranchInst->getSuccessor (1 )) {
217
- auto *NewBranchInst =
218
- BranchInst::Create ( OldKillBlockSucc, PredBranchInst);
218
+ auto *NewBranchInst = BranchInst::Create (
219
+ OldKillBlockSucc, PredBranchInst-> getIterator () );
219
220
NewBranchInst->copyMetadata (*PredBranchInst);
220
221
PredBranchInst->eraseFromParent ();
221
222
}
0 commit comments