[llvm] [ConstantHoisting] Add a TTI hook to prevent hoisting. (PR #69004)

David Green via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 16 00:01:31 PDT 2023


davemgreen wrote:

This should probably be in getIntImmCostInst, similar to the Arm version:
```
InstructionCost ARMTTIImpl::getIntImmCostInst(unsigned Opcode, unsigned Idx,
                                              const APInt &Imm, Type *Ty,
                                              TTI::TargetCostKind CostKind,
                                              Instruction *Inst) {
  // Division by a constant can be turned into multiplication, but only if we
  // know it's constant. So it's not so much that the immediate is cheap (it's
  // not), but that the alternative is worse.
  // FIXME: this is probably unneeded with GlobalISel.
  if ((Opcode == Instruction::SDiv || Opcode == Instruction::UDiv ||
       Opcode == Instruction::SRem || Opcode == Instruction::URem) &&
      Idx == 1)
    return 0;
```

https://github.com/llvm/llvm-project/pull/69004


More information about the llvm-commits mailing list