[PATCH] D37019: Add select simplifications

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 22 17:51:55 PDT 2017


craig.topper added a comment.

I was only asking about using this portion of simplifyUsingDistributiveLaws

  // (op (select (a, c, b)), (select (a, d, b))) -> (select (a, (op c, d), 0))
  // (op (select (a, b, c)), (select (a, b, d))) -> (select (a, 0, (op c, d)))
  if (auto *SI0 = dyn_cast<SelectInst>(LHS)) {
    if (auto *SI1 = dyn_cast<SelectInst>(RHS)) {
      if (SI0->getCondition() == SI1->getCondition()) {
        Value *SI = nullptr;
        if (Value *V =
                SimplifyBinOp(TopLevelOpcode, SI0->getFalseValue(),
                              SI1->getFalseValue(), SQ.getWithInstruction(&I)))
          SI = Builder.CreateSelect(SI0->getCondition(),
                                    Builder.CreateBinOp(TopLevelOpcode,
                                                        SI0->getTrueValue(),
                                                        SI1->getTrueValue()),
                                    V);
        if (Value *V =
                SimplifyBinOp(TopLevelOpcode, SI0->getTrueValue(),
                              SI1->getTrueValue(), SQ.getWithInstruction(&I)))
          SI = Builder.CreateSelect(
              SI0->getCondition(), V,
              Builder.CreateBinOp(TopLevelOpcode, SI0->getFalseValue(),
                                  SI1->getFalseValue()));
        if (SI) {
          SI->takeName(&I);
          return SI;
        }
      }
    }
  }

And since that's defering all of the intelligence to InstSimplify, I really hope its safe without fastmath. And it would never create a new instruction because InstSimplify isn't alllowed to. I believe it would also handle "select C, 0, B + select C, A, 0 -> select C, A, B"


https://reviews.llvm.org/D37019





More information about the llvm-commits mailing list