[llvm] [AMDGPU] Filter candidates of LiveRegOptimizer for profitable cases (PR #124624)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 29 13:55:23 PST 2025


================
@@ -125,8 +130,41 @@ class LiveRegOptimizer {
     return LK.first != TargetLoweringBase::TypeLegal;
   }
 
-  LiveRegOptimizer(Module &Mod, const GCNSubtarget &ST)
-      : Mod(Mod), DL(Mod.getDataLayout()), ST(ST),
+  // Filtering based on operation or its cost.
+  // If an operation incurs high enough cost or natively work on
+  // vector of illegal type, ie. v2i8, then it makes sense to try
+  // to avoid scalarizing across BB.
+  bool shouldReplaceBasedOnOp(Instruction *II) {
+    // Ignore pseudos
+    if (II->isDebugOrPseudoInst())
+      return false;
+
+    // Instruction Cost
+    const auto Cost = TTI.getInstructionCost(
+        II, TargetTransformInfo::TargetCostKind::TCK_SizeAndLatency);
+    LLVM_DEBUG(dbgs() << "shouldReplaceBasedOnOp: " << *II << " Cost=" << Cost
+                      << '\n';);
+    if (Cost >= 8)
+      return true;
+
+    // Intrinsics - assume they natively handle illegal type
+    if (isa<IntrinsicInst>(II))
----------------
choikwa wrote:

Do you mean expand on TTI::isTypeLegal? like isTypeAndOpLegal? The former only checks if it has registered RegClass to hold the type natively. I assume the latter might make redundant some logic in ISelLowering for determining custom legalization for Type & Op.

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


More information about the llvm-commits mailing list