Skip to content

Commit

Permalink
Revert "[IRSim] Adding support for isomorphic predicates"
Browse files Browse the repository at this point in the history
Reverting due to unit test errors between commits.

This reverts commit 0503926.
  • Loading branch information
AndrewLitteken committed Dec 23, 2020
1 parent 47877c9 commit 45a4f34
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 400 deletions.
22 changes: 0 additions & 22 deletions llvm/include/llvm/Analysis/IRSimilarityIdentifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,29 +122,13 @@ struct IRInstructionData : ilist_node<IRInstructionData> {
/// considered similar.
bool Legal;

/// This is only relevant if we are wrapping a CmpInst where we needed to
/// change the predicate of a compare instruction from a greater than form
/// to a less than form. It is None otherwise.
Optional<CmpInst::Predicate> RevisedPredicate;

/// Gather the information that is difficult to gather for an Instruction, or
/// is changed. i.e. the operands of an Instruction and the Types of those
/// operands. This extra information allows for similarity matching to make
/// assertions that allow for more flexibility when checking for whether an
/// Instruction performs the same operation.
IRInstructionData(Instruction &I, bool Legality, IRInstructionDataList &IDL);

/// Get the predicate that the compare instruction is using for hashing the
/// instruction. the IRInstructionData must be wrapping a CmpInst.
CmpInst::Predicate getPredicate() const;

/// A function that swaps the predicates to their less than form if they are
/// in a greater than form. Otherwise, the predicate is unchanged.
///
/// \param CI - The comparison operation to find a consistent preidcate for.
/// \return the consistent comparison predicate.
static CmpInst::Predicate predicateForConsistency(CmpInst *CI);

/// Hashes \p Value based on its opcode, types, and operand types.
/// Two IRInstructionData instances produce the same hash when they perform
/// the same operation.
Expand Down Expand Up @@ -177,12 +161,6 @@ struct IRInstructionData : ilist_node<IRInstructionData> {
for (Value *V : ID.OperVals)
OperTypes.push_back(V->getType());

if (isa<CmpInst>(ID.Inst))
return llvm::hash_combine(
llvm::hash_value(ID.Inst->getOpcode()),
llvm::hash_value(ID.Inst->getType()),
llvm::hash_value(ID.getPredicate()),
llvm::hash_combine_range(OperTypes.begin(), OperTypes.end()));
return llvm::hash_combine(
llvm::hash_value(ID.Inst->getOpcode()),
llvm::hash_value(ID.Inst->getType()),
Expand Down
77 changes: 4 additions & 73 deletions llvm/lib/Analysis/IRSimilarityIdentifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,84 +26,15 @@ using namespace IRSimilarity;
IRInstructionData::IRInstructionData(Instruction &I, bool Legality,
IRInstructionDataList &IDList)
: Inst(&I), Legal(Legality), IDL(&IDList) {
// We check for whether we have a comparison instruction. If it is, we
// find the "less than" version of the predicate for consistency for
// comparison instructions throught the program.
if (CmpInst *C = dyn_cast<CmpInst>(&I)) {
CmpInst::Predicate Predicate = predicateForConsistency(C);
if (Predicate != C->getPredicate())
RevisedPredicate = Predicate;
}

// Here we collect the operands and their types for determining whether
// the structure of the operand use matches between two different candidates.
for (Use &OI : I.operands()) {
if (isa<CmpInst>(I) && RevisedPredicate.hasValue()) {
// If we have a CmpInst where the predicate is reversed, it means the
// operands must be reversed as well.
OperVals.insert(OperVals.begin(), OI.get());
continue;
}

// Here we collect the operands to be used to determine whether two
// instructions are similar to one another.
for (Use &OI : I.operands())
OperVals.push_back(OI.get());
}
}

CmpInst::Predicate IRInstructionData::predicateForConsistency(CmpInst *CI) {
switch (CI->getPredicate()) {
case CmpInst::FCMP_OGT:
case CmpInst::FCMP_UGT:
case CmpInst::FCMP_OGE:
case CmpInst::FCMP_UGE:
case CmpInst::ICMP_SGT:
case CmpInst::ICMP_UGT:
case CmpInst::ICMP_SGE:
case CmpInst::ICMP_UGE:
return CI->getSwappedPredicate();
default:
return CI->getPredicate();
}
}

CmpInst::Predicate IRInstructionData::getPredicate() const {
assert(isa<CmpInst>(Inst) &&
"Can only get a predicate from a compare instruction");

if (RevisedPredicate.hasValue())
return RevisedPredicate.getValue();

return cast<CmpInst>(Inst)->getPredicate();
}

bool IRSimilarity::isClose(const IRInstructionData &A,
const IRInstructionData &B) {

if (!A.Legal || !B.Legal)
return false;

// Check if we are performing the same sort of operation on the same types
// but not on the same values.
if (A.Inst->isSameOperationAs(B.Inst))
return true;

// If there is a predicate, this means that either there is a swapped
// predicate, or that the types are different, we want to make sure that
// the predicates are equivalent via swapping.
if (isa<CmpInst>(A.Inst) && isa<CmpInst>(B.Inst)) {

if (A.getPredicate() != B.getPredicate())
return false;

// If the predicates are the same via swap, make sure that the types are
// still the same.
auto ZippedTypes = zip(A.OperVals, B.OperVals);

return all_of(ZippedTypes, [](std::tuple<llvm::Value *, llvm::Value *> R) {
return std::get<0>(R)->getType() == std::get<1>(R)->getType();
});
}

return false;
return A.Legal && A.Inst->isSameOperationAs(B.Inst);
}

// TODO: This is the same as the MachineOutliner, and should be consolidated
Expand Down
170 changes: 0 additions & 170 deletions llvm/test/Transforms/IROutliner/outlining-isomorphic-predicates.ll

This file was deleted.

Loading

0 comments on commit 45a4f34

Please sign in to comment.