@@ -955,6 +955,7 @@ void GradientUtils::branchToCorrespondingTarget(BasicBlock* ctx, IRBuilder <>& B
955
955
956
956
Value* phi = lookupValueFromCache (BuilderM, ctx, cache);
957
957
958
+
958
959
if (replacePHIs == nullptr ) {
959
960
SwitchInst* swtch = BuilderM.CreateSwitch (phi, *done[std::make_pair (block, si->getDefaultDest ())].begin ());
960
961
for (auto switchcase : si->cases ()) {
@@ -974,6 +975,12 @@ void GradientUtils::branchToCorrespondingTarget(BasicBlock* ctx, IRBuilder <>& B
974
975
}
975
976
val = BuilderM.CreateNot (val);
976
977
}
978
+ if (&*BuilderM.GetInsertPoint () == pair.second ) {
979
+ if (pair.second ->getNextNode ())
980
+ BuilderM.SetInsertPoint (pair.second ->getNextNode ());
981
+ else
982
+ BuilderM.SetInsertPoint (pair.second ->getParent ());
983
+ }
977
984
pair.second ->replaceAllUsesWith (val);
978
985
pair.second ->eraseFromParent ();
979
986
}
@@ -1049,6 +1056,12 @@ void GradientUtils::branchToCorrespondingTarget(BasicBlock* ctx, IRBuilder <>& B
1049
1056
} else {
1050
1057
val = BuilderM.CreateICmpEQ (ConstantInt::get (T, i), which);
1051
1058
}
1059
+ if (&*BuilderM.GetInsertPoint () == found->second ) {
1060
+ if (found->second ->getNextNode ())
1061
+ BuilderM.SetInsertPoint (found->second ->getNextNode ());
1062
+ else
1063
+ BuilderM.SetInsertPoint (found->second ->getParent ());
1064
+ }
1052
1065
found->second ->replaceAllUsesWith (val);
1053
1066
found->second ->eraseFromParent ();
1054
1067
}
0 commit comments