[llvm] [LoopIdiomVectorize] Recognize and transform minidx pattern (PR #144987)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 1 07:15:08 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp -- llvm/lib/Transforms/Vectorize/LoopIdiomVectorize.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/lib/Transforms/Vectorize/LoopIdiomVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopIdiomVectorize.cpp
index 59e407cc8..b2a152710 100644
--- a/llvm/lib/Transforms/Vectorize/LoopIdiomVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopIdiomVectorize.cpp
@@ -317,7 +317,8 @@ bool LoopIdiomVectorize::recognizeMinIdxPattern() {
// 1. add(sext(sub(0 - SecondIndex)), sext(FirstIndex))
// 2. add(sext(FirstIndex), sext(sub(0 - SecondIndex)))
// This depends on whether canonicalization has been done or not.
- // TODO: Handle the case where there is no sign extension and return type is i64.
+ // TODO: Handle the case where there is no sign extension and return type is
+ // i64.
if (match(ICmpSLTFirstVal, m_Add(m_SExt(m_Sub(m_ZeroInt(), m_Value())),
(m_SExt(m_Value()))))) {
FirstIndex = dyn_cast<Instruction>(ICmpSLTFirstVal)->getOperand(1);
@@ -442,24 +443,23 @@ bool LoopIdiomVectorize::transformMinIdxPattern(
auto *VecTy = ScalableVectorType::get(
LoadType, VF); // This is the vector type for i32 values
-
// High-level overview of the transformation:
// We divide the process in three phases:
// In the first phase, we process a chunk which is not multiple of VF.
- // We do this by rounding down the `SecondIndex` to the nearest multiple of VF.
- // The minimum value and the index of the minimum value are computed for this chunk.
- // In the second phase, we process all chunks which are multiple of VF.
- // In the third phase, we process the last chunk which is not multiple of VF.
- // The third phase is required because the FirstIndex is necessary to start from zero
- // thus we take max(0, FirstIndex) as the starting index.
+ // We do this by rounding down the `SecondIndex` to the nearest multiple of
+ // VF. The minimum value and the index of the minimum value are computed for
+ // this chunk. In the second phase, we process all chunks which are multiple
+ // of VF. In the third phase, we process the last chunk which is not multiple
+ // of VF. The third phase is required because the FirstIndex is necessary to
+ // start from zero thus we take max(0, FirstIndex) as the starting index.
// Overview of the algorithm to compute minindex within a chunk:
// 1. We compare the current loaded vector against a splat of infinity.
- // 2. Further, we set the bits until we find the first set bit in the output of the
- // above comparison. This is realized using the `cttz` intrinsic.
- // 3. Next, we count the number of bits set and this gives us the offset from the
- // base. The base of the chunk is updated in each phase.
- // Step 1 and 2 are done using brkb + cnt which is realized using the `cttz` intrinsic.
+ // 2. Further, we set the bits until we find the first set bit in the output
+ // of the above comparison. This is realized using the `cttz` intrinsic.
+ // 3. Next, we count the number of bits set and this gives us the offset from
+ // the base. The base of the chunk is updated in each phase. Step 1 and 2 are
+ // done using brkb + cnt which is realized using the `cttz` intrinsic.
// The below basic blocks are used to process the first phase
// and are for processing the chunk which is not multiple of VF.
@@ -468,7 +468,7 @@ bool LoopIdiomVectorize::transformMinIdxPattern(
BasicBlock::Create(Ctx, "minidx.partial.1.if", F);
BasicBlock *MinIdxPartial1ProcExit =
BasicBlock::Create(Ctx, "minidx.partial.1.proc.exit", F);
-
+
// The below basic blocks are used to process the second phase
// and are for processing the chunks which are multiple of VF.
BasicBlock *MinIdxWhileBodyLrPh =
@@ -511,8 +511,8 @@ bool LoopIdiomVectorize::transformMinIdxPattern(
Builder.CreateSub(ConstantInt::get(I64Ty, 0), VLen, "minidx.not");
Value *And = Builder.CreateAnd(SecondIndex, Not, "minidx.and");
- // %minidx.umax = tail call i64 @llvm.umax.i64(i64 %minidx.and, i64 %FirstIndex)
- // %minidx.add = add i64 %SecondIndex, 1
+ // %minidx.umax = tail call i64 @llvm.umax.i64(i64 %minidx.and, i64
+ // %FirstIndex) %minidx.add = add i64 %SecondIndex, 1
Value *Umax = Builder.CreateIntrinsic(
Intrinsic::smax, {I64Ty}, {And, FirstIndex}, nullptr, "minidx.umax");
Value *Add =
``````````
</details>
https://github.com/llvm/llvm-project/pull/144987
More information about the llvm-commits
mailing list