[PATCH] D16978: [InstCombine] Try harder to simplify ~(X & Y) -> ~X | ~Y and ~(X | Y) -> ~X & ~Y when X and Y have more than one uses.

Chad Rosier via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 14 13:46:59 PDT 2016


mcrosier added inline comments.

================
Comment at: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:1350
@@ +1349,3 @@
+  // - Constant) - A` if we are willing to invert some of the uses.
+  if (BinaryOperator *BO = dyn_cast<BinaryOperator>(V)) {
+    if (BO->getOpcode() == Instruction::Add ||
----------------
This might read a bit better with something like:

  if (BinaryOperator *BO = dyn_cast<BinaryOperator>(V)) {
    // Must be an 'add' or a 'sub'.
    unsigned Opc = BO->getOpcode();
    if (Opc != Instruction::Add && Opc != Instruction::Sub)
      return false;
    // At least one operand must be a constant.
    if (!isa<Constant>(BO->getOperand(0)) &&
        !isa<Constant>(BO->getOperand(1)))
        return false;
  }

Also, is it not the case that constants are always canonicalized to the RHS, which would mean the check on operands 0 is unnecessary?


http://reviews.llvm.org/D16978





More information about the llvm-commits mailing list