Skip to content

Commit b80ff2f

Browse files
committed
[NewGVN] Only perform symbolic evaluation on instructions (NFC)
This patch restricts the argument of performSymbolicEvaluation to an Instruction and simplifies the code accordingly. Differential Revision: https://reviews.llvm.org/D156994
1 parent 1cf970d commit b80ff2f

File tree

1 file changed

+79
-86
lines changed

1 file changed

+79
-86
lines changed

llvm/lib/Transforms/Scalar/NewGVN.cpp

Lines changed: 79 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ class NewGVN {
774774

775775
// Symbolic evaluation.
776776
ExprResult checkExprResults(Expression *, Instruction *, Value *) const;
777-
ExprResult performSymbolicEvaluation(Value *,
777+
ExprResult performSymbolicEvaluation(Instruction *,
778778
SmallPtrSetImpl<Value *> &) const;
779779
const Expression *performSymbolicLoadCoercion(Type *, Value *, LoadInst *,
780780
Instruction *,
@@ -1961,95 +1961,88 @@ NewGVN::ExprResult NewGVN::performSymbolicCmpEvaluation(Instruction *I) const {
19611961
return createExpression(I);
19621962
}
19631963

1964-
// Substitute and symbolize the value before value numbering.
1964+
// Substitute and symbolize the instruction before value numbering.
19651965
NewGVN::ExprResult
1966-
NewGVN::performSymbolicEvaluation(Value *V,
1966+
NewGVN::performSymbolicEvaluation(Instruction *I,
19671967
SmallPtrSetImpl<Value *> &Visited) const {
19681968

19691969
const Expression *E = nullptr;
1970-
if (auto *C = dyn_cast<Constant>(V))
1971-
E = createConstantExpression(C);
1972-
else if (isa<Argument>(V) || isa<GlobalVariable>(V)) {
1973-
E = createVariableExpression(V);
1974-
} else {
1975-
// TODO: memory intrinsics.
1976-
// TODO: Some day, we should do the forward propagation and reassociation
1977-
// parts of the algorithm.
1978-
auto *I = cast<Instruction>(V);
1979-
switch (I->getOpcode()) {
1980-
case Instruction::ExtractValue:
1981-
case Instruction::InsertValue:
1982-
E = performSymbolicAggrValueEvaluation(I);
1983-
break;
1984-
case Instruction::PHI: {
1985-
SmallVector<ValPair, 3> Ops;
1986-
auto *PN = cast<PHINode>(I);
1987-
for (unsigned i = 0; i < PN->getNumOperands(); ++i)
1988-
Ops.push_back({PN->getIncomingValue(i), PN->getIncomingBlock(i)});
1989-
// Sort to ensure the invariant createPHIExpression requires is met.
1990-
sortPHIOps(Ops);
1991-
E = performSymbolicPHIEvaluation(Ops, I, getBlockForValue(I));
1992-
} break;
1993-
case Instruction::Call:
1994-
return performSymbolicCallEvaluation(I);
1995-
break;
1996-
case Instruction::Store:
1997-
E = performSymbolicStoreEvaluation(I);
1998-
break;
1999-
case Instruction::Load:
2000-
E = performSymbolicLoadEvaluation(I);
2001-
break;
2002-
case Instruction::BitCast:
2003-
case Instruction::AddrSpaceCast:
2004-
case Instruction::Freeze:
2005-
return createExpression(I);
2006-
break;
2007-
case Instruction::ICmp:
2008-
case Instruction::FCmp:
2009-
return performSymbolicCmpEvaluation(I);
2010-
break;
2011-
case Instruction::FNeg:
2012-
case Instruction::Add:
2013-
case Instruction::FAdd:
2014-
case Instruction::Sub:
2015-
case Instruction::FSub:
2016-
case Instruction::Mul:
2017-
case Instruction::FMul:
2018-
case Instruction::UDiv:
2019-
case Instruction::SDiv:
2020-
case Instruction::FDiv:
2021-
case Instruction::URem:
2022-
case Instruction::SRem:
2023-
case Instruction::FRem:
2024-
case Instruction::Shl:
2025-
case Instruction::LShr:
2026-
case Instruction::AShr:
2027-
case Instruction::And:
2028-
case Instruction::Or:
2029-
case Instruction::Xor:
2030-
case Instruction::Trunc:
2031-
case Instruction::ZExt:
2032-
case Instruction::SExt:
2033-
case Instruction::FPToUI:
2034-
case Instruction::FPToSI:
2035-
case Instruction::UIToFP:
2036-
case Instruction::SIToFP:
2037-
case Instruction::FPTrunc:
2038-
case Instruction::FPExt:
2039-
case Instruction::PtrToInt:
2040-
case Instruction::IntToPtr:
2041-
case Instruction::Select:
2042-
case Instruction::ExtractElement:
2043-
case Instruction::InsertElement:
2044-
case Instruction::GetElementPtr:
2045-
return createExpression(I);
2046-
break;
2047-
case Instruction::ShuffleVector:
2048-
// FIXME: Add support for shufflevector to createExpression.
2049-
return ExprResult::none();
2050-
default:
2051-
return ExprResult::none();
2052-
}
1970+
// TODO: memory intrinsics.
1971+
// TODO: Some day, we should do the forward propagation and reassociation
1972+
// parts of the algorithm.
1973+
switch (I->getOpcode()) {
1974+
case Instruction::ExtractValue:
1975+
case Instruction::InsertValue:
1976+
E = performSymbolicAggrValueEvaluation(I);
1977+
break;
1978+
case Instruction::PHI: {
1979+
SmallVector<ValPair, 3> Ops;
1980+
auto *PN = cast<PHINode>(I);
1981+
for (unsigned i = 0; i < PN->getNumOperands(); ++i)
1982+
Ops.push_back({PN->getIncomingValue(i), PN->getIncomingBlock(i)});
1983+
// Sort to ensure the invariant createPHIExpression requires is met.
1984+
sortPHIOps(Ops);
1985+
E = performSymbolicPHIEvaluation(Ops, I, getBlockForValue(I));
1986+
} break;
1987+
case Instruction::Call:
1988+
return performSymbolicCallEvaluation(I);
1989+
break;
1990+
case Instruction::Store:
1991+
E = performSymbolicStoreEvaluation(I);
1992+
break;
1993+
case Instruction::Load:
1994+
E = performSymbolicLoadEvaluation(I);
1995+
break;
1996+
case Instruction::BitCast:
1997+
case Instruction::AddrSpaceCast:
1998+
case Instruction::Freeze:
1999+
return createExpression(I);
2000+
break;
2001+
case Instruction::ICmp:
2002+
case Instruction::FCmp:
2003+
return performSymbolicCmpEvaluation(I);
2004+
break;
2005+
case Instruction::FNeg:
2006+
case Instruction::Add:
2007+
case Instruction::FAdd:
2008+
case Instruction::Sub:
2009+
case Instruction::FSub:
2010+
case Instruction::Mul:
2011+
case Instruction::FMul:
2012+
case Instruction::UDiv:
2013+
case Instruction::SDiv:
2014+
case Instruction::FDiv:
2015+
case Instruction::URem:
2016+
case Instruction::SRem:
2017+
case Instruction::FRem:
2018+
case Instruction::Shl:
2019+
case Instruction::LShr:
2020+
case Instruction::AShr:
2021+
case Instruction::And:
2022+
case Instruction::Or:
2023+
case Instruction::Xor:
2024+
case Instruction::Trunc:
2025+
case Instruction::ZExt:
2026+
case Instruction::SExt:
2027+
case Instruction::FPToUI:
2028+
case Instruction::FPToSI:
2029+
case Instruction::UIToFP:
2030+
case Instruction::SIToFP:
2031+
case Instruction::FPTrunc:
2032+
case Instruction::FPExt:
2033+
case Instruction::PtrToInt:
2034+
case Instruction::IntToPtr:
2035+
case Instruction::Select:
2036+
case Instruction::ExtractElement:
2037+
case Instruction::InsertElement:
2038+
case Instruction::GetElementPtr:
2039+
return createExpression(I);
2040+
break;
2041+
case Instruction::ShuffleVector:
2042+
// FIXME: Add support for shufflevector to createExpression.
2043+
return ExprResult::none();
2044+
default:
2045+
return ExprResult::none();
20532046
}
20542047
return ExprResult::some(E);
20552048
}

0 commit comments

Comments
 (0)