Skip to content

Commit ea8ab29

Browse files
committed
Division by a constant
1 parent 8d439cf commit ea8ab29

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,16 +454,21 @@ InstructionCost AArch64TTIImpl::getIntImmCostInst(unsigned Opcode, unsigned Idx,
454454
case Instruction::Add:
455455
case Instruction::Sub:
456456
case Instruction::Mul:
457-
case Instruction::UDiv:
458-
case Instruction::SDiv:
459-
case Instruction::URem:
460-
case Instruction::SRem:
461457
case Instruction::And:
462458
case Instruction::Or:
463459
case Instruction::Xor:
464460
case Instruction::ICmp:
465461
ImmIdx = 1;
466462
break;
463+
464+
// Division by a constant can be turned into multiplication, but only if we
465+
// know it's constant. So it's not so much that the immediate is cheap (it's
466+
// not), but that the alternative is worse.
467+
case Instruction::UDiv:
468+
case Instruction::SDiv:
469+
case Instruction::URem:
470+
case Instruction::SRem:
471+
467472
// Always return TCC_Free for the shift value of a shift instruction.
468473
case Instruction::Shl:
469474
case Instruction::LShr:

0 commit comments

Comments
 (0)