Skip to content

Commit a3a798d

Browse files
committed
[InlineCost] Remove visitUnaryInstruction()
The simplifyInstruction() in visitUnaryInstruction() does not trigger for all of check-llvm. Looking at all delegates to UnaryInstruction in InstVisitor, the only instructions that either don't have a visitor in CallAnalyzer, or redirect to UnaryInstruction, are VAArgInst and Alloca. VAArgInst will never get simplified, and visitUnaryInstruction(Alloca) would always return false anyway. Reviewed By: mtrofin, lebedev.ri Differential Revision: https://reviews.llvm.org/D101577
1 parent 544be70 commit a3a798d

File tree

1 file changed

+7
-23
lines changed

1 file changed

+7
-23
lines changed

llvm/lib/Analysis/InlineCost.cpp

+7-23
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
390390
bool visitPtrToInt(PtrToIntInst &I);
391391
bool visitIntToPtr(IntToPtrInst &I);
392392
bool visitCastInst(CastInst &I);
393-
bool visitUnaryInstruction(UnaryInstruction &I);
394393
bool visitCmpInst(CmpInst &I);
395394
bool visitSub(BinaryOperator &I);
396395
bool visitBinaryOperator(BinaryOperator &I);
@@ -1040,6 +1039,8 @@ bool CallAnalyzer::isGEPFree(GetElementPtrInst &GEP) {
10401039
}
10411040

10421041
bool CallAnalyzer::visitAlloca(AllocaInst &I) {
1042+
disableSROA(I.getOperand(0));
1043+
10431044
// Check whether inlining will turn a dynamic alloca into a static
10441045
// alloca and handle that case.
10451046
if (I.isArrayAllocation()) {
@@ -1057,11 +1058,9 @@ bool CallAnalyzer::visitAlloca(AllocaInst &I) {
10571058
AllocatedSize = SaturatingMultiplyAdd(
10581059
AllocSize->getLimitedValue(), DL.getTypeAllocSize(Ty).getKnownMinSize(),
10591060
AllocatedSize);
1060-
if (AllocatedSize > InlineConstants::MaxSimplifiedDynamicAllocaToInline) {
1061+
if (AllocatedSize > InlineConstants::MaxSimplifiedDynamicAllocaToInline)
10611062
HasDynamicAlloca = true;
1062-
return false;
1063-
}
1064-
return Base::visitAlloca(I);
1063+
return false;
10651064
}
10661065
}
10671066

@@ -1072,15 +1071,13 @@ bool CallAnalyzer::visitAlloca(AllocaInst &I) {
10721071
SaturatingAdd(DL.getTypeAllocSize(Ty).getKnownMinSize(), AllocatedSize);
10731072
}
10741073

1075-
// We will happily inline static alloca instructions.
1076-
if (I.isStaticAlloca())
1077-
return Base::visitAlloca(I);
1078-
10791074
// FIXME: This is overly conservative. Dynamic allocas are inefficient for
10801075
// a variety of reasons, and so we would like to not inline them into
10811076
// functions which don't currently have a dynamic alloca. This simply
10821077
// disables inlining altogether in the presence of a dynamic alloca.
1083-
HasDynamicAlloca = true;
1078+
if (!I.isStaticAlloca())
1079+
HasDynamicAlloca = true;
1080+
10841081
return false;
10851082
}
10861083

@@ -1367,19 +1364,6 @@ bool CallAnalyzer::visitCastInst(CastInst &I) {
13671364
TargetTransformInfo::TCC_Free;
13681365
}
13691366

1370-
bool CallAnalyzer::visitUnaryInstruction(UnaryInstruction &I) {
1371-
Value *Operand = I.getOperand(0);
1372-
if (simplifyInstruction(I, [&](SmallVectorImpl<Constant *> &COps) {
1373-
return ConstantFoldInstOperands(&I, COps[0], DL);
1374-
}))
1375-
return true;
1376-
1377-
// Disable any SROA on the argument to arbitrary unary instructions.
1378-
disableSROA(Operand);
1379-
1380-
return false;
1381-
}
1382-
13831367
bool CallAnalyzer::paramHasAttr(Argument *A, Attribute::AttrKind Attr) {
13841368
return CandidateCall.paramHasAttr(A->getArgNo(), Attr);
13851369
}

0 commit comments

Comments
 (0)