Sync
Browse files- dataset.jsonl +1 -1
- dataset/105785.json +2 -1
- scripts/llvm_helper.py +3 -3
dataset.jsonl
CHANGED
@@ -31,7 +31,7 @@
|
|
31 |
{"bug_id": "133751", "issue_url": "https://github.com/llvm/llvm-project/issues/133751", "bug_type": "crash", "base_commit": "2d7add6e2e56baf46504a8a22dec42b61f63360f", "knowledge_cutoff": "2025-03-31T16:55:56Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "bfd8cc0a3e82c5e6345a66dd5db5242accb6874b", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[8854, 8860]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["BoUpSLP::buildTree_rec"]}}, "patch": "commit bfd8cc0a3e82c5e6345a66dd5db5242accb6874b\nAuthor: Alexey Bataev <[email protected]>\nDate: Mon Mar 31 10:31:18 2025 -0700\n\n [SLP]Fix a check for the whole register use\n \n Need to check the value type, not the return type, of the instructions,\n when doing the analysis for the whole register use to prevent a compiler\n crash.\n \n Fixes #133751\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex a4b0378abc07..0679eac17658 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -8854,7 +8854,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,\n // FIXME: Reshuffing scalars is not supported yet for non-power-of-2 ops.\n if ((UserTreeIdx.UserTE &&\n UserTreeIdx.UserTE->hasNonWholeRegisterOrNonPowerOf2Vec(*TTI)) ||\n- !hasFullVectorsOrPowerOf2(*TTI, VL.front()->getType(), VL.size())) {\n+ !hasFullVectorsOrPowerOf2(*TTI, getValueType(VL.front()),\n+ VL.size())) {\n LLVM_DEBUG(dbgs() << \"SLP: Reshuffling scalars not yet supported \"\n \"for nodes with padding.\\n\");\n auto Invalid = ScheduleBundle::invalid();\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/X86/cmp-values-non-full-registers.ll", "commands": ["opt -S --passes=slp-vectorizer -mtriple=x86_64-grtev4-linux-gnu < %s"], "tests": [{"test_name": "<module>", "test_body": "\ndefine void @test() {\n;\nentry:\n br i1 false, label %bb1, label %bb2\n\nbb2:\n %cmp14.us = fcmp ogt x86_fp80 0xK00000000000000000000, 0xK00000000000000000000\n %imax.2.us = select i1 %cmp14.us, i64 0, i64 0\n %jmax.2.us = select i1 %cmp14.us, i64 0, i64 0\n %cmp13.us = fcmp olt x86_fp80 0xK00000000000000000000, 0xK00000000000000000000\n %imin.2.us = select i1 %cmp13.us, i64 0, i64 0\n %jmin.2.us = select i1 %cmp13.us, i64 0, i64 0\n br label %bb1\n\nbb1:\n %storemerge64 = phi i64 [ 0, %entry ], [ %imin.2.us, %bb2 ]\n %storemerge63 = phi i64 [ 0, %entry ], [ %jmin.2.us, %bb2 ]\n %storemerge62 = phi i64 [ 0, %entry ], [ %imax.2.us, %bb2 ]\n %storemerge = phi i64 [ 0, %entry ], [ %jmax.2.us, %bb2 ]\n ret void\n}"}]}], "issue": {"title": "SLPVectorizer: \"Reshuffling scalars not yet supported for nodes with padding\" assert", "body": "```\n$ cat /tmp/a.ll\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-grtev4-linux-gnu\"\n\ndefine void @gsl_matrix_long_double_minmax_index() {\nentry:\n br i1 false, label %cleanup22, label %for.cond6.preheader.us.preheader\n\nfor.cond6.preheader.us.preheader: ; preds = %entry\n %cmp14.us = fcmp ogt x86_fp80 0xK00000000000000000000, 0xK00000000000000000000\n %imax.2.us = select i1 %cmp14.us, i64 0, i64 0\n %jmax.2.us = select i1 %cmp14.us, i64 0, i64 0\n %cmp13.us = fcmp olt x86_fp80 0xK00000000000000000000, 0xK00000000000000000000\n %imin.2.us = select i1 %cmp13.us, i64 0, i64 0\n %jmin.2.us = select i1 %cmp13.us, i64 0, i64 0\n br label %cleanup22\n\ncleanup22: ; preds = %for.cond6.preheader.us.preheader, %entry\n %storemerge64 = phi i64 [ 0, %entry ], [ %imin.2.us, %for.cond6.preheader.us.preheader ]\n %storemerge63 = phi i64 [ 0, %entry ], [ %jmin.2.us, %for.cond6.preheader.us.preheader ]\n %storemerge62 = phi i64 [ 0, %entry ], [ %imax.2.us, %for.cond6.preheader.us.preheader ]\n %storemerge = phi i64 [ 0, %entry ], [ %jmax.2.us, %for.cond6.preheader.us.preheader ]\n ret void\n}\n$ opt -p slp-vectorizer /tmp/a.ll -disable-output\nopt: ../../llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:3714: TreeEntry *llvm::slpvectorizer::BoUpSLP::newTreeEntry(ArrayRef<Value *>, TreeEntry::EntryState, ScheduleBundle &, const InstructionsState &, const EdgeInfo &, ArrayRef<int>, ArrayRef<unsigned int>): Assertion `(hasFullVectorsOrPowerOf2(*TTI, \ngetValueType(VL.front()), VL.size()) || ReuseShuffleIndices.empty()) && \"Reshuffling scalars not yet supported for nodes with padding\"' failed. \n\n```\n\n@alexey-bataev ", "author": "aeubanks", "labels": ["llvm:SLPVectorizer", "crash-on-valid"], "comments": []}, "verified": true}
|
32 |
{"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}
|
33 |
{"bug_id": "150479", "issue_url": "https://github.com/llvm/llvm-project/issues/150479", "bug_type": "crash", "base_commit": "8952225d88a5ce58a65c8b8695c610f4499d7181", "knowledge_cutoff": "2025-07-24T17:33:31Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "c9cea24fe68e24750b2d479144f839e1c2ec9d2b", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[6861, 6867], [15704, 15710], [15803, 15809], [15816, 15822], [16438, 16461], [16470, 16482], [16512, 16522], [16554, 16560], [16586, 16592], [21001, 21009], [21253, 21258]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["BoUpSLP::computeMinimumValueSizes", "BoUpSLP::getLastInstructionInBundle", "BoUpSLP::getReorderingData", "BoUpSLP::isGatherShuffledSingleRegisterEntry"]}}, "patch": "commit c9cea24fe68e24750b2d479144f839e1c2ec9d2b\nAuthor: Alexey Bataev <[email protected]>\nDate: Thu Jul 24 11:40:26 2025 -0700\n\n [SLP] Check if the user node has state before trying getting main instruction/opcode\n \n Need to check if the parent node has state to prevent compiler crashes.\n Fixes #150479\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex 0adad5a90d31..44dc43d5e77c 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -6861,7 +6861,7 @@ BoUpSLP::getReorderingData(const TreeEntry &TE, bool TopToBottom,\n return std::move(ResOrder);\n }\n if (TE.State == TreeEntry::StridedVectorize && !TopToBottom &&\n- (!TE.UserTreeIndex ||\n+ (!TE.UserTreeIndex || !TE.UserTreeIndex.UserTE->hasState() ||\n !Instruction::isBinaryOp(TE.UserTreeIndex.UserTE->getOpcode())) &&\n (TE.ReorderIndices.empty() || isReverseOrder(TE.ReorderIndices)))\n return std::nullopt;\n@@ -15704,7 +15704,8 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry(\n const BasicBlock *TEInsertBlock = nullptr;\n // Main node of PHI entries keeps the correct order of operands/incoming\n // blocks.\n- if (auto *PHI = dyn_cast<PHINode>(TEUseEI.UserTE->getMainOp());\n+ if (auto *PHI = dyn_cast_or_null<PHINode>(\n+ TEUseEI.UserTE->hasState() ? TEUseEI.UserTE->getMainOp() : nullptr);\n PHI && TEUseEI.UserTE->State != TreeEntry::SplitVectorize) {\n TEInsertBlock = PHI->getIncomingBlock(TEUseEI.EdgeIdx);\n TEInsertPt = TEInsertBlock->getTerminator();\n@@ -15803,7 +15804,8 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry(\n \"Expected only single user of a gather node.\");\n const EdgeInfo &UseEI = TEPtr->UserTreeIndex;\n \n- PHINode *UserPHI = UseEI.UserTE->State != TreeEntry::SplitVectorize\n+ PHINode *UserPHI = (UseEI.UserTE->State != TreeEntry::SplitVectorize &&\n+ UseEI.UserTE->hasState())\n ? dyn_cast<PHINode>(UseEI.UserTE->getMainOp())\n : nullptr;\n Instruction *InsertPt =\n@@ -15816,7 +15818,8 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry(\n TEUseEI.UserTE->isAltShuffle()) &&\n all_of(TEUseEI.UserTE->Scalars, isUsedOutsideBlock)) {\n if (UseEI.UserTE->State != TreeEntry::Vectorize ||\n- (UseEI.UserTE->getOpcode() == Instruction::PHI &&\n+ (UseEI.UserTE->hasState() &&\n+ UseEI.UserTE->getOpcode() == Instruction::PHI &&\n !UseEI.UserTE->isAltShuffle()) ||\n !all_of(UseEI.UserTE->Scalars, isUsedOutsideBlock))\n continue;\n@@ -16438,24 +16441,31 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {\n // Get the basic block this bundle is in. All instructions in the bundle\n // should be in this block (except for extractelement-like instructions with\n // constant indices or gathered loads or copyables).\n- auto *Front = E->getMainOp();\n+ Instruction *Front;\n+ unsigned Opcode;\n+ if (E->hasState()) {\n+ Front = E->getMainOp();\n+ Opcode = E->getOpcode();\n+ } else {\n+ Front = cast<Instruction>(*find_if(E->Scalars, IsaPred<Instruction>));\n+ Opcode = Front->getOpcode();\n+ }\n auto *BB = Front->getParent();\n- assert(((GatheredLoadsEntriesFirst.has_value() &&\n- E->getOpcode() == Instruction::Load && E->isGather() &&\n- E->Idx < *GatheredLoadsEntriesFirst) ||\n- E->State == TreeEntry::SplitVectorize || E->hasCopyableElements() ||\n- all_of(E->Scalars,\n- [=](Value *V) -> bool {\n- if (E->getOpcode() == Instruction::GetElementPtr &&\n- !isa<GetElementPtrInst>(V))\n- return true;\n- auto *I = dyn_cast<Instruction>(V);\n- return !I || !E->getMatchingMainOpOrAltOp(I) ||\n- I->getParent() == BB ||\n- isVectorLikeInstWithConstOps(I);\n- })) &&\n- \"Expected gathered loads or GEPs or instructions from same basic \"\n- \"block.\");\n+ assert(\n+ ((GatheredLoadsEntriesFirst.has_value() && Opcode == Instruction::Load &&\n+ E->isGather() && E->Idx < *GatheredLoadsEntriesFirst) ||\n+ E->State == TreeEntry::SplitVectorize || E->hasCopyableElements() ||\n+ all_of(E->Scalars,\n+ [=](Value *V) -> bool {\n+ if (Opcode == Instruction::GetElementPtr &&\n+ !isa<GetElementPtrInst>(V))\n+ return true;\n+ auto *I = dyn_cast<Instruction>(V);\n+ return !I || !E->getMatchingMainOpOrAltOp(I) ||\n+ I->getParent() == BB || isVectorLikeInstWithConstOps(I);\n+ })) &&\n+ \"Expected gathered loads or GEPs or instructions from same basic \"\n+ \"block.\");\n \n auto FindLastInst = [&]() {\n Instruction *LastInst = Front;\n@@ -16470,13 +16480,13 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {\n LastInst = I;\n continue;\n }\n- assert(((E->getOpcode() == Instruction::GetElementPtr &&\n+ assert(((Opcode == Instruction::GetElementPtr &&\n !isa<GetElementPtrInst>(I)) ||\n E->State == TreeEntry::SplitVectorize ||\n (isVectorLikeInstWithConstOps(LastInst) &&\n isVectorLikeInstWithConstOps(I)) ||\n (GatheredLoadsEntriesFirst.has_value() &&\n- E->getOpcode() == Instruction::Load && E->isGather() &&\n+ Opcode == Instruction::Load && E->isGather() &&\n E->Idx < *GatheredLoadsEntriesFirst)) &&\n \"Expected vector-like or non-GEP in GEP node insts only.\");\n if (!DT->isReachableFromEntry(LastInst->getParent())) {\n@@ -16512,11 +16522,11 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {\n FirstInst = I;\n continue;\n }\n- assert(((E->getOpcode() == Instruction::GetElementPtr &&\n- !isa<GetElementPtrInst>(I)) ||\n- (isVectorLikeInstWithConstOps(FirstInst) &&\n- isVectorLikeInstWithConstOps(I))) &&\n- \"Expected vector-like or non-GEP in GEP node insts only.\");\n+ assert(((Opcode == Instruction::GetElementPtr &&\n+ !isa<GetElementPtrInst>(I)) ||\n+ (isVectorLikeInstWithConstOps(FirstInst) &&\n+ isVectorLikeInstWithConstOps(I))) &&\n+ \"Expected vector-like or non-GEP in GEP node insts only.\");\n if (!DT->isReachableFromEntry(FirstInst->getParent())) {\n FirstInst = I;\n continue;\n@@ -16554,7 +16564,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {\n // Set insertpoint for gathered loads to the very first load.\n if (GatheredLoadsEntriesFirst.has_value() &&\n E->Idx >= *GatheredLoadsEntriesFirst && !E->isGather() &&\n- E->getOpcode() == Instruction::Load) {\n+ Opcode == Instruction::Load) {\n Res = FindFirstInst();\n EntryToLastInstruction.try_emplace(E, Res);\n return *Res;\n@@ -16586,7 +16596,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {\n };\n const ScheduleBundle *Bundle = FindScheduleBundle(E);\n if (!E->isGather() && !Bundle) {\n- if ((E->getOpcode() == Instruction::GetElementPtr &&\n+ if ((Opcode == Instruction::GetElementPtr &&\n any_of(E->Scalars,\n [](Value *V) {\n return !isa<GetElementPtrInst>(V) && isa<Instruction>(V);\n@@ -21001,9 +21011,10 @@ void BoUpSLP::computeMinimumValueSizes() {\n if (!isa<CastInst, BinaryOperator, FreezeInst, PHINode,\n SelectInst>(U) ||\n isa<SIToFPInst, UIToFPInst>(U) ||\n- !isa<CastInst, BinaryOperator, FreezeInst, PHINode,\n- SelectInst>(UserTE->getMainOp()) ||\n- isa<SIToFPInst, UIToFPInst>(UserTE->getMainOp()))\n+ (UserTE->hasState() &&\n+ (!isa<CastInst, BinaryOperator, FreezeInst, PHINode,\n+ SelectInst>(UserTE->getMainOp()) ||\n+ isa<SIToFPInst, UIToFPInst>(UserTE->getMainOp()))))\n return true;\n unsigned UserTESz = DL->getTypeSizeInBits(\n UserTE->Scalars.front()->getType());\n@@ -21253,6 +21264,7 @@ void BoUpSLP::computeMinimumValueSizes() {\n NodeIdx < VectorizableTree.size() &&\n VectorizableTree[NodeIdx]->UserTreeIndex &&\n VectorizableTree[NodeIdx]->UserTreeIndex.EdgeIdx == 0 &&\n+ VectorizableTree[NodeIdx]->UserTreeIndex.UserTE->hasState() &&\n VectorizableTree[NodeIdx]->UserTreeIndex.UserTE->getOpcode() ==\n Instruction::Trunc &&\n !VectorizableTree[NodeIdx]->UserTreeIndex.UserTE->isAltShuffle();\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/X86/user-node-no-state.ll", "commands": ["opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s"], "tests": [{"test_name": "<module>", "test_body": "\n@g = global [128 x i8] zeroinitializer, align 16\n\ndefine i64 @test() {\n;\nentry:\n %0 = load i64, ptr @g, align 8\n br label %func_154.exit.func_146.exit_crit_edge.i\n\nfunc_154.exit.func_146.exit_crit_edge.i:\n %1 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 80), align 16\n %2 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 88), align 8\n %3 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 32), align 16\n %4 = load i64, ptr @g, align 16\n %5 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 8), align 8\n %6 = load i64, ptr @g, align 16\n %7 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 24), align 8\n %8 = xor i64 %1, %2\n %9 = xor i64 %8, %3\n %10 = xor i64 %9, %4\n %11 = xor i64 %10, %5\n %12 = xor i64 %11, %6\n %13 = xor i64 %12, %7\n %14 = xor i64 %13, %0\n ret i64 %14\n}"}]}], "issue": {"title": "[SLPVectorizer] Assertion `valid() && \"InstructionsState is invalid.\"' failed.", "body": "Reproducer: https://godbolt.org/z/Pj96ao9TK\n```\n; bin/opt -passes=slp-vectorizer test.ll -S\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@g = global [128 x i8] zeroinitializer, align 16\n\ndefine i64 @main() {\nentry:\n %0 = load i64, ptr @g, align 8\n br label %func_154.exit.func_146.exit_crit_edge.i\n\nfunc_154.exit.func_146.exit_crit_edge.i: ; preds = %entry\n %1 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 80), align 16\n %2 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 88), align 8\n %3 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 32), align 16\n %4 = load i64, ptr @g, align 16\n %5 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 8), align 8\n %6 = load i64, ptr @g, align 16\n %7 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 24), align 8\n %8 = xor i64 %1, %2\n %9 = xor i64 %8, %3\n %10 = xor i64 %9, %4\n %11 = xor i64 %10, %5\n %12 = xor i64 %11, %6\n %13 = xor i64 %12, %7\n %14 = xor i64 %13, %0\n ret i64 %14\n}\n```\n```\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:1204: llvm::Instruction* {anonymous}::InstructionsState::getMainOp() const: Assertion `valid() && \"InstructionsState is invalid.\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\nStack dump:\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=slp-vectorizer <source>\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\n2.\tRunning pass \"slp-vectorizer\" on function \"main\"\n #0 0x0000000005664458 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5664458)\n #1 0x0000000005661304 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x000075a3c1242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x000075a3c12969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x000075a3c1242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x000075a3c12287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x000075a3c122871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #7 0x000075a3c1239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #8 0x00000000034a0043 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x34a0043)\n #9 0x0000000003513355 llvm::slpvectorizer::BoUpSLP::getLastInstructionInBundle(llvm::slpvectorizer::BoUpSLP::TreeEntry const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3513355)\n#10 0x000000000355424e llvm::slpvectorizer::BoUpSLP::isGatherShuffledSingleRegisterEntry(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::MutableArrayRef<int>, llvm::SmallVectorImpl<llvm::slpvectorizer::BoUpSLP::TreeEntry const*>&, unsigned int, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x355424e)\n#11 0x0000000003558408 llvm::slpvectorizer::BoUpSLP::isGatherShuffledEntry(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallVectorImpl<int>&, llvm::SmallVectorImpl<llvm::SmallVector<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, 6u>>&, unsigned int, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3558408)\n#12 0x000000000355a2de llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::processBuildVector<llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator, llvm::InstructionCost, llvm::TargetTransformInfo, llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP, llvm::SmallPtrSetImpl<llvm::Value*>>(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::Type*, llvm::TargetTransformInfo&, llvm::ArrayRef<llvm::Value*>&, llvm::slpvectorizer::BoUpSLP&, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x355a2de)\n#13 0x000000000355c98f llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x355c98f)\n#14 0x000000000359597f llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>, llvm::InstructionCost) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x359597f)\n#15 0x000000000359ba1b (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&, llvm::AssumptionCache*) SLPVectorizer.cpp:0:0\n#16 0x000000000359ef90 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x359ef90)\n#17 0x00000000035a430b llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0\n#18 0x00000000035a8c0f llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x35a8c0f)\n#19 0x00000000035aef06 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0\n#20 0x00000000035af9eb llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x35af9eb)\n#21 0x0000000002dab8ce llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2dab8ce)\n#22 0x0000000005456241 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5456241)\n#23 0x0000000000eb675e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xeb675e)\n#24 0x0000000005456714 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5456714)\n#25 0x0000000000eb6a2e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xeb6a2e)\n#26 0x00000000054542e1 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x54542e1)\n#27 0x0000000000964bfa 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+0x964bfa)\n#28 0x0000000000958c79 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x958c79)\n#29 0x000075a3c1229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#30 0x000075a3c1229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#31 0x000000000094fd45 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x94fd45)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```\n\nI found this crash when fuzzing the code in https://github.com/llvm/llvm-project/pull/137297.\n", "author": "dtcxzyw", "labels": ["llvm:SLPVectorizer", "crash-on-valid", "generated by fuzzer"], "comments": []}, "verified": true}
|
34 |
-
{"bug_id": "105785", "issue_url": "https://github.com/llvm/llvm-project/issues/105785", "bug_type": "miscompilation", "base_commit": "1241c762c165972690c4edfb82ec7421c1e64658", "knowledge_cutoff": "2024-08-23T05:45:52Z", "lit_test_dir": ["llvm/test/Transforms/ConstraintElimination"], "hints": {"fix_commit": "85b6aac7c25f9d2a976a76045ace1e7afebb5965", "components": ["ConstraintElimination"], "bug_location_lineno": {"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": [[1464, 1470]]}, "bug_location_funcname": {"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": ["checkAndReplaceCmp"]}}, "patch": "commit 3ff9d92aae0945daa85ec6f85f05a3aeaaa9f962\nAuthor: Yingwei Zheng <[email protected]>\nDate: Fri Aug 23 16:06:00 2024 +0800\n\n [ConstraintElim] Fix miscompilation caused by PR97974 (#105790)\n \n Fixes https://github.com/llvm/llvm-project/issues/105785.\n \n (cherry picked from commit 85b6aac7c25f9d2a976a76045ace1e7afebb5965)\n\ndiff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp\nindex c31173879af1..37022104d0a9 100644\n--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp\n+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp\n@@ -1464,7 +1464,7 @@ static bool checkAndReplaceCmp(CmpIntrinsic *I, ConstraintInfo &Info,\n ToRemove.push_back(I);\n return true;\n }\n- if (checkCondition(ICmpInst::ICMP_EQ, LHS, RHS, I, Info)) {\n+ if (checkCondition(ICmpInst::ICMP_EQ, LHS, RHS, I, Info).value_or(false)) {\n I->replaceAllUsesWith(ConstantInt::get(I->getType(), 0));\n ToRemove.push_back(I);\n return true;\n", "tests": [{"file": "llvm/test/Transforms/ConstraintElimination/pr105785.ll", "commands": ["opt -passes=constraint-elimination -S %s"], "tests": [{"test_name": "pr105785", "test_body": "define void @pr105785(ptr %p) {\nentry:\n br label %for.cond\n\nfor.cond: ; preds = %for.cond1, %entry\n %for.ind = phi i32 [ 0, %entry ], [ 1, %for.cond1 ]\n %cmp = icmp eq i32 %for.ind, 0\n br i1 %cmp, label %for.cond1, label %for.end6\n\nfor.cond1: ; preds = %for.body3, %for.cond\n %for.ind2 = phi i32 [ %inc, %for.body3 ], [ 0, %for.cond ]\n %cmp2 = icmp ult i32 %for.ind2, 3\n br i1 %cmp2, label %for.body3, label %for.cond\n\nfor.body3: ; preds = %for.cond1\n %scmp = call i32 @llvm.scmp.i32.i32(i32 %for.ind, i32 1)\n store i32 %scmp, ptr %p, align 4\n %inc = add nuw nsw i32 %for.ind2, 1\n br label %for.cond1\n\nfor.end6: ; preds = %for.cond\n ret void\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.scmp.i32.i32(i32, i32) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}]}], "issue": {"title": "[ConstraintElim] Miscompilation with cmp intrinsic", "body": "Reproducer: https://alive2.llvm.org/ce/z/Tvz2NA\r\n```\r\n; bin/opt -passes=constraint-elimination test.ll -S\r\ndefine void @h(ptr %p) {\r\nentry:\r\n br label %for.cond\r\n\r\nfor.cond: ; preds = %for.cond1, %entry\r\n %storemerge = phi i32 [ 0, %entry ], [ 1, %for.cond1 ]\r\n %cmp = icmp eq i32 %storemerge, 0\r\n br i1 %cmp, label %for.cond1, label %for.end6\r\n\r\nfor.cond1: ; preds = %for.cond, %for.body3\r\n %i.0 = phi i32 [ %inc, %for.body3 ], [ 0, %for.cond ]\r\n %cmp2 = icmp ult i32 %i.0, 3\r\n br i1 %cmp2, label %for.body3, label %for.cond\r\n\r\nfor.body3: ; preds = %for.cond1\r\n %sub.i = tail call range(i32 -1, 2) i32 @llvm.scmp.i32.i32(i32 1, i32 %storemerge)\r\n store i32 %sub.i, ptr %p, align 4\r\n %inc = add nuw nsw i32 %i.0, 1\r\n br label %for.cond1\r\n\r\nfor.end6:\r\n ret void\r\n}\r\n```\r\n\r\n```\r\ndefine void @h(ptr %p) {\r\nentry:\r\n br label %for.cond\r\n\r\nfor.cond: ; preds = %for.cond1, %entry\r\n %storemerge = phi i32 [ 0, %entry ], [ 1, %for.cond1 ]\r\n %cmp = icmp eq i32 %storemerge, 0\r\n br i1 %cmp, label %for.cond1, label %for.end6\r\n\r\nfor.cond1: ; preds = %for.body3, %for.cond\r\n %i.0 = phi i32 [ %inc, %for.body3 ], [ 0, %for.cond ]\r\n %cmp2 = icmp ult i32 %i.0, 3\r\n br i1 %cmp2, label %for.body3, label %for.cond\r\n\r\nfor.body3: ; preds = %for.cond1\r\n store i32 0, ptr %p, align 4\r\n %inc = add nuw nsw i32 %i.0, 1\r\n br label %for.cond1\r\n\r\nfor.end6: ; preds = %for.cond\r\n ret void\r\n}\r\n```\r\n\r\nThe result of scmp should be 1 instead of 0.\r\n\r\nReduced C reproducer:\r\n```\r\n#include <stdio.h>\r\n#include <stdint.h>\r\n\r\nint builtin_scmp(int d, int e) { return (d > e) - (d < e); }\r\nint32_t f = 0;\r\nint64_t g = 0;\r\nvoid h() {\r\n for (f = 0; f <= 0; f++) {\r\n int i;\r\n for (i = 0; i < 3; i++)\r\n g = builtin_scmp(1, f);\r\n }\r\n}\r\nint main() {\r\n h();\r\n printf(\"%d\\n\", (int)g);\r\n return 0;\r\n}\r\n```\r\n\r\nI will post a fix later.\r\n", "author": "dtcxzyw", "labels": ["miscompilation", "llvm:transforms"], "comments": []}, "verified": true}
|
35 |
{"bug_id": "117518", "issue_url": "https://github.com/llvm/llvm-project/issues/117518", "bug_type": "crash", "base_commit": "3de21477c49172081e502b47d608e729915f0914", "knowledge_cutoff": "2024-11-25T05:31:23Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "f953b5eb72df77fc301aac210eab31c6270ff771", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[10875, 10883], [14372, 14378]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["finalize"]}}, "patch": "commit f953b5eb72df77fc301aac210eab31c6270ff771\nAuthor: Alexey Bataev <[email protected]>\nDate: Mon Nov 25 08:29:22 2024 -0800\n\n [SLP]Relax assertion about subvectors mask size\n \n SubVectorsMask might be less than CommonMask, if the vectors with larger\n number of elements are permuted or reused elements are used. Need to\n consider this when estimation/building the vector to avoid compiler\n crash\n \n Fixes #117518\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex 73218f377a06..34b80c1e3608 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -10875,9 +10875,10 @@ public:\n CommonMask[Idx] = Idx;\n // Add subvectors permutation cost.\n if (!SubVectorsMask.empty()) {\n- assert(SubVectorsMask.size() == CommonMask.size() &&\n+ assert(SubVectorsMask.size() <= CommonMask.size() &&\n \"Expected same size of masks for subvectors and common mask.\");\n- SmallVector<int> SVMask(SubVectorsMask.begin(), SubVectorsMask.end());\n+ SmallVector<int> SVMask(CommonMask.size(), PoisonMaskElem);\n+ copy(SubVectorsMask, SVMask.begin());\n for (auto [I1, I2] : zip(SVMask, CommonMask)) {\n if (I2 != PoisonMaskElem) {\n assert(I1 == PoisonMaskElem && \"Expected unused subvectors mask\");\n@@ -14372,7 +14373,8 @@ public:\n if (SubVectorsMask.empty()) {\n Vec = CreateSubVectors(Vec, CommonMask);\n } else {\n- SmallVector<int> SVMask(SubVectorsMask.begin(), SubVectorsMask.end());\n+ SmallVector<int> SVMask(CommonMask.size(), PoisonMaskElem);\n+ copy(SubVectorsMask, SVMask.begin());\n for (auto [I1, I2] : zip(SVMask, CommonMask)) {\n if (I2 != PoisonMaskElem) {\n assert(I1 == PoisonMaskElem && \"Expected unused subvectors mask\");\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/X86/non-power-of-2-subvectors-insert.ll", "commands": ["opt -S --passes=slp-vectorizer -slp-threshold=-300 -mtriple=x86_64-unknown-linux-gnu < %s"], "tests": [{"test_name": "<module>", "test_body": "\ndefine void @test() {\n;\n %xor108.i.i.i = xor i64 0, 1\n %conv115.i.i.i = trunc i64 %xor108.i.i.i to i16\n %add.i.i.i.i = or i16 %conv115.i.i.i, 0\n %add.i.frozen.i.i.i = freeze i16 %add.i.i.i.i\n %.cmp.not.i.i.i = icmp eq i16 %add.i.frozen.i.i.i, 0\n %cond.i1002.1.i.i.i = lshr i64 0, 0\n %conv115.1.i.i.i = trunc i64 %cond.i1002.1.i.i.i to i16\n %add.i.1.i.i.i = or i16 %conv115.1.i.i.i, 0\n %add.i.frozen.1.i.i.i = freeze i16 %add.i.1.i.i.i\n %.cmp.not.1.i.i.i = icmp eq i16 %add.i.frozen.1.i.i.i, 0\n %cond.i1002.2.i.i.i = lshr i64 %xor108.i.i.i, 0\n %conv115.2.i.i.i = trunc i64 %cond.i1002.2.i.i.i to i16\n %add.i.2.i.i.i = or i16 %conv115.2.i.i.i, 0\n %add.i.frozen.2.i.i.i = freeze i16 %add.i.2.i.i.i\n %.cmp.not.2.i.i.i = icmp eq i16 %add.i.frozen.2.i.i.i, 0\n %cond.i1002.3.i.i.i = lshr i64 0, 0\n %conv115.3.i.i.i = trunc i64 %cond.i1002.3.i.i.i to i16\n %add.i.3.i.i.i = or i16 %conv115.3.i.i.i, 0\n %add.i.frozen.3.i.i.i = freeze i16 %add.i.3.i.i.i\n %.cmp.not.3.i.i.i = icmp eq i16 %add.i.frozen.3.i.i.i, 0\n %conv115.i.i.i.1 = trunc i64 %xor108.i.i.i to i16\n %add.i.i.i.i.1 = or i16 %conv115.i.i.i.1, 0\n %add.i.frozen.i.i.i.1 = freeze i16 %add.i.i.i.i.1\n %.cmp.not.i.i.i.1 = icmp eq i16 %add.i.frozen.i.i.i.1, 0\n %cond.i1002.1.i.i.i.1 = lshr i64 0, 0\n %conv115.1.i.i.i.1 = trunc i64 %cond.i1002.1.i.i.i.1 to i16\n %add.i.1.i.i.i.1 = or i16 %conv115.1.i.i.i.1, 0\n %add.i.frozen.1.i.i.i.1 = freeze i16 %add.i.1.i.i.i.1\n %.cmp.not.1.i.i.i.1 = icmp eq i16 %add.i.frozen.1.i.i.i.1, 0\n %cond.i1002.2.i.i.i.1 = lshr i64 0, 0\n %conv115.2.i.i.i.1 = trunc i64 %cond.i1002.2.i.i.i.1 to i16\n %add.i.2.i.i.i.1 = or i16 %conv115.2.i.i.i.1, 0\n %add.i.frozen.2.i.i.i.1 = freeze i16 %add.i.2.i.i.i.1\n %.cmp.not.2.i.i.i.1 = icmp eq i16 %add.i.frozen.2.i.i.i.1, 0\n %cond.i1002.3.i.i.i.1 = lshr i64 0, 0\n %conv115.3.i.i.i.1 = trunc i64 %cond.i1002.3.i.i.i.1 to i16\n %add.i.3.i.i.i.1 = or i16 %conv115.3.i.i.i.1, 0\n %add.i.frozen.3.i.i.i.1 = freeze i16 %add.i.3.i.i.i.1\n %.cmp.not.3.i.i.i.1 = icmp eq i16 %add.i.frozen.3.i.i.i.1, 0\n %conv115.i.i.i.2 = trunc i64 %xor108.i.i.i to i16\n %add.i.i.i.i.2 = or i16 %conv115.i.i.i.2, 0\n %add.i.frozen.i.i.i.2 = freeze i16 %add.i.i.i.i.2\n %.cmp.not.i.i.i.2 = icmp eq i16 %add.i.frozen.i.i.i.2, 0\n %cond.i1002.1.i.i.i.2 = lshr i64 0, 0\n %conv115.1.i.i.i.2 = trunc i64 %cond.i1002.1.i.i.i.2 to i16\n %add.i.1.i.i.i.2 = or i16 %conv115.1.i.i.i.2, 0\n %add.i.frozen.1.i.i.i.2 = freeze i16 %add.i.1.i.i.i.2\n %.cmp.not.1.i.i.i.2 = icmp eq i16 %add.i.frozen.1.i.i.i.2, 0\n %cond.i1002.2.i.i.i.2 = lshr i64 0, 0\n %conv115.2.i.i.i.2 = trunc i64 %cond.i1002.2.i.i.i.2 to i16\n %add.i.2.i.i.i.2 = or i16 %conv115.2.i.i.i.2, 0\n %add.i.frozen.2.i.i.i.2 = freeze i16 %add.i.2.i.i.i.2\n %.cmp.not.2.i.i.i.2 = icmp eq i16 %add.i.frozen.2.i.i.i.2, 0\n %cond.i1002.3.i.i.i.2 = lshr i64 0, 0\n %conv115.3.i.i.i.2 = trunc i64 %cond.i1002.3.i.i.i.2 to i16\n %add.i.3.i.i.i.2 = or i16 %conv115.3.i.i.i.2, 0\n %add.i.frozen.3.i.i.i.2 = freeze i16 %add.i.3.i.i.i.2\n %.cmp.not.3.i.i.i.2 = icmp eq i16 %add.i.frozen.3.i.i.i.2, 0\n %conv115.i.i.i.3 = trunc i64 %xor108.i.i.i to i16\n %add.i.i.i.i.3 = or i16 %conv115.i.i.i.3, 0\n %add.i.frozen.i.i.i.3 = freeze i16 %add.i.i.i.i.3\n %.cmp.not.i.i.i.3 = icmp eq i16 %add.i.frozen.i.i.i.3, 0\n %cond.i1002.1.i.i.i.3 = lshr i64 0, 0\n %conv115.1.i.i.i.3 = trunc i64 %cond.i1002.1.i.i.i.3 to i16\n %add.i.1.i.i.i.3 = or i16 %conv115.1.i.i.i.3, 0\n %add.i.frozen.1.i.i.i.3 = freeze i16 %add.i.1.i.i.i.3\n %.cmp.not.1.i.i.i.3 = icmp eq i16 %add.i.frozen.1.i.i.i.3, 0\n %cond.i1002.2.i.i.i.3 = lshr i64 0, 0\n %conv115.2.i.i.i.3 = trunc i64 %cond.i1002.2.i.i.i.3 to i16\n %add.i.2.i.i.i.3 = or i16 %conv115.2.i.i.i.3, 0\n %add.i.frozen.2.i.i.i.3 = freeze i16 %add.i.2.i.i.i.3\n %.cmp.not.2.i.i.i.3 = icmp eq i16 %add.i.frozen.2.i.i.i.3, 0\n %cond.i1002.3.i.i.i.3 = lshr i64 0, 0\n %conv115.3.i.i.i.3 = trunc i64 %cond.i1002.3.i.i.i.3 to i16\n %add.i.3.i.i.i.3 = or i16 %conv115.3.i.i.i.3, 0\n %add.i.frozen.3.i.i.i.3 = freeze i16 %add.i.3.i.i.i.3\n %.cmp.not.3.i.i.i.3 = icmp eq i16 %add.i.frozen.3.i.i.i.3, 0\n ret void\n}"}]}], "issue": {"title": "[SLPVectorizer] Assertion `SubVectorsMask.size() == CommonMask.size() && \"Expected same size of masks for subvectors and common mask.\"' failed.", "body": "Reproducer: https://godbolt.org/z/chKcKacPK\r\n```\r\n; bin/opt -passes=slp-vectorizer test.ll -S\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine void @test() {\r\n %xor108.i.i.i = xor i64 0, 1\r\n %conv115.i.i.i = trunc i64 %xor108.i.i.i to i16\r\n %add.i.i.i.i = or i16 %conv115.i.i.i, 0\r\n %add.i.frozen.i.i.i = freeze i16 %add.i.i.i.i\r\n %.cmp.not.i.i.i = icmp eq i16 %add.i.frozen.i.i.i, 0\r\n %cond.i1002.1.i.i.i = lshr i64 0, 0\r\n %conv115.1.i.i.i = trunc i64 %cond.i1002.1.i.i.i to i16\r\n %add.i.1.i.i.i = or i16 %conv115.1.i.i.i, 0\r\n %add.i.frozen.1.i.i.i = freeze i16 %add.i.1.i.i.i\r\n %.cmp.not.1.i.i.i = icmp eq i16 %add.i.frozen.1.i.i.i, 0\r\n %cond.i1002.2.i.i.i = lshr i64 %xor108.i.i.i, 0\r\n %conv115.2.i.i.i = trunc i64 %cond.i1002.2.i.i.i to i16\r\n %add.i.2.i.i.i = or i16 %conv115.2.i.i.i, 0\r\n %add.i.frozen.2.i.i.i = freeze i16 %add.i.2.i.i.i\r\n %.cmp.not.2.i.i.i = icmp eq i16 %add.i.frozen.2.i.i.i, 0\r\n %cond.i1002.3.i.i.i = lshr i64 0, 0\r\n %conv115.3.i.i.i = trunc i64 %cond.i1002.3.i.i.i to i16\r\n %add.i.3.i.i.i = or i16 %conv115.3.i.i.i, 0\r\n %add.i.frozen.3.i.i.i = freeze i16 %add.i.3.i.i.i\r\n %.cmp.not.3.i.i.i = icmp eq i16 %add.i.frozen.3.i.i.i, 0\r\n %conv115.i.i.i.1 = trunc i64 %xor108.i.i.i to i16\r\n %add.i.i.i.i.1 = or i16 %conv115.i.i.i.1, 0\r\n %add.i.frozen.i.i.i.1 = freeze i16 %add.i.i.i.i.1\r\n %.cmp.not.i.i.i.1 = icmp eq i16 %add.i.frozen.i.i.i.1, 0\r\n %cond.i1002.1.i.i.i.1 = lshr i64 0, 0\r\n %conv115.1.i.i.i.1 = trunc i64 %cond.i1002.1.i.i.i.1 to i16\r\n %add.i.1.i.i.i.1 = or i16 %conv115.1.i.i.i.1, 0\r\n %add.i.frozen.1.i.i.i.1 = freeze i16 %add.i.1.i.i.i.1\r\n %.cmp.not.1.i.i.i.1 = icmp eq i16 %add.i.frozen.1.i.i.i.1, 0\r\n %cond.i1002.2.i.i.i.1 = lshr i64 0, 0\r\n %conv115.2.i.i.i.1 = trunc i64 %cond.i1002.2.i.i.i.1 to i16\r\n %add.i.2.i.i.i.1 = or i16 %conv115.2.i.i.i.1, 0\r\n %add.i.frozen.2.i.i.i.1 = freeze i16 %add.i.2.i.i.i.1\r\n %.cmp.not.2.i.i.i.1 = icmp eq i16 %add.i.frozen.2.i.i.i.1, 0\r\n %cond.i1002.3.i.i.i.1 = lshr i64 0, 0\r\n %conv115.3.i.i.i.1 = trunc i64 %cond.i1002.3.i.i.i.1 to i16\r\n %add.i.3.i.i.i.1 = or i16 %conv115.3.i.i.i.1, 0\r\n %add.i.frozen.3.i.i.i.1 = freeze i16 %add.i.3.i.i.i.1\r\n %.cmp.not.3.i.i.i.1 = icmp eq i16 %add.i.frozen.3.i.i.i.1, 0\r\n %conv115.i.i.i.2 = trunc i64 %xor108.i.i.i to i16\r\n %add.i.i.i.i.2 = or i16 %conv115.i.i.i.2, 0\r\n %add.i.frozen.i.i.i.2 = freeze i16 %add.i.i.i.i.2\r\n %.cmp.not.i.i.i.2 = icmp eq i16 %add.i.frozen.i.i.i.2, 0\r\n %cond.i1002.1.i.i.i.2 = lshr i64 0, 0\r\n %conv115.1.i.i.i.2 = trunc i64 %cond.i1002.1.i.i.i.2 to i16\r\n %add.i.1.i.i.i.2 = or i16 %conv115.1.i.i.i.2, 0\r\n %add.i.frozen.1.i.i.i.2 = freeze i16 %add.i.1.i.i.i.2\r\n %.cmp.not.1.i.i.i.2 = icmp eq i16 %add.i.frozen.1.i.i.i.2, 0\r\n %cond.i1002.2.i.i.i.2 = lshr i64 0, 0\r\n %conv115.2.i.i.i.2 = trunc i64 %cond.i1002.2.i.i.i.2 to i16\r\n %add.i.2.i.i.i.2 = or i16 %conv115.2.i.i.i.2, 0\r\n %add.i.frozen.2.i.i.i.2 = freeze i16 %add.i.2.i.i.i.2\r\n %.cmp.not.2.i.i.i.2 = icmp eq i16 %add.i.frozen.2.i.i.i.2, 0\r\n %cond.i1002.3.i.i.i.2 = lshr i64 0, 0\r\n %conv115.3.i.i.i.2 = trunc i64 %cond.i1002.3.i.i.i.2 to i16\r\n %add.i.3.i.i.i.2 = or i16 %conv115.3.i.i.i.2, 0\r\n %add.i.frozen.3.i.i.i.2 = freeze i16 %add.i.3.i.i.i.2\r\n %.cmp.not.3.i.i.i.2 = icmp eq i16 %add.i.frozen.3.i.i.i.2, 0\r\n %conv115.i.i.i.3 = trunc i64 %xor108.i.i.i to i16\r\n %add.i.i.i.i.3 = or i16 %conv115.i.i.i.3, 0\r\n %add.i.frozen.i.i.i.3 = freeze i16 %add.i.i.i.i.3\r\n %.cmp.not.i.i.i.3 = icmp eq i16 %add.i.frozen.i.i.i.3, 0\r\n %cond.i1002.1.i.i.i.3 = lshr i64 0, 0\r\n %conv115.1.i.i.i.3 = trunc i64 %cond.i1002.1.i.i.i.3 to i16\r\n %add.i.1.i.i.i.3 = or i16 %conv115.1.i.i.i.3, 0\r\n %add.i.frozen.1.i.i.i.3 = freeze i16 %add.i.1.i.i.i.3\r\n %.cmp.not.1.i.i.i.3 = icmp eq i16 %add.i.frozen.1.i.i.i.3, 0\r\n %cond.i1002.2.i.i.i.3 = lshr i64 0, 0\r\n %conv115.2.i.i.i.3 = trunc i64 %cond.i1002.2.i.i.i.3 to i16\r\n %add.i.2.i.i.i.3 = or i16 %conv115.2.i.i.i.3, 0\r\n %add.i.frozen.2.i.i.i.3 = freeze i16 %add.i.2.i.i.i.3\r\n %.cmp.not.2.i.i.i.3 = icmp eq i16 %add.i.frozen.2.i.i.i.3, 0\r\n %cond.i1002.3.i.i.i.3 = lshr i64 0, 0\r\n %conv115.3.i.i.i.3 = trunc i64 %cond.i1002.3.i.i.i.3 to i16\r\n %add.i.3.i.i.i.3 = or i16 %conv115.3.i.i.i.3, 0\r\n %add.i.frozen.3.i.i.i.3 = freeze i16 %add.i.3.i.i.i.3\r\n %.cmp.not.3.i.i.i.3 = icmp eq i16 %add.i.frozen.3.i.i.i.3, 0\r\n ret void\r\n}\r\n```\r\n```\r\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:10880: llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator::finalize(llvm::ArrayRef<int>, llvm::ArrayRef<std::pair<const llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int> >, llvm::ArrayRef<int>, unsigned int, llvm::function_ref<void(llvm::Value*&, llvm::SmallVectorImpl<int>&)>): Assertion `SubVectorsMask.size() == CommonMask.size() && \"Expected same size of masks for subvectors and common mask.\"' 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.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=slp-vectorizer <source>\r\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\r\n2.\tRunning pass \"slp-vectorizer\" on function \"test\"\r\n #0 0x00000000051b7378 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x51b7378)\r\n #1 0x00000000051b4d6c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007ac42d642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007ac42d6969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007ac42d642476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007ac42d6287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00007ac42d62871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x00007ac42d639e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x00000000041e9132 llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator::finalize(llvm::ArrayRef<int>, llvm::ArrayRef<std::pair<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, unsigned int>>, llvm::ArrayRef<int>, unsigned int, llvm::function_ref<void (llvm::Value*&, llvm::SmallVectorImpl<int>&)>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41e9132)\r\n #9 0x00000000042256f9 llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::processBuildVector<llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator, llvm::InstructionCost, llvm::TargetTransformInfo, llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP, llvm::SmallPtrSetImpl<llvm::Value*>>(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::Type*, llvm::TargetTransformInfo&, llvm::ArrayRef<llvm::Value*>&, llvm::slpvectorizer::BoUpSLP&, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x42256f9)\r\n#10 0x000000000422f707 llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x422f707)\r\n#11 0x00000000042636a1 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x42636a1)\r\n#12 0x000000000426d57c llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x426d57c)\r\n#13 0x000000000427168f bool llvm::SLPVectorizerPass::vectorizeCmpInsts<std::reverse_iterator<llvm::CmpInst* const*>>(llvm::iterator_range<std::reverse_iterator<llvm::CmpInst* const*>>, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x427168f)\r\n#14 0x0000000004271fdb llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&)::'lambda3'(bool)::operator()(bool) const SLPVectorizer.cpp:0:0\r\n#15 0x0000000004275785 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4275785)\r\n#16 0x000000000427bf86 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0\r\n#17 0x000000000427ca9b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x427ca9b)\r\n#18 0x0000000002fcc5ce llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2fcc5ce)\r\n#19 0x0000000004fb6a68 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fb6a68)\r\n#20 0x0000000000e3dd4e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe3dd4e)\r\n#21 0x0000000004fb548e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fb548e)\r\n#22 0x0000000000e3d3fe llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe3d3fe)\r\n#23 0x0000000004fb4ec0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fb4ec0)\r\n#24 0x000000000090ce7a 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+0x90ce7a)\r\n#25 0x00000000008ff519 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ff519)\r\n#26 0x00007ac42d629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#27 0x00007ac42d629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#28 0x00000000008f6d6e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f6d6e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "dtcxzyw", "labels": ["llvm:SLPVectorizer", "crash-on-valid"], "comments": []}, "verified": true}
|
36 |
{"bug_id": "100298", "issue_url": "https://github.com/llvm/llvm-project/issues/100298", "bug_type": "miscompilation", "base_commit": "75642a00e15b722bdfb90726be31f1c8adaeb0c5", "knowledge_cutoff": "2024-07-24T04:19:53Z", "lit_test_dir": ["llvm/test/Transforms/InstCombine"], "hints": {"fix_commit": "59eae919c938f890e9b9b4be8a3fa3cb1b11ed89", "components": ["ValueTracking"], "bug_location_lineno": {"llvm/include/llvm/Analysis/SimplifyQuery.h": [[130, 135]], "llvm/lib/Analysis/ValueTracking.cpp": [[1435, 1441], [1468, 1474], [1546, 1552], [2329, 2335], [2943, 2949], [3509, 3515], [4001, 4007], [5909, 5918]]}, "bug_location_funcname": {"llvm/include/llvm/Analysis/SimplifyQuery.h": ["getWithCondContext"], "llvm/lib/Analysis/ValueTracking.cpp": ["ComputeNumSignBitsImpl", "computeKnownBitsFromOperator", "computeKnownFPClass", "isKnownNonZeroFromOperator", "isKnownToBeAPowerOfTwo", "isNonEqualPHIs"]}}, "patch": "commit a87fbeb3a77a53ded341277c5b326f7696d47594\nAuthor: Yingwei Zheng <[email protected]>\nDate: Wed Jul 24 20:06:36 2024 +0800\n\n [ValueTracking] Don't use CondContext in dataflow analysis of phi nodes (#100316)\n \n See the following case:\n ```\n define i16 @pr100298() {\n entry:\n br label %for.inc\n \n for.inc:\n %indvar = phi i32 [ -15, %entry ], [ %mask, %for.inc ]\n %add = add nsw i32 %indvar, 9\n %mask = and i32 %add, 65535\n %cmp1 = icmp ugt i32 %mask, 5\n br i1 %cmp1, label %for.inc, label %for.end\n \n for.end:\n %conv = trunc i32 %add to i16\n %cmp2 = icmp ugt i32 %mask, 3\n %shl = shl nuw i16 %conv, 14\n %res = select i1 %cmp2, i16 %conv, i16 %shl\n ret i16 %res\n }\n ```\n \n When computing knownbits of `%shl` with `%cmp2=false`, we cannot use\n this condition in the analysis of `%mask (%for.inc -> %for.inc)`.\n \n Fixes https://github.com/llvm/llvm-project/issues/100298.\n \n (cherry picked from commit 59eae919c938f890e9b9b4be8a3fa3cb1b11ed89)\n\ndiff --git a/llvm/include/llvm/Analysis/SimplifyQuery.h b/llvm/include/llvm/Analysis/SimplifyQuery.h\nindex a560744f0122..e8f43c8c2e91 100644\n--- a/llvm/include/llvm/Analysis/SimplifyQuery.h\n+++ b/llvm/include/llvm/Analysis/SimplifyQuery.h\n@@ -130,6 +130,12 @@ struct SimplifyQuery {\n Copy.CC = &CC;\n return Copy;\n }\n+\n+ SimplifyQuery getWithoutCondContext() const {\n+ SimplifyQuery Copy(*this);\n+ Copy.CC = nullptr;\n+ return Copy;\n+ }\n };\n \n } // end namespace llvm\ndiff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp\nindex 40fe1ffe13f1..4b77c0046cc7 100644\n--- a/llvm/lib/Analysis/ValueTracking.cpp\n+++ b/llvm/lib/Analysis/ValueTracking.cpp\n@@ -1435,7 +1435,7 @@ static void computeKnownBitsFromOperator(const Operator *I,\n // inferred hold at original context instruction. TODO: It may be\n // correct to use the original context. IF warranted, explore and\n // add sufficient tests to cover.\n- SimplifyQuery RecQ = Q;\n+ SimplifyQuery RecQ = Q.getWithoutCondContext();\n RecQ.CxtI = P;\n computeKnownBits(R, DemandedElts, Known2, Depth + 1, RecQ);\n switch (Opcode) {\n@@ -1468,7 +1468,7 @@ static void computeKnownBitsFromOperator(const Operator *I,\n // phi. This is important because that is where the value is actually\n // \"evaluated\" even though it is used later somewhere else. (see also\n // D69571).\n- SimplifyQuery RecQ = Q;\n+ SimplifyQuery RecQ = Q.getWithoutCondContext();\n \n unsigned OpNum = P->getOperand(0) == R ? 0 : 1;\n Instruction *RInst = P->getIncomingBlock(OpNum)->getTerminator();\n@@ -1546,7 +1546,7 @@ static void computeKnownBitsFromOperator(const Operator *I,\n // phi. This is important because that is where the value is actually\n // \"evaluated\" even though it is used later somewhere else. (see also\n // D69571).\n- SimplifyQuery RecQ = Q;\n+ SimplifyQuery RecQ = Q.getWithoutCondContext();\n RecQ.CxtI = P->getIncomingBlock(u)->getTerminator();\n \n Known2 = KnownBits(BitWidth);\n@@ -2329,7 +2329,7 @@ bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero, unsigned Depth,\n // it is an induction variable where in each step its value is a power of\n // two.\n auto *PN = cast<PHINode>(I);\n- SimplifyQuery RecQ = Q;\n+ SimplifyQuery RecQ = Q.getWithoutCondContext();\n \n // Check if it is an induction variable and always power of two.\n if (isPowerOfTwoRecurrence(PN, OrZero, Depth, RecQ))\n@@ -2943,7 +2943,7 @@ static bool isKnownNonZeroFromOperator(const Operator *I,\n return true;\n \n // Check if all incoming values are non-zero using recursion.\n- SimplifyQuery RecQ = Q;\n+ SimplifyQuery RecQ = Q.getWithoutCondContext();\n unsigned NewDepth = std::max(Depth, MaxAnalysisRecursionDepth - 1);\n return llvm::all_of(PN->operands(), [&](const Use &U) {\n if (U.get() == PN)\n@@ -3509,7 +3509,7 @@ static bool isNonEqualPHIs(const PHINode *PN1, const PHINode *PN2,\n if (UsedFullRecursion)\n return false;\n \n- SimplifyQuery RecQ = Q;\n+ SimplifyQuery RecQ = Q.getWithoutCondContext();\n RecQ.CxtI = IncomBB->getTerminator();\n if (!isKnownNonEqual(IV1, IV2, DemandedElts, Depth + 1, RecQ))\n return false;\n@@ -4001,7 +4001,7 @@ static unsigned ComputeNumSignBitsImpl(const Value *V,\n \n // Take the minimum of all incoming values. This can't infinitely loop\n // because of our depth threshold.\n- SimplifyQuery RecQ = Q;\n+ SimplifyQuery RecQ = Q.getWithoutCondContext();\n Tmp = TyBits;\n for (unsigned i = 0, e = NumIncomingValues; i != e; ++i) {\n if (Tmp == 1) return Tmp;\n@@ -5909,10 +5909,10 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,\n // Recurse, but cap the recursion to two levels, because we don't want\n // to waste time spinning around in loops. We need at least depth 2 to\n // detect known sign bits.\n- computeKnownFPClass(\n- IncValue, DemandedElts, InterestedClasses, KnownSrc,\n- PhiRecursionLimit,\n- Q.getWithInstruction(P->getIncomingBlock(U)->getTerminator()));\n+ computeKnownFPClass(IncValue, DemandedElts, InterestedClasses, KnownSrc,\n+ PhiRecursionLimit,\n+ Q.getWithoutCondContext().getWithInstruction(\n+ P->getIncomingBlock(U)->getTerminator()));\n \n if (First) {\n Known = KnownSrc;\n", "tests": [{"file": "llvm/test/Transforms/InstCombine/pr100298.ll", "commands": ["opt -S -passes=instcombine < %s"], "tests": [{"test_name": "pr100298", "test_body": "define i16 @pr100298() {\nentry:\n br label %for.inc\n\nfor.inc: ; preds = %for.inc, %entry\n %indvar = phi i32 [ -15, %entry ], [ %mask, %for.inc ]\n %add = add nsw i32 %indvar, 9\n %mask = and i32 %add, 65535\n %cmp1 = icmp ugt i32 %mask, 5\n br i1 %cmp1, label %for.inc, label %for.end\n\nfor.end: ; preds = %for.inc\n %conv = trunc i32 %add to i16\n %cmp2 = icmp ugt i32 %mask, 3\n %shl = shl nuw i16 %conv, 14\n %res = select i1 %cmp2, i16 %conv, i16 %shl\n ret i16 %res\n}\n"}]}], "issue": {"title": "Miscompilation at O3", "body": "```\r\n#include \"csmith.h\"\r\nuint32_t a;\r\nint16_t c;\r\nvoid d() {\r\n for (a = -15; a >= 6; a = safe_add_func_uint16_t_u_u(a, 9))\r\n ;\r\n c = safe_lshift_func_int16_t_s_u(safe_lshift_func_uint16_t_u_s(a,14), 0);\r\n}\r\nint main() {\r\n d();\r\n printf(\"%d\\n\", c);\r\n return 0;\r\n}\r\n```\r\n\r\n```\r\ndtcxzyw@dtcxzyw:~/WorkSpace/Projects/compilers/LLVM/llvm-build$ gcc -O0 test.c -fsanitize=undefined -I/usr/include/csmith -w\r\ndtcxzyw@dtcxzyw:~/WorkSpace/Projects/compilers/LLVM/llvm-build$ ./a.out \r\n-16384\r\ndtcxzyw@dtcxzyw:~/WorkSpace/Projects/compilers/LLVM/llvm-build$ bin/clang -O3 test.c -I/usr/include/csmith -w\r\ndtcxzyw@dtcxzyw:~/WorkSpace/Projects/compilers/LLVM/llvm-build$ ./a.out \r\n0\r\n```\r\n\r\nllvm version: 2d6ff0c533aa1b0fe6d91764846f636c4a4e911c", "author": "dtcxzyw", "labels": ["miscompilation", "llvm:analysis"], "comments": [{"author": "dtcxzyw", "body": "Reduced testcase: https://alive2.llvm.org/ce/z/9fExrA\r\n```\r\n; bin/opt -passes=instcombine test.ll -S\r\ndefine i16 @src() {\r\nentry:\r\n br label %for.inc\r\n\r\nfor.inc:\r\n %storemerge6 = phi i32 [ -15, %entry ], [ %conv1, %for.inc ]\r\n %add.i = add nsw i32 %storemerge6, 9\r\n %conv1 = and i32 %add.i, 65535\r\n %cmp = icmp ugt i32 %conv1, 5\r\n br i1 %cmp, label %for.inc, label %for.end\r\n\r\nfor.end:\r\n %conv2 = trunc nuw nsw i32 %conv1 to i16\r\n %cmp3.i = icmp ugt i32 %conv1, 3\r\n %0 = shl nuw i16 %conv2, 14\r\n %cond.in.i = select i1 %cmp3.i, i16 %conv2, i16 %0\r\n ret i16 %cond.in.i\r\n}\r\n```"}]}, "verified": true}
|
37 |
{"bug_id": "101337", "issue_url": "https://github.com/llvm/llvm-project/issues/101337", "bug_type": "crash", "base_commit": "1b936e4812ab395328203f65cacd4ffe02bb318e", "knowledge_cutoff": "2024-07-31T14:11:24Z", "lit_test_dir": ["llvm/test/Transforms/LoopVectorize"], "hints": {"fix_commit": "cd08fadd03904806fa26a1f117879ddae34fbf67", "components": ["LoopVectorize"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [[7080, 7086]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": ["LoopVectorizationPlanner::cost"]}}, "patch": "commit cd08fadd03904806fa26a1f117879ddae34fbf67\nAuthor: Florian Hahn <[email protected]>\nDate: Mon Aug 12 14:45:43 2024 +0100\n\n [LV] Include chains feeding inductions in cost precomputation.\n \n Include chain of ops feeding inductions in cost precomputation for\n inductions, not just the induction increment. In VPlan, those\n instructions will be cleaned up, as both phi and increment are generated\n by VPWidenIntOrFpInductionRecipe independently.\n \n Fixes https://github.com/llvm/llvm-project/issues/101337.\n\ndiff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\nindex 542d74ef0e1e..41e4b0fcd9b0 100644\n--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n@@ -7080,7 +7080,16 @@ InstructionCost LoopVectorizationPlanner::cost(VPlan &Plan,\n for (const auto &[IV, IndDesc] : Legal->getInductionVars()) {\n Instruction *IVInc = cast<Instruction>(\n IV->getIncomingValueForBlock(OrigLoop->getLoopLatch()));\n- SmallVector<Instruction *> IVInsts = {IV, IVInc};\n+ SmallVector<Instruction *> IVInsts = {IVInc};\n+ for (unsigned I = 0; I != IVInsts.size(); I++) {\n+ for (Value *Op : IVInsts[I]->operands()) {\n+ auto *OpI = dyn_cast<Instruction>(Op);\n+ if (Op == IV || !OpI || !OrigLoop->contains(OpI) || !Op->hasOneUse())\n+ continue;\n+ IVInsts.push_back(OpI);\n+ }\n+ }\n+ IVInsts.push_back(IV);\n for (User *U : IV->users()) {\n auto *CI = cast<Instruction>(U);\n if (!CostCtx.CM.isOptimizableIVTruncate(CI, VF))\n", "tests": [{"file": "llvm/test/Transforms/LoopVectorize/X86/induction-costs.ll", "commands": ["opt -p loop-vectorize -mtriple=x86_64-apple-macosx -S %s"], "tests": [{"test_name": "iv_and_step_trunc", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine i16 @iv_and_step_trunc() {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %rec = phi i16 [ 0, %entry ], [ %rec.next, %loop ]\n %iv.next = add i64 %iv, 1\n %0 = trunc i64 %iv to i16\n %1 = trunc i64 %iv.next to i16\n %rec.next = mul i16 %0, %1\n %ec = icmp eq i64 %iv, 1\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i16 %rec\n}\n"}, {"test_name": "wombat2", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @wombat2(i32 %arg, ptr %dst) #0 {\nentry:\n %mul = mul i32 %arg, 3\n %zext = zext i32 %arg to i64\n br label %loop\n\nloop: ; preds = %loop, %entry\n %phi = phi i64 [ 4, %entry ], [ %add, %loop ]\n %phi2 = phi i32 [ %mul, %entry ], [ %trunc.1, %loop ]\n %getelementptr = getelementptr i32, ptr %dst, i64 %phi\n %and = and i32 %phi2, 12\n store i32 %and, ptr %getelementptr, align 4\n %mul3 = mul i64 %phi, %zext\n %add = add i64 %phi, 1\n %icmp = icmp ugt i64 %phi, 65\n %trunc.0 = trunc i64 %mul3 to i60\n %trunc.1 = trunc i60 %trunc.0 to i32\n br i1 %icmp, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"target-cpu\"=\"skylake-avx512\" \"target-features\"=\"-avx512f\" }\n"}, {"test_name": "with_dead_use", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @with_dead_use(i32 %arg, ptr %dst) #0 {\nentry:\n %mul = mul i32 %arg, 3\n %zext = zext i32 %arg to i64\n br label %loop\n\nloop: ; preds = %loop, %entry\n %phi = phi i64 [ 4, %entry ], [ %add, %loop ]\n %phi2 = phi i32 [ %mul, %entry ], [ %trunc, %loop ]\n %getelementptr = getelementptr i32, ptr %dst, i64 %phi\n %and = and i32 %phi2, 12\n store i32 %and, ptr %getelementptr, align 4\n %mul3 = mul i64 %phi, %zext\n %add = add i64 %phi, 1\n %icmp = icmp ugt i64 %phi, 65\n %trunc = trunc i64 %mul3 to i32\n %dead.and = and i32 %trunc, 123\n br i1 %icmp, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"target-cpu\"=\"skylake-avx512\" \"target-features\"=\"-avx512f\" }\n"}, {"test_name": "test_scalar_predicated_cost", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine i32 @test_scalar_predicated_cost(i64 %x, i64 %y, ptr %A) #0 {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %cmp9.not = icmp ule i64 %iv, %y\n br i1 %cmp9.not, label %loop.latch, label %if.then\n\nif.then: ; preds = %loop.header\n %or = or i64 %x, %iv\n %gep = getelementptr i32, ptr %A, i64 %iv\n %t = trunc i64 %or to i32\n store i32 %t, ptr %gep, align 4\n br label %loop.latch\n\nloop.latch: ; preds = %if.then, %loop.header\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, 100\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret i32 0\n}\n\nattributes #0 = { \"min-legal-vector-width\"=\"0\" \"target-cpu\"=\"skylake-avx512\" }\n"}, {"test_name": "truncated_ivs_with_wide_and_scalar_uses", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @truncated_ivs_with_wide_and_scalar_uses(i1 %c, ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.16 = trunc i64 %iv to i16\n %iv.32 = trunc i64 %iv to i32\n %gep = getelementptr i16, ptr %dst, i32 %iv.32\n %sel = select i1 %c, i16 %iv.16, i16 10\n store i16 %sel, ptr %gep, align 2\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, 64\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n"}, {"test_name": "multiple_truncated_ivs_with_wide_uses", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @multiple_truncated_ivs_with_wide_uses(i1 %c, ptr %A, ptr %B) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.16 = trunc i64 %iv to i16\n %iv.32 = trunc i64 %iv to i32\n %sel = select i1 %c, i16 %iv.16, i16 10\n %gep.A = getelementptr i16, ptr %A, i64 %iv\n store i16 %sel, ptr %gep.A, align 2\n %gep.B = getelementptr i32, ptr %B, i64 %iv\n store i32 %iv.32, ptr %gep.B, align 4\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, 64\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n"}, {"test_name": "wide_iv_trunc_reuse", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @wide_iv_trunc_reuse(ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 1, %entry ], [ %iv.next, %loop ]\n %iv.2 = phi i32 [ 0, %entry ], [ %iv.trunc, %loop ]\n store i32 %iv.2, ptr %dst, align 4\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, 0\n %iv.trunc = trunc i64 %iv to i32\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n"}, {"test_name": "iv_used_widened_and_truncated", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine i32 @iv_used_widened_and_truncated(ptr %dst, i64 %N) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep = getelementptr { i32, [8 x i32] }, ptr %dst, i64 %iv\n %t = trunc i64 %iv to i32\n store i32 %t, ptr %gep, align 8\n %iv.next = add i64 %iv, 1\n %c = icmp eq i64 %iv, %N\n br i1 %c, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i32 0\n}\n\nattributes #0 = { \"min-legal-vector-width\"=\"0\" \"target-cpu\"=\"skylake-avx512\" }\n"}, {"test_name": "wombat", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @wombat(i32 %arg, ptr %dst) #0 {\nentry:\n %mul = mul i32 %arg, 3\n %zext = zext i32 %arg to i64\n br label %loop\n\nloop: ; preds = %loop, %entry\n %phi = phi i64 [ 4, %entry ], [ %add, %loop ]\n %phi2 = phi i32 [ %mul, %entry ], [ %trunc, %loop ]\n %getelementptr = getelementptr i32, ptr %dst, i64 %phi\n %and = and i32 %phi2, 12\n store i32 %and, ptr %getelementptr, align 4\n %mul3 = mul i64 %phi, %zext\n %add = add i64 %phi, 1\n %icmp = icmp ugt i64 %phi, 65\n %trunc = trunc i64 %mul3 to i32\n br i1 %icmp, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"target-cpu\"=\"skylake-avx512\" \"target-features\"=\"-avx512f\" }\n"}, {"test_name": "wide_iv_trunc", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @wide_iv_trunc(ptr %dst, i64 %N) {\nentry:\n %cmp = icmp ult i64 %N, 8\n br i1 %cmp, label %loop, label %exit\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.trunc = trunc i64 %iv to i32\n store i32 %iv.trunc, ptr %dst, align 4\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, %N\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop, %entry\n ret void\n}\n"}, {"test_name": "multiple_pointer_ivs_with_scalar_uses_only", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @multiple_pointer_ivs_with_scalar_uses_only(ptr %A, ptr %B) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv.1 = phi i32 [ 100, %entry ], [ %dec, %loop ]\n %iv.2 = phi i32 [ 2048, %entry ], [ %add38, %loop ]\n %ptr.iv.1 = phi ptr [ %A, %entry ], [ %outptr.0, %loop ]\n %ptr.iv.2 = phi ptr [ %B, %entry ], [ %incdec.ptr36, %loop ]\n %ptr.iv.3 = phi ptr [ %B, %entry ], [ %incdec.ptr33, %loop ]\n %incdec.ptr33 = getelementptr i8, ptr %ptr.iv.3, i64 1\n %0 = load i8, ptr %ptr.iv.3, align 1\n %conv34 = zext i8 %0 to i32\n %incdec.ptr36 = getelementptr i8, ptr %ptr.iv.2, i64 1\n %1 = load i8, ptr %ptr.iv.2, align 1\n %conv37 = zext i8 %1 to i32\n %add38 = add i32 %conv34, %conv37\n %shr42 = lshr i32 %iv.2, 1\n %conv43 = trunc i32 %shr42 to i8\n store i8 %conv43, ptr %ptr.iv.1, align 1\n %dec = add i32 %iv.1, 1\n %outptr.0 = getelementptr i8, ptr %ptr.iv.1, i64 2\n %cmp30.not = icmp eq i32 %dec, 0\n br i1 %cmp30.not, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"min-legal-vector-width\"=\"0\" \"target-cpu\"=\"skylake-avx512\" }\n"}]}], "issue": {"title": "Assertion `VF.Width == BestVF && \"VPlan cost model and legacy cost model disagreed\"' failed.", "body": "To reproduce run opt with \r\n```\r\n-passes=loop-vectorize --mcpu=skylake-avx512 --mattr=+prfchw,-cldemote,+avx,+aes,+sahf,+pclmul,-xop,+crc32,+xsaves,-avx512fp16,-usermsr,-sm4,-egpr,+sse4.1,-avx512ifma,+xsave,+sse4.2,-tsxldtrk,-sm3,-ptwrite,-widekl,+invpcid,+64bit,+xsavec,-avx10.1-512,-avx512vpopcntdq,+cmov,-avx512vp2intersect,+avx512cd,+movbe,-avxvnniint8,-ccmp,-amx-int8,-kl,-avx10.1-256,+evex512,-avxvnni,+rtm,+adx,+avx2,-hreset,-movdiri,-serialize,-sha512,-vpclmulqdq,+avx512vl,-uintr,-cf,+clflushopt,-raoint,-cmpccxadd,+bmi,-amx-tile,+sse,-gfni,-avxvnniint16,-amx-fp16,-zu,-ndd,+xsaveopt,+rdrnd,+avx512f,-amx-bf16,-avx512bf16,-avx512vnni,-push2pop2,+cx8,+avx512bw,+sse3,+pku,-nf,+fsgsbase,-clzero,-mwaitx,-lwp,+lzcnt,-sha,-movdir64b,-ppx,-wbnoinvd,-enqcmd,-avxneconvert,-tbm,-pconfig,-amx-complex,+ssse3,+cx16,+bmi2,+fma,+popcnt,-avxifma,+f16c,-avx512bitalg,-rdpru,+clwb,+mmx,+sse2,+rdseed,-avx512vbmi2,-prefetchi,-rdpid,-fma4,-avx512vbmi,-shstk,-vaes,-waitpkg,-sgx,+fxsr,+avx512dq,-sse4a,-avx512f\r\n```\r\nwith the following test:\r\n```\r\n; ModuleID = './reduced.ll'\r\nsource_filename = \"./reduced.ll\"\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine void @wombat(i32 %arg) #0 gc \"statepoint-example\" {\r\nbb:\r\n %mul = mul i32 %arg, 3\r\n %zext = zext i32 %arg to i64\r\n br label %bb1\r\n\r\nbb1: ; preds = %bb1, %bb\r\n %phi = phi i64 [ %add, %bb1 ], [ 4, %bb ]\r\n %phi2 = phi i32 [ %trunc, %bb1 ], [ %mul, %bb ]\r\n %getelementptr = getelementptr i32, ptr addrspace(1) null, i64 %phi\r\n %and = and i32 %phi2, 0\r\n store i32 0, ptr addrspace(1) %getelementptr, align 4\r\n %mul3 = mul i64 %phi, %zext\r\n %add = add i64 %phi, 1\r\n %icmp = icmp ugt i64 %phi, 65\r\n %trunc = trunc i64 %mul3 to i32\r\n br i1 %icmp, label %bb4, label %bb1\r\n\r\nbb4: ; preds = %bb1\r\n ret void\r\n}\r\n```\r\nReproducer: https://godbolt.org/z/nPsP7h51n\r\n\r\nStack dump:\r\n```\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=loop-vectorize --mcpu=skylake-avx512 --mattr=+prfchw,-cldemote,+avx,+aes,+sahf,+pclmul,-xop,+crc32,+xsaves,-avx512fp16,-usermsr,-sm4,-egpr,+sse4.1,-avx512ifma,+xsave,+sse4.2,-tsxldtrk,-sm3,-ptwrite,-widekl,+invpcid,+64bit,+xsavec,-avx10.1-512,-avx512vpopcntdq,+cmov,-avx512vp2intersect,+avx512cd,+movbe,-avxvnniint8,-ccmp,-amx-int8,-kl,-avx10.1-256,+evex512,-avxvnni,+rtm,+adx,+avx2,-hreset,-movdiri,-serialize,-sha512,-vpclmulqdq,+avx512vl,-uintr,-cf,+clflushopt,-raoint,-cmpccxadd,+bmi,-amx-tile,+sse,-gfni,-avxvnniint16,-amx-fp16,-zu,-ndd,+xsaveopt,+rdrnd,+avx512f,-amx-bf16,-avx512bf16,-avx512vnni,-push2pop2,+cx8,+avx512bw,+sse3,+pku,-nf,+fsgsbase,-clzero,-mwaitx,-lwp,+lzcnt,-sha,-movdir64b,-ppx,-wbnoinvd,-enqcmd,-avxneconvert,-tbm,-pconfig,-amx-complex,+ssse3,+cx16,+bmi2,+fma,+popcnt,-avxifma,+f16c,-avx512bitalg,-rdpru,+clwb,+mmx,+sse2,+rdseed,-avx512vbmi2,-prefetchi,-rdpid,-fma4,-avx512vbmi,-shstk,-vaes,-waitpkg,-sgx,+fxsr,+avx512dq,-sse4a,-avx512f <source>\r\n1.\tRunning pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"<source>\"\r\n2.\tRunning pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"wombat\"\r\n #0 0x0000000004f053c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f053c8)\r\n #1 0x0000000004f02b3c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007458cc042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007458cc0969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007458cc042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007458cc0287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00007458cc02871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x00007458cc039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x0000000003f83f37 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f83f37)\r\n #9 0x0000000003f86659 llvm::LoopVectorizePass::runImpl(llvm::Function&, llvm::ScalarEvolution&, llvm::LoopInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::BlockFrequencyInfo*, llvm::TargetLibraryInfo*, llvm::DemandedBits&, llvm::AssumptionCache&, llvm::LoopAccessInfoManager&, llvm::OptimizationRemarkEmitter&, llvm::ProfileSummaryInfo*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f86659)\r\n#10 0x0000000003f86cd2 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f86cd2)\r\n#11 0x0000000002e596ce llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2e596ce)\r\n#12 0x0000000004d02758 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d02758)\r\n#13 0x0000000000de089e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xde089e)\r\n#14 0x0000000004d0114e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d0114e)\r\n#15 0x0000000000de0eee llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xde0eee)\r\n#16 0x0000000004cff2b0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4cff2b0)\r\n#17 0x00000000008e3752 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+0x8e3752)\r\n#18 0x00000000008d667c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d667c)\r\n#19 0x00007458cc029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#20 0x00007458cc029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#21 0x00000000008cdade _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8cdade)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "TatyanaDoubts", "labels": ["vectorizers", "crash"], "comments": [{"author": "patrick-rivos", "body": "Potentially related: https://github.com/llvm/llvm-project/issues/100591"}]}, "verified": true}
|
|
|
31 |
{"bug_id": "133751", "issue_url": "https://github.com/llvm/llvm-project/issues/133751", "bug_type": "crash", "base_commit": "2d7add6e2e56baf46504a8a22dec42b61f63360f", "knowledge_cutoff": "2025-03-31T16:55:56Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "bfd8cc0a3e82c5e6345a66dd5db5242accb6874b", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[8854, 8860]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["BoUpSLP::buildTree_rec"]}}, "patch": "commit bfd8cc0a3e82c5e6345a66dd5db5242accb6874b\nAuthor: Alexey Bataev <[email protected]>\nDate: Mon Mar 31 10:31:18 2025 -0700\n\n [SLP]Fix a check for the whole register use\n \n Need to check the value type, not the return type, of the instructions,\n when doing the analysis for the whole register use to prevent a compiler\n crash.\n \n Fixes #133751\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex a4b0378abc07..0679eac17658 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -8854,7 +8854,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,\n // FIXME: Reshuffing scalars is not supported yet for non-power-of-2 ops.\n if ((UserTreeIdx.UserTE &&\n UserTreeIdx.UserTE->hasNonWholeRegisterOrNonPowerOf2Vec(*TTI)) ||\n- !hasFullVectorsOrPowerOf2(*TTI, VL.front()->getType(), VL.size())) {\n+ !hasFullVectorsOrPowerOf2(*TTI, getValueType(VL.front()),\n+ VL.size())) {\n LLVM_DEBUG(dbgs() << \"SLP: Reshuffling scalars not yet supported \"\n \"for nodes with padding.\\n\");\n auto Invalid = ScheduleBundle::invalid();\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/X86/cmp-values-non-full-registers.ll", "commands": ["opt -S --passes=slp-vectorizer -mtriple=x86_64-grtev4-linux-gnu < %s"], "tests": [{"test_name": "<module>", "test_body": "\ndefine void @test() {\n;\nentry:\n br i1 false, label %bb1, label %bb2\n\nbb2:\n %cmp14.us = fcmp ogt x86_fp80 0xK00000000000000000000, 0xK00000000000000000000\n %imax.2.us = select i1 %cmp14.us, i64 0, i64 0\n %jmax.2.us = select i1 %cmp14.us, i64 0, i64 0\n %cmp13.us = fcmp olt x86_fp80 0xK00000000000000000000, 0xK00000000000000000000\n %imin.2.us = select i1 %cmp13.us, i64 0, i64 0\n %jmin.2.us = select i1 %cmp13.us, i64 0, i64 0\n br label %bb1\n\nbb1:\n %storemerge64 = phi i64 [ 0, %entry ], [ %imin.2.us, %bb2 ]\n %storemerge63 = phi i64 [ 0, %entry ], [ %jmin.2.us, %bb2 ]\n %storemerge62 = phi i64 [ 0, %entry ], [ %imax.2.us, %bb2 ]\n %storemerge = phi i64 [ 0, %entry ], [ %jmax.2.us, %bb2 ]\n ret void\n}"}]}], "issue": {"title": "SLPVectorizer: \"Reshuffling scalars not yet supported for nodes with padding\" assert", "body": "```\n$ cat /tmp/a.ll\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-grtev4-linux-gnu\"\n\ndefine void @gsl_matrix_long_double_minmax_index() {\nentry:\n br i1 false, label %cleanup22, label %for.cond6.preheader.us.preheader\n\nfor.cond6.preheader.us.preheader: ; preds = %entry\n %cmp14.us = fcmp ogt x86_fp80 0xK00000000000000000000, 0xK00000000000000000000\n %imax.2.us = select i1 %cmp14.us, i64 0, i64 0\n %jmax.2.us = select i1 %cmp14.us, i64 0, i64 0\n %cmp13.us = fcmp olt x86_fp80 0xK00000000000000000000, 0xK00000000000000000000\n %imin.2.us = select i1 %cmp13.us, i64 0, i64 0\n %jmin.2.us = select i1 %cmp13.us, i64 0, i64 0\n br label %cleanup22\n\ncleanup22: ; preds = %for.cond6.preheader.us.preheader, %entry\n %storemerge64 = phi i64 [ 0, %entry ], [ %imin.2.us, %for.cond6.preheader.us.preheader ]\n %storemerge63 = phi i64 [ 0, %entry ], [ %jmin.2.us, %for.cond6.preheader.us.preheader ]\n %storemerge62 = phi i64 [ 0, %entry ], [ %imax.2.us, %for.cond6.preheader.us.preheader ]\n %storemerge = phi i64 [ 0, %entry ], [ %jmax.2.us, %for.cond6.preheader.us.preheader ]\n ret void\n}\n$ opt -p slp-vectorizer /tmp/a.ll -disable-output\nopt: ../../llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:3714: TreeEntry *llvm::slpvectorizer::BoUpSLP::newTreeEntry(ArrayRef<Value *>, TreeEntry::EntryState, ScheduleBundle &, const InstructionsState &, const EdgeInfo &, ArrayRef<int>, ArrayRef<unsigned int>): Assertion `(hasFullVectorsOrPowerOf2(*TTI, \ngetValueType(VL.front()), VL.size()) || ReuseShuffleIndices.empty()) && \"Reshuffling scalars not yet supported for nodes with padding\"' failed. \n\n```\n\n@alexey-bataev ", "author": "aeubanks", "labels": ["llvm:SLPVectorizer", "crash-on-valid"], "comments": []}, "verified": true}
|
32 |
{"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}
|
33 |
{"bug_id": "150479", "issue_url": "https://github.com/llvm/llvm-project/issues/150479", "bug_type": "crash", "base_commit": "8952225d88a5ce58a65c8b8695c610f4499d7181", "knowledge_cutoff": "2025-07-24T17:33:31Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "c9cea24fe68e24750b2d479144f839e1c2ec9d2b", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[6861, 6867], [15704, 15710], [15803, 15809], [15816, 15822], [16438, 16461], [16470, 16482], [16512, 16522], [16554, 16560], [16586, 16592], [21001, 21009], [21253, 21258]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["BoUpSLP::computeMinimumValueSizes", "BoUpSLP::getLastInstructionInBundle", "BoUpSLP::getReorderingData", "BoUpSLP::isGatherShuffledSingleRegisterEntry"]}}, "patch": "commit c9cea24fe68e24750b2d479144f839e1c2ec9d2b\nAuthor: Alexey Bataev <[email protected]>\nDate: Thu Jul 24 11:40:26 2025 -0700\n\n [SLP] Check if the user node has state before trying getting main instruction/opcode\n \n Need to check if the parent node has state to prevent compiler crashes.\n Fixes #150479\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex 0adad5a90d31..44dc43d5e77c 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -6861,7 +6861,7 @@ BoUpSLP::getReorderingData(const TreeEntry &TE, bool TopToBottom,\n return std::move(ResOrder);\n }\n if (TE.State == TreeEntry::StridedVectorize && !TopToBottom &&\n- (!TE.UserTreeIndex ||\n+ (!TE.UserTreeIndex || !TE.UserTreeIndex.UserTE->hasState() ||\n !Instruction::isBinaryOp(TE.UserTreeIndex.UserTE->getOpcode())) &&\n (TE.ReorderIndices.empty() || isReverseOrder(TE.ReorderIndices)))\n return std::nullopt;\n@@ -15704,7 +15704,8 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry(\n const BasicBlock *TEInsertBlock = nullptr;\n // Main node of PHI entries keeps the correct order of operands/incoming\n // blocks.\n- if (auto *PHI = dyn_cast<PHINode>(TEUseEI.UserTE->getMainOp());\n+ if (auto *PHI = dyn_cast_or_null<PHINode>(\n+ TEUseEI.UserTE->hasState() ? TEUseEI.UserTE->getMainOp() : nullptr);\n PHI && TEUseEI.UserTE->State != TreeEntry::SplitVectorize) {\n TEInsertBlock = PHI->getIncomingBlock(TEUseEI.EdgeIdx);\n TEInsertPt = TEInsertBlock->getTerminator();\n@@ -15803,7 +15804,8 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry(\n \"Expected only single user of a gather node.\");\n const EdgeInfo &UseEI = TEPtr->UserTreeIndex;\n \n- PHINode *UserPHI = UseEI.UserTE->State != TreeEntry::SplitVectorize\n+ PHINode *UserPHI = (UseEI.UserTE->State != TreeEntry::SplitVectorize &&\n+ UseEI.UserTE->hasState())\n ? dyn_cast<PHINode>(UseEI.UserTE->getMainOp())\n : nullptr;\n Instruction *InsertPt =\n@@ -15816,7 +15818,8 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry(\n TEUseEI.UserTE->isAltShuffle()) &&\n all_of(TEUseEI.UserTE->Scalars, isUsedOutsideBlock)) {\n if (UseEI.UserTE->State != TreeEntry::Vectorize ||\n- (UseEI.UserTE->getOpcode() == Instruction::PHI &&\n+ (UseEI.UserTE->hasState() &&\n+ UseEI.UserTE->getOpcode() == Instruction::PHI &&\n !UseEI.UserTE->isAltShuffle()) ||\n !all_of(UseEI.UserTE->Scalars, isUsedOutsideBlock))\n continue;\n@@ -16438,24 +16441,31 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {\n // Get the basic block this bundle is in. All instructions in the bundle\n // should be in this block (except for extractelement-like instructions with\n // constant indices or gathered loads or copyables).\n- auto *Front = E->getMainOp();\n+ Instruction *Front;\n+ unsigned Opcode;\n+ if (E->hasState()) {\n+ Front = E->getMainOp();\n+ Opcode = E->getOpcode();\n+ } else {\n+ Front = cast<Instruction>(*find_if(E->Scalars, IsaPred<Instruction>));\n+ Opcode = Front->getOpcode();\n+ }\n auto *BB = Front->getParent();\n- assert(((GatheredLoadsEntriesFirst.has_value() &&\n- E->getOpcode() == Instruction::Load && E->isGather() &&\n- E->Idx < *GatheredLoadsEntriesFirst) ||\n- E->State == TreeEntry::SplitVectorize || E->hasCopyableElements() ||\n- all_of(E->Scalars,\n- [=](Value *V) -> bool {\n- if (E->getOpcode() == Instruction::GetElementPtr &&\n- !isa<GetElementPtrInst>(V))\n- return true;\n- auto *I = dyn_cast<Instruction>(V);\n- return !I || !E->getMatchingMainOpOrAltOp(I) ||\n- I->getParent() == BB ||\n- isVectorLikeInstWithConstOps(I);\n- })) &&\n- \"Expected gathered loads or GEPs or instructions from same basic \"\n- \"block.\");\n+ assert(\n+ ((GatheredLoadsEntriesFirst.has_value() && Opcode == Instruction::Load &&\n+ E->isGather() && E->Idx < *GatheredLoadsEntriesFirst) ||\n+ E->State == TreeEntry::SplitVectorize || E->hasCopyableElements() ||\n+ all_of(E->Scalars,\n+ [=](Value *V) -> bool {\n+ if (Opcode == Instruction::GetElementPtr &&\n+ !isa<GetElementPtrInst>(V))\n+ return true;\n+ auto *I = dyn_cast<Instruction>(V);\n+ return !I || !E->getMatchingMainOpOrAltOp(I) ||\n+ I->getParent() == BB || isVectorLikeInstWithConstOps(I);\n+ })) &&\n+ \"Expected gathered loads or GEPs or instructions from same basic \"\n+ \"block.\");\n \n auto FindLastInst = [&]() {\n Instruction *LastInst = Front;\n@@ -16470,13 +16480,13 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {\n LastInst = I;\n continue;\n }\n- assert(((E->getOpcode() == Instruction::GetElementPtr &&\n+ assert(((Opcode == Instruction::GetElementPtr &&\n !isa<GetElementPtrInst>(I)) ||\n E->State == TreeEntry::SplitVectorize ||\n (isVectorLikeInstWithConstOps(LastInst) &&\n isVectorLikeInstWithConstOps(I)) ||\n (GatheredLoadsEntriesFirst.has_value() &&\n- E->getOpcode() == Instruction::Load && E->isGather() &&\n+ Opcode == Instruction::Load && E->isGather() &&\n E->Idx < *GatheredLoadsEntriesFirst)) &&\n \"Expected vector-like or non-GEP in GEP node insts only.\");\n if (!DT->isReachableFromEntry(LastInst->getParent())) {\n@@ -16512,11 +16522,11 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {\n FirstInst = I;\n continue;\n }\n- assert(((E->getOpcode() == Instruction::GetElementPtr &&\n- !isa<GetElementPtrInst>(I)) ||\n- (isVectorLikeInstWithConstOps(FirstInst) &&\n- isVectorLikeInstWithConstOps(I))) &&\n- \"Expected vector-like or non-GEP in GEP node insts only.\");\n+ assert(((Opcode == Instruction::GetElementPtr &&\n+ !isa<GetElementPtrInst>(I)) ||\n+ (isVectorLikeInstWithConstOps(FirstInst) &&\n+ isVectorLikeInstWithConstOps(I))) &&\n+ \"Expected vector-like or non-GEP in GEP node insts only.\");\n if (!DT->isReachableFromEntry(FirstInst->getParent())) {\n FirstInst = I;\n continue;\n@@ -16554,7 +16564,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {\n // Set insertpoint for gathered loads to the very first load.\n if (GatheredLoadsEntriesFirst.has_value() &&\n E->Idx >= *GatheredLoadsEntriesFirst && !E->isGather() &&\n- E->getOpcode() == Instruction::Load) {\n+ Opcode == Instruction::Load) {\n Res = FindFirstInst();\n EntryToLastInstruction.try_emplace(E, Res);\n return *Res;\n@@ -16586,7 +16596,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {\n };\n const ScheduleBundle *Bundle = FindScheduleBundle(E);\n if (!E->isGather() && !Bundle) {\n- if ((E->getOpcode() == Instruction::GetElementPtr &&\n+ if ((Opcode == Instruction::GetElementPtr &&\n any_of(E->Scalars,\n [](Value *V) {\n return !isa<GetElementPtrInst>(V) && isa<Instruction>(V);\n@@ -21001,9 +21011,10 @@ void BoUpSLP::computeMinimumValueSizes() {\n if (!isa<CastInst, BinaryOperator, FreezeInst, PHINode,\n SelectInst>(U) ||\n isa<SIToFPInst, UIToFPInst>(U) ||\n- !isa<CastInst, BinaryOperator, FreezeInst, PHINode,\n- SelectInst>(UserTE->getMainOp()) ||\n- isa<SIToFPInst, UIToFPInst>(UserTE->getMainOp()))\n+ (UserTE->hasState() &&\n+ (!isa<CastInst, BinaryOperator, FreezeInst, PHINode,\n+ SelectInst>(UserTE->getMainOp()) ||\n+ isa<SIToFPInst, UIToFPInst>(UserTE->getMainOp()))))\n return true;\n unsigned UserTESz = DL->getTypeSizeInBits(\n UserTE->Scalars.front()->getType());\n@@ -21253,6 +21264,7 @@ void BoUpSLP::computeMinimumValueSizes() {\n NodeIdx < VectorizableTree.size() &&\n VectorizableTree[NodeIdx]->UserTreeIndex &&\n VectorizableTree[NodeIdx]->UserTreeIndex.EdgeIdx == 0 &&\n+ VectorizableTree[NodeIdx]->UserTreeIndex.UserTE->hasState() &&\n VectorizableTree[NodeIdx]->UserTreeIndex.UserTE->getOpcode() ==\n Instruction::Trunc &&\n !VectorizableTree[NodeIdx]->UserTreeIndex.UserTE->isAltShuffle();\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/X86/user-node-no-state.ll", "commands": ["opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s"], "tests": [{"test_name": "<module>", "test_body": "\n@g = global [128 x i8] zeroinitializer, align 16\n\ndefine i64 @test() {\n;\nentry:\n %0 = load i64, ptr @g, align 8\n br label %func_154.exit.func_146.exit_crit_edge.i\n\nfunc_154.exit.func_146.exit_crit_edge.i:\n %1 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 80), align 16\n %2 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 88), align 8\n %3 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 32), align 16\n %4 = load i64, ptr @g, align 16\n %5 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 8), align 8\n %6 = load i64, ptr @g, align 16\n %7 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 24), align 8\n %8 = xor i64 %1, %2\n %9 = xor i64 %8, %3\n %10 = xor i64 %9, %4\n %11 = xor i64 %10, %5\n %12 = xor i64 %11, %6\n %13 = xor i64 %12, %7\n %14 = xor i64 %13, %0\n ret i64 %14\n}"}]}], "issue": {"title": "[SLPVectorizer] Assertion `valid() && \"InstructionsState is invalid.\"' failed.", "body": "Reproducer: https://godbolt.org/z/Pj96ao9TK\n```\n; bin/opt -passes=slp-vectorizer test.ll -S\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@g = global [128 x i8] zeroinitializer, align 16\n\ndefine i64 @main() {\nentry:\n %0 = load i64, ptr @g, align 8\n br label %func_154.exit.func_146.exit_crit_edge.i\n\nfunc_154.exit.func_146.exit_crit_edge.i: ; preds = %entry\n %1 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 80), align 16\n %2 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 88), align 8\n %3 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 32), align 16\n %4 = load i64, ptr @g, align 16\n %5 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 8), align 8\n %6 = load i64, ptr @g, align 16\n %7 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 24), align 8\n %8 = xor i64 %1, %2\n %9 = xor i64 %8, %3\n %10 = xor i64 %9, %4\n %11 = xor i64 %10, %5\n %12 = xor i64 %11, %6\n %13 = xor i64 %12, %7\n %14 = xor i64 %13, %0\n ret i64 %14\n}\n```\n```\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:1204: llvm::Instruction* {anonymous}::InstructionsState::getMainOp() const: Assertion `valid() && \"InstructionsState is invalid.\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\nStack dump:\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=slp-vectorizer <source>\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\n2.\tRunning pass \"slp-vectorizer\" on function \"main\"\n #0 0x0000000005664458 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5664458)\n #1 0x0000000005661304 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x000075a3c1242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x000075a3c12969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x000075a3c1242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x000075a3c12287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x000075a3c122871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #7 0x000075a3c1239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #8 0x00000000034a0043 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x34a0043)\n #9 0x0000000003513355 llvm::slpvectorizer::BoUpSLP::getLastInstructionInBundle(llvm::slpvectorizer::BoUpSLP::TreeEntry const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3513355)\n#10 0x000000000355424e llvm::slpvectorizer::BoUpSLP::isGatherShuffledSingleRegisterEntry(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::MutableArrayRef<int>, llvm::SmallVectorImpl<llvm::slpvectorizer::BoUpSLP::TreeEntry const*>&, unsigned int, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x355424e)\n#11 0x0000000003558408 llvm::slpvectorizer::BoUpSLP::isGatherShuffledEntry(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallVectorImpl<int>&, llvm::SmallVectorImpl<llvm::SmallVector<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, 6u>>&, unsigned int, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3558408)\n#12 0x000000000355a2de llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::processBuildVector<llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator, llvm::InstructionCost, llvm::TargetTransformInfo, llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP, llvm::SmallPtrSetImpl<llvm::Value*>>(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::Type*, llvm::TargetTransformInfo&, llvm::ArrayRef<llvm::Value*>&, llvm::slpvectorizer::BoUpSLP&, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x355a2de)\n#13 0x000000000355c98f llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x355c98f)\n#14 0x000000000359597f llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>, llvm::InstructionCost) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x359597f)\n#15 0x000000000359ba1b (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&, llvm::AssumptionCache*) SLPVectorizer.cpp:0:0\n#16 0x000000000359ef90 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x359ef90)\n#17 0x00000000035a430b llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0\n#18 0x00000000035a8c0f llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x35a8c0f)\n#19 0x00000000035aef06 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0\n#20 0x00000000035af9eb llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x35af9eb)\n#21 0x0000000002dab8ce llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2dab8ce)\n#22 0x0000000005456241 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5456241)\n#23 0x0000000000eb675e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xeb675e)\n#24 0x0000000005456714 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5456714)\n#25 0x0000000000eb6a2e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xeb6a2e)\n#26 0x00000000054542e1 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x54542e1)\n#27 0x0000000000964bfa 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+0x964bfa)\n#28 0x0000000000958c79 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x958c79)\n#29 0x000075a3c1229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#30 0x000075a3c1229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#31 0x000000000094fd45 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x94fd45)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```\n\nI found this crash when fuzzing the code in https://github.com/llvm/llvm-project/pull/137297.\n", "author": "dtcxzyw", "labels": ["llvm:SLPVectorizer", "crash-on-valid", "generated by fuzzer"], "comments": []}, "verified": true}
|
34 |
+
{"bug_id": "105785", "issue_url": "https://github.com/llvm/llvm-project/issues/105785", "bug_type": "miscompilation", "base_commit": "1241c762c165972690c4edfb82ec7421c1e64658", "knowledge_cutoff": "2024-08-23T05:45:52Z", "lit_test_dir": ["llvm/test/Transforms/ConstraintElimination"], "hints": {"fix_commit": "85b6aac7c25f9d2a976a76045ace1e7afebb5965", "components": ["ConstraintElimination"], "bug_location_lineno": {"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": [[1464, 1470]]}, "bug_location_funcname": {"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": ["checkAndReplaceCmp"]}}, "patch": "commit 3ff9d92aae0945daa85ec6f85f05a3aeaaa9f962\nAuthor: Yingwei Zheng <[email protected]>\nDate: Fri Aug 23 16:06:00 2024 +0800\n\n [ConstraintElim] Fix miscompilation caused by PR97974 (#105790)\n \n Fixes https://github.com/llvm/llvm-project/issues/105785.\n \n (cherry picked from commit 85b6aac7c25f9d2a976a76045ace1e7afebb5965)\n\ndiff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp\nindex c31173879af1..37022104d0a9 100644\n--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp\n+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp\n@@ -1464,7 +1464,7 @@ static bool checkAndReplaceCmp(CmpIntrinsic *I, ConstraintInfo &Info,\n ToRemove.push_back(I);\n return true;\n }\n- if (checkCondition(ICmpInst::ICMP_EQ, LHS, RHS, I, Info)) {\n+ if (checkCondition(ICmpInst::ICMP_EQ, LHS, RHS, I, Info).value_or(false)) {\n I->replaceAllUsesWith(ConstantInt::get(I->getType(), 0));\n ToRemove.push_back(I);\n return true;\n", "tests": [{"file": "llvm/test/Transforms/ConstraintElimination/pr105785.ll", "commands": ["opt -passes=constraint-elimination -S %s"], "tests": [{"test_name": "pr105785", "test_body": "define void @pr105785(ptr %p) {\nentry:\n br label %for.cond\n\nfor.cond: ; preds = %for.cond1, %entry\n %for.ind = phi i32 [ 0, %entry ], [ 1, %for.cond1 ]\n %cmp = icmp eq i32 %for.ind, 0\n br i1 %cmp, label %for.cond1, label %for.end6\n\nfor.cond1: ; preds = %for.body3, %for.cond\n %for.ind2 = phi i32 [ %inc, %for.body3 ], [ 0, %for.cond ]\n %cmp2 = icmp ult i32 %for.ind2, 3\n br i1 %cmp2, label %for.body3, label %for.cond\n\nfor.body3: ; preds = %for.cond1\n %scmp = call i32 @llvm.scmp.i32.i32(i32 %for.ind, i32 1)\n store i32 %scmp, ptr %p, align 4\n %inc = add nuw nsw i32 %for.ind2, 1\n br label %for.cond1\n\nfor.end6: ; preds = %for.cond\n ret void\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.scmp.i32.i32(i32, i32) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": "-src-unroll=4 -tgt-unroll=4"}]}], "issue": {"title": "[ConstraintElim] Miscompilation with cmp intrinsic", "body": "Reproducer: https://alive2.llvm.org/ce/z/Tvz2NA\r\n```\r\n; bin/opt -passes=constraint-elimination test.ll -S\r\ndefine void @h(ptr %p) {\r\nentry:\r\n br label %for.cond\r\n\r\nfor.cond: ; preds = %for.cond1, %entry\r\n %storemerge = phi i32 [ 0, %entry ], [ 1, %for.cond1 ]\r\n %cmp = icmp eq i32 %storemerge, 0\r\n br i1 %cmp, label %for.cond1, label %for.end6\r\n\r\nfor.cond1: ; preds = %for.cond, %for.body3\r\n %i.0 = phi i32 [ %inc, %for.body3 ], [ 0, %for.cond ]\r\n %cmp2 = icmp ult i32 %i.0, 3\r\n br i1 %cmp2, label %for.body3, label %for.cond\r\n\r\nfor.body3: ; preds = %for.cond1\r\n %sub.i = tail call range(i32 -1, 2) i32 @llvm.scmp.i32.i32(i32 1, i32 %storemerge)\r\n store i32 %sub.i, ptr %p, align 4\r\n %inc = add nuw nsw i32 %i.0, 1\r\n br label %for.cond1\r\n\r\nfor.end6:\r\n ret void\r\n}\r\n```\r\n\r\n```\r\ndefine void @h(ptr %p) {\r\nentry:\r\n br label %for.cond\r\n\r\nfor.cond: ; preds = %for.cond1, %entry\r\n %storemerge = phi i32 [ 0, %entry ], [ 1, %for.cond1 ]\r\n %cmp = icmp eq i32 %storemerge, 0\r\n br i1 %cmp, label %for.cond1, label %for.end6\r\n\r\nfor.cond1: ; preds = %for.body3, %for.cond\r\n %i.0 = phi i32 [ %inc, %for.body3 ], [ 0, %for.cond ]\r\n %cmp2 = icmp ult i32 %i.0, 3\r\n br i1 %cmp2, label %for.body3, label %for.cond\r\n\r\nfor.body3: ; preds = %for.cond1\r\n store i32 0, ptr %p, align 4\r\n %inc = add nuw nsw i32 %i.0, 1\r\n br label %for.cond1\r\n\r\nfor.end6: ; preds = %for.cond\r\n ret void\r\n}\r\n```\r\n\r\nThe result of scmp should be 1 instead of 0.\r\n\r\nReduced C reproducer:\r\n```\r\n#include <stdio.h>\r\n#include <stdint.h>\r\n\r\nint builtin_scmp(int d, int e) { return (d > e) - (d < e); }\r\nint32_t f = 0;\r\nint64_t g = 0;\r\nvoid h() {\r\n for (f = 0; f <= 0; f++) {\r\n int i;\r\n for (i = 0; i < 3; i++)\r\n g = builtin_scmp(1, f);\r\n }\r\n}\r\nint main() {\r\n h();\r\n printf(\"%d\\n\", (int)g);\r\n return 0;\r\n}\r\n```\r\n\r\nI will post a fix later.\r\n", "author": "dtcxzyw", "labels": ["miscompilation", "llvm:transforms"], "comments": []}, "verified": true}
|
35 |
{"bug_id": "117518", "issue_url": "https://github.com/llvm/llvm-project/issues/117518", "bug_type": "crash", "base_commit": "3de21477c49172081e502b47d608e729915f0914", "knowledge_cutoff": "2024-11-25T05:31:23Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "f953b5eb72df77fc301aac210eab31c6270ff771", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[10875, 10883], [14372, 14378]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["finalize"]}}, "patch": "commit f953b5eb72df77fc301aac210eab31c6270ff771\nAuthor: Alexey Bataev <[email protected]>\nDate: Mon Nov 25 08:29:22 2024 -0800\n\n [SLP]Relax assertion about subvectors mask size\n \n SubVectorsMask might be less than CommonMask, if the vectors with larger\n number of elements are permuted or reused elements are used. Need to\n consider this when estimation/building the vector to avoid compiler\n crash\n \n Fixes #117518\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex 73218f377a06..34b80c1e3608 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -10875,9 +10875,10 @@ public:\n CommonMask[Idx] = Idx;\n // Add subvectors permutation cost.\n if (!SubVectorsMask.empty()) {\n- assert(SubVectorsMask.size() == CommonMask.size() &&\n+ assert(SubVectorsMask.size() <= CommonMask.size() &&\n \"Expected same size of masks for subvectors and common mask.\");\n- SmallVector<int> SVMask(SubVectorsMask.begin(), SubVectorsMask.end());\n+ SmallVector<int> SVMask(CommonMask.size(), PoisonMaskElem);\n+ copy(SubVectorsMask, SVMask.begin());\n for (auto [I1, I2] : zip(SVMask, CommonMask)) {\n if (I2 != PoisonMaskElem) {\n assert(I1 == PoisonMaskElem && \"Expected unused subvectors mask\");\n@@ -14372,7 +14373,8 @@ public:\n if (SubVectorsMask.empty()) {\n Vec = CreateSubVectors(Vec, CommonMask);\n } else {\n- SmallVector<int> SVMask(SubVectorsMask.begin(), SubVectorsMask.end());\n+ SmallVector<int> SVMask(CommonMask.size(), PoisonMaskElem);\n+ copy(SubVectorsMask, SVMask.begin());\n for (auto [I1, I2] : zip(SVMask, CommonMask)) {\n if (I2 != PoisonMaskElem) {\n assert(I1 == PoisonMaskElem && \"Expected unused subvectors mask\");\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/X86/non-power-of-2-subvectors-insert.ll", "commands": ["opt -S --passes=slp-vectorizer -slp-threshold=-300 -mtriple=x86_64-unknown-linux-gnu < %s"], "tests": [{"test_name": "<module>", "test_body": "\ndefine void @test() {\n;\n %xor108.i.i.i = xor i64 0, 1\n %conv115.i.i.i = trunc i64 %xor108.i.i.i to i16\n %add.i.i.i.i = or i16 %conv115.i.i.i, 0\n %add.i.frozen.i.i.i = freeze i16 %add.i.i.i.i\n %.cmp.not.i.i.i = icmp eq i16 %add.i.frozen.i.i.i, 0\n %cond.i1002.1.i.i.i = lshr i64 0, 0\n %conv115.1.i.i.i = trunc i64 %cond.i1002.1.i.i.i to i16\n %add.i.1.i.i.i = or i16 %conv115.1.i.i.i, 0\n %add.i.frozen.1.i.i.i = freeze i16 %add.i.1.i.i.i\n %.cmp.not.1.i.i.i = icmp eq i16 %add.i.frozen.1.i.i.i, 0\n %cond.i1002.2.i.i.i = lshr i64 %xor108.i.i.i, 0\n %conv115.2.i.i.i = trunc i64 %cond.i1002.2.i.i.i to i16\n %add.i.2.i.i.i = or i16 %conv115.2.i.i.i, 0\n %add.i.frozen.2.i.i.i = freeze i16 %add.i.2.i.i.i\n %.cmp.not.2.i.i.i = icmp eq i16 %add.i.frozen.2.i.i.i, 0\n %cond.i1002.3.i.i.i = lshr i64 0, 0\n %conv115.3.i.i.i = trunc i64 %cond.i1002.3.i.i.i to i16\n %add.i.3.i.i.i = or i16 %conv115.3.i.i.i, 0\n %add.i.frozen.3.i.i.i = freeze i16 %add.i.3.i.i.i\n %.cmp.not.3.i.i.i = icmp eq i16 %add.i.frozen.3.i.i.i, 0\n %conv115.i.i.i.1 = trunc i64 %xor108.i.i.i to i16\n %add.i.i.i.i.1 = or i16 %conv115.i.i.i.1, 0\n %add.i.frozen.i.i.i.1 = freeze i16 %add.i.i.i.i.1\n %.cmp.not.i.i.i.1 = icmp eq i16 %add.i.frozen.i.i.i.1, 0\n %cond.i1002.1.i.i.i.1 = lshr i64 0, 0\n %conv115.1.i.i.i.1 = trunc i64 %cond.i1002.1.i.i.i.1 to i16\n %add.i.1.i.i.i.1 = or i16 %conv115.1.i.i.i.1, 0\n %add.i.frozen.1.i.i.i.1 = freeze i16 %add.i.1.i.i.i.1\n %.cmp.not.1.i.i.i.1 = icmp eq i16 %add.i.frozen.1.i.i.i.1, 0\n %cond.i1002.2.i.i.i.1 = lshr i64 0, 0\n %conv115.2.i.i.i.1 = trunc i64 %cond.i1002.2.i.i.i.1 to i16\n %add.i.2.i.i.i.1 = or i16 %conv115.2.i.i.i.1, 0\n %add.i.frozen.2.i.i.i.1 = freeze i16 %add.i.2.i.i.i.1\n %.cmp.not.2.i.i.i.1 = icmp eq i16 %add.i.frozen.2.i.i.i.1, 0\n %cond.i1002.3.i.i.i.1 = lshr i64 0, 0\n %conv115.3.i.i.i.1 = trunc i64 %cond.i1002.3.i.i.i.1 to i16\n %add.i.3.i.i.i.1 = or i16 %conv115.3.i.i.i.1, 0\n %add.i.frozen.3.i.i.i.1 = freeze i16 %add.i.3.i.i.i.1\n %.cmp.not.3.i.i.i.1 = icmp eq i16 %add.i.frozen.3.i.i.i.1, 0\n %conv115.i.i.i.2 = trunc i64 %xor108.i.i.i to i16\n %add.i.i.i.i.2 = or i16 %conv115.i.i.i.2, 0\n %add.i.frozen.i.i.i.2 = freeze i16 %add.i.i.i.i.2\n %.cmp.not.i.i.i.2 = icmp eq i16 %add.i.frozen.i.i.i.2, 0\n %cond.i1002.1.i.i.i.2 = lshr i64 0, 0\n %conv115.1.i.i.i.2 = trunc i64 %cond.i1002.1.i.i.i.2 to i16\n %add.i.1.i.i.i.2 = or i16 %conv115.1.i.i.i.2, 0\n %add.i.frozen.1.i.i.i.2 = freeze i16 %add.i.1.i.i.i.2\n %.cmp.not.1.i.i.i.2 = icmp eq i16 %add.i.frozen.1.i.i.i.2, 0\n %cond.i1002.2.i.i.i.2 = lshr i64 0, 0\n %conv115.2.i.i.i.2 = trunc i64 %cond.i1002.2.i.i.i.2 to i16\n %add.i.2.i.i.i.2 = or i16 %conv115.2.i.i.i.2, 0\n %add.i.frozen.2.i.i.i.2 = freeze i16 %add.i.2.i.i.i.2\n %.cmp.not.2.i.i.i.2 = icmp eq i16 %add.i.frozen.2.i.i.i.2, 0\n %cond.i1002.3.i.i.i.2 = lshr i64 0, 0\n %conv115.3.i.i.i.2 = trunc i64 %cond.i1002.3.i.i.i.2 to i16\n %add.i.3.i.i.i.2 = or i16 %conv115.3.i.i.i.2, 0\n %add.i.frozen.3.i.i.i.2 = freeze i16 %add.i.3.i.i.i.2\n %.cmp.not.3.i.i.i.2 = icmp eq i16 %add.i.frozen.3.i.i.i.2, 0\n %conv115.i.i.i.3 = trunc i64 %xor108.i.i.i to i16\n %add.i.i.i.i.3 = or i16 %conv115.i.i.i.3, 0\n %add.i.frozen.i.i.i.3 = freeze i16 %add.i.i.i.i.3\n %.cmp.not.i.i.i.3 = icmp eq i16 %add.i.frozen.i.i.i.3, 0\n %cond.i1002.1.i.i.i.3 = lshr i64 0, 0\n %conv115.1.i.i.i.3 = trunc i64 %cond.i1002.1.i.i.i.3 to i16\n %add.i.1.i.i.i.3 = or i16 %conv115.1.i.i.i.3, 0\n %add.i.frozen.1.i.i.i.3 = freeze i16 %add.i.1.i.i.i.3\n %.cmp.not.1.i.i.i.3 = icmp eq i16 %add.i.frozen.1.i.i.i.3, 0\n %cond.i1002.2.i.i.i.3 = lshr i64 0, 0\n %conv115.2.i.i.i.3 = trunc i64 %cond.i1002.2.i.i.i.3 to i16\n %add.i.2.i.i.i.3 = or i16 %conv115.2.i.i.i.3, 0\n %add.i.frozen.2.i.i.i.3 = freeze i16 %add.i.2.i.i.i.3\n %.cmp.not.2.i.i.i.3 = icmp eq i16 %add.i.frozen.2.i.i.i.3, 0\n %cond.i1002.3.i.i.i.3 = lshr i64 0, 0\n %conv115.3.i.i.i.3 = trunc i64 %cond.i1002.3.i.i.i.3 to i16\n %add.i.3.i.i.i.3 = or i16 %conv115.3.i.i.i.3, 0\n %add.i.frozen.3.i.i.i.3 = freeze i16 %add.i.3.i.i.i.3\n %.cmp.not.3.i.i.i.3 = icmp eq i16 %add.i.frozen.3.i.i.i.3, 0\n ret void\n}"}]}], "issue": {"title": "[SLPVectorizer] Assertion `SubVectorsMask.size() == CommonMask.size() && \"Expected same size of masks for subvectors and common mask.\"' failed.", "body": "Reproducer: https://godbolt.org/z/chKcKacPK\r\n```\r\n; bin/opt -passes=slp-vectorizer test.ll -S\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine void @test() {\r\n %xor108.i.i.i = xor i64 0, 1\r\n %conv115.i.i.i = trunc i64 %xor108.i.i.i to i16\r\n %add.i.i.i.i = or i16 %conv115.i.i.i, 0\r\n %add.i.frozen.i.i.i = freeze i16 %add.i.i.i.i\r\n %.cmp.not.i.i.i = icmp eq i16 %add.i.frozen.i.i.i, 0\r\n %cond.i1002.1.i.i.i = lshr i64 0, 0\r\n %conv115.1.i.i.i = trunc i64 %cond.i1002.1.i.i.i to i16\r\n %add.i.1.i.i.i = or i16 %conv115.1.i.i.i, 0\r\n %add.i.frozen.1.i.i.i = freeze i16 %add.i.1.i.i.i\r\n %.cmp.not.1.i.i.i = icmp eq i16 %add.i.frozen.1.i.i.i, 0\r\n %cond.i1002.2.i.i.i = lshr i64 %xor108.i.i.i, 0\r\n %conv115.2.i.i.i = trunc i64 %cond.i1002.2.i.i.i to i16\r\n %add.i.2.i.i.i = or i16 %conv115.2.i.i.i, 0\r\n %add.i.frozen.2.i.i.i = freeze i16 %add.i.2.i.i.i\r\n %.cmp.not.2.i.i.i = icmp eq i16 %add.i.frozen.2.i.i.i, 0\r\n %cond.i1002.3.i.i.i = lshr i64 0, 0\r\n %conv115.3.i.i.i = trunc i64 %cond.i1002.3.i.i.i to i16\r\n %add.i.3.i.i.i = or i16 %conv115.3.i.i.i, 0\r\n %add.i.frozen.3.i.i.i = freeze i16 %add.i.3.i.i.i\r\n %.cmp.not.3.i.i.i = icmp eq i16 %add.i.frozen.3.i.i.i, 0\r\n %conv115.i.i.i.1 = trunc i64 %xor108.i.i.i to i16\r\n %add.i.i.i.i.1 = or i16 %conv115.i.i.i.1, 0\r\n %add.i.frozen.i.i.i.1 = freeze i16 %add.i.i.i.i.1\r\n %.cmp.not.i.i.i.1 = icmp eq i16 %add.i.frozen.i.i.i.1, 0\r\n %cond.i1002.1.i.i.i.1 = lshr i64 0, 0\r\n %conv115.1.i.i.i.1 = trunc i64 %cond.i1002.1.i.i.i.1 to i16\r\n %add.i.1.i.i.i.1 = or i16 %conv115.1.i.i.i.1, 0\r\n %add.i.frozen.1.i.i.i.1 = freeze i16 %add.i.1.i.i.i.1\r\n %.cmp.not.1.i.i.i.1 = icmp eq i16 %add.i.frozen.1.i.i.i.1, 0\r\n %cond.i1002.2.i.i.i.1 = lshr i64 0, 0\r\n %conv115.2.i.i.i.1 = trunc i64 %cond.i1002.2.i.i.i.1 to i16\r\n %add.i.2.i.i.i.1 = or i16 %conv115.2.i.i.i.1, 0\r\n %add.i.frozen.2.i.i.i.1 = freeze i16 %add.i.2.i.i.i.1\r\n %.cmp.not.2.i.i.i.1 = icmp eq i16 %add.i.frozen.2.i.i.i.1, 0\r\n %cond.i1002.3.i.i.i.1 = lshr i64 0, 0\r\n %conv115.3.i.i.i.1 = trunc i64 %cond.i1002.3.i.i.i.1 to i16\r\n %add.i.3.i.i.i.1 = or i16 %conv115.3.i.i.i.1, 0\r\n %add.i.frozen.3.i.i.i.1 = freeze i16 %add.i.3.i.i.i.1\r\n %.cmp.not.3.i.i.i.1 = icmp eq i16 %add.i.frozen.3.i.i.i.1, 0\r\n %conv115.i.i.i.2 = trunc i64 %xor108.i.i.i to i16\r\n %add.i.i.i.i.2 = or i16 %conv115.i.i.i.2, 0\r\n %add.i.frozen.i.i.i.2 = freeze i16 %add.i.i.i.i.2\r\n %.cmp.not.i.i.i.2 = icmp eq i16 %add.i.frozen.i.i.i.2, 0\r\n %cond.i1002.1.i.i.i.2 = lshr i64 0, 0\r\n %conv115.1.i.i.i.2 = trunc i64 %cond.i1002.1.i.i.i.2 to i16\r\n %add.i.1.i.i.i.2 = or i16 %conv115.1.i.i.i.2, 0\r\n %add.i.frozen.1.i.i.i.2 = freeze i16 %add.i.1.i.i.i.2\r\n %.cmp.not.1.i.i.i.2 = icmp eq i16 %add.i.frozen.1.i.i.i.2, 0\r\n %cond.i1002.2.i.i.i.2 = lshr i64 0, 0\r\n %conv115.2.i.i.i.2 = trunc i64 %cond.i1002.2.i.i.i.2 to i16\r\n %add.i.2.i.i.i.2 = or i16 %conv115.2.i.i.i.2, 0\r\n %add.i.frozen.2.i.i.i.2 = freeze i16 %add.i.2.i.i.i.2\r\n %.cmp.not.2.i.i.i.2 = icmp eq i16 %add.i.frozen.2.i.i.i.2, 0\r\n %cond.i1002.3.i.i.i.2 = lshr i64 0, 0\r\n %conv115.3.i.i.i.2 = trunc i64 %cond.i1002.3.i.i.i.2 to i16\r\n %add.i.3.i.i.i.2 = or i16 %conv115.3.i.i.i.2, 0\r\n %add.i.frozen.3.i.i.i.2 = freeze i16 %add.i.3.i.i.i.2\r\n %.cmp.not.3.i.i.i.2 = icmp eq i16 %add.i.frozen.3.i.i.i.2, 0\r\n %conv115.i.i.i.3 = trunc i64 %xor108.i.i.i to i16\r\n %add.i.i.i.i.3 = or i16 %conv115.i.i.i.3, 0\r\n %add.i.frozen.i.i.i.3 = freeze i16 %add.i.i.i.i.3\r\n %.cmp.not.i.i.i.3 = icmp eq i16 %add.i.frozen.i.i.i.3, 0\r\n %cond.i1002.1.i.i.i.3 = lshr i64 0, 0\r\n %conv115.1.i.i.i.3 = trunc i64 %cond.i1002.1.i.i.i.3 to i16\r\n %add.i.1.i.i.i.3 = or i16 %conv115.1.i.i.i.3, 0\r\n %add.i.frozen.1.i.i.i.3 = freeze i16 %add.i.1.i.i.i.3\r\n %.cmp.not.1.i.i.i.3 = icmp eq i16 %add.i.frozen.1.i.i.i.3, 0\r\n %cond.i1002.2.i.i.i.3 = lshr i64 0, 0\r\n %conv115.2.i.i.i.3 = trunc i64 %cond.i1002.2.i.i.i.3 to i16\r\n %add.i.2.i.i.i.3 = or i16 %conv115.2.i.i.i.3, 0\r\n %add.i.frozen.2.i.i.i.3 = freeze i16 %add.i.2.i.i.i.3\r\n %.cmp.not.2.i.i.i.3 = icmp eq i16 %add.i.frozen.2.i.i.i.3, 0\r\n %cond.i1002.3.i.i.i.3 = lshr i64 0, 0\r\n %conv115.3.i.i.i.3 = trunc i64 %cond.i1002.3.i.i.i.3 to i16\r\n %add.i.3.i.i.i.3 = or i16 %conv115.3.i.i.i.3, 0\r\n %add.i.frozen.3.i.i.i.3 = freeze i16 %add.i.3.i.i.i.3\r\n %.cmp.not.3.i.i.i.3 = icmp eq i16 %add.i.frozen.3.i.i.i.3, 0\r\n ret void\r\n}\r\n```\r\n```\r\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:10880: llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator::finalize(llvm::ArrayRef<int>, llvm::ArrayRef<std::pair<const llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int> >, llvm::ArrayRef<int>, unsigned int, llvm::function_ref<void(llvm::Value*&, llvm::SmallVectorImpl<int>&)>): Assertion `SubVectorsMask.size() == CommonMask.size() && \"Expected same size of masks for subvectors and common mask.\"' 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.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=slp-vectorizer <source>\r\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\r\n2.\tRunning pass \"slp-vectorizer\" on function \"test\"\r\n #0 0x00000000051b7378 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x51b7378)\r\n #1 0x00000000051b4d6c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007ac42d642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007ac42d6969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007ac42d642476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007ac42d6287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00007ac42d62871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x00007ac42d639e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x00000000041e9132 llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator::finalize(llvm::ArrayRef<int>, llvm::ArrayRef<std::pair<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, unsigned int>>, llvm::ArrayRef<int>, unsigned int, llvm::function_ref<void (llvm::Value*&, llvm::SmallVectorImpl<int>&)>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41e9132)\r\n #9 0x00000000042256f9 llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::processBuildVector<llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator, llvm::InstructionCost, llvm::TargetTransformInfo, llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP, llvm::SmallPtrSetImpl<llvm::Value*>>(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::Type*, llvm::TargetTransformInfo&, llvm::ArrayRef<llvm::Value*>&, llvm::slpvectorizer::BoUpSLP&, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x42256f9)\r\n#10 0x000000000422f707 llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x422f707)\r\n#11 0x00000000042636a1 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x42636a1)\r\n#12 0x000000000426d57c llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x426d57c)\r\n#13 0x000000000427168f bool llvm::SLPVectorizerPass::vectorizeCmpInsts<std::reverse_iterator<llvm::CmpInst* const*>>(llvm::iterator_range<std::reverse_iterator<llvm::CmpInst* const*>>, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x427168f)\r\n#14 0x0000000004271fdb llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&)::'lambda3'(bool)::operator()(bool) const SLPVectorizer.cpp:0:0\r\n#15 0x0000000004275785 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4275785)\r\n#16 0x000000000427bf86 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0\r\n#17 0x000000000427ca9b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x427ca9b)\r\n#18 0x0000000002fcc5ce llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2fcc5ce)\r\n#19 0x0000000004fb6a68 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fb6a68)\r\n#20 0x0000000000e3dd4e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe3dd4e)\r\n#21 0x0000000004fb548e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fb548e)\r\n#22 0x0000000000e3d3fe llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe3d3fe)\r\n#23 0x0000000004fb4ec0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fb4ec0)\r\n#24 0x000000000090ce7a 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+0x90ce7a)\r\n#25 0x00000000008ff519 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ff519)\r\n#26 0x00007ac42d629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#27 0x00007ac42d629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#28 0x00000000008f6d6e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f6d6e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "dtcxzyw", "labels": ["llvm:SLPVectorizer", "crash-on-valid"], "comments": []}, "verified": true}
|
36 |
{"bug_id": "100298", "issue_url": "https://github.com/llvm/llvm-project/issues/100298", "bug_type": "miscompilation", "base_commit": "75642a00e15b722bdfb90726be31f1c8adaeb0c5", "knowledge_cutoff": "2024-07-24T04:19:53Z", "lit_test_dir": ["llvm/test/Transforms/InstCombine"], "hints": {"fix_commit": "59eae919c938f890e9b9b4be8a3fa3cb1b11ed89", "components": ["ValueTracking"], "bug_location_lineno": {"llvm/include/llvm/Analysis/SimplifyQuery.h": [[130, 135]], "llvm/lib/Analysis/ValueTracking.cpp": [[1435, 1441], [1468, 1474], [1546, 1552], [2329, 2335], [2943, 2949], [3509, 3515], [4001, 4007], [5909, 5918]]}, "bug_location_funcname": {"llvm/include/llvm/Analysis/SimplifyQuery.h": ["getWithCondContext"], "llvm/lib/Analysis/ValueTracking.cpp": ["ComputeNumSignBitsImpl", "computeKnownBitsFromOperator", "computeKnownFPClass", "isKnownNonZeroFromOperator", "isKnownToBeAPowerOfTwo", "isNonEqualPHIs"]}}, "patch": "commit a87fbeb3a77a53ded341277c5b326f7696d47594\nAuthor: Yingwei Zheng <[email protected]>\nDate: Wed Jul 24 20:06:36 2024 +0800\n\n [ValueTracking] Don't use CondContext in dataflow analysis of phi nodes (#100316)\n \n See the following case:\n ```\n define i16 @pr100298() {\n entry:\n br label %for.inc\n \n for.inc:\n %indvar = phi i32 [ -15, %entry ], [ %mask, %for.inc ]\n %add = add nsw i32 %indvar, 9\n %mask = and i32 %add, 65535\n %cmp1 = icmp ugt i32 %mask, 5\n br i1 %cmp1, label %for.inc, label %for.end\n \n for.end:\n %conv = trunc i32 %add to i16\n %cmp2 = icmp ugt i32 %mask, 3\n %shl = shl nuw i16 %conv, 14\n %res = select i1 %cmp2, i16 %conv, i16 %shl\n ret i16 %res\n }\n ```\n \n When computing knownbits of `%shl` with `%cmp2=false`, we cannot use\n this condition in the analysis of `%mask (%for.inc -> %for.inc)`.\n \n Fixes https://github.com/llvm/llvm-project/issues/100298.\n \n (cherry picked from commit 59eae919c938f890e9b9b4be8a3fa3cb1b11ed89)\n\ndiff --git a/llvm/include/llvm/Analysis/SimplifyQuery.h b/llvm/include/llvm/Analysis/SimplifyQuery.h\nindex a560744f0122..e8f43c8c2e91 100644\n--- a/llvm/include/llvm/Analysis/SimplifyQuery.h\n+++ b/llvm/include/llvm/Analysis/SimplifyQuery.h\n@@ -130,6 +130,12 @@ struct SimplifyQuery {\n Copy.CC = &CC;\n return Copy;\n }\n+\n+ SimplifyQuery getWithoutCondContext() const {\n+ SimplifyQuery Copy(*this);\n+ Copy.CC = nullptr;\n+ return Copy;\n+ }\n };\n \n } // end namespace llvm\ndiff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp\nindex 40fe1ffe13f1..4b77c0046cc7 100644\n--- a/llvm/lib/Analysis/ValueTracking.cpp\n+++ b/llvm/lib/Analysis/ValueTracking.cpp\n@@ -1435,7 +1435,7 @@ static void computeKnownBitsFromOperator(const Operator *I,\n // inferred hold at original context instruction. TODO: It may be\n // correct to use the original context. IF warranted, explore and\n // add sufficient tests to cover.\n- SimplifyQuery RecQ = Q;\n+ SimplifyQuery RecQ = Q.getWithoutCondContext();\n RecQ.CxtI = P;\n computeKnownBits(R, DemandedElts, Known2, Depth + 1, RecQ);\n switch (Opcode) {\n@@ -1468,7 +1468,7 @@ static void computeKnownBitsFromOperator(const Operator *I,\n // phi. This is important because that is where the value is actually\n // \"evaluated\" even though it is used later somewhere else. (see also\n // D69571).\n- SimplifyQuery RecQ = Q;\n+ SimplifyQuery RecQ = Q.getWithoutCondContext();\n \n unsigned OpNum = P->getOperand(0) == R ? 0 : 1;\n Instruction *RInst = P->getIncomingBlock(OpNum)->getTerminator();\n@@ -1546,7 +1546,7 @@ static void computeKnownBitsFromOperator(const Operator *I,\n // phi. This is important because that is where the value is actually\n // \"evaluated\" even though it is used later somewhere else. (see also\n // D69571).\n- SimplifyQuery RecQ = Q;\n+ SimplifyQuery RecQ = Q.getWithoutCondContext();\n RecQ.CxtI = P->getIncomingBlock(u)->getTerminator();\n \n Known2 = KnownBits(BitWidth);\n@@ -2329,7 +2329,7 @@ bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero, unsigned Depth,\n // it is an induction variable where in each step its value is a power of\n // two.\n auto *PN = cast<PHINode>(I);\n- SimplifyQuery RecQ = Q;\n+ SimplifyQuery RecQ = Q.getWithoutCondContext();\n \n // Check if it is an induction variable and always power of two.\n if (isPowerOfTwoRecurrence(PN, OrZero, Depth, RecQ))\n@@ -2943,7 +2943,7 @@ static bool isKnownNonZeroFromOperator(const Operator *I,\n return true;\n \n // Check if all incoming values are non-zero using recursion.\n- SimplifyQuery RecQ = Q;\n+ SimplifyQuery RecQ = Q.getWithoutCondContext();\n unsigned NewDepth = std::max(Depth, MaxAnalysisRecursionDepth - 1);\n return llvm::all_of(PN->operands(), [&](const Use &U) {\n if (U.get() == PN)\n@@ -3509,7 +3509,7 @@ static bool isNonEqualPHIs(const PHINode *PN1, const PHINode *PN2,\n if (UsedFullRecursion)\n return false;\n \n- SimplifyQuery RecQ = Q;\n+ SimplifyQuery RecQ = Q.getWithoutCondContext();\n RecQ.CxtI = IncomBB->getTerminator();\n if (!isKnownNonEqual(IV1, IV2, DemandedElts, Depth + 1, RecQ))\n return false;\n@@ -4001,7 +4001,7 @@ static unsigned ComputeNumSignBitsImpl(const Value *V,\n \n // Take the minimum of all incoming values. This can't infinitely loop\n // because of our depth threshold.\n- SimplifyQuery RecQ = Q;\n+ SimplifyQuery RecQ = Q.getWithoutCondContext();\n Tmp = TyBits;\n for (unsigned i = 0, e = NumIncomingValues; i != e; ++i) {\n if (Tmp == 1) return Tmp;\n@@ -5909,10 +5909,10 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,\n // Recurse, but cap the recursion to two levels, because we don't want\n // to waste time spinning around in loops. We need at least depth 2 to\n // detect known sign bits.\n- computeKnownFPClass(\n- IncValue, DemandedElts, InterestedClasses, KnownSrc,\n- PhiRecursionLimit,\n- Q.getWithInstruction(P->getIncomingBlock(U)->getTerminator()));\n+ computeKnownFPClass(IncValue, DemandedElts, InterestedClasses, KnownSrc,\n+ PhiRecursionLimit,\n+ Q.getWithoutCondContext().getWithInstruction(\n+ P->getIncomingBlock(U)->getTerminator()));\n \n if (First) {\n Known = KnownSrc;\n", "tests": [{"file": "llvm/test/Transforms/InstCombine/pr100298.ll", "commands": ["opt -S -passes=instcombine < %s"], "tests": [{"test_name": "pr100298", "test_body": "define i16 @pr100298() {\nentry:\n br label %for.inc\n\nfor.inc: ; preds = %for.inc, %entry\n %indvar = phi i32 [ -15, %entry ], [ %mask, %for.inc ]\n %add = add nsw i32 %indvar, 9\n %mask = and i32 %add, 65535\n %cmp1 = icmp ugt i32 %mask, 5\n br i1 %cmp1, label %for.inc, label %for.end\n\nfor.end: ; preds = %for.inc\n %conv = trunc i32 %add to i16\n %cmp2 = icmp ugt i32 %mask, 3\n %shl = shl nuw i16 %conv, 14\n %res = select i1 %cmp2, i16 %conv, i16 %shl\n ret i16 %res\n}\n"}]}], "issue": {"title": "Miscompilation at O3", "body": "```\r\n#include \"csmith.h\"\r\nuint32_t a;\r\nint16_t c;\r\nvoid d() {\r\n for (a = -15; a >= 6; a = safe_add_func_uint16_t_u_u(a, 9))\r\n ;\r\n c = safe_lshift_func_int16_t_s_u(safe_lshift_func_uint16_t_u_s(a,14), 0);\r\n}\r\nint main() {\r\n d();\r\n printf(\"%d\\n\", c);\r\n return 0;\r\n}\r\n```\r\n\r\n```\r\ndtcxzyw@dtcxzyw:~/WorkSpace/Projects/compilers/LLVM/llvm-build$ gcc -O0 test.c -fsanitize=undefined -I/usr/include/csmith -w\r\ndtcxzyw@dtcxzyw:~/WorkSpace/Projects/compilers/LLVM/llvm-build$ ./a.out \r\n-16384\r\ndtcxzyw@dtcxzyw:~/WorkSpace/Projects/compilers/LLVM/llvm-build$ bin/clang -O3 test.c -I/usr/include/csmith -w\r\ndtcxzyw@dtcxzyw:~/WorkSpace/Projects/compilers/LLVM/llvm-build$ ./a.out \r\n0\r\n```\r\n\r\nllvm version: 2d6ff0c533aa1b0fe6d91764846f636c4a4e911c", "author": "dtcxzyw", "labels": ["miscompilation", "llvm:analysis"], "comments": [{"author": "dtcxzyw", "body": "Reduced testcase: https://alive2.llvm.org/ce/z/9fExrA\r\n```\r\n; bin/opt -passes=instcombine test.ll -S\r\ndefine i16 @src() {\r\nentry:\r\n br label %for.inc\r\n\r\nfor.inc:\r\n %storemerge6 = phi i32 [ -15, %entry ], [ %conv1, %for.inc ]\r\n %add.i = add nsw i32 %storemerge6, 9\r\n %conv1 = and i32 %add.i, 65535\r\n %cmp = icmp ugt i32 %conv1, 5\r\n br i1 %cmp, label %for.inc, label %for.end\r\n\r\nfor.end:\r\n %conv2 = trunc nuw nsw i32 %conv1 to i16\r\n %cmp3.i = icmp ugt i32 %conv1, 3\r\n %0 = shl nuw i16 %conv2, 14\r\n %cond.in.i = select i1 %cmp3.i, i16 %conv2, i16 %0\r\n ret i16 %cond.in.i\r\n}\r\n```"}]}, "verified": true}
|
37 |
{"bug_id": "101337", "issue_url": "https://github.com/llvm/llvm-project/issues/101337", "bug_type": "crash", "base_commit": "1b936e4812ab395328203f65cacd4ffe02bb318e", "knowledge_cutoff": "2024-07-31T14:11:24Z", "lit_test_dir": ["llvm/test/Transforms/LoopVectorize"], "hints": {"fix_commit": "cd08fadd03904806fa26a1f117879ddae34fbf67", "components": ["LoopVectorize"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [[7080, 7086]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": ["LoopVectorizationPlanner::cost"]}}, "patch": "commit cd08fadd03904806fa26a1f117879ddae34fbf67\nAuthor: Florian Hahn <[email protected]>\nDate: Mon Aug 12 14:45:43 2024 +0100\n\n [LV] Include chains feeding inductions in cost precomputation.\n \n Include chain of ops feeding inductions in cost precomputation for\n inductions, not just the induction increment. In VPlan, those\n instructions will be cleaned up, as both phi and increment are generated\n by VPWidenIntOrFpInductionRecipe independently.\n \n Fixes https://github.com/llvm/llvm-project/issues/101337.\n\ndiff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\nindex 542d74ef0e1e..41e4b0fcd9b0 100644\n--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n@@ -7080,7 +7080,16 @@ InstructionCost LoopVectorizationPlanner::cost(VPlan &Plan,\n for (const auto &[IV, IndDesc] : Legal->getInductionVars()) {\n Instruction *IVInc = cast<Instruction>(\n IV->getIncomingValueForBlock(OrigLoop->getLoopLatch()));\n- SmallVector<Instruction *> IVInsts = {IV, IVInc};\n+ SmallVector<Instruction *> IVInsts = {IVInc};\n+ for (unsigned I = 0; I != IVInsts.size(); I++) {\n+ for (Value *Op : IVInsts[I]->operands()) {\n+ auto *OpI = dyn_cast<Instruction>(Op);\n+ if (Op == IV || !OpI || !OrigLoop->contains(OpI) || !Op->hasOneUse())\n+ continue;\n+ IVInsts.push_back(OpI);\n+ }\n+ }\n+ IVInsts.push_back(IV);\n for (User *U : IV->users()) {\n auto *CI = cast<Instruction>(U);\n if (!CostCtx.CM.isOptimizableIVTruncate(CI, VF))\n", "tests": [{"file": "llvm/test/Transforms/LoopVectorize/X86/induction-costs.ll", "commands": ["opt -p loop-vectorize -mtriple=x86_64-apple-macosx -S %s"], "tests": [{"test_name": "iv_and_step_trunc", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine i16 @iv_and_step_trunc() {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %rec = phi i16 [ 0, %entry ], [ %rec.next, %loop ]\n %iv.next = add i64 %iv, 1\n %0 = trunc i64 %iv to i16\n %1 = trunc i64 %iv.next to i16\n %rec.next = mul i16 %0, %1\n %ec = icmp eq i64 %iv, 1\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i16 %rec\n}\n"}, {"test_name": "wombat2", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @wombat2(i32 %arg, ptr %dst) #0 {\nentry:\n %mul = mul i32 %arg, 3\n %zext = zext i32 %arg to i64\n br label %loop\n\nloop: ; preds = %loop, %entry\n %phi = phi i64 [ 4, %entry ], [ %add, %loop ]\n %phi2 = phi i32 [ %mul, %entry ], [ %trunc.1, %loop ]\n %getelementptr = getelementptr i32, ptr %dst, i64 %phi\n %and = and i32 %phi2, 12\n store i32 %and, ptr %getelementptr, align 4\n %mul3 = mul i64 %phi, %zext\n %add = add i64 %phi, 1\n %icmp = icmp ugt i64 %phi, 65\n %trunc.0 = trunc i64 %mul3 to i60\n %trunc.1 = trunc i60 %trunc.0 to i32\n br i1 %icmp, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"target-cpu\"=\"skylake-avx512\" \"target-features\"=\"-avx512f\" }\n"}, {"test_name": "with_dead_use", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @with_dead_use(i32 %arg, ptr %dst) #0 {\nentry:\n %mul = mul i32 %arg, 3\n %zext = zext i32 %arg to i64\n br label %loop\n\nloop: ; preds = %loop, %entry\n %phi = phi i64 [ 4, %entry ], [ %add, %loop ]\n %phi2 = phi i32 [ %mul, %entry ], [ %trunc, %loop ]\n %getelementptr = getelementptr i32, ptr %dst, i64 %phi\n %and = and i32 %phi2, 12\n store i32 %and, ptr %getelementptr, align 4\n %mul3 = mul i64 %phi, %zext\n %add = add i64 %phi, 1\n %icmp = icmp ugt i64 %phi, 65\n %trunc = trunc i64 %mul3 to i32\n %dead.and = and i32 %trunc, 123\n br i1 %icmp, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"target-cpu\"=\"skylake-avx512\" \"target-features\"=\"-avx512f\" }\n"}, {"test_name": "test_scalar_predicated_cost", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine i32 @test_scalar_predicated_cost(i64 %x, i64 %y, ptr %A) #0 {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %cmp9.not = icmp ule i64 %iv, %y\n br i1 %cmp9.not, label %loop.latch, label %if.then\n\nif.then: ; preds = %loop.header\n %or = or i64 %x, %iv\n %gep = getelementptr i32, ptr %A, i64 %iv\n %t = trunc i64 %or to i32\n store i32 %t, ptr %gep, align 4\n br label %loop.latch\n\nloop.latch: ; preds = %if.then, %loop.header\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, 100\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret i32 0\n}\n\nattributes #0 = { \"min-legal-vector-width\"=\"0\" \"target-cpu\"=\"skylake-avx512\" }\n"}, {"test_name": "truncated_ivs_with_wide_and_scalar_uses", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @truncated_ivs_with_wide_and_scalar_uses(i1 %c, ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.16 = trunc i64 %iv to i16\n %iv.32 = trunc i64 %iv to i32\n %gep = getelementptr i16, ptr %dst, i32 %iv.32\n %sel = select i1 %c, i16 %iv.16, i16 10\n store i16 %sel, ptr %gep, align 2\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, 64\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n"}, {"test_name": "multiple_truncated_ivs_with_wide_uses", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @multiple_truncated_ivs_with_wide_uses(i1 %c, ptr %A, ptr %B) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.16 = trunc i64 %iv to i16\n %iv.32 = trunc i64 %iv to i32\n %sel = select i1 %c, i16 %iv.16, i16 10\n %gep.A = getelementptr i16, ptr %A, i64 %iv\n store i16 %sel, ptr %gep.A, align 2\n %gep.B = getelementptr i32, ptr %B, i64 %iv\n store i32 %iv.32, ptr %gep.B, align 4\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, 64\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n"}, {"test_name": "wide_iv_trunc_reuse", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @wide_iv_trunc_reuse(ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 1, %entry ], [ %iv.next, %loop ]\n %iv.2 = phi i32 [ 0, %entry ], [ %iv.trunc, %loop ]\n store i32 %iv.2, ptr %dst, align 4\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, 0\n %iv.trunc = trunc i64 %iv to i32\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n"}, {"test_name": "iv_used_widened_and_truncated", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine i32 @iv_used_widened_and_truncated(ptr %dst, i64 %N) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep = getelementptr { i32, [8 x i32] }, ptr %dst, i64 %iv\n %t = trunc i64 %iv to i32\n store i32 %t, ptr %gep, align 8\n %iv.next = add i64 %iv, 1\n %c = icmp eq i64 %iv, %N\n br i1 %c, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i32 0\n}\n\nattributes #0 = { \"min-legal-vector-width\"=\"0\" \"target-cpu\"=\"skylake-avx512\" }\n"}, {"test_name": "wombat", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @wombat(i32 %arg, ptr %dst) #0 {\nentry:\n %mul = mul i32 %arg, 3\n %zext = zext i32 %arg to i64\n br label %loop\n\nloop: ; preds = %loop, %entry\n %phi = phi i64 [ 4, %entry ], [ %add, %loop ]\n %phi2 = phi i32 [ %mul, %entry ], [ %trunc, %loop ]\n %getelementptr = getelementptr i32, ptr %dst, i64 %phi\n %and = and i32 %phi2, 12\n store i32 %and, ptr %getelementptr, align 4\n %mul3 = mul i64 %phi, %zext\n %add = add i64 %phi, 1\n %icmp = icmp ugt i64 %phi, 65\n %trunc = trunc i64 %mul3 to i32\n br i1 %icmp, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"target-cpu\"=\"skylake-avx512\" \"target-features\"=\"-avx512f\" }\n"}, {"test_name": "wide_iv_trunc", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @wide_iv_trunc(ptr %dst, i64 %N) {\nentry:\n %cmp = icmp ult i64 %N, 8\n br i1 %cmp, label %loop, label %exit\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.trunc = trunc i64 %iv to i32\n store i32 %iv.trunc, ptr %dst, align 4\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, %N\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop, %entry\n ret void\n}\n"}, {"test_name": "multiple_pointer_ivs_with_scalar_uses_only", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @multiple_pointer_ivs_with_scalar_uses_only(ptr %A, ptr %B) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv.1 = phi i32 [ 100, %entry ], [ %dec, %loop ]\n %iv.2 = phi i32 [ 2048, %entry ], [ %add38, %loop ]\n %ptr.iv.1 = phi ptr [ %A, %entry ], [ %outptr.0, %loop ]\n %ptr.iv.2 = phi ptr [ %B, %entry ], [ %incdec.ptr36, %loop ]\n %ptr.iv.3 = phi ptr [ %B, %entry ], [ %incdec.ptr33, %loop ]\n %incdec.ptr33 = getelementptr i8, ptr %ptr.iv.3, i64 1\n %0 = load i8, ptr %ptr.iv.3, align 1\n %conv34 = zext i8 %0 to i32\n %incdec.ptr36 = getelementptr i8, ptr %ptr.iv.2, i64 1\n %1 = load i8, ptr %ptr.iv.2, align 1\n %conv37 = zext i8 %1 to i32\n %add38 = add i32 %conv34, %conv37\n %shr42 = lshr i32 %iv.2, 1\n %conv43 = trunc i32 %shr42 to i8\n store i8 %conv43, ptr %ptr.iv.1, align 1\n %dec = add i32 %iv.1, 1\n %outptr.0 = getelementptr i8, ptr %ptr.iv.1, i64 2\n %cmp30.not = icmp eq i32 %dec, 0\n br i1 %cmp30.not, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"min-legal-vector-width\"=\"0\" \"target-cpu\"=\"skylake-avx512\" }\n"}]}], "issue": {"title": "Assertion `VF.Width == BestVF && \"VPlan cost model and legacy cost model disagreed\"' failed.", "body": "To reproduce run opt with \r\n```\r\n-passes=loop-vectorize --mcpu=skylake-avx512 --mattr=+prfchw,-cldemote,+avx,+aes,+sahf,+pclmul,-xop,+crc32,+xsaves,-avx512fp16,-usermsr,-sm4,-egpr,+sse4.1,-avx512ifma,+xsave,+sse4.2,-tsxldtrk,-sm3,-ptwrite,-widekl,+invpcid,+64bit,+xsavec,-avx10.1-512,-avx512vpopcntdq,+cmov,-avx512vp2intersect,+avx512cd,+movbe,-avxvnniint8,-ccmp,-amx-int8,-kl,-avx10.1-256,+evex512,-avxvnni,+rtm,+adx,+avx2,-hreset,-movdiri,-serialize,-sha512,-vpclmulqdq,+avx512vl,-uintr,-cf,+clflushopt,-raoint,-cmpccxadd,+bmi,-amx-tile,+sse,-gfni,-avxvnniint16,-amx-fp16,-zu,-ndd,+xsaveopt,+rdrnd,+avx512f,-amx-bf16,-avx512bf16,-avx512vnni,-push2pop2,+cx8,+avx512bw,+sse3,+pku,-nf,+fsgsbase,-clzero,-mwaitx,-lwp,+lzcnt,-sha,-movdir64b,-ppx,-wbnoinvd,-enqcmd,-avxneconvert,-tbm,-pconfig,-amx-complex,+ssse3,+cx16,+bmi2,+fma,+popcnt,-avxifma,+f16c,-avx512bitalg,-rdpru,+clwb,+mmx,+sse2,+rdseed,-avx512vbmi2,-prefetchi,-rdpid,-fma4,-avx512vbmi,-shstk,-vaes,-waitpkg,-sgx,+fxsr,+avx512dq,-sse4a,-avx512f\r\n```\r\nwith the following test:\r\n```\r\n; ModuleID = './reduced.ll'\r\nsource_filename = \"./reduced.ll\"\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine void @wombat(i32 %arg) #0 gc \"statepoint-example\" {\r\nbb:\r\n %mul = mul i32 %arg, 3\r\n %zext = zext i32 %arg to i64\r\n br label %bb1\r\n\r\nbb1: ; preds = %bb1, %bb\r\n %phi = phi i64 [ %add, %bb1 ], [ 4, %bb ]\r\n %phi2 = phi i32 [ %trunc, %bb1 ], [ %mul, %bb ]\r\n %getelementptr = getelementptr i32, ptr addrspace(1) null, i64 %phi\r\n %and = and i32 %phi2, 0\r\n store i32 0, ptr addrspace(1) %getelementptr, align 4\r\n %mul3 = mul i64 %phi, %zext\r\n %add = add i64 %phi, 1\r\n %icmp = icmp ugt i64 %phi, 65\r\n %trunc = trunc i64 %mul3 to i32\r\n br i1 %icmp, label %bb4, label %bb1\r\n\r\nbb4: ; preds = %bb1\r\n ret void\r\n}\r\n```\r\nReproducer: https://godbolt.org/z/nPsP7h51n\r\n\r\nStack dump:\r\n```\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=loop-vectorize --mcpu=skylake-avx512 --mattr=+prfchw,-cldemote,+avx,+aes,+sahf,+pclmul,-xop,+crc32,+xsaves,-avx512fp16,-usermsr,-sm4,-egpr,+sse4.1,-avx512ifma,+xsave,+sse4.2,-tsxldtrk,-sm3,-ptwrite,-widekl,+invpcid,+64bit,+xsavec,-avx10.1-512,-avx512vpopcntdq,+cmov,-avx512vp2intersect,+avx512cd,+movbe,-avxvnniint8,-ccmp,-amx-int8,-kl,-avx10.1-256,+evex512,-avxvnni,+rtm,+adx,+avx2,-hreset,-movdiri,-serialize,-sha512,-vpclmulqdq,+avx512vl,-uintr,-cf,+clflushopt,-raoint,-cmpccxadd,+bmi,-amx-tile,+sse,-gfni,-avxvnniint16,-amx-fp16,-zu,-ndd,+xsaveopt,+rdrnd,+avx512f,-amx-bf16,-avx512bf16,-avx512vnni,-push2pop2,+cx8,+avx512bw,+sse3,+pku,-nf,+fsgsbase,-clzero,-mwaitx,-lwp,+lzcnt,-sha,-movdir64b,-ppx,-wbnoinvd,-enqcmd,-avxneconvert,-tbm,-pconfig,-amx-complex,+ssse3,+cx16,+bmi2,+fma,+popcnt,-avxifma,+f16c,-avx512bitalg,-rdpru,+clwb,+mmx,+sse2,+rdseed,-avx512vbmi2,-prefetchi,-rdpid,-fma4,-avx512vbmi,-shstk,-vaes,-waitpkg,-sgx,+fxsr,+avx512dq,-sse4a,-avx512f <source>\r\n1.\tRunning pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"<source>\"\r\n2.\tRunning pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"wombat\"\r\n #0 0x0000000004f053c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f053c8)\r\n #1 0x0000000004f02b3c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007458cc042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007458cc0969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007458cc042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007458cc0287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00007458cc02871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x00007458cc039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x0000000003f83f37 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f83f37)\r\n #9 0x0000000003f86659 llvm::LoopVectorizePass::runImpl(llvm::Function&, llvm::ScalarEvolution&, llvm::LoopInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::BlockFrequencyInfo*, llvm::TargetLibraryInfo*, llvm::DemandedBits&, llvm::AssumptionCache&, llvm::LoopAccessInfoManager&, llvm::OptimizationRemarkEmitter&, llvm::ProfileSummaryInfo*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f86659)\r\n#10 0x0000000003f86cd2 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f86cd2)\r\n#11 0x0000000002e596ce llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2e596ce)\r\n#12 0x0000000004d02758 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d02758)\r\n#13 0x0000000000de089e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xde089e)\r\n#14 0x0000000004d0114e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d0114e)\r\n#15 0x0000000000de0eee llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xde0eee)\r\n#16 0x0000000004cff2b0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4cff2b0)\r\n#17 0x00000000008e3752 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+0x8e3752)\r\n#18 0x00000000008d667c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d667c)\r\n#19 0x00007458cc029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#20 0x00007458cc029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#21 0x00000000008cdade _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8cdade)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "TatyanaDoubts", "labels": ["vectorizers", "crash"], "comments": [{"author": "patrick-rivos", "body": "Potentially related: https://github.com/llvm/llvm-project/issues/100591"}]}, "verified": true}
|
dataset/105785.json
CHANGED
@@ -36,7 +36,8 @@
|
|
36 |
"tests": [
|
37 |
{
|
38 |
"test_name": "pr105785",
|
39 |
-
"test_body": "define void @pr105785(ptr %p) {\nentry:\n br label %for.cond\n\nfor.cond: ; preds = %for.cond1, %entry\n %for.ind = phi i32 [ 0, %entry ], [ 1, %for.cond1 ]\n %cmp = icmp eq i32 %for.ind, 0\n br i1 %cmp, label %for.cond1, label %for.end6\n\nfor.cond1: ; preds = %for.body3, %for.cond\n %for.ind2 = phi i32 [ %inc, %for.body3 ], [ 0, %for.cond ]\n %cmp2 = icmp ult i32 %for.ind2, 3\n br i1 %cmp2, label %for.body3, label %for.cond\n\nfor.body3: ; preds = %for.cond1\n %scmp = call i32 @llvm.scmp.i32.i32(i32 %for.ind, i32 1)\n store i32 %scmp, ptr %p, align 4\n %inc = add nuw nsw i32 %for.ind2, 1\n br label %for.cond1\n\nfor.end6: ; preds = %for.cond\n ret void\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.scmp.i32.i32(i32, i32) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"
|
|
|
40 |
}
|
41 |
]
|
42 |
}
|
|
|
36 |
"tests": [
|
37 |
{
|
38 |
"test_name": "pr105785",
|
39 |
+
"test_body": "define void @pr105785(ptr %p) {\nentry:\n br label %for.cond\n\nfor.cond: ; preds = %for.cond1, %entry\n %for.ind = phi i32 [ 0, %entry ], [ 1, %for.cond1 ]\n %cmp = icmp eq i32 %for.ind, 0\n br i1 %cmp, label %for.cond1, label %for.end6\n\nfor.cond1: ; preds = %for.body3, %for.cond\n %for.ind2 = phi i32 [ %inc, %for.body3 ], [ 0, %for.cond ]\n %cmp2 = icmp ult i32 %for.ind2, 3\n br i1 %cmp2, label %for.body3, label %for.cond\n\nfor.body3: ; preds = %for.cond1\n %scmp = call i32 @llvm.scmp.i32.i32(i32 %for.ind, i32 1)\n store i32 %scmp, ptr %p, align 4\n %inc = add nuw nsw i32 %for.ind2, 1\n br label %for.cond1\n\nfor.end6: ; preds = %for.cond\n ret void\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.scmp.i32.i32(i32, i32) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n",
|
40 |
+
"additional_args": "-src-unroll=4 -tgt-unroll=4"
|
41 |
}
|
42 |
]
|
43 |
}
|
scripts/llvm_helper.py
CHANGED
@@ -19,7 +19,7 @@ import re
|
|
19 |
import tempfile
|
20 |
|
21 |
# NOTE: llvm-lit requires psutil
|
22 |
-
import psutil
|
23 |
|
24 |
llvm_dir = os.environ["LAB_LLVM_DIR"]
|
25 |
llvm_build_dir = os.environ["LAB_LLVM_BUILD_DIR"]
|
@@ -190,7 +190,7 @@ def alive2_check(src: str, tgt: str, additional_args: str):
|
|
190 |
src_file.name,
|
191 |
tgt_file.name,
|
192 |
]
|
193 |
-
if additional_args
|
194 |
args += additional_args.strip().split(" ")
|
195 |
|
196 |
out = subprocess.check_output(args, stderr=subprocess.STDOUT).decode()
|
@@ -284,7 +284,7 @@ def verify_dispatch(
|
|
284 |
new_input = copy_triple(input, output)
|
285 |
new_input = copy_datalayout(new_input, output)
|
286 |
res, log = alive2_check(new_input, output.decode(), additional_args)
|
287 |
-
if repro
|
288 |
res = not res
|
289 |
if isinstance(log, str):
|
290 |
log = decode_output(out.stderr) + "\n" + log
|
|
|
19 |
import tempfile
|
20 |
|
21 |
# NOTE: llvm-lit requires psutil
|
22 |
+
import psutil # noqa: F401
|
23 |
|
24 |
llvm_dir = os.environ["LAB_LLVM_DIR"]
|
25 |
llvm_build_dir = os.environ["LAB_LLVM_BUILD_DIR"]
|
|
|
190 |
src_file.name,
|
191 |
tgt_file.name,
|
192 |
]
|
193 |
+
if additional_args is not None:
|
194 |
args += additional_args.strip().split(" ")
|
195 |
|
196 |
out = subprocess.check_output(args, stderr=subprocess.STDOUT).decode()
|
|
|
284 |
new_input = copy_triple(input, output)
|
285 |
new_input = copy_datalayout(new_input, output)
|
286 |
res, log = alive2_check(new_input, output.decode(), additional_args)
|
287 |
+
if repro:
|
288 |
res = not res
|
289 |
if isinstance(log, str):
|
290 |
log = decode_output(out.stderr) + "\n" + log
|