Skip to content

Commit 2f1d93f

Browse files
committed
Avoid using the 'insertvalue' instruction here.
Fast ISel isn't able to handle 'insertvalue' and it causes a large slowdown during -O0 compilation. We don't necessarily need to generate an aggregate of the values here if they're just going to be extracted directly afterwards. <rdar://problem/10530851> llvm-svn: 146481
1 parent 42b99e0 commit 2f1d93f

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

llvm/lib/CodeGen/SjLjEHPrepare.cpp

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ namespace {
6969

7070
private:
7171
bool setupEntryBlockAndCallSites(Function &F);
72+
void substituteLPadValues(LandingPadInst *LPI, Value *ExnVal,
73+
Value *SelVal, IRBuilder<> &Builder);
7274
Value *setupFunctionContext(Function &F, ArrayRef<LandingPadInst*> LPads);
7375
void lowerIncomingArguments(Function &F);
7476
void lowerAcrossUnwindEdges(Function &F, ArrayRef<InvokeInst*> Invokes);
@@ -138,6 +140,36 @@ static void MarkBlocksLiveIn(BasicBlock *BB,
138140
MarkBlocksLiveIn(*PI, LiveBBs);
139141
}
140142

143+
/// substituteLPadValues - Substitute the values returned by the landingpad
144+
/// instruction with those returned by the personality function.
145+
void SjLjEHPass::substituteLPadValues(LandingPadInst *LPI, Value *ExnVal,
146+
Value *SelVal, IRBuilder<> &Builder) {
147+
SmallVector<Value*, 8> UseWorkList(LPI->use_begin(), LPI->use_end());
148+
while (!UseWorkList.empty()) {
149+
Value *Val = UseWorkList.pop_back_val();
150+
ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(Val);
151+
if (!EVI) continue;
152+
if (EVI->getNumIndices() != 1) continue;
153+
if (*EVI->idx_begin() == 0)
154+
EVI->replaceAllUsesWith(ExnVal);
155+
else if (*EVI->idx_begin() == 1)
156+
EVI->replaceAllUsesWith(SelVal);
157+
if (EVI->getNumUses() == 0)
158+
EVI->eraseFromParent();
159+
}
160+
161+
if (LPI->getNumUses() == 0) return;
162+
163+
// There are still some uses of LPI. Construct an aggregate with the exception
164+
// values and replace the LPI with that aggregate.
165+
Type *LPadType = LPI->getType();
166+
Value *LPadVal = UndefValue::get(LPadType);
167+
LPadVal = Builder.CreateInsertValue(LPadVal, ExnVal, 0, "lpad.val");
168+
LPadVal = Builder.CreateInsertValue(LPadVal, SelVal, 1, "lpad.val");
169+
170+
LPI->replaceAllUsesWith(LPadVal);
171+
}
172+
141173
/// setupFunctionContext - Allocate the function context on the stack and fill
142174
/// it with all of the data that we know at this point.
143175
Value *SjLjEHPass::
@@ -189,12 +221,7 @@ setupFunctionContext(Function &F, ArrayRef<LandingPadInst*> LPads) {
189221
ExnVal = Builder.CreateIntToPtr(ExnVal, Type::getInt8PtrTy(F.getContext()));
190222
Value *SelVal = Builder.CreateLoad(SelectorAddr, true, "exn_selector_val");
191223

192-
Type *LPadType = LPI->getType();
193-
Value *LPadVal = UndefValue::get(LPadType);
194-
LPadVal = Builder.CreateInsertValue(LPadVal, ExnVal, 0, "lpad.val");
195-
LPadVal = Builder.CreateInsertValue(LPadVal, SelVal, 1, "lpad.val");
196-
197-
LPI->replaceAllUsesWith(LPadVal);
224+
substituteLPadValues(LPI, ExnVal, SelVal, Builder);
198225
}
199226

200227
// Personality function

0 commit comments

Comments
 (0)