[llvm] [LV] Use ICMP_UGE for BranchOnCount when VF is scalable (PR #102575)

Pengcheng Wang via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 8 23:49:38 PDT 2024


https://github.com/wangpc-pp created https://github.com/llvm/llvm-project/pull/102575

So that SCEV can analyse the bound of loop count.

This can fix issue found in #100564.


>From ea3c3808621778db1adfef638e115381d0293eae Mon Sep 17 00:00:00 2001
From: Wang Pengcheng <wangpengcheng.pp at bytedance.com>
Date: Fri, 9 Aug 2024 14:46:55 +0800
Subject: [PATCH] [LV] Use ICMP_UGE for BranchOnCount when VF is scalable

So that SCEV can analyse the bound of loop count.

This can fix issue found in #100564.
---
 llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index c2ca13720c27b7..cf360de1bffc8d 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -524,7 +524,10 @@ Value *VPInstruction::generatePerPart(VPTransformState &State, unsigned Part) {
     // First create the compare.
     Value *IV = State.get(getOperand(0), Part, /*IsScalar*/ true);
     Value *TC = State.get(getOperand(1), Part, /*IsScalar*/ true);
-    Value *Cond = Builder.CreateICmpEQ(IV, TC);
+    // Use ICMP_UGE so that SCEV can analyse the bound of loop count for
+    // scalable VF.
+    Value *Cond = Builder.CreateICmp(
+        State.VF.isScalable() ? ICmpInst::ICMP_UGE : ICmpInst::ICMP_EQ, IV, TC);
 
     // Now create the branch.
     auto *Plan = getParent()->getPlan();



More information about the llvm-commits mailing list