#include "llvm/Instructions.h"
#include "llvm/Pass.h"
#include "llvm/Type.h"
+#include "llvm/Support/Compiler.h"
using namespace llvm;
// Register the ValueNumbering interface, providing a nice name to refer to.
/// lexically identical expressions. This does not require any ahead of time
/// analysis, so it is a very fast default implementation.
///
- struct BasicVN : public ImmutablePass, public ValueNumbering {
+ struct VISIBILITY_HIDDEN BasicVN
+ : public ImmutablePass, public ValueNumbering {
/// getEqualNumberNodes - Return nodes with the same value number as the
/// specified Value. This fills in the argument vector with any equal
/// values.
/// BVNImpl - Implement BasicVN in terms of a visitor class that
/// handles the different types of instructions as appropriate.
///
- struct BVNImpl : public InstVisitor<BVNImpl> {
+ struct VISIBILITY_HIDDEN BVNImpl : public InstVisitor<BVNImpl> {
std::vector<Value*> &RetVals;
BVNImpl(std::vector<Value*> &RV) : RetVals(RV) {}
for (Value::use_iterator UI = Op->use_begin(), UE = Op->use_end();
UI != UE; ++UI)
if (CastInst *Other = dyn_cast<CastInst>(*UI))
- // Check that the types are the same, since this code handles casts...
- if (Other->getType() == I.getType() &&
+ // Check that the opcode is the same
+ if (Other->getOpcode() == Instruction::CastOps(I.getOpcode()) &&
+ // Check that the destination types are the same
+ Other->getType() == I.getType() &&
// Is it embedded in the same function? (This could be false if LHS
// is a constant or global!)
Other->getParent()->getParent() == F &&
I1.getParent()->getParent() != I2->getParent()->getParent())
return false;
+ // If they are CmpInst instructions, check their predicates
+ if (CmpInst *CI1 = dyn_cast<CmpInst>(&const_cast<Instruction&>(I1)))
+ if (CI1->getPredicate() != cast<CmpInst>(I2)->getPredicate())
+ return false;
+
// They are identical if both operands are the same!
if (I1.getOperand(0) == I2->getOperand(0) &&
I1.getOperand(1) == I2->getOperand(1))