[llvm] 9c0a065 - [SLP]Fix a crash for non-profitable non-schedulable single buildvector node tree, if the threshold allows its vectorization.
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 22 07:44:56 PDT 2024
Author: Alexey Bataev
Date: 2024-03-22T07:44:23-07:00
New Revision: 9c0a0659d40f613e873e416833d2293365b48e06
URL: https://github.com/llvm/llvm-project/commit/9c0a0659d40f613e873e416833d2293365b48e06
DIFF: https://github.com/llvm/llvm-project/commit/9c0a0659d40f613e873e416833d2293365b48e06.diff
LOG: [SLP]Fix a crash for non-profitable non-schedulable single buildvector node tree, if the threshold allows its vectorization.
Added:
llvm/test/Transforms/SLPVectorizer/RISCV/small-tree-not-schedulable-bv-node.ll
Modified:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 7295ae0ba90b43..0f7afa2fc25c29 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -9278,6 +9278,8 @@ bool BoUpSLP::isTreeTinyAndNotFullyVectorizable(bool ForReduction) const {
bool IsAllowedSingleBVNode =
VectorizableTree.size() > 1 ||
(VectorizableTree.size() == 1 && VectorizableTree.front()->getOpcode() &&
+ VectorizableTree.front()->getOpcode() != Instruction::PHI &&
+ VectorizableTree.front()->getOpcode() != Instruction::GetElementPtr &&
allSameBlock(VectorizableTree.front()->Scalars));
if (any_of(VectorizableTree, [&](const std::unique_ptr<TreeEntry> &TE) {
return TE->State == TreeEntry::NeedToGather &&
diff --git a/llvm/test/Transforms/SLPVectorizer/RISCV/small-tree-not-schedulable-bv-node.ll b/llvm/test/Transforms/SLPVectorizer/RISCV/small-tree-not-schedulable-bv-node.ll
new file mode 100644
index 00000000000000..26f3fcae3a3334
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/RISCV/small-tree-not-schedulable-bv-node.ll
@@ -0,0 +1,263 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
+; RUN: opt -S -mtriple=riscv64-unknown-linux-gnu -slp-threshold=-100 -mattr=+v < %s | FileCheck %s
+
+define void @test1() personality ptr null {
+; CHECK-LABEL: define void @test1(
+; CHECK-SAME: ) #[[ATTR0:[0-9]+]] personality ptr null {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CALL33:%.*]] = invoke ptr null(i64 0, ptr null)
+; CHECK-NEXT: to label [[INVOKE_CONT32:%.*]] unwind label [[LPAD31_LOOPEXIT:%.*]]
+; CHECK: invoke.cont32:
+; CHECK-NEXT: invoke void null(ptr null, ptr null)
+; CHECK-NEXT: to label [[INVOKE_CONT37:%.*]] unwind label [[LPAD34_LOOPEXIT:%.*]]
+; CHECK: invoke.cont37:
+; CHECK-NEXT: unreachable
+; CHECK: lpad31.loopexit:
+; CHECK-NEXT: [[LPAD_LOOPEXIT:%.*]] = landingpad { ptr, i32 }
+; CHECK-NEXT: cleanup
+; CHECK-NEXT: br label [[EHCLEANUP47:%.*]]
+; CHECK: lpad34.loopexit:
+; CHECK-NEXT: [[DOTLCSSA101:%.*]] = phi ptr [ null, [[INVOKE_CONT32]] ]
+; CHECK-NEXT: [[CALL33_LCSSA96:%.*]] = phi ptr [ [[CALL33]], [[INVOKE_CONT32]] ]
+; CHECK-NEXT: [[LPAD_LOOPEXIT56:%.*]] = landingpad { ptr, i32 }
+; CHECK-NEXT: cleanup
+; CHECK-NEXT: br label [[LPAD34_BODY:%.*]]
+; CHECK: lpad34.loopexit.split-lp:
+; CHECK-NEXT: [[LPAD_LOOPEXIT_SPLIT_LP57:%.*]] = landingpad { ptr, i32 }
+; CHECK-NEXT: cleanup
+; CHECK-NEXT: br label [[LPAD34_BODY]]
+; CHECK: lpad34.body:
+; CHECK-NEXT: [[TMP0:%.*]] = phi ptr [ [[DOTLCSSA101]], [[LPAD34_LOOPEXIT]] ], [ null, [[LPAD34_LOOPEXIT_SPLIT_LP:%.*]] ]
+; CHECK-NEXT: [[CALL3399:%.*]] = phi ptr [ [[CALL33_LCSSA96]], [[LPAD34_LOOPEXIT]] ], [ null, [[LPAD34_LOOPEXIT_SPLIT_LP]] ]
+; CHECK-NEXT: br label [[EHCLEANUP47]]
+; CHECK: ehcleanup47:
+; CHECK-NEXT: resume { ptr, i32 } zeroinitializer
+;
+entry:
+ %call33 = invoke ptr null(i64 0, ptr null)
+ to label %invoke.cont32 unwind label %lpad31.loopexit
+
+invoke.cont32:
+ invoke void null(ptr null, ptr null)
+ to label %invoke.cont37 unwind label %lpad34.loopexit
+
+invoke.cont37:
+ unreachable
+
+lpad31.loopexit:
+ %lpad.loopexit = landingpad { ptr, i32 }
+ cleanup
+ br label %ehcleanup47
+
+lpad34.loopexit:
+ %.lcssa101 = phi ptr [ null, %invoke.cont32 ]
+ %call33.lcssa96 = phi ptr [ %call33, %invoke.cont32 ]
+ %lpad.loopexit56 = landingpad { ptr, i32 }
+ cleanup
+ br label %lpad34.body
+
+lpad34.loopexit.split-lp:
+ %lpad.loopexit.split-lp57 = landingpad { ptr, i32 }
+ cleanup
+ br label %lpad34.body
+
+lpad34.body:
+ %0 = phi ptr [ %.lcssa101, %lpad34.loopexit ], [ null, %lpad34.loopexit.split-lp ]
+ %call3399 = phi ptr [ %call33.lcssa96, %lpad34.loopexit ], [ null, %lpad34.loopexit.split-lp ]
+ br label %ehcleanup47
+
+ehcleanup47:
+ resume { ptr, i32 } zeroinitializer
+}
+
+define i32 @test2(i64 %idx.ext.i48.pre-phi) {
+; CHECK-LABEL: define i32 @test2(
+; CHECK-SAME: i64 [[IDX_EXT_I48_PRE_PHI:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[DO_ACTION:%.*]]
+; CHECK: do_action:
+; CHECK-NEXT: switch i32 0, label [[SW_DEFAULT:%.*]] [
+; CHECK-NEXT: i32 1, label [[CLEANUP185:%.*]]
+; CHECK-NEXT: i32 2, label [[CLEANUP185]]
+; CHECK-NEXT: i32 0, label [[CLEANUP185]]
+; CHECK-NEXT: i32 4, label [[CLEANUP185]]
+; CHECK-NEXT: i32 5, label [[CLEANUP185]]
+; CHECK-NEXT: i32 6, label [[CLEANUP185]]
+; CHECK-NEXT: i32 7, label [[CLEANUP185]]
+; CHECK-NEXT: i32 8, label [[CLEANUP185]]
+; CHECK-NEXT: i32 9, label [[CLEANUP185]]
+; CHECK-NEXT: i32 10, label [[CLEANUP185]]
+; CHECK-NEXT: i32 11, label [[CLEANUP185]]
+; CHECK-NEXT: i32 12, label [[CLEANUP185]]
+; CHECK-NEXT: i32 13, label [[CLEANUP185]]
+; CHECK-NEXT: i32 14, label [[CLEANUP185]]
+; CHECK-NEXT: i32 15, label [[CLEANUP185]]
+; CHECK-NEXT: i32 16, label [[CLEANUP185]]
+; CHECK-NEXT: i32 17, label [[CLEANUP185]]
+; CHECK-NEXT: i32 18, label [[CLEANUP185]]
+; CHECK-NEXT: i32 19, label [[CLEANUP185]]
+; CHECK-NEXT: i32 20, label [[CLEANUP185]]
+; CHECK-NEXT: i32 21, label [[CLEANUP185]]
+; CHECK-NEXT: i32 22, label [[CLEANUP185]]
+; CHECK-NEXT: i32 23, label [[CLEANUP185]]
+; CHECK-NEXT: i32 24, label [[CLEANUP185]]
+; CHECK-NEXT: i32 25, label [[CLEANUP185]]
+; CHECK-NEXT: i32 26, label [[CLEANUP185]]
+; CHECK-NEXT: i32 27, label [[CLEANUP185]]
+; CHECK-NEXT: i32 28, label [[CLEANUP185]]
+; CHECK-NEXT: i32 29, label [[CLEANUP185]]
+; CHECK-NEXT: i32 30, label [[CLEANUP185]]
+; CHECK-NEXT: i32 31, label [[CLEANUP185]]
+; CHECK-NEXT: i32 32, label [[CLEANUP185]]
+; CHECK-NEXT: i32 33, label [[CLEANUP185]]
+; CHECK-NEXT: i32 34, label [[CLEANUP185]]
+; CHECK-NEXT: i32 35, label [[CLEANUP185]]
+; CHECK-NEXT: i32 36, label [[CLEANUP185]]
+; CHECK-NEXT: i32 37, label [[CLEANUP185]]
+; CHECK-NEXT: i32 38, label [[CLEANUP185]]
+; CHECK-NEXT: i32 39, label [[CLEANUP185]]
+; CHECK-NEXT: i32 40, label [[CLEANUP185]]
+; CHECK-NEXT: i32 41, label [[CLEANUP185]]
+; CHECK-NEXT: i32 42, label [[CLEANUP185]]
+; CHECK-NEXT: i32 43, label [[CLEANUP185]]
+; CHECK-NEXT: i32 44, label [[CLEANUP185]]
+; CHECK-NEXT: i32 45, label [[CLEANUP185]]
+; CHECK-NEXT: i32 46, label [[CLEANUP185]]
+; CHECK-NEXT: i32 47, label [[CLEANUP185]]
+; CHECK-NEXT: i32 48, label [[CLEANUP185]]
+; CHECK-NEXT: i32 49, label [[CLEANUP185]]
+; CHECK-NEXT: i32 50, label [[CLEANUP185]]
+; CHECK-NEXT: i32 51, label [[CLEANUP185]]
+; CHECK-NEXT: i32 52, label [[CLEANUP185]]
+; CHECK-NEXT: i32 53, label [[CLEANUP185]]
+; CHECK-NEXT: i32 54, label [[CLEANUP185]]
+; CHECK-NEXT: i32 55, label [[CLEANUP185]]
+; CHECK-NEXT: i32 56, label [[CLEANUP185]]
+; CHECK-NEXT: i32 57, label [[DO_ACTION]]
+; CHECK-NEXT: i32 58, label [[CLEANUP185]]
+; CHECK-NEXT: i32 59, label [[CLEANUP185]]
+; CHECK-NEXT: i32 60, label [[DO_ACTION]]
+; CHECK-NEXT: i32 61, label [[DO_ACTION]]
+; CHECK-NEXT: i32 62, label [[CLEANUP185]]
+; CHECK-NEXT: i32 70, label [[SW_BB175:%.*]]
+; CHECK-NEXT: i32 64, label [[CLEANUP185]]
+; CHECK-NEXT: i32 65, label [[DO_ACTION]]
+; CHECK-NEXT: i32 66, label [[DO_ACTION]]
+; CHECK-NEXT: i32 67, label [[CLEANUP185]]
+; CHECK-NEXT: i32 72, label [[CLEANUP185]]
+; CHECK-NEXT: i32 69, label [[DO_ACTION]]
+; CHECK-NEXT: i32 71, label [[CLEANUP185]]
+; CHECK-NEXT: ]
+; CHECK: yy_get_previous_state.exit.loopexit:
+; CHECK-NEXT: br label [[YY_FIND_ACTION_BACKEDGE:%.*]]
+; CHECK: yy_find_action.backedge:
+; CHECK-NEXT: [[YY_BP_1_BE:%.*]] = phi ptr [ [[ADD_PTR_I49:%.*]], [[SW_BB175]] ], [ null, [[YY_GET_PREVIOUS_STATE_EXIT_LOOPEXIT:%.*]] ]
+; CHECK-NEXT: [[YY_CP_2_BE:%.*]] = phi ptr [ [[ARRAYIDX178:%.*]], [[SW_BB175]] ], [ null, [[YY_GET_PREVIOUS_STATE_EXIT_LOOPEXIT]] ]
+; CHECK-NEXT: br label [[DO_ACTION]]
+; CHECK: sw.bb175:
+; CHECK-NEXT: [[ARRAYIDX178]] = getelementptr i8, ptr null, i64 0
+; CHECK-NEXT: [[ADD_PTR_I49]] = getelementptr i8, ptr null, i64 [[IDX_EXT_I48_PRE_PHI]]
+; CHECK-NEXT: [[CMP5_I50:%.*]] = icmp ult ptr [[ADD_PTR_I49]], [[ARRAYIDX178]]
+; CHECK-NEXT: br label [[YY_FIND_ACTION_BACKEDGE]]
+; CHECK: sw.default:
+; CHECK-NEXT: unreachable
+; CHECK: cleanup185:
+; CHECK-NEXT: ret i32 0
+;
+entry:
+ br label %do_action
+
+do_action:
+ switch i32 0, label %sw.default [
+ i32 1, label %cleanup185
+ i32 2, label %cleanup185
+ i32 0, label %cleanup185
+ i32 4, label %cleanup185
+ i32 5, label %cleanup185
+ i32 6, label %cleanup185
+ i32 7, label %cleanup185
+ i32 8, label %cleanup185
+ i32 9, label %cleanup185
+ i32 10, label %cleanup185
+ i32 11, label %cleanup185
+ i32 12, label %cleanup185
+ i32 13, label %cleanup185
+ i32 14, label %cleanup185
+ i32 15, label %cleanup185
+ i32 16, label %cleanup185
+ i32 17, label %cleanup185
+ i32 18, label %cleanup185
+ i32 19, label %cleanup185
+ i32 20, label %cleanup185
+ i32 21, label %cleanup185
+ i32 22, label %cleanup185
+ i32 23, label %cleanup185
+ i32 24, label %cleanup185
+ i32 25, label %cleanup185
+ i32 26, label %cleanup185
+ i32 27, label %cleanup185
+ i32 28, label %cleanup185
+ i32 29, label %cleanup185
+ i32 30, label %cleanup185
+ i32 31, label %cleanup185
+ i32 32, label %cleanup185
+ i32 33, label %cleanup185
+ i32 34, label %cleanup185
+ i32 35, label %cleanup185
+ i32 36, label %cleanup185
+ i32 37, label %cleanup185
+ i32 38, label %cleanup185
+ i32 39, label %cleanup185
+ i32 40, label %cleanup185
+ i32 41, label %cleanup185
+ i32 42, label %cleanup185
+ i32 43, label %cleanup185
+ i32 44, label %cleanup185
+ i32 45, label %cleanup185
+ i32 46, label %cleanup185
+ i32 47, label %cleanup185
+ i32 48, label %cleanup185
+ i32 49, label %cleanup185
+ i32 50, label %cleanup185
+ i32 51, label %cleanup185
+ i32 52, label %cleanup185
+ i32 53, label %cleanup185
+ i32 54, label %cleanup185
+ i32 55, label %cleanup185
+ i32 56, label %cleanup185
+ i32 57, label %do_action
+ i32 58, label %cleanup185
+ i32 59, label %cleanup185
+ i32 60, label %do_action
+ i32 61, label %do_action
+ i32 62, label %cleanup185
+ i32 70, label %sw.bb175
+ i32 64, label %cleanup185
+ i32 65, label %do_action
+ i32 66, label %do_action
+ i32 67, label %cleanup185
+ i32 72, label %cleanup185
+ i32 69, label %do_action
+ i32 71, label %cleanup185
+ ]
+
+yy_get_previous_state.exit.loopexit:
+ br label %yy_find_action.backedge
+
+yy_find_action.backedge:
+ %yy_bp.1.be = phi ptr [ %add.ptr.i49, %sw.bb175 ], [ null, %yy_get_previous_state.exit.loopexit ]
+ %yy_cp.2.be = phi ptr [ %arrayidx178, %sw.bb175 ], [ null, %yy_get_previous_state.exit.loopexit ]
+ br label %do_action
+
+sw.bb175:
+ %arrayidx178 = getelementptr i8, ptr null, i64 0
+ %add.ptr.i49 = getelementptr i8, ptr null, i64 %idx.ext.i48.pre-phi
+ %cmp5.i50 = icmp ult ptr %add.ptr.i49, %arrayidx178
+ br label %yy_find_action.backedge
+
+sw.default:
+ unreachable
+
+cleanup185:
+ ret i32 0
+}
More information about the llvm-commits
mailing list