@@ -164,6 +164,10 @@ static bool isParentOrSameContext(LoopContext & possibleChild, LoopContext & pos
164
164
165
165
// Case 2: The correct exiting block terminator unconditionally branches a different block, change to a conditional branch depending on if we are the first iteration
166
166
} else if (succ.size () == 1 ) {
167
+ lc.latchMerge ->getTerminator ()->eraseFromParent ();
168
+ mergeBuilder.SetInsertPoint (lc.latchMerge );
169
+
170
+ assert (mergeBuilder.GetInsertBlock ()->size () == 0 || !isa<BranchInst>(mergeBuilder.GetInsertBlock ()->back ()));
167
171
168
172
// If first iteration, branch to the exiting block, otherwise the backlatch
169
173
mergeBuilder.CreateCondBr (firstiter, succ[0 ], reverseBlocks[backlatch]);
@@ -187,6 +191,8 @@ static bool isParentOrSameContext(LoopContext & possibleChild, LoopContext & pos
187
191
188
192
lc.latchMerge ->getTerminator ()->eraseFromParent ();
189
193
mergeBuilder.SetInsertPoint (lc.latchMerge );
194
+
195
+ assert (mergeBuilder.GetInsertBlock ()->size () == 0 || !isa<BranchInst>(mergeBuilder.GetInsertBlock ()->back ()));
190
196
mergeBuilder.CreateCondBr (firstiter, splitBlock, reverseBlocks[backlatch]);
191
197
192
198
}
@@ -858,6 +864,7 @@ void GradientUtils::branchToCorrespondingTarget(BasicBlock* ctx, IRBuilder <>& B
858
864
859
865
if (targetToPreds.size () == 1 ) {
860
866
if (replacePHIs == nullptr ) {
867
+ assert (BuilderM.GetInsertBlock ()->size () == 0 || !isa<BranchInst>(BuilderM.GetInsertBlock ()->back ()));
861
868
BuilderM.CreateBr ( targetToPreds.begin ()->first );
862
869
} else {
863
870
for (auto pair : *replacePHIs) {
@@ -962,6 +969,7 @@ void GradientUtils::branchToCorrespondingTarget(BasicBlock* ctx, IRBuilder <>& B
962
969
Value* phi = lookupValueFromCache (BuilderM, ctx, cache);
963
970
964
971
if (replacePHIs == nullptr ) {
972
+ assert (BuilderM.GetInsertBlock ()->size () == 0 || !isa<BranchInst>(BuilderM.GetInsertBlock ()->back ()));
965
973
BuilderM.CreateCondBr (phi, *done[std::make_pair (block, branch->getSuccessor (0 ))].begin (), *done[std::make_pair (block, branch->getSuccessor (1 ))].begin ());
966
974
} else {
967
975
for (auto pair : *replacePHIs) {
@@ -1076,6 +1084,7 @@ void GradientUtils::branchToCorrespondingTarget(BasicBlock* ctx, IRBuilder <>& B
1076
1084
1077
1085
if (replacePHIs == nullptr ) {
1078
1086
if (targetToPreds.size () == 2 ) {
1087
+ assert (BuilderM.GetInsertBlock ()->size () == 0 || !isa<BranchInst>(BuilderM.GetInsertBlock ()->back ()));
1079
1088
BuilderM.CreateCondBr (which, /* true*/ targets[1 ], /* false*/ targets[0 ]);
1080
1089
} else {
1081
1090
auto swit = BuilderM.CreateSwitch (which, targets.back (), targets.size ()-1 );
0 commit comments