[llvm] [VPlan] Use zext instead of sext for Index in VPDerivedIVRecipe expansion. nfc (PR #208692)
Mel Chen via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 10 03:55:18 PDT 2026
https://github.com/Mel-Chen created https://github.com/llvm/llvm-project/pull/208692
expandVPDerivedIV extends/truncates the index to the step's integer type before computing the derived IV. The index always non-negative since it represents an trip count,. Therefore, extending it should use createScalarZExtOrTrunc rather than createScalarSExtOrTrunc, which better reflects its actual unsigned semantics.
>From a23d9d54e8b71f71b48212105af240ea746bc396 Mon Sep 17 00:00:00 2001
From: Mel Chen <mel.chen at sifive.com>
Date: Fri, 10 Jul 2026 03:48:57 -0700
Subject: [PATCH] [VPlan] Use zext instead of sext for canonical IV in
VPDerivedIVRecipe expansion (NFC)
expandVPDerivedIV extends/truncates the canonical induction variable
(Index) to the step's integer type before computing the derived IV.
The canonical IV is always non-negative (it represents an unsigned
trip count), so extending it should use createScalarZExtOrTrunc
rather than createScalarSExtOrTrunc, which better reflects its actual
unsigned semantics.
Since the canonical IV's sign bit is never set, sext and zext
currently produce identical results, so this is NFC.
---
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index 343ee02007966..9c14a06e1ee27 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -4092,7 +4092,7 @@ static void expandVPDerivedIV(VPDerivedIVRecipe *R) {
Type *StepTy = Step->getScalarType();
Type *IndexTy = Index->getScalarType();
Index = StepTy->isIntegerTy()
- ? Builder.createScalarSExtOrTrunc(
+ ? Builder.createScalarZExtOrTrunc(
Index, StepTy, IndexTy, DebugLoc::getCompilerGenerated())
: Builder.createScalarCast(Instruction::SIToFP, Index, StepTy,
DebugLoc::getCompilerGenerated());
More information about the llvm-commits
mailing list