[PATCH] D16836: [CodeGenPrepare] Don't transform select instructions into branches when both of operands are cheap

Junmo Park via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 2 23:59:56 PST 2016


flyingforyou added a comment.

  // Sink expensive instructions into the conditional blocks to avoid executing
  // them speculatively.
  if (sinkSelectOperand(TTI, SI->getTrueValue())) {
    TrueBlock = BasicBlock::Create(SI->getContext(), "select.true.sink",
                                   EndBlock->getParent(), EndBlock);
    auto *TrueBranch = BranchInst::Create(EndBlock, TrueBlock);
    auto *TrueInst = cast<Instruction>(SI->getTrueValue());
    TrueInst->moveBefore(TrueBranch);
  }
  if (sinkSelectOperand(TTI, SI->getFalseValue())) {
    FalseBlock = BasicBlock::Create(SI->getContext(), "select.false.sink",
                                    EndBlock->getParent(), EndBlock);
    auto *FalseBranch = BranchInst::Create(EndBlock, FalseBlock);
    auto *FalseInst = cast<Instruction>(SI->getFalseValue());
    FalseInst->moveBefore(FalseBranch);
  }

After investigating more, Select optimization only consider just one instruction. So without this patch, we do transform, even if we don't have sinking instruction.
I want to listen from Sanjay who made this change first.


http://reviews.llvm.org/D16836





More information about the llvm-commits mailing list