Skip to content

Commit 4e96dc6

Browse files
committed
[AArch64] Consider negated powers of 2 when calculating throughput cost
Negated powers of 2 have similar or (exact in the case of remainder) codegen with lowering sdiv. In the case of sdiv, it just negates the result in the end anyway, so nothing dissimilar at all.
1 parent eb6577d commit 4e96dc6

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4005,15 +4005,15 @@ InstructionCost AArch64TTIImpl::getArithmeticInstrCost(
40054005
// have similar cost.
40064006
auto VT = TLI->getValueType(DL, Ty);
40074007
if (VT.isScalarInteger() && VT.getSizeInBits() <= 64) {
4008-
if (Op2Info.isPowerOf2()) {
4008+
if (Op2Info.isPowerOf2() || Op2Info.isNegatedPowerOf2()) {
40094009
return ISD == ISD::SDIV ? (3 * AddCost + AsrCost)
40104010
: (3 * AsrCost + AddCost);
40114011
} else {
40124012
return MulCost + AsrCost + 2 * AddCost;
40134013
}
40144014
} else if (VT.isVector()) {
40154015
InstructionCost UsraCost = 2 * AsrCost;
4016-
if (Op2Info.isPowerOf2()) {
4016+
if (Op2Info.isPowerOf2() || Op2Info.isNegatedPowerOf2()) {
40174017
// Division with scalable types corresponds to native 'asrd'
40184018
// instruction when SVE is available.
40194019
// e.g. %1 = sdiv <vscale x 4 x i32> %a, splat (i32 8)

0 commit comments

Comments
 (0)