[PATCH] D135991: [AArch64] Fix cost model for `udiv` instruction when one of the operands is a uniform constant

Dave Green via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 9 02:04:20 PST 2022


dmgreen added a comment.

Thanks. The existing code is pretty odd, we may want to clean it up at some point. The new code seems better though. If you can clean it up a little as suggested and explain the difference with the scalar costs then this sounds good to me.



================
Comment at: llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp:18
 #include "llvm/CodeGen/CostTable.h"
+#include "llvm/CodeGen/ISDOpcodes.h"
 #include "llvm/CodeGen/TargetLowering.h"
----------------
Are these changes necessary?


================
Comment at: llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp:2081
     if (Ty->isVectorTy()) {
+
       if (TLI->isOperationLegalOrCustom(ISD, LT.second) && ST->hasSVE()) {
----------------
Remove this change now?


================
Comment at: llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp:2109
       } else {
+        // if one of the operands is a uniform constant then the cost for each
+        // element is Cost for insertion, extraction and division.
----------------
if -> If


================
Comment at: llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp:2117
+            InstructionCost DivCost = BaseT::getArithmeticInstrCost(
+                Instruction::UDiv, Ty->getScalarType(), CostKind, Op1Info,
+                Op2Info);
----------------
Should UDiv be Opcode, to handle SDiv a little better?


================
Comment at: llvm/test/Analysis/CostModel/AArch64/div.ll:181
 ; CHECK-NEXT:  Cost Model: Found an estimated cost of 7 for instruction: %I64 = sdiv i64 undef, 7
-; CHECK-NEXT:  Cost Model: Found an estimated cost of 48 for instruction: %V2i64 = sdiv <2 x i64> undef, <i64 7, i64 7>
-; CHECK-NEXT:  Cost Model: Found an estimated cost of 96 for instruction: %V4i64 = sdiv <4 x i64> undef, <i64 7, i64 7, i64 7, i64 7>
-; CHECK-NEXT:  Cost Model: Found an estimated cost of 192 for instruction: %V8i64 = sdiv <8 x i64> undef, <i64 7, i64 7, i64 7, i64 7, i64 7, i64 7, i64 7, i64 7>
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 10 for instruction: %V2i64 = sdiv <2 x i64> undef, <i64 7, i64 7>
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 20 for instruction: %V4i64 = sdiv <4 x i64> undef, <i64 7, i64 7, i64 7, i64 7>
----------------
Can you explain why this isn't (7+4)*2 = 22? Is the scalar cost treated as 1?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135991/new/

https://reviews.llvm.org/D135991



More information about the llvm-commits mailing list