@@ -169,7 +169,6 @@ bool RISCVPromoteConstant::runOnFunction(Function &F,
169169 for (Use *U : Uses) {
170170 Instruction *UserInst = cast<Instruction>(U->getUser ());
171171 BasicBlock *InsertionBB;
172- BasicBlock::iterator InsertionPt;
173172
174173 // If the user is a PHI node, we must insert the load in the
175174 // corresponding predecessor basic block. Otherwise, it's inserted into
@@ -179,9 +178,11 @@ bool RISCVPromoteConstant::runOnFunction(Function &F,
179178 else
180179 InsertionBB = UserInst->getParent ();
181180
182- // It is always safe to insert in the first insertion point in the BB,
183- // so do that and let other passes reorder.
184- InsertionPt = InsertionBB->getFirstInsertionPt ();
181+ if (isa<CatchSwitchInst>(InsertionBB->getTerminator ())) {
182+ LLVM_DEBUG (dbgs () << " Bailing out: catchswitch means thre is no valid "
183+ " insertion point.\n " );
184+ return false ;
185+ }
185186
186187 auto CacheKey = std::make_pair (Const, InsertionBB);
187188 Value *LoadedVal = nullptr ;
@@ -191,7 +192,9 @@ bool RISCVPromoteConstant::runOnFunction(Function &F,
191192 LoadedVal = LocalLoads.at (CacheKey);
192193 } else {
193194 // Otherwise, create a new GEP and Load at the correct insertion point.
194- IRBuilder<> Builder (InsertionBB, InsertionPt);
195+ // It is always safe to insert in the first insertion point in the BB,
196+ // so do that and let other passes reorder.
197+ IRBuilder<> Builder (InsertionBB, InsertionBB->getFirstInsertionPt ());
195198 Value *ElementPtr = Builder.CreateConstInBoundsGEP2_64 (
196199 GlobalArray->getValueType (), GlobalArray, 0 , Idx, " double.addr" );
197200 LoadedVal = Builder.CreateLoad (DoubleTy, ElementPtr, " double.val" );
0 commit comments