Datasets:

Modalities:
Text
Formats:
json
Size:
< 1K
Tags:
code
DOI:
Libraries:
Datasets
pandas
License:
dtcxzyw's picture
Sync
8d5ae49
raw
history blame
8.88 kB
{
"bug_id": "101213",
"issue_url": "https://github.com/llvm/llvm-project/issues/101213",
"bug_type": "crash",
"base_commit": "8364a6e108faea1a6f05f7bb53720a6fc101fed2",
"knowledge_cutoff": "2024-07-30T18:00:09Z",
"lit_test_dir": [
"llvm/test/Transforms/SLPVectorizer"
],
"hints": {
"fix_commit": "f70f1228035c9610de38e0e376afdacb647c4ad9",
"components": [
"SLPVectorizer"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
[
13909,
13919
]
]
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
"BoUpSLP::vectorizeTree"
]
}
},
"patch": "commit f70f1228035c9610de38e0e376afdacb647c4ad9\nAuthor: Alexey Bataev <[email protected]>\nDate: Tue Jul 30 14:02:51 2024 -0700\n\n [SLP]Fix PR101213: Reuse extractelement, only if its vector operand comes before new vector value.\n \n When trying to reuse extractelement instruction, need to check that it\n is inserted into proper position. Its original vector operand should\n come before new vector value, otherwise new extractelement instruction\n must be generated.\n \n Fixes https://github.com/llvm/llvm-project/issues/101213\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex 6501a14d8778..cf87b8621027 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -13909,11 +13909,16 @@ Value *BoUpSLP::vectorizeTree(\n }\n if (!Ex) {\n // \"Reuse\" the existing extract to improve final codegen.\n- if (auto *ES = dyn_cast<ExtractElementInst>(Scalar)) {\n+ if (auto *ES = dyn_cast<ExtractElementInst>(Scalar);\n+ ES && isa<Instruction>(Vec)) {\n Value *V = ES->getVectorOperand();\n if (const TreeEntry *ETE = getTreeEntry(V))\n V = ETE->VectorizedValue;\n- Ex = Builder.CreateExtractElement(V, ES->getIndexOperand());\n+ if (auto *IV = dyn_cast<Instruction>(V);\n+ !IV || IV == Vec || IV->comesBefore(cast<Instruction>(Vec)))\n+ Ex = Builder.CreateExtractElement(V, ES->getIndexOperand());\n+ else\n+ Ex = Builder.CreateExtractElement(Vec, Lane);\n } else if (ReplaceGEP) {\n // Leave the GEPs as is, they are free in most cases and better to\n // keep them as GEPs.\n",
"tests": [
{
"file": "llvm/test/Transforms/SLPVectorizer/X86/extract-vectorized-operand.ll",
"commands": [
"opt -S --passes=slp-vectorizer -slp-threshold=-99999 < %s -mtriple=x86_64-unknown-linux-gnu"
],
"tests": [
{
"test_name": "test",
"test_body": "define void @test() {\nbb:\n %0 = shufflevector <2 x ptr addrspace(1)> zeroinitializer, <2 x ptr addrspace(1)> zeroinitializer, <2 x i32> <i32 1, i32 0>\n %1 = extractelement <2 x ptr addrspace(1)> %0, i32 0\n %2 = extractelement <2 x ptr addrspace(1)> %0, i32 1\n br label %bb43\n\nbb20: ; No predecessors!\n br label %bb105\n\nbb43: ; preds = %bb51, %bb\n %phi441 = phi ptr addrspace(1) [ %4, %bb51 ], [ %2, %bb ]\n %phi452 = phi ptr addrspace(1) [ %5, %bb51 ], [ %1, %bb ]\n br i1 false, label %bb105, label %bb51\n\nbb51: ; preds = %bb54, %bb43\n %3 = phi <2 x ptr addrspace(1)> [ poison, %bb54 ], [ zeroinitializer, %bb43 ]\n %4 = extractelement <2 x ptr addrspace(1)> %3, i32 0\n %5 = extractelement <2 x ptr addrspace(1)> %3, i32 1\n br label %bb43\n\nbb54: ; No predecessors!\n br label %bb51\n\nbb105: ; preds = %bb43, %bb20\n %phi106 = phi ptr addrspace(1) [ %1, %bb20 ], [ null, %bb43 ]\n ret void\n}\n"
}
]
}
],
"issue": {
"title": "[SLPVectorizer] Instruction does not dominate all uses! LLVM ERROR: Broken module found, compilation aborted!",
"body": "To reproduce run the following test with -passes slp-vectorizer -slp-threshold=-99999\r\n[Test.ll.tgz](https://github.com/user-attachments/files/16431764/Test.ll.tgz)\r\n\r\nReproducer : https://godbolt.org/z/GW41a7WP6\r\n\r\nStack dump:\r\n```\r\nInstruction does not dominate all uses!\r\n %2 = shufflevector <2 x ptr addrspace(1)> %0, <2 x ptr addrspace(1)> poison, <2 x i32> <i32 1, i32 0>\r\n %1 = extractelement <2 x ptr addrspace(1)> %2, i32 0\r\nLLVM ERROR: Broken module found, compilation aborted!\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes slp-vectorizer -slp-threshold=-99999 <source>\r\n1.\tRunning pass \"verify\" on module \"<source>\"\r\n #0 0x0000000004eff778 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4eff778)\r\n #1 0x0000000004efceec SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007c0269e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007c0269e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007c0269e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007c0269e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00000000007b3ff7 llvm::json::operator==(llvm::json::Value const&, llvm::json::Value const&) (.cold) JSON.cpp:0:0\r\n #7 0x0000000004e396a8 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e396a8)\r\n #8 0x0000000004d360f0 llvm::VerifierPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d360f0)\r\n #9 0x00000000008d865e llvm::detail::PassModel<llvm::Module, llvm::VerifierPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d865e)\r\n#10 0x0000000004cf9c90 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4cf9c90)\r\n#11 0x00000000008e33d2 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8e33d2)\r\n#12 0x00000000008d62fc optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d62fc)\r\n#13 0x00007c0269e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#14 0x00007c0269e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#15 0x00000000008cd75e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8cd75e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```\r\n",
"author": "TatyanaDoubts",
"labels": [
"llvm:SLPVectorizer",
"llvm:crash"
],
"comments": [
{
"author": "Zentrik",
"body": "@alexey-bataev Hi, is there a way to backport this fix for llvm 19, I tried just cherry picking f70f1228035c9610de38e0e376afdacb647c4ad9 but I ended up getting assertion failures of the form `/workspace/srcdir/llvm-project/llvm/lib/IR/Instruction.cpp:321: bool llvm::Instruction::comesBefore(const llvm::Instruction*) const: Assertion 'getParent() == Other->getParent() && \"cross-BB instruction order comparison\"' failed.'`. \r\nI can create an IR reproducer for that failure if need be.\r\nThank you.\r\n\r\nEDIT: Would just adding a check that they're in the same basic block work?"
},
{
"author": "alexey-bataev",
"body": "> @alexey-bataev Hi, is there a way to backport this fix for llvm 19, I tried just cherry picking [f70f122](https://github.com/llvm/llvm-project/commit/f70f1228035c9610de38e0e376afdacb647c4ad9) but I ended up getting assertion failures of the form `/workspace/srcdir/llvm-project/llvm/lib/IR/Instruction.cpp:321: bool llvm::Instruction::comesBefore(const llvm::Instruction*) const: Assertion 'getParent() == Other->getParent() && \"cross-BB instruction order comparison\"' failed.'`. I can create an IR reproducer for that failure if need be. Thank you.\r\n> \r\n> EDIT: Would just adding a check that they're in the same basic block work?\r\n\r\nYes, check for the same parent should fix it"
}
]
},
"verified": true
}