[PATCH] D140580: [SLP]Do not emit many extractelements, reuse the single one emitted.
Alexey Bataev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 27 07:33:28 PST 2023
ABataev added a comment.
In D140580#4151643 <https://reviews.llvm.org/D140580#4151643>, @DaniilSuchkov wrote:
> This patch is causing a crash even after the 26fec4e845a833214d2b0036ea90f1b1c2418d50 <https://reviews.llvm.org/rG26fec4e845a833214d2b0036ea90f1b1c2418d50>
> IR:
>
> target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2"
> target triple = "x86_64-unknown-linux-gnu"
>
> define void @foo() #0 {
> bb:
> br label %bb1
>
> bb1: ; preds = %bb1, %bb
> %inst = phi i32 [ poison, %bb ], [ %inst58, %bb1 ]
> %inst2 = getelementptr inbounds i32, ptr addrspace(1) poison, i64 poison
> %inst3 = load i32, ptr addrspace(1) %inst2, align 4
> %inst4 = add i32 %inst3, -1
> store i32 %inst4, ptr addrspace(1) %inst2, align 4
> %inst5 = add i32 poison, -1
> %inst6 = mul i32 %inst4, %inst
> %inst7 = mul i32 %inst6, %inst5
> %inst8 = add nuw nsw i64 poison, 1
> %inst9 = getelementptr inbounds i32, ptr addrspace(1) poison, i64 %inst8
> %inst10 = load i32, ptr addrspace(1) %inst9, align 4
> %inst11 = add i32 %inst10, -1
> store i32 %inst11, ptr addrspace(1) %inst9, align 4
> %inst12 = add i32 poison, -1
> %inst13 = mul i32 %inst11, %inst7
> %inst14 = mul i32 %inst13, %inst12
> %inst15 = getelementptr inbounds i32, ptr addrspace(1) poison, i64 poison
> %inst16 = load i32, ptr addrspace(1) %inst15, align 4
> %inst17 = add i32 %inst16, -1
> store i32 %inst17, ptr addrspace(1) %inst15, align 4
> %inst18 = add i32 poison, -1
> %inst19 = mul i32 %inst17, %inst14
> %inst20 = mul i32 %inst19, %inst18
> %inst21 = add nuw nsw i64 poison, 1
> %inst22 = getelementptr inbounds i32, ptr addrspace(1) poison, i64 %inst21
> %inst23 = load i32, ptr addrspace(1) %inst22, align 4
> %inst24 = add i32 %inst23, -1
> store i32 %inst24, ptr addrspace(1) %inst22, align 4
> %inst25 = add i32 poison, -1
> %inst26 = mul i32 %inst24, %inst20
> %inst27 = mul i32 %inst26, %inst25
> %inst28 = getelementptr inbounds i32, ptr addrspace(1) poison, i64 poison
> %inst29 = load i32, ptr addrspace(1) %inst28, align 4
> %inst30 = add i32 %inst29, -1
> store i32 %inst30, ptr addrspace(1) %inst28, align 4
> %inst31 = mul i32 %inst30, 47961
> %inst32 = add i32 %inst31, -1
> %inst33 = mul i32 %inst30, %inst27
> %inst34 = mul i32 %inst33, %inst32
> %inst35 = add nuw nsw i64 poison, 1
> %inst36 = getelementptr inbounds i32, ptr addrspace(1) poison, i64 %inst35
> %inst37 = load i32, ptr addrspace(1) %inst36, align 4
> %inst38 = add i32 %inst37, -1
> store i32 %inst38, ptr addrspace(1) %inst36, align 4
> %inst39 = mul i32 %inst38, 47961
> %inst40 = add i32 %inst39, -1
> %inst41 = mul i32 %inst38, %inst34
> %inst42 = mul i32 %inst41, %inst40
> %inst43 = add nuw nsw i64 %inst35, 1
> %inst44 = getelementptr inbounds i32, ptr addrspace(1) poison, i64 %inst43
> %inst45 = load i32, ptr addrspace(1) %inst44, align 4
> %inst46 = add i32 %inst45, -1
> store i32 %inst46, ptr addrspace(1) %inst44, align 4
> %inst47 = mul i32 %inst46, 47961
> %inst48 = add i32 %inst47, -1
> %inst49 = mul i32 %inst46, %inst42
> %inst50 = mul i32 %inst49, %inst48
> %inst51 = add nuw nsw i64 %inst43, 1
> %inst52 = getelementptr inbounds i32, ptr addrspace(1) poison, i64 %inst51
> %inst53 = load i32, ptr addrspace(1) %inst52, align 4
> %inst54 = add i32 %inst53, -1
> store i32 %inst54, ptr addrspace(1) %inst52, align 4
> %inst55 = mul i32 %inst54, 47961
> %inst56 = add i32 %inst55, -1
> %inst57 = mul i32 %inst54, %inst50
> %inst58 = mul i32 %inst57, %inst56
> br label %bb1
> }
>
> attributes #0 = { "target-features"="+avx" }
>
> Command:
>
> opt -passes=slp-vectorizer -disable-output ir.ll
>
> Result:
>
> opt: llvm-project/llvm/include/llvm/ADT/DenseMap.h:1251: llvm::DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, IsConst>::value_type* llvm::DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, IsConst>::operator->() const [with KeyT = llvm::Value*; ValueT = llvm::SmallVector<llvm::Instruction*>; KeyInfoT = llvm::DenseMapInfo<llvm::Value*, void>; Bucket = llvm::detail::DenseMapPair<llvm::Value*, llvm::SmallVector<llvm::Instruction*> >; bool IsConst = false; llvm::DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, IsConst>::pointer = llvm::detail::DenseMapPair<llvm::Value*, llvm::SmallVector<llvm::Instruction*> >*; llvm::DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, IsConst>::value_type = llvm::detail::DenseMapPair<llvm::Value*, llvm::SmallVector<llvm::Instruction*> >]: Assertion `Ptr != End && "dereferencing end() iterator"' failed.
> PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
> Stack dump:
> 0. Program arguments: bin/opt -passes=slp-vectorizer -disable-output bugpoint-reduced-simplified-minimized.ll
> #0 0x0000000003ab5864 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) llvm-project/llvm/lib/Support/Unix/Signals.inc:565:0
> #1 0x0000000003ab5c53 PrintStackTraceSignalHandler(void*) llvm-project/llvm/lib/Support/Unix/Signals.inc:639:0
> #2 0x0000000003ab3783 llvm::sys::RunSignalHandlers() llvm-project/llvm/lib/Support/Signals.cpp:104:0
> #3 0x0000000003ab529f SignalHandler(int) llvm-project/llvm/lib/Support/Unix/Signals.inc:410:0
> #4 0x00007f1bd34035e0 __restore_rt sigaction.c:0:0
> #5 0x00007f1bd1f691f7 raise (/lib64/libc.so.6+0x351f7)
> #6 0x00007f1bd1f6a8e8 abort (/lib64/libc.so.6+0x368e8)
> #7 0x00007f1bd1f62266 __assert_fail_base (/lib64/libc.so.6+0x2e266)
> #8 0x00007f1bd1f62312 (/lib64/libc.so.6+0x2e312)
> #9 0x0000000003dd059a llvm::DenseMapIterator<llvm::Value*, llvm::SmallVector<llvm::Instruction*, 6u>, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, llvm::SmallVector<llvm::Instruction*, 6u>>, false>::operator->() const llvm-project/llvm/include/llvm/ADT/DenseMap.h:1252:0
> #10 0x0000000003d87336 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:13046:0
> #11 0x0000000003d8a956 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Value*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&)::'lambda'(llvm::Instruction*, llvm::Value*&, llvm::Value*&)::operator()(llvm::Instruction*, llvm::Value*&, llvm::Value*&) const llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:13745:0
> #12 0x0000000003d8abcb llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Value*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:13760:0
> #13 0x0000000003d8af43 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Value*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*) llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:13812:0
> #14 0x0000000003d8d040 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:14254:0
> #15 0x0000000003d7ef19 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:11703:0
> #16 0x0000000003d7ea2f llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:11634:0
> #17 0x0000000003f47c92 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:90:0
> #18 0x000000000312d1bc llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) llvm-project/llvm/include/llvm/IR/PassManager.h:521:0
> #19 0x0000000003f506ce llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:90:0
> #20 0x000000000312cb92 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) llvm-project/llvm/lib/IR/PassManager.cpp:125:0
> #21 0x0000000003f50632 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:90:0
> #22 0x000000000312cecc llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) llvm-project/llvm/include/llvm/IR/PassManager.h:521:0
> #23 0x0000000001bf4eeb llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool) llvm-project/llvm/tools/opt/NewPMDriver.cpp:522:0
> #24 0x0000000001c1f4f2 main llvm-project/llvm/tools/opt/opt.cpp:719:0
> #25 0x00007f1bd1f55c05 __libc_start_main (/lib64/libc.so.6+0x21c05)
> #26 0x0000000001bed2a9 _start (llvm-project/buildDA/bin/opt+0x1bed2a9)
>
> It doesn't crash if I revert 26fec4e845a833214d2b0036ea90f1b1c2418d50 <https://reviews.llvm.org/rG26fec4e845a833214d2b0036ea90f1b1c2418d50> and 5dccea5a68fb5181ab88ce6faac4668934f35cd7 <https://reviews.llvm.org/rG5dccea5a68fb5181ab88ce6faac4668934f35cd7>.
Fixed in 5f53e85f8aa92ff0cf7d674a92491e06683f73ef <https://reviews.llvm.org/rG5f53e85f8aa92ff0cf7d674a92491e06683f73ef>
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D140580/new/
https://reviews.llvm.org/D140580
More information about the llvm-commits
mailing list