[llvm-branch-commits] [llvm] [SLP] Check if instructions exist after vectorization (#120434) (PR #120505)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Dec 18 16:25:12 PST 2024


https://github.com/DianQK created https://github.com/llvm/llvm-project/pull/120505

Fixes #120433.

(cherry picked from commit e7a4d78ad328d02bf515b2fa4af8b2c188a6a636)

>From d7f48a12a6e95df78f0a28618f51af21d8395623 Mon Sep 17 00:00:00 2001
From: DianQK <dianqk at dianqk.net>
Date: Thu, 19 Dec 2024 06:21:57 +0800
Subject: [PATCH] [SLP] Check if instructions exist after vectorization
 (#120434)

Fixes #120433.

(cherry picked from commit e7a4d78ad328d02bf515b2fa4af8b2c188a6a636)
---
 .../Transforms/Vectorize/SLPVectorizer.cpp    |  5 +-
 .../SLPVectorizer/slp-deleted-inst.ll         | 51 +++++++++++++++++++
 2 files changed, 55 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Transforms/SLPVectorizer/slp-deleted-inst.ll

diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 746ba51a981fe0..fd08d5d9d7556a 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -18596,8 +18596,11 @@ bool SLPVectorizerPass::vectorizeCmpInsts(iterator_range<ItT> CmpInsts,
     if (R.isDeleted(I))
       continue;
     for (Value *Op : I->operands())
-      if (auto *RootOp = dyn_cast<Instruction>(Op))
+      if (auto *RootOp = dyn_cast<Instruction>(Op)) {
         Changed |= vectorizeRootInstruction(nullptr, RootOp, BB, R, TTI);
+        if (R.isDeleted(I))
+          break;
+      }
   }
   // Try to vectorize operands as vector bundles.
   for (CmpInst *I : CmpInsts) {
diff --git a/llvm/test/Transforms/SLPVectorizer/slp-deleted-inst.ll b/llvm/test/Transforms/SLPVectorizer/slp-deleted-inst.ll
new file mode 100644
index 00000000000000..d3995f1bb7f85d
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/slp-deleted-inst.ll
@@ -0,0 +1,51 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -S -passes=slp-vectorizer < %s | FileCheck %s
+
+define void @foo() {
+; CHECK-LABEL: define void @foo() {
+; CHECK-NEXT:  [[BB:.*]]:
+; CHECK-NEXT:    br label %[[BB1:.*]]
+; CHECK:       [[BB1]]:
+; CHECK-NEXT:    [[TMP0:%.*]] = phi <2 x i32> [ [[TMP11:%.*]], %[[BB3:.*]] ], [ zeroinitializer, %[[BB]] ]
+; CHECK-NEXT:    br label %[[BB3]]
+; CHECK:       [[BB3]]:
+; CHECK-NEXT:    [[TMP1:%.*]] = trunc <2 x i32> [[TMP0]] to <2 x i1>
+; CHECK-NEXT:    [[TMP2:%.*]] = mul <2 x i1> [[TMP1]], zeroinitializer
+; CHECK-NEXT:    [[TMP3:%.*]] = or <2 x i1> zeroinitializer, [[TMP2]]
+; CHECK-NEXT:    [[TMP4:%.*]] = and <2 x i1> [[TMP3]], zeroinitializer
+; CHECK-NEXT:    [[TMP5:%.*]] = extractelement <2 x i1> [[TMP4]], i32 0
+; CHECK-NEXT:    [[TMP6:%.*]] = zext i1 [[TMP5]] to i32
+; CHECK-NEXT:    [[TMP7:%.*]] = extractelement <2 x i1> [[TMP4]], i32 1
+; CHECK-NEXT:    [[TMP8:%.*]] = zext i1 [[TMP7]] to i32
+; CHECK-NEXT:    [[I22:%.*]] = or i32 [[TMP6]], [[TMP8]]
+; CHECK-NEXT:    [[TMP9:%.*]] = insertelement <2 x i32> <i32 poison, i32 0>, i32 [[I22]], i32 0
+; CHECK-NEXT:    [[TMP10:%.*]] = icmp ult <2 x i32> [[TMP9]], zeroinitializer
+; CHECK-NEXT:    [[TMP11]] = select <2 x i1> [[TMP10]], <2 x i32> zeroinitializer, <2 x i32> zeroinitializer
+; CHECK-NEXT:    br label %[[BB1]]
+;
+bb:
+  br label %bb1
+
+bb1:                                              ; preds = %bb3, %bb
+  %i = phi i32 [ %i26, %bb3 ], [ 0, %bb ]
+  %i2 = phi i32 [ %i24, %bb3 ], [ 0, %bb ]
+  br label %bb3
+
+bb3:                                              ; preds = %bb1
+  %i4 = zext i32 %i2 to i64
+  %i5 = mul i64 %i4, 0
+  %i10 = or i64 0, %i5
+  %i11 = trunc i64 %i10 to i32
+  %i12 = and i32 %i11, 0
+  %i13 = zext i32 %i to i64
+  %i14 = mul i64 %i13, 0
+  %i19 = or i64 0, %i14
+  %i20 = trunc i64 %i19 to i32
+  %i21 = and i32 %i20, 0
+  %i22 = or i32 %i12, %i21
+  %i23 = icmp ult i32 %i22, 0
+  %i24 = select i1 %i23, i32 0, i32 0
+  %i25 = icmp ult i32 0, 0
+  %i26 = select i1 %i25, i32 0, i32 0
+  br label %bb1
+}



More information about the llvm-branch-commits mailing list