diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp --- a/llvm/lib/Transforms/Scalar/NewGVN.cpp +++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp @@ -774,7 +774,7 @@ // Symbolic evaluation. ExprResult checkExprResults(Expression *, Instruction *, Value *) const; - ExprResult performSymbolicEvaluation(Value *, + ExprResult performSymbolicEvaluation(Instruction *, SmallPtrSetImpl &) const; const Expression *performSymbolicLoadCoercion(Type *, Value *, LoadInst *, Instruction *, @@ -1961,95 +1961,88 @@ return createExpression(I); } -// Substitute and symbolize the value before value numbering. +// Substitute and symbolize the instruction before value numbering. NewGVN::ExprResult -NewGVN::performSymbolicEvaluation(Value *V, +NewGVN::performSymbolicEvaluation(Instruction *I, SmallPtrSetImpl &Visited) const { const Expression *E = nullptr; - if (auto *C = dyn_cast(V)) - E = createConstantExpression(C); - else if (isa(V) || isa(V)) { - E = createVariableExpression(V); - } else { - // TODO: memory intrinsics. - // TODO: Some day, we should do the forward propagation and reassociation - // parts of the algorithm. - auto *I = cast(V); - switch (I->getOpcode()) { - case Instruction::ExtractValue: - case Instruction::InsertValue: - E = performSymbolicAggrValueEvaluation(I); - break; - case Instruction::PHI: { - SmallVector Ops; - auto *PN = cast(I); - for (unsigned i = 0; i < PN->getNumOperands(); ++i) - Ops.push_back({PN->getIncomingValue(i), PN->getIncomingBlock(i)}); - // Sort to ensure the invariant createPHIExpression requires is met. - sortPHIOps(Ops); - E = performSymbolicPHIEvaluation(Ops, I, getBlockForValue(I)); - } break; - case Instruction::Call: - return performSymbolicCallEvaluation(I); - break; - case Instruction::Store: - E = performSymbolicStoreEvaluation(I); - break; - case Instruction::Load: - E = performSymbolicLoadEvaluation(I); - break; - case Instruction::BitCast: - case Instruction::AddrSpaceCast: - case Instruction::Freeze: - return createExpression(I); - break; - case Instruction::ICmp: - case Instruction::FCmp: - return performSymbolicCmpEvaluation(I); - break; - case Instruction::FNeg: - case Instruction::Add: - case Instruction::FAdd: - case Instruction::Sub: - case Instruction::FSub: - case Instruction::Mul: - case Instruction::FMul: - case Instruction::UDiv: - case Instruction::SDiv: - case Instruction::FDiv: - case Instruction::URem: - case Instruction::SRem: - case Instruction::FRem: - case Instruction::Shl: - case Instruction::LShr: - case Instruction::AShr: - case Instruction::And: - case Instruction::Or: - case Instruction::Xor: - case Instruction::Trunc: - case Instruction::ZExt: - case Instruction::SExt: - case Instruction::FPToUI: - case Instruction::FPToSI: - case Instruction::UIToFP: - case Instruction::SIToFP: - case Instruction::FPTrunc: - case Instruction::FPExt: - case Instruction::PtrToInt: - case Instruction::IntToPtr: - case Instruction::Select: - case Instruction::ExtractElement: - case Instruction::InsertElement: - case Instruction::GetElementPtr: - return createExpression(I); - break; - case Instruction::ShuffleVector: - // FIXME: Add support for shufflevector to createExpression. - return ExprResult::none(); - default: - return ExprResult::none(); - } + // TODO: memory intrinsics. + // TODO: Some day, we should do the forward propagation and reassociation + // parts of the algorithm. + switch (I->getOpcode()) { + case Instruction::ExtractValue: + case Instruction::InsertValue: + E = performSymbolicAggrValueEvaluation(I); + break; + case Instruction::PHI: { + SmallVector Ops; + auto *PN = cast(I); + for (unsigned i = 0; i < PN->getNumOperands(); ++i) + Ops.push_back({PN->getIncomingValue(i), PN->getIncomingBlock(i)}); + // Sort to ensure the invariant createPHIExpression requires is met. + sortPHIOps(Ops); + E = performSymbolicPHIEvaluation(Ops, I, getBlockForValue(I)); + } break; + case Instruction::Call: + return performSymbolicCallEvaluation(I); + break; + case Instruction::Store: + E = performSymbolicStoreEvaluation(I); + break; + case Instruction::Load: + E = performSymbolicLoadEvaluation(I); + break; + case Instruction::BitCast: + case Instruction::AddrSpaceCast: + case Instruction::Freeze: + return createExpression(I); + break; + case Instruction::ICmp: + case Instruction::FCmp: + return performSymbolicCmpEvaluation(I); + break; + case Instruction::FNeg: + case Instruction::Add: + case Instruction::FAdd: + case Instruction::Sub: + case Instruction::FSub: + case Instruction::Mul: + case Instruction::FMul: + case Instruction::UDiv: + case Instruction::SDiv: + case Instruction::FDiv: + case Instruction::URem: + case Instruction::SRem: + case Instruction::FRem: + case Instruction::Shl: + case Instruction::LShr: + case Instruction::AShr: + case Instruction::And: + case Instruction::Or: + case Instruction::Xor: + case Instruction::Trunc: + case Instruction::ZExt: + case Instruction::SExt: + case Instruction::FPToUI: + case Instruction::FPToSI: + case Instruction::UIToFP: + case Instruction::SIToFP: + case Instruction::FPTrunc: + case Instruction::FPExt: + case Instruction::PtrToInt: + case Instruction::IntToPtr: + case Instruction::Select: + case Instruction::ExtractElement: + case Instruction::InsertElement: + case Instruction::GetElementPtr: + return createExpression(I); + break; + case Instruction::ShuffleVector: + // FIXME: Add support for shufflevector to createExpression. + return ExprResult::none(); + default: + return ExprResult::none(); } return ExprResult::some(E); }