[llvm-commits] [llvm] r151365 - in /llvm/trunk: lib/Transforms/Scalar/GVN.cpp test/Transforms/GVN/commute.ll
Dan Gohman
gohman at apple.com
Fri Feb 24 10:59:37 PST 2012
On Feb 24, 2012, at 7:16 AM, Duncan Sands wrote:
>
> + if (I->isCommutative()) {
> + // Ensure that commutative instructions that only differ by a permutation
> + // of their operands get the same value number by sorting the operand value
> + // numbers. Since all commutative instructions have two operands it is more
> + // efficient to sort by hand rather than using, say, std::sort.
> + assert(I->getNumOperands() == 2 && "Unsupported commutative instruction!");
> + if (e.varargs[0] > e.varargs[1])
> + std::swap(e.varargs[0], e.varargs[1]);
> + }
The reassociate pass already canonicalizes the order of operands in
add instructions. Is it really desirable for GVN to redo it?
>
> if (CmpInst *C = dyn_cast<CmpInst>(I)) {
> - e.opcode = (C->getOpcode() << 8) | C->getPredicate();
> + // Sort the operand value numbers so x<y and y>x get the same value number.
> + CmpInst::Predicate Predicate = C->getPredicate();
> + if (e.varargs[0] > e.varargs[1]) {
> + std::swap(e.varargs[0], e.varargs[1]);
> + Predicate = CmpInst::getSwappedPredicate(Predicate);
> + }
> + e.opcode = (C->getOpcode() << 8) | Predicate;
Reassociate doesn't canonicalize comparisons like it does adds,
but it easily could.
Dan
More information about the llvm-commits
mailing list