[llvm] [LV] Cost EVL width-adjusting zext/trunc as free (PR #225016)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 23 03:12:20 PDT 2026


================
@@ -1360,9 +1360,17 @@ InstructionCost VPInstruction::computeCost(ElementCount VF,
   // NOTE: At the moment it seems only possible to expose this path for
   // the trunc, zext and sext opcodes.
   // TODO: Update VF arg to use onlyFirstLaneUsed once WidenCast is unified.
-  if (Instruction::isCast(getOpcode()))
+  if (Instruction::isCast(getOpcode())) {
+    // A scalar zext/trunc that only adjusts the width of an
+    // ExplicitVectorLength to the canonical IV type is free: it feeds only
+    // the IV increment and AVL decrement, which are modeled as free below.
+    if ((getOpcode() == Instruction::ZExt ||
+         getOpcode() == Instruction::Trunc) &&
+        match(getOperand(0), m_EVL(m_VPValue())))
+      return 0;
----------------
lukel97 wrote:

Nit, does `match(this, m_ZExtOrTrunc(m_EVL(m_VPValue()))` also work?

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


More information about the llvm-commits mailing list