Datasets:

Modalities:
Text
Formats:
json
Size:
< 1K
Tags:
code
DOI:
Libraries:
Datasets
pandas
License:
dtcxzyw's picture
Sync
8d5ae49
raw
history blame
16.9 kB
{
"bug_id": "106780",
"issue_url": "https://github.com/llvm/llvm-project/issues/106780",
"bug_type": "crash",
"base_commit": "5aa83eb677d2f8cba0c2ad3dcc14f3f4e80a0bba",
"knowledge_cutoff": "2024-08-30T19:02:15Z",
"lit_test_dir": [
"llvm/test/Transforms/LoopVectorize"
],
"hints": {
"fix_commit": "654bb4e9f287f9ccb5142d1c62a9ab17c16e29d7",
"components": [
"LoopVectorize"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [
[
6817,
6822
]
]
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [
"LoopVectorizationCostModel::collectValuesToIgnore"
]
}
},
"patch": "commit 654bb4e9f287f9ccb5142d1c62a9ab17c16e29d7\nAuthor: Florian Hahn <[email protected]>\nDate: Sun Sep 1 20:35:28 2024 +0100\n\n [LV] Don't consider branches leaving loop in collectValuesToIgnore.\n \n Branches exiting the loop will remain regardless, so don't consider them\n in collectValuesToIgnore.\n \n This fixes another divergence between legacy and VPlan-based cost model.\n \n Fixes https://github.com/llvm/llvm-project/issues/106780.\n\ndiff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\nindex fa05b8dd2242..a8722db654f5 100644\n--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n@@ -6817,6 +6817,9 @@ void LoopVectorizationCostModel::collectValuesToIgnore() {\n if (auto *Br = dyn_cast_or_null<BranchInst>(Op)) {\n BasicBlock *ThenBB = Br->getSuccessor(0);\n BasicBlock *ElseBB = Br->getSuccessor(1);\n+ // Don't considers branches leaving the loop for simplification.\n+ if (!TheLoop->contains(ThenBB) || !TheLoop->contains(ElseBB))\n+ continue;\n bool ThenEmpty = IsEmptyBlock(ThenBB);\n bool ElseEmpty = IsEmptyBlock(ElseBB);\n if ((ThenEmpty && ElseEmpty) ||\n",
"tests": [
{
"file": "llvm/test/Transforms/LoopVectorize/RISCV/dead-ops-cost.ll",
"commands": [
"opt -p loop-vectorize -mtriple riscv64-linux-gnu -mattr=+v,+f -S %s"
],
"tests": [
{
"test_name": "dead_load",
"test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine void @dead_load(ptr %p, i16 %start) {\nentry:\n %start.ext = sext i16 %start to i64\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ %start.ext, %entry ], [ %iv.next, %loop ]\n %gep = getelementptr i16, ptr %p, i64 %iv\n store i16 0, ptr %gep, align 2\n %l = load i16, ptr %gep, align 2\n %iv.next = add i64 %iv, 3\n %cmp = icmp slt i64 %iv, 111\n br i1 %cmp, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n"
},
{
"test_name": "cost_of_exit_branch_and_cond_insts",
"test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i16 @llvm.umax.i16(i16, i16) #0\n\ndefine i32 @cost_of_exit_branch_and_cond_insts(ptr %a, ptr %b, i1 %c, i16 %x) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]\n br i1 %c, label %then, label %loop.exiting\n\nthen: ; preds = %loop.header\n %gep = getelementptr inbounds i32, ptr %b, i32 %iv\n store i1 false, ptr %a, align 1\n store i32 0, ptr %gep, align 4\n br label %loop.exiting\n\nloop.exiting: ; preds = %then, %loop.header\n %iv.next = add i32 %iv, 1\n %umax = tail call i16 @llvm.umax.i16(i16 %x, i16 111)\n %umax.ext = zext i16 %umax to i32\n %sub = sub i32 770, %umax.ext\n %ec = icmp slt i32 %iv, %sub\n br i1 %ec, label %loop.latch, label %exit\n\nloop.latch: ; preds = %loop.exiting\n br label %loop.header\n\nexit: ; preds = %loop.exiting\n br label %return\n\nreturn: ; preds = %exit\n ret i32 0\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"
},
{
"test_name": "dead_live_out_due_to_scalar_epilogue_required",
"test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine i8 @dead_live_out_due_to_scalar_epilogue_required(ptr %src, ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %idxprom = sext i32 %iv to i64\n %gep.src = getelementptr i8, ptr %src, i64 %idxprom\n %l = load i8, ptr %gep.src, align 1\n %gep.dst = getelementptr i8, ptr %dst, i64 %idxprom\n store i8 0, ptr %gep.dst, align 1\n %iv.next = add i32 %iv, 4\n %cmp = icmp ult i32 %iv, 1001\n br i1 %cmp, label %loop, label %exit\n\nexit: ; preds = %loop\n %r = phi i8 [ %l, %loop ]\n ret i8 %r\n}\n"
}
]
}
],
"issue": {
"title": "[VPlan] Assertion \" VPlan cost model and legacy cost model disagreed\"' failed.",
"body": "Tested using ef7b18a53c0d186dcda1e322be6035407fdedb55\r\n\r\nTestcase:\r\n```c\r\nunsigned short a;\r\nextern int b;\r\nvoid c(_Bool d, int e, long long f[], unsigned short g[][16],\r\n unsigned short h[][16], unsigned short i[][13], short j[][13],\r\n int k[][21], unsigned char l[][21][21], signed char m[][24]) {\r\n for (short n = 0; n < 5; n += -5532)\r\n for (char o = 0; o < 3; o += d)\r\n for (int p = 0; p < -({ g[d][1] > 0115 ? g[d][1] : 0115; }) + 770; p++)\r\n for (_Bool q = 0; q < (_Bool)e; q = 5)\r\n for (_Bool r = 2048749519 ? 8 ? f[d] : 0 : 0; r < 1; r = h)\r\n b = a = 0;\r\n}\r\nvoid hash();\r\nunsigned short a = 6;\r\nlong long f[6];\r\nunsigned short g[6][16];\r\nunsigned short h[1][16];\r\nunsigned short i[1][13];\r\nshort j[1][13];\r\nint k[1][21];\r\nunsigned char l[1][21][21];\r\nsigned char m[1][24];\r\nint main() {\r\n for (long s = 0; s < 6; ++s)\r\n f[s] = 6;\r\n for (long s = 0; s < 16; ++s)\r\n for (long n = 0; n < 16; ++n)\r\n g[s][n] = 7;\r\n c(1, 407418382874, f, g, h, i, j, k, l, m);\r\n hash(a);\r\n}\r\n```\r\nc command:\r\n```\r\n/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/clang -fno-strict-aliasing -march=rv64gcv -flto -O3 -fuse-ld=lld red.c -o rv64gcv.out -w\r\n```\r\n\r\nLLVM IR testcase:\r\n```llvm ir\r\n; ModuleID = 'reduced.bc'\r\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"riscv64-unknown-linux-gnu\"\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare i16 @llvm.umax.i16(i16, i16) #0\r\n\r\ndefine i32 @main(ptr %a) #1 {\r\nentry:\r\n br label %for.cond22.preheader.us.us76.us.us.us.us.i.1\r\n\r\nfor.cond22.preheader.us.us76.us.us.us.us.i.1: ; preds = %for.cond22.preheader.us.us76.us.us.us.usthread-pre-split.i.1, %entry\r\n %p.072.us.us77.us.us.us.us.i.1 = phi i32 [ %inc.us.us80.us.us.us.us.i.1, %for.cond22.preheader.us.us76.us.us.us.usthread-pre-split.i.1 ], [ 0, %entry ]\r\n br i1 false, label %for.body41.lr.ph.us.us.us.us.us.us.us.i.1, label %for.cond22.for.cond.cleanup28_crit_edge.us.us.us.us.us.us.i.1\r\n\r\nfor.body41.lr.ph.us.us.us.us.us.us.us.i.1: ; preds = %for.cond22.preheader.us.us76.us.us.us.us.i.1\r\n store i1 false, ptr %a, align 1\r\n store i32 0, ptr null, align 4\r\n br label %for.cond22.for.cond.cleanup28_crit_edge.us.us.us.us.us.us.i.1\r\n\r\nfor.cond22.for.cond.cleanup28_crit_edge.us.us.us.us.us.us.i.1: ; preds = %for.body41.lr.ph.us.us.us.us.us.us.us.i.1, %for.cond22.preheader.us.us76.us.us.us.us.i.1\r\n %inc.us.us80.us.us.us.us.i.1 = add i32 %p.072.us.us77.us.us.us.us.i.1, 1\r\n %narrow.us.us81.us.us.us.us.i.1 = tail call i16 @llvm.umax.i16(i16 0, i16 0)\r\n %spec.select.us.us82.us.us.us.us.i.1 = zext i16 %narrow.us.us81.us.us.us.us.i.1 to i32\r\n %add.us.us83.us.us.us.us.i.1 = sub i32 770, %spec.select.us.us82.us.us.us.us.i.1\r\n %cmp18.us.us84.us.us.us.us.i.1 = icmp slt i32 %p.072.us.us77.us.us.us.us.i.1, %add.us.us83.us.us.us.us.i.1\r\n br i1 %cmp18.us.us84.us.us.us.us.i.1, label %for.cond22.preheader.us.us76.us.us.us.usthread-pre-split.i.1, label %for.cond22.for.cond.cleanup28_crit_edge.us.us.us.us.us.us.i.1.for.cond.cleanup20.us.us.us.us.i.1_crit_edge\r\n\r\nfor.cond22.for.cond.cleanup28_crit_edge.us.us.us.us.us.us.i.1.for.cond.cleanup20.us.us.us.us.i.1_crit_edge: ; preds = %for.cond22.for.cond.cleanup28_crit_edge.us.us.us.us.us.us.i.1\r\n br label %for.cond.cleanup20.us.us.us.us.i.1\r\n\r\nfor.cond.cleanup20.us.us.us.us.i.1: ; preds = %for.cond22.for.cond.cleanup28_crit_edge.us.us.us.us.us.us.i.1.for.cond.cleanup20.us.us.us.us.i.1_crit_edge\r\n ret i32 0\r\n\r\nfor.cond22.preheader.us.us76.us.us.us.usthread-pre-split.i.1: ; preds = %for.cond22.for.cond.cleanup28_crit_edge.us.us.us.us.us.us.i.1\r\n br label %for.cond22.preheader.us.us76.us.us.us.us.i.1\r\n}\r\n\r\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\nattributes #1 = { \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-b,-e,-experimental-smctr,-experimental-smmpm,-experimental-smnpm,-experimental-ssctr,-experimental-ssnpm,-experimental-sspm,-experimental-supm,-experimental-zacas,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-experimental-zvbc32e,-experimental-zvkgs,-h,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smepmp,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssqosid,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zaamo,-zabha,-zalrsc,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-ztso,-zvbb,-zvbc,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b\" }\r\n```\r\n\r\nCommand/backtrace:\r\n```\r\n> /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes=loop-vectorize reduced.ll -S\r\nopt: /scratch/tc-testing/tc-compiler-fuzz-trunk/llvm/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7366: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), CostCtx, OrigLoop)) && \" VPlan cost model and legacy cost model disagreed\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0. Program arguments: /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes=loop-vectorize reduced.ll -S\r\n1. Running pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"reduced.ll\"\r\n2. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"main\"\r\n #0 0x00005e8221f7d690 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x301e690)\r\n #1 0x00005e8221f7aa9f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x301ba9f)\r\n #2 0x00005e8221f7abf5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x0000772c88c42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x0000772c88c969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x0000772c88c969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x0000772c88c969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x0000772c88c42476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x0000772c88c287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x0000772c88c2871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x0000772c88c39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x00005e8220f4a3e0 llvm::LoopVectorizationPlanner::computeBestVF() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1feb3e0)\r\n#12 0x00005e8220f60ffb llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2001ffb)\r\n#13 0x00005e8220f64011 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2005011)\r\n#14 0x00005e8220f64687 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2005687)\r\n#15 0x00005e821fdc0fb6 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe61fb6)\r\n#16 0x00005e8221d8858f llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e2958f)\r\n#17 0x00005e821fdc4146 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe65146)\r\n#18 0x00005e8221d8730b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e2830b)\r\n#19 0x00005e821fdc03e6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe613e6)\r\n#20 0x00005e8221d8534d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e2634d)\r\n#21 0x00005e821f5e6ee6 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) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x687ee6)\r\n#22 0x00005e821f5d8c71 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x679c71)\r\n#23 0x0000772c88c29d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#24 0x0000772c88c29e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#25 0x0000772c88c29e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#26 0x00005e821f5cf025 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x670025)\r\nzsh: IOT instruction (core dumped) /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt\r\n```\r\nhttps://godbolt.org/z/ej1Gax953\r\n\r\nFound via fuzzer\r\n\r\nRelated/prior issue: https://github.com/llvm/llvm-project/issues/106641\r\n\r\ncc @fhahn",
"author": "patrick-rivos",
"labels": [
"vectorizers",
"crash"
],
"comments": []
},
"verified": true
}