diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp --- a/llvm/lib/IR/Instruction.cpp +++ b/llvm/lib/IR/Instruction.cpp @@ -408,6 +408,9 @@ bool IgnoreAlignment = false) { assert(I1->getOpcode() == I2->getOpcode() && "Can not compare special state of different instructions"); + assert(I1->getNumOperands() == I2->getNumOperands() && + "Can not compare special state of instructions with different number " + "of operands"); if (const AllocaInst *AI = dyn_cast(I1)) return AI->getAllocatedType() == cast(I2)->getAllocatedType() && @@ -464,8 +467,59 @@ if (const ShuffleVectorInst *SVI = dyn_cast(I1)) return SVI->getShuffleMask() == cast(I2)->getShuffleMask(); - - return true; + if (const ReturnInst *RI = dyn_cast(I1)) { + if (RI->getReturnValue() != nullptr) + return RI->getReturnValue()->getType() == + cast(I2)->getReturnValue()->getType(); + else + return cast(I2)->getReturnValue() == nullptr; + } + if (const BranchInst *BI = dyn_cast(I1)) + return BI->isConditional() == cast(I2)->isConditional(); + if (const SwitchInst *SI = dyn_cast(I1)) + return SI->getCondition()->getType() == + cast(I2)->getCondition()->getType(); + if (const IndirectBrInst *IBI = dyn_cast(I1)) + return true; + if (const ResumeInst *RI = dyn_cast(I1)) + return RI->getValue()->getType() == + cast(I2)->getValue()->getType(); + if (const CatchSwitchInst *CSI = dyn_cast(I1)) + return CSI->unwindsToCaller() == + cast(I2)->unwindsToCaller(); + if (const CatchReturnInst *CRI = dyn_cast(I1)) + return true; + if (const CleanupReturnInst *CRI = dyn_cast(I1)) + return CRI->unwindsToCaller() == + cast(I2)->unwindsToCaller(); + if (const UnreachableInst *UI = dyn_cast(I1)) + return true; + if (const UnaryOperator *UI = dyn_cast(I1)) + return true; + if (const BinaryOperator *BI = dyn_cast(I1)) + return true; + if (const GetElementPtrInst *GEP1 = dyn_cast(I1)) + return GEP1->isInBounds() == cast(I2)->isInBounds(); + if (const CastInst *CI = dyn_cast(I1)) + return true; + if (const CleanupPadInst *CI = dyn_cast(I1)) + return true; + if (const CatchPadInst *CPI = dyn_cast(I1)) + return haveSameSpecialState(CPI->getCatchSwitch(), + cast(I2)->getCatchSwitch()); + if (const PHINode *PI = dyn_cast(I1)) + return true; + if (const SelectInst *SI = dyn_cast(I1)) + return true; + if (const VAArgInst *VI = dyn_cast(I1)) + return true; + if (const ExtractElementInst *EI = dyn_cast(I1)) + return true; + if (const InsertElementInst *II = dyn_cast(I1)) + return true; + if (const LandingPadInst *LI = dyn_cast(I1)) + return LI->isCleanup() == cast(I2)->isCleanup(); + llvm_unreachable("Instructions to compare are unknown"); } bool Instruction::isIdenticalTo(const Instruction *I) const {