From fc27e25a6ef7afa604bd126660515f1db2f33db2 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 16 Oct 2008 01:24:45 +0000 Subject: [PATCH] Fix Instruction::isIdenticalTo and isSameOperationAs to recognize additional information in Loads, Stores, Calls, Invokes, InsertValueInsts, and ExtractValueInsts. llvm-svn: 57620 --- llvm/lib/VMCore/Instruction.cpp | 63 +++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 6 deletions(-) diff --git a/llvm/lib/VMCore/Instruction.cpp b/llvm/lib/VMCore/Instruction.cpp index 067a4bb639f8..01b69cad2afd 100644 --- a/llvm/lib/VMCore/Instruction.cpp +++ b/llvm/lib/VMCore/Instruction.cpp @@ -172,13 +172,39 @@ bool Instruction::isIdenticalTo(Instruction *I) const { // Check special state that is a part of some instructions. if (const LoadInst *LI = dyn_cast(this)) - return LI->isVolatile() == cast(I)->isVolatile(); + return LI->isVolatile() == cast(I)->isVolatile() && + LI->getAlignment() == cast(I)->getAlignment(); if (const StoreInst *SI = dyn_cast(this)) - return SI->isVolatile() == cast(I)->isVolatile(); + return SI->isVolatile() == cast(I)->isVolatile() && + SI->getAlignment() == cast(I)->getAlignment(); if (const CmpInst *CI = dyn_cast(this)) return CI->getPredicate() == cast(I)->getPredicate(); if (const CallInst *CI = dyn_cast(this)) - return CI->isTailCall() == cast(I)->isTailCall(); + return CI->isTailCall() == cast(I)->isTailCall() && + CI->getCallingConv() == cast(I)->getCallingConv() && + CI->getAttributes().getRawPointer() == + cast(I)->getAttributes().getRawPointer(); + if (const InvokeInst *CI = dyn_cast(this)) + return CI->getCallingConv() == cast(I)->getCallingConv() && + CI->getAttributes().getRawPointer() == + cast(I)->getAttributes().getRawPointer(); + if (const InsertValueInst *IVI = dyn_cast(this)) { + if (IVI->getNumIndices() != cast(I)->getNumIndices()) + return false; + for (unsigned i = 0, e = IVI->getNumIndices(); i != e; ++i) + if (IVI->idx_begin()[i] != cast(I)->idx_begin()[i]) + return false; + return true; + } + if (const ExtractValueInst *EVI = dyn_cast(this)) { + if (EVI->getNumIndices() != cast(I)->getNumIndices()) + return false; + for (unsigned i = 0, e = EVI->getNumIndices(); i != e; ++i) + if (EVI->idx_begin()[i] != cast(I)->idx_begin()[i]) + return false; + return true; + } + return true; } @@ -196,13 +222,38 @@ bool Instruction::isSameOperationAs(Instruction *I) const { // Check special state that is a part of some instructions. if (const LoadInst *LI = dyn_cast(this)) - return LI->isVolatile() == cast(I)->isVolatile(); + return LI->isVolatile() == cast(I)->isVolatile() && + LI->getAlignment() == cast(I)->getAlignment(); if (const StoreInst *SI = dyn_cast(this)) - return SI->isVolatile() == cast(I)->isVolatile(); + return SI->isVolatile() == cast(I)->isVolatile() && + SI->getAlignment() == cast(I)->getAlignment(); if (const CmpInst *CI = dyn_cast(this)) return CI->getPredicate() == cast(I)->getPredicate(); if (const CallInst *CI = dyn_cast(this)) - return CI->isTailCall() == cast(I)->isTailCall(); + return CI->isTailCall() == cast(I)->isTailCall() && + CI->getCallingConv() == cast(I)->getCallingConv() && + CI->getAttributes().getRawPointer() == + cast(I)->getAttributes().getRawPointer(); + if (const InvokeInst *CI = dyn_cast(this)) + return CI->getCallingConv() == cast(I)->getCallingConv() && + CI->getAttributes().getRawPointer() == + cast(I)->getAttributes().getRawPointer(); + if (const InsertValueInst *IVI = dyn_cast(this)) { + if (IVI->getNumIndices() != cast(I)->getNumIndices()) + return false; + for (unsigned i = 0, e = IVI->getNumIndices(); i != e; ++i) + if (IVI->idx_begin()[i] != cast(I)->idx_begin()[i]) + return false; + return true; + } + if (const ExtractValueInst *EVI = dyn_cast(this)) { + if (EVI->getNumIndices() != cast(I)->getNumIndices()) + return false; + for (unsigned i = 0, e = EVI->getNumIndices(); i != e; ++i) + if (EVI->idx_begin()[i] != cast(I)->idx_begin()[i]) + return false; + return true; + } return true; }