diff --git "a/dataset.jsonl" "b/dataset.jsonl" --- "a/dataset.jsonl" +++ "b/dataset.jsonl" @@ -1,4 +1,5 @@ {"bug_id": "128770", "issue_url": "https://github.com/llvm/llvm-project/issues/128770", "bug_type": "crash", "base_commit": "7f482aa848c5f136d2b32431f91f88492c78c709", "knowledge_cutoff": "2025-02-25T20:34:44Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "418a9872851ef5342b29baa36dd672129f129953", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[13353, 13358], [13453, 13459]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["BoUpSLP::isGatherShuffledSingleRegisterEntry"]}}, "patch": "commit 418a9872851ef5342b29baa36dd672129f129953\nAuthor: Alexey Bataev \nDate: Wed Feb 26 12:59:27 2025 -0800\n\n [SLP]Do not use node, if it is a subvector or buildvector node\n \n If the buildvector has some matches with another node, which is\n a subvector of another buildvector node, need to check for this and\n cancel matching to avoid incorrect ordering of the nodes.\n \n Fixes #128770\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex 02fea2eaf9d4..b25b09306aca 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -13353,6 +13353,14 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry(\n return EdgeInfo(const_cast(TE), 0);\n return TE->UserTreeIndex;\n };\n+ auto HasGatherUser = [&](const TreeEntry *TE) {\n+ while (TE->Idx != 0 && TE->UserTreeIndex) {\n+ if (TE->UserTreeIndex.EdgeIdx == UINT_MAX)\n+ return true;\n+ TE = TE->UserTreeIndex.UserTE;\n+ }\n+ return false;\n+ };\n const EdgeInfo TEUseEI = GetUserEntry(TE);\n if (!TEUseEI)\n return std::nullopt;\n@@ -13453,7 +13461,8 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry(\n // If the user instruction is used for some reason in different\n // vectorized nodes - make it depend on index.\n if (TEUseEI.UserTE != UseEI.UserTE &&\n- TEUseEI.UserTE->Idx < UseEI.UserTE->Idx)\n+ (TEUseEI.UserTE->Idx < UseEI.UserTE->Idx ||\n+ HasGatherUser(TEUseEI.UserTE)))\n continue;\n }\n \n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/X86/buildvector-reused-with-bv-subvector.ll", "commands": ["opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -mcpu=skylake < %s"], "tests": [{"test_name": "", "test_body": "\ndefine void @test(ptr %0, i64 %1, i64 %2) {\n;\n %4 = ptrtoint ptr %0 to i64\n %5 = ptrtoint ptr %0 to i64\n %6 = ptrtoint ptr %0 to i64\n %7 = ptrtoint ptr %0 to i64\n %8 = ptrtoint ptr %0 to i64\n br label %.preheader.lr.ph\n\n.preheader.lr.ph:\n br label %.preheader.us.us.preheader\n\n.preheader.us.us.preheader:\n %9 = or i64 %1, %7\n %10 = or i64 %2, %7\n %11 = or i64 %1, %4\n %12 = or i64 %1, %8\n %13 = or i64 %5, %8\n %14 = or i64 %8, %4\n %15 = or i64 %5, %6\n %16 = or i64 %6, %4\n br label %.preheader.us.us\n\n.preheader.us.us:\n %diff.check1 = icmp ult i64 %9, 32\n %diff.check2 = icmp ult i64 %10, 32\n %conflict.rdx3 = or i1 %diff.check1, %diff.check2\n %diff.check4 = icmp ult i64 %11, 32\n %conflict.rdx5 = or i1 %conflict.rdx3, %diff.check4\n %diff.check6 = icmp ult i64 %12, 32\n %conflict.rdx7 = or i1 %conflict.rdx5, %diff.check6\n %diff.check8 = icmp ult i64 %13, 32\n %conflict.rdx9 = or i1 %conflict.rdx7, %diff.check8\n %diff.check10 = icmp ult i64 %14, 32\n %conflict.rdx11 = or i1 %conflict.rdx9, %diff.check10\n %diff.check12 = icmp ult i64 %15, 32\n %conflict.rdx13 = or i1 %conflict.rdx11, %diff.check12\n %diff.check14 = icmp ult i64 %16, 32\n %conflict.rdx15 = or i1 %conflict.rdx13, %diff.check14\n br i1 %conflict.rdx15, label %scalar.ph, label %.preheader.us.us\n\nscalar.ph:\n ret void\n}"}]}], "issue": {"title": "SLP: Instruction does not dominate all uses (insertelement/shufflevector)", "body": "[slp.ll.gz](https://github.com/user-attachments/files/18972113/slp.ll.gz)\n\nReproducer: `opt -passes=slp-vectorizer slp.ll -mcpu=skylake`\n\n@alexey-bataev can you please take a look?", "author": "vzakhari", "labels": ["llvm:SLPVectorizer", "crash"], "comments": []}, "verified": true} +{"bug_id": "127739", "issue_url": "https://github.com/llvm/llvm-project/issues/127739", "bug_type": "crash", "base_commit": "d6301b218c6698ceb0db1753c8de480d37d11cf8", "knowledge_cutoff": "2025-02-19T03:17:57Z", "lit_test_dir": ["llvm/test/Transforms/Scalarizer"], "hints": {"fix_commit": "1440f02259abf585f0c2965bd4ececf0f3499405", "components": ["Scalarizer"], "bug_location_lineno": {"llvm/lib/Transforms/Scalar/Scalarizer.cpp": [[719, 731], [1083, 1088]]}, "bug_location_funcname": {"llvm/lib/Transforms/Scalar/Scalarizer.cpp": ["ScalarizerVisitor::splitCall", "ScalarizerVisitor::visitExtractValueInst"]}}, "patch": "commit 1440f02259abf585f0c2965bd4ececf0f3499405\nAuthor: Deric C. \nDate: Tue Mar 4 13:10:31 2025 -0800\n\n [Scalarizer] Ensure valid VectorSplits for each struct element in `visitExtractValueInst` (#128538)\n \n Fixes #127739\n \n The `visitExtractValueInst` is missing a check that was present in\n `splitCall` / `visitCallInst`.\n This check ensures that each struct element has a VectorSplit, and that\n each VectorSplit contains the same number of elements packed per\n fragment.\n \n ---------\n \n Co-authored-by: Jay Foad \n\ndiff --git a/llvm/lib/Transforms/Scalar/Scalarizer.cpp b/llvm/lib/Transforms/Scalar/Scalarizer.cpp\nindex 2b27150112ad..820c8e12d244 100644\n--- a/llvm/lib/Transforms/Scalar/Scalarizer.cpp\n+++ b/llvm/lib/Transforms/Scalar/Scalarizer.cpp\n@@ -719,13 +719,12 @@ bool ScalarizerVisitor::splitCall(CallInst &CI) {\n for (unsigned I = 1; I < CallType->getNumContainedTypes(); I++) {\n std::optional CurrVS =\n getVectorSplit(cast(CallType->getContainedType(I)));\n- // This case does not seem to happen, but it is possible for\n- // VectorSplit.NumPacked >= NumElems. If that happens a VectorSplit\n- // is not returned and we will bailout of handling this call.\n- // The secondary bailout case is if NumPacked does not match.\n- // This can happen if ScalarizeMinBits is not set to the default.\n- // This means with certain ScalarizeMinBits intrinsics like frexp\n- // will only scalarize when the struct elements have the same bitness.\n+ // It is possible for VectorSplit.NumPacked >= NumElems. If that happens a\n+ // VectorSplit is not returned and we will bailout of handling this call.\n+ // The secondary bailout case is if NumPacked does not match. This can\n+ // happen if ScalarizeMinBits is not set to the default. This means with\n+ // certain ScalarizeMinBits intrinsics like frexp will only scalarize when\n+ // the struct elements have the same bitness.\n if (!CurrVS || CurrVS->NumPacked != VS->NumPacked)\n return false;\n if (isVectorIntrinsicWithStructReturnOverloadAtField(ID, I, TTI))\n@@ -1083,6 +1082,18 @@ bool ScalarizerVisitor::visitExtractValueInst(ExtractValueInst &EVI) {\n std::optional VS = getVectorSplit(VecType);\n if (!VS)\n return false;\n+ for (unsigned I = 1; I < OpTy->getNumContainedTypes(); I++) {\n+ std::optional CurrVS =\n+ getVectorSplit(cast(OpTy->getContainedType(I)));\n+ // It is possible for VectorSplit.NumPacked >= NumElems. If that happens a\n+ // VectorSplit is not returned and we will bailout of handling this call.\n+ // The secondary bailout case is if NumPacked does not match. This can\n+ // happen if ScalarizeMinBits is not set to the default. This means with\n+ // certain ScalarizeMinBits intrinsics like frexp will only scalarize when\n+ // the struct elements have the same bitness.\n+ if (!CurrVS || CurrVS->NumPacked != VS->NumPacked)\n+ return false;\n+ }\n IRBuilder<> Builder(&EVI);\n Scatterer Op0 = scatter(&EVI, Op, *VS);\n assert(!EVI.getIndices().empty() && \"Make sure an index exists\");\n", "tests": [{"file": "llvm/test/Transforms/Scalarizer/min-bits.ll", "commands": ["opt %s -passes='function(scalarizer,dce)' -S", "opt %s -passes='function(scalarizer,dce)' -S", "opt %s -passes='function(scalarizer,dce)' -S"], "tests": [{"test_name": "load_add_store_v2i16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @load_add_store_v2i16(ptr %pa, ptr %pb) {\n %a = load <2 x i16>, ptr %pa, align 8\n %b = load <2 x i16>, ptr %pb, align 8\n %c = add <2 x i16> %a, %b\n store <2 x i16> %c, ptr %pa, align 8\n ret void\n}\n"}, {"test_name": "select_uniform_condition_v3f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <3 x half> @select_uniform_condition_v3f16(<3 x half> %a, <3 x half> %b, i1 %cc) {\n %r = select i1 %cc, <3 x half> %a, <3 x half> %b\n ret <3 x half> %r\n}\n"}, {"test_name": "call_v4f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <4 x half> @call_v4f16(<4 x half> %a, <4 x half> %b) {\n %r = call <4 x half> @llvm.minnum.v4f16(<4 x half> %a, <4 x half> %b)\n ret <4 x half> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x half> @llvm.minnum.v4f16(<4 x half>, <4 x half>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "unary_v4f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <4 x half> @unary_v4f16(<4 x half> %a) {\n %r = fneg <4 x half> %a\n ret <4 x half> %r\n}\n"}, {"test_name": "gep1_v4", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <4 x ptr> @gep1_v4(ptr %base, <4 x i16> %a) {\n %p = getelementptr i32, ptr %base, <4 x i16> %a\n ret <4 x ptr> %p\n}\n"}, {"test_name": "fptosi_v3f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <3 x i16> @fptosi_v3f16(<3 x half> %a) {\n %r = fptosi <3 x half> %a to <3 x i16>\n ret <3 x i16> %r\n}\n"}, {"test_name": "binary_v2f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <2 x half> @binary_v2f16(<2 x half> %a, <2 x half> %b) {\n %r = fadd <2 x half> %a, %b\n ret <2 x half> %r\n}\n"}, {"test_name": "gep3_v4", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <4 x ptr> @gep3_v4(<4 x ptr> %base, <4 x i16> %a) {\n %p = getelementptr i32, <4 x ptr> %base, <4 x i16> %a\n ret <4 x ptr> %p\n}\n"}, {"test_name": "fptosi_v4f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <4 x i16> @fptosi_v4f16(<4 x half> %a) {\n %r = fptosi <4 x half> %a to <4 x i16>\n ret <4 x i16> %r\n}\n"}, {"test_name": "binary_v3f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <3 x half> @binary_v3f16(<3 x half> %a, <3 x half> %b) {\n %r = fadd <3 x half> %a, %b\n ret <3 x half> %r\n}\n"}, {"test_name": "load_add_store_v4i16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @load_add_store_v4i16(ptr %pa, ptr %pb) {\n %a = load <4 x i16>, ptr %pa, align 8\n %b = load <4 x i16>, ptr %pb, align 8\n %c = add <4 x i16> %a, %b\n store <4 x i16> %c, ptr %pa, align 8\n ret void\n}\n"}, {"test_name": "select_uniform_condition_v2f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <2 x half> @select_uniform_condition_v2f16(<2 x half> %a, <2 x half> %b, i1 %cc) {\n %r = select i1 %cc, <2 x half> %a, <2 x half> %b\n ret <2 x half> %r\n}\n"}, {"test_name": "shufflevector_shrink", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @shufflevector_shrink(ptr %pa) {\n %a = load <4 x i16>, ptr %pa, align 8\n %r = shufflevector <4 x i16> %a, <4 x i16> poison, <2 x i32> \n store <2 x i16> %r, ptr %pa, align 4\n ret void\n}\n"}, {"test_name": "phi_v2f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @phi_v2f16(ptr %base, i64 %bound) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %x = phi <2 x half> [ zeroinitializer, %entry ], [ %x.next, %loop ]\n %idx = phi i64 [ 0, %entry ], [ %idx.next, %loop ]\n %p = getelementptr <2 x half>, ptr %base, i64 %idx\n %a = load <2 x half>, ptr %p, align 2\n %x.next = fadd <2 x half> %x, %a\n %idx.next = add i64 %idx, 1\n %cc = icmp ult i64 %idx.next, %bound\n br i1 %cc, label %loop, label %end\n\nend: ; preds = %loop\n store <2 x half> %x.next, ptr %base, align 4\n ret void\n}\n"}, {"test_name": "frexp_v2f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine noundef <2 x half> @frexp_v2f16(<2 x half> noundef %h) {\n %r = call { <2 x half>, <2 x i32> } @llvm.frexp.v2f16.v2i32(<2 x half> %h)\n %e0 = extractvalue { <2 x half>, <2 x i32> } %r, 0\n ret <2 x half> %e0\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare { <2 x half>, <2 x i32> } @llvm.frexp.v2f16.v2i32(<2 x half>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "load_insertelement_v3i16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <3 x i16> @load_insertelement_v3i16(ptr %pa, i16 %b) {\n %a = load <3 x i16>, ptr %pa, align 8\n %r = insertelement <3 x i16> %a, i16 %b, i64 2\n ret <3 x i16> %r\n}\n"}, {"test_name": "load_add_store_v3i16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @load_add_store_v3i16(ptr %pa, ptr %pb) {\n %a = load <3 x i16>, ptr %pa, align 8\n %b = load <3 x i16>, ptr %pb, align 8\n %c = add <3 x i16> %a, %b\n store <3 x i16> %c, ptr %pa, align 8\n ret void\n}\n"}, {"test_name": "fptosi_v2f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <2 x i16> @fptosi_v2f16(<2 x half> %a) {\n %r = fptosi <2 x half> %a to <2 x i16>\n ret <2 x i16> %r\n}\n"}, {"test_name": "insertelement_v4i16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @insertelement_v4i16(ptr %p, <4 x i16> %a, i16 %b) {\n %r = insertelement <4 x i16> %a, i16 %b, i64 3\n store <4 x i16> %r, ptr %p, align 8\n ret void\n}\n"}, {"test_name": "load_insertelement_v2i16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <2 x i16> @load_insertelement_v2i16(ptr %pa, i16 %b) {\n %a = load <2 x i16>, ptr %pa, align 4\n %r = insertelement <2 x i16> %a, i16 %b, i64 1\n ret <2 x i16> %r\n}\n"}, {"test_name": "load_insertelement_v4i16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <4 x i16> @load_insertelement_v4i16(ptr %pa, i16 %b) {\n %a = load <4 x i16>, ptr %pa, align 8\n %r = insertelement <4 x i16> %a, i16 %b, i64 3\n ret <4 x i16> %r\n}\n"}, {"test_name": "insertelement_v2i16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @insertelement_v2i16(ptr %p, <2 x i16> %a, i16 %b) {\n %r = insertelement <2 x i16> %a, i16 %b, i64 1\n store <2 x i16> %r, ptr %p, align 4\n ret void\n}\n"}, {"test_name": "shufflevector_grow", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @shufflevector_grow(ptr %pa, ptr %pb) {\n %a = load <2 x i16>, ptr %pa, align 4\n %b = load <2 x i16>, ptr %pb, align 4\n %r = shufflevector <2 x i16> %a, <2 x i16> %b, <4 x i32> \n store <4 x i16> %r, ptr %pa, align 8\n ret void\n}\n"}, {"test_name": "uadd_with_overflow_v3i32", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <3 x i32> @uadd_with_overflow_v3i32(<3 x i32> %a, <3 x i32> %b) {\n %t = call { <3 x i32>, <3 x i1> } @llvm.uadd.with.overflow.v3i32(<3 x i32> %a, <3 x i32> %b)\n %r = extractvalue { <3 x i32>, <3 x i1> } %t, 0\n ret <3 x i32> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare { <3 x i32>, <3 x i1> } @llvm.uadd.with.overflow.v3i32(<3 x i32>, <3 x i32>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "insertelement_v3i16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @insertelement_v3i16(ptr %p, <3 x i16> %a, i16 %b) {\n %r = insertelement <3 x i16> %a, i16 %b, i64 2\n store <3 x i16> %r, ptr %p, align 8\n ret void\n}\n"}, {"test_name": "call_v2f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <2 x half> @call_v2f16(<2 x half> %a, <2 x half> %b) {\n %r = call <2 x half> @llvm.minnum.v2f16(<2 x half> %a, <2 x half> %b)\n ret <2 x half> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <2 x half> @llvm.minnum.v2f16(<2 x half>, <2 x half>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "phi_v3f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @phi_v3f16(ptr %base, i64 %bound) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %x = phi <3 x half> [ zeroinitializer, %entry ], [ %x.next, %loop ]\n %idx = phi i64 [ 0, %entry ], [ %idx.next, %loop ]\n %p = getelementptr <3 x half>, ptr %base, i64 %idx\n %a = load <3 x half>, ptr %p, align 2\n %x.next = fadd <3 x half> %x, %a\n %idx.next = add i64 %idx, 1\n %cc = icmp ult i64 %idx.next, %bound\n br i1 %cc, label %loop, label %end\n\nend: ; preds = %loop\n store <3 x half> %x.next, ptr %base, align 8\n ret void\n}\n"}, {"test_name": "phi_v4f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @phi_v4f16(ptr %base, i64 %bound) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %x = phi <4 x half> [ zeroinitializer, %entry ], [ %x.next, %loop ]\n %idx = phi i64 [ 0, %entry ], [ %idx.next, %loop ]\n %p = getelementptr <4 x half>, ptr %base, i64 %idx\n %a = load <4 x half>, ptr %p, align 2\n %x.next = fadd <4 x half> %x, %a\n %idx.next = add i64 %idx, 1\n %cc = icmp ult i64 %idx.next, %bound\n br i1 %cc, label %loop, label %end\n\nend: ; preds = %loop\n store <4 x half> %x.next, ptr %base, align 8\n ret void\n}\n"}, {"test_name": "call_v3f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <3 x half> @call_v3f16(<3 x half> %a, <3 x half> %b) {\n %r = call <3 x half> @llvm.minnum.v3f16(<3 x half> %a, <3 x half> %b)\n ret <3 x half> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <3 x half> @llvm.minnum.v3f16(<3 x half>, <3 x half>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "binary_v4f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <4 x half> @binary_v4f16(<4 x half> %a, <4 x half> %b) {\n %r = fadd <4 x half> %a, %b\n ret <4 x half> %r\n}\n"}, {"test_name": "fpext_v4f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <4 x float> @fpext_v4f16(<4 x half> %a) {\n %r = fpext <4 x half> %a to <4 x float>\n ret <4 x float> %r\n}\n"}, {"test_name": "load_add_store_v4i10", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @load_add_store_v4i10(ptr %pa, ptr %pb) {\n %a = load <4 x i10>, ptr %pa, align 8\n %b = load <4 x i10>, ptr %pb, align 8\n %c = add <4 x i10> %a, %b\n store <4 x i10> %c, ptr %pa, align 8\n ret void\n}\n"}, {"test_name": "unary_v3f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <3 x half> @unary_v3f16(<3 x half> %a) {\n %r = fneg <3 x half> %a\n ret <3 x half> %r\n}\n"}, {"test_name": "unary_v2f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <2 x half> @unary_v2f16(<2 x half> %a) {\n %r = fneg <2 x half> %a\n ret <2 x half> %r\n}\n"}, {"test_name": "select_uniform_condition_v4f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <4 x half> @select_uniform_condition_v4f16(<4 x half> %a, <4 x half> %b, i1 %cc) {\n %r = select i1 %cc, <4 x half> %a, <4 x half> %b\n ret <4 x half> %r\n}\n"}]}], "issue": {"title": "[Scalarizer] Test *_with_overflow crash with min-bits=32 and min-bits=16", "body": "first reported here: https://github.com/llvm/llvm-project/pull/127520\nintroduced by: https://github.com/llvm/llvm-project/pull/126815\n\n```llvm\n; RUN: opt %s -passes='function(scalarizer,dce)' -S | FileCheck %s --check-prefixes=CHECK,MIN16\n; RUN: opt %s -passes='function(scalarizer,dce)' -S | FileCheck %s --check-prefixes=CHECK,MIN32\n\ndefine <3 x i32> @call_v3i32(<3 x i32> %a, <3 x i32> %b) {\n; CHECK-LABEL: @call_v3i32(\n; CHECK-NEXT: [[T:%.*]] = call { <3 x i32>, <3 x i1> } @llvm.uadd.with.overflow.v3i32(<3 x i32> [[A:%.*]], <3 x i32> [[B:%.*]])\n; CHECK-NEXT: [[R:%.*]] = extractvalue { <3 x i32>, <3 x i1> } [[T]], 0\n; CHECK-NEXT: ret <3 x i32> [[R]]\n;\n %t = call { <3 x i32>, <3 x i1> } @llvm.uadd.with.overflow.v3i32(<3 x i32> %a, <3 x i32> %b)\n %r = extractvalue { <3 x i32>, <3 x i1> } %t, 0\n ret <3 x i32> %r\n}\n\n```\n\n```bash\nopt: include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From *) [To = llvm::VectorType, From = llvm::Type]: Assertion `isa(Val) && \"cast() argument of incompatible type!\"' 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 -passes=function(scalarizer,dce) -S\n1.\tRunning pass \"function(scalarizer,dce)\" on module \"\"\n2.\tRunning pass \"scalarizer\" on function \"call_v3i32\"\n #0 0x0000000004028908 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (opt+0x4028908)\n #1 0x000000000402643e llvm::sys::RunSignalHandlers() (opt+0x402643e)\n #2 0x0000000004029131 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #3 0x000075c457a45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)\n #4 0x000075c457a9eb2c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\n #5 0x000075c457a9eb2c __pthread_kill_internal ./nptl/pthread_kill.c:78:10\n #6 0x000075c457a9eb2c pthread_kill ./nptl/pthread_kill.c:89:10\n #7 0x000075c457a4527e raise ./signal/../sysdeps/posix/raise.c:27:6\n #8 0x000075c457a288ff abort ./stdlib/abort.c:81:7\n #9 0x000075c457a2881b _nl_load_domain ./intl/loadmsgcat.c:1177:9\n#10 0x000075c457a3b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)\n#11 0x0000000004143bea (opt+0x4143bea)\n#12 0x00000000049addf4 (anonymous namespace)::Scatterer::operator[](unsigned int) Scalarizer.cpp:0:0\n#13 0x00000000049aa142 (anonymous namespace)::ScalarizerVisitor::visit(llvm::Function&) Scalarizer.cpp:0:0\n#14 0x00000000049a5419 llvm::ScalarizerPass::run(llvm::Function&, llvm::AnalysisManager&) (opt+0x49a5419)\n```\n\nNo line numbers, Looks like we have some missing debug symbols I suspect the assert is coming from `ScalarizerVisitor::visitExtractValueInst`\n\nThere is a use of Scatterer::operator[] as part of creating the ExtractValue IR.\n\n```cpp\nfor (unsigned OpIdx = 0; OpIdx < Op0.size(); ++OpIdx) {\n Value *ResElem = Builder.CreateExtractValue(\n Op0[OpIdx], Index, EVI.getName() + \".elem\" + Twine(Index));\n Res.push_back(ResElem);\n }\n```\n\nWe likely need to check `VS.NumPacked` before calling `Scatterer::operator[]`\n\nBecause that operator is using `Frag * VS.NumPacked` to create the exrtractElement instruction.\n\n```cpp\n CV[Frag] = Builder.CreateExtractElement(V, Frag * VS.NumPacked,\n V->getName() + \".i\" + Twine(Frag))\n```\n\n ", "author": "farzonl", "labels": ["crash-on-valid", "llvm:analysis"], "comments": [{"author": "farzonl", "body": "@Icohedron can you look into this issue. I'm also noticing a second potential issue:\n\n`call { <3 x i32>, <3 x i1> }`\n\nThe struct return elements are not the same type. one is vec3 of i32 one is and one is vec3 of i1. you need to add the `*_with_overflow` intrinsics to `isVectorIntrinsicWithStructReturnOverloadAtField` if these types are not the same."}, {"author": "Icohedron", "body": "I'm on it"}, {"author": "jayfoad", "body": "As mentioned in #127996, note that you can also provoke this bug by adding `min-bits=64` to `test/Transforms/Scalarizer/frexp.ll`."}, {"author": "Icohedron", "body": "> [@Icohedron](https://github.com/Icohedron) can you look into this issue. I'm also noticing a second potential issue:\n> \n> `call { <3 x i32>, <3 x i1> }`\n> \n> The struct return elements are not the same type. one is vec3 of i32 one is and one is vec3 of i1. you need to add the `*_with_overflow` intrinsics to `isVectorIntrinsicWithStructReturnOverloadAtField` if these types are not the same.\n\n`isVectorIntrinsicWithStructReturnOverloadAtField` appears to only be for intrinsic name-mangling when there is more than one possible type for the the 2nd element in the struct return type (see [splitCall](https://github.com/llvm/llvm-project/blob/5f8da7e7738f043dbde447e48622e9b2afb5ba92/llvm/lib/Transforms/Scalar/Scalarizer.cpp#L770) and [getOrInsertDeclaration](https://github.com/llvm/llvm-project/blob/5f8da7e7738f043dbde447e48622e9b2afb5ba92/llvm/lib/IR/Intrinsics.cpp#L763)). For the `*_with_overflow` intrinsics, the 2nd element of the return struct is always i1, so it does not need to be added to `isVectorIntrinsicWithStructReturnOverloadAtField`.\n\nAdding the `*_with_overflow` intrinsic to `isVectorIntrinsicWithStructReturnOverloadAtField` results in a broken LLVM module.\n```\nIntrinsic name not mangled correctly for type arguments! Should be: llvm.uadd.with.overflow.i32\nptr @llvm.uadd.with.overflow.i32.i1\nLLVM ERROR: Broken module found, compilation aborted!\n```"}]}, "verified": true} {"bug_id": "126181", "issue_url": "https://github.com/llvm/llvm-project/issues/126181", "bug_type": "miscompilation", "base_commit": "317a644ae6d501f1a1ec54d17ea8559bcdea35c0", "knowledge_cutoff": "2025-02-07T05:51:32Z", "lit_test_dir": ["llvm/test/Transforms/DeadStoreElimination"], "hints": {"fix_commit": "2d31a12dbe2339d20844ede70cbb54dbaf4ceea9", "components": ["DeadStoreElimination"], "bug_location_lineno": {"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": [[2283, 2289]]}, "bug_location_funcname": {"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": ["DSEState::getInitializesArgMemLoc"]}}, "patch": "commit 2d31a12dbe2339d20844ede70cbb54dbaf4ceea9\nAuthor: Nikita Popov \nDate: Mon Feb 10 10:34:03 2025 +0100\n\n [DSE] Don't use initializes on byval argument (#126259)\n \n There are two ways we can fix this problem, depending on how the\n semantics of byval and initializes should interact:\n \n * Don't infer initializes on byval arguments. initializes on byval\n refers to the original caller memory (or having both attributes is made\n a verifier error).\n * Infer initializes on byval, but don't use it in DSE. initializes on\n byval refers to the callee copy. This matches the semantics of readonly\n on byval. This is slightly more powerful, for example, we could do a\n backend optimization where byval + initializes will allocate the full\n size of byval on the stack but not copy over the parts covered by\n initializes.\n \n I went with the second variant here, skipping byval + initializes in DSE\n (FunctionAttrs already doesn't propagate initializes past byval). I'm\n open to going in the other direction though.\n \n Fixes https://github.com/llvm/llvm-project/issues/126181.\n\ndiff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp\nindex 05b4f176bfc3..38454053b039 100644\n--- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp\n+++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp\n@@ -2283,7 +2283,9 @@ DSEState::getInitializesArgMemLoc(const Instruction *I) {\n for (unsigned Idx = 0, Count = CB->arg_size(); Idx < Count; ++Idx) {\n ConstantRangeList Inits;\n Attribute InitializesAttr = CB->getParamAttr(Idx, Attribute::Initializes);\n- if (InitializesAttr.isValid())\n+ // initializes on byval arguments refers to the callee copy, not the\n+ // original memory the caller passed in.\n+ if (InitializesAttr.isValid() && !CB->isByValArgument(Idx))\n Inits = InitializesAttr.getValueAsConstantRangeList();\n \n Value *CurArg = CB->getArgOperand(Idx);\n", "tests": [{"file": "llvm/test/Transforms/DeadStoreElimination/inter-procedural.ll", "commands": ["opt < %s -passes=dse -enable-dse-initializes-attr-improvement -S"], "tests": [{"test_name": "test_byval", "test_body": "%struct.a = type { i32, i64, i32, i32 }\n\n@e = dso_local global { i32, [4 x i8], i64, i32, i32 } { i32 5, [4 x i8] zeroinitializer, i64 0, i32 1, i32 90986701 }, align 8\n\ndefine i8 @ad(ptr byval(%struct.a) %ah) {\nentry:\n store i32 0, ptr %ah, align 8\n %call = call i64 @af(ptr %ah)\n %0 = load i8, ptr %ah, align 1\n ret i8 %0\n}\n\ndefine i64 @af(ptr byval(%struct.a) initializes((0, 24)) %am) {\nentry:\n call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %am, ptr noundef nonnull align 8 dereferenceable(24) @e, i64 24, i1 false)\n ret i64 0\n}\n\ndefine i32 @main() {\n %res = call i8 @ad(ptr @e)\n %val = sext i8 %res to i32\n ret i32 %val\n}\n", "lli_expected_out": ""}]}], "issue": {"title": "[FuncAttrs] `initializes` is incorrectly set on parameters with `byval`", "body": "Reproducer: https://godbolt.org/z/Mcx1nY4E7\n```\n; bin/opt -passes=function-attrs reduced.ll -S\n%struct.a = type { i32, i64, i32, i32 }\n\n@e = dso_local global { i32, [4 x i8], i64, i32, i32 } { i32 5, [4 x i8] zeroinitializer, i64 0, i32 1, i32 90986701 }, align 8\n\ndefine i8 @ad(ptr byval(%struct.a) %ah) {\nentry:\n store i32 0, ptr %ah, align 8\n %call = call i64 @af(ptr %ah)\n %0 = load i8, ptr %ah, align 1\n ret i8 %0\n}\n\ndefine i64 @af(ptr byval(%struct.a) %am) {\nentry:\n call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %am, ptr noundef nonnull align 8 dereferenceable(24) @e, i64 24, i1 false)\n ret i64 0\n}\n\n```\n```\ndefine i8 @ad(ptr byval(%struct.a) captures(none) initializes((0, 4)) %ah) #0 {\n store i32 0, ptr %ah, align 8\n %call = call i64 @af(ptr %ah)\n %0 = load i8, ptr %ah, align 1\n ret i8 %0\n}\n\ndefine noundef i64 @af(ptr writeonly byval(%struct.a) captures(none) initializes((0, 24)) %am) #0 {\n call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %am, ptr noundef nonnull align 8 dereferenceable(24) @e, i64 24, i1 false)\n ret i64 0\n}\n```\nAfter DSE:\n```\ndefine i8 @ad(ptr byval(%struct.a) captures(none) initializes((0, 4)) %ah) #0 {\n %call = call i64 @af(ptr %ah)\n %0 = load i8, ptr %ah, align 1\n ret i8 %0\n}\n\ndefine noundef i64 @af(ptr writeonly byval(%struct.a) captures(none) initializes((0, 24)) %am) #0 {\n ret i64 0\n}\n```\n\nllvm version: d21fc58aeeaa7f0369a24dbe70a0360e0edbf76f\n", "author": "dtcxzyw", "labels": ["miscompilation", "llvm:transforms"], "comments": [{"author": "nikic", "body": "> We should also emit the padding for %struct.a.\n\nWithout commenting on whether we should or shouldn't, why is not having the padding a miscompile? As this is not a packed struct, for a i64:64 target, LLVM will implicitly insert the padding and it should have the correct size."}, {"author": "dtcxzyw", "body": "> As this is not a packed struct, for a i64:64 target, LLVM will implicitly insert the padding and it should have the correct size.\n\nSorry. It is a DSE bug.\n"}, {"author": "dtcxzyw", "body": "cc @haopliu "}, {"author": "nikic", "body": "@dtcxzyw I think your new IR is over-reduced. You have `initializes((0, 24)` on `@af`, so I think eliminating the store is correct."}, {"author": "dtcxzyw", "body": "> [@dtcxzyw](https://github.com/dtcxzyw) I think your new IR is over-reduced. You have `initializes((0, 24)` on `@af`, so I think eliminating the store is correct.\n\nFixed."}, {"author": "nikic", "body": "There are two ways we can fix this, depending on what we want the semantics to do:\n\n 1. Don't infer initializes on byval arguments. initializes on byval refers to the original caller memory (or having both attributes is made a verifier error).\n 2. Infer initializes on byval, but don't use it in DSE. initializes on byval refers to the callee copy. This matches the semantics of readonly on byval.\n\nI think variant 2 is marginally more powerful. For example, we could do a backend optimization where byval + initializes will allocate the full size of byval on the stack but not copy over the parts covered by initializes."}]}, "verified": true} {"bug_id": "113143", "issue_url": "https://github.com/llvm/llvm-project/issues/113143", "bug_type": "crash", "base_commit": "42ba452aa94e4da277842d8990ad958a6256e558", "knowledge_cutoff": "2024-10-21T10:11:54Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "9e03920cbf946e7ba282e99213707643a23ae5fb", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[12466, 12472]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["BoUpSLP::isGatherShuffledSingleRegisterEntry"]}}, "patch": "commit 9e03920cbf946e7ba282e99213707643a23ae5fb\nAuthor: Alexey Bataev \nDate: Mon Oct 21 08:57:36 2024 -0700\n\n [SLP]Ignore root gather node, when searching for reuses\n \n Root gather/buildvector node should be ignored when SLP vectorizer tries\n to find matching gather nodes, vectorized earlier. This node is\n definitely the last one in the pipeline and it does not have users. It\n may cause the compiler crash\n \n Fixes #113143\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex 1098bf578d2d..a11e3f3815cb 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -12466,7 +12466,7 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry(\n // Build a list of tree entries where V is used.\n SmallPtrSet VToTEs;\n for (const TreeEntry *TEPtr : ValueToGatherNodes.find(V)->second) {\n- if (TEPtr == TE)\n+ if (TEPtr == TE || TEPtr->Idx == 0)\n continue;\n assert(any_of(TEPtr->Scalars,\n [&](Value *V) { return GatheredScalars.contains(V); }) &&\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/X86/root-gather-reused-scalar.ll", "commands": ["opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s"], "tests": [{"test_name": "test", "test_body": "define void @test(ptr %a, i32 %0, i32 %1, i1 %cmp1) {\nentry:\n %2 = load i32, ptr %a, align 4\n %tobool10.not = icmp eq i32 %0, 0\n %cmp4.3 = icmp ne i32 %1, 0\n %3 = and i1 %cmp4.3, %tobool10.not\n %cmp2.2 = xor i1 %tobool10.not, true\n %conv3.2 = zext i1 %cmp2.2 to i32\n %cmp4.2 = icmp ne i32 %2, %conv3.2\n %cmp2.1 = xor i1 %cmp1, true\n %conv3.1 = zext i1 %cmp2.1 to i32\n %cmp4.1 = icmp ne i32 %2, %conv3.1\n %4 = select i1 %3, i1 %cmp4.2, i1 false\n %5 = select i1 %4, i1 %cmp4.1, i1 false\n %and.3 = zext i1 %5 to i32\n store i32 %and.3, ptr %a, align 4\n ret void\n}\n"}]}], "issue": {"title": "clang crashes on valid code at -O2 on x86_64-linux-gnu: Assertion `TEPtr->UserTreeIndices.size() == 1 && \"Expected only single user of a gather node.\"' failed ", "body": "It appears to be a recent regression as it doesn't reproduce with 19.1.0 and earlier. \r\n\r\nCompiler Explorer: https://godbolt.org/z/a1W3c5ard\r\n\r\n```\r\n[523] % clangtk -v\r\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git df8b785838a2db01b4d056e603f7317209accefb)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /local/suz-local/software/local/clang-trunk/bin\r\nBuild config: +assertions\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9\r\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\r\nCandidate multilib: .;@m64\r\nSelected multilib: .;@m64\r\n[524] % \r\n[524] % clangtk -O2 small.c\r\nclang-20: /local/suz-local/software/clangbuild/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:12559: std::optional llvm::slpvectorizer::BoUpSLP::isGatherShuffledSingleRegisterEntry(const llvm::slpvectorizer::BoUpSLP::TreeEntry*, llvm::ArrayRef, llvm::MutableArrayRef, llvm::SmallVectorImpl&, unsigned int, bool): Assertion `TEPtr->UserTreeIndices.size() == 1 && \"Expected only single user of a gather node.\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.\r\nStack dump:\r\n0.\tProgram arguments: /local/suz-local/software/local/clang-trunk/bin/clang-20 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name small.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/local/suz-local/software/emitesting/bugs/20241020-clangtk-m64-O2-build-231331/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/20241020-clangtk-m64-O2-build-231331/delta -resource-dir /local/suz-local/software/local/clang-trunk/lib/clang/20 -I /usr/local/include -I /local/suz-local/software/local/include -internal-isystem /local/suz-local/software/local/clang-trunk/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/small-572b89.o -x c small.c\r\n1.\t parser at end of file\r\n2.\tOptimizer\r\n3.\tRunning pass \"function(float2int,lower-constant-intrinsics,loop(loop-rotate,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize,infer-alignment,loop-load-elim,instcombine,simplifycfg,slp-vectorizer,vector-combine,instcombine,loop-unroll,transform-warning,sroa,infer-alignment,instcombine,loop-mssa(licm),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg)\" on module \"small.c\"\r\n4.\tRunning pass \"slp-vectorizer\" on function \"main\"\r\n #0 0x0000560576c8b9af llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x43f29af)\r\n #1 0x0000560576c89184 SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007f4623c27420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\r\n #3 0x00007f462365e00b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\r\n #4 0x00007f462363d859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\r\n #5 0x00007f462363d729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\r\n #6 0x00007f462363d729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\r\n #7 0x00007f462364efd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\r\n #8 0x0000560578707edc llvm::slpvectorizer::BoUpSLP::isGatherShuffledSingleRegisterEntry(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef, llvm::MutableArrayRef, llvm::SmallVectorImpl&, unsigned int, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5e6eedc)\r\n #9 0x0000560578708cd8 llvm::slpvectorizer::BoUpSLP::isGatherShuffledEntry(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef, llvm::SmallVectorImpl&, llvm::SmallVectorImpl>&, unsigned int, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5e6fcd8)\r\n#10 0x000056057870a6f3 llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::processBuildVector, llvm::slpvectorizer::BoUpSLP, llvm::SmallPtrSetImpl>(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::Type*, llvm::TargetTransformInfo&, llvm::ArrayRef&, llvm::slpvectorizer::BoUpSLP&, llvm::SmallPtrSetImpl&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5e716f3)\r\n#11 0x000056057870cde7 llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef, llvm::SmallPtrSetImpl&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5e73de7)\r\n#12 0x0000560578745f69 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5eacf69)\r\n#13 0x000056057874b57b (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\r\n#14 0x000056057874eb79 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::SmallVectorImpl&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5eb5b79)\r\n#15 0x000056057875349b llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0\r\n#16 0x0000560578757d50 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5ebed50)\r\n#17 0x000056057875e590 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#18 0x000056057875f263 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5ec6263)\r\n#19 0x00005605781e0e66 llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5947e66)\r\n#20 0x0000560576614891 llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x3d7b891)\r\n#21 0x000056057410e656 llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x1875656)\r\n#22 0x00005605766131fd llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x3d7a1fd)\r\n#23 0x000056057410d196 llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x1874196)\r\n#24 0x0000560576612c31 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x3d79c31)\r\n#25 0x0000560576f44dd3 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr>&, std::unique_ptr>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\r\n#26 0x0000560576f483a8 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr, std::unique_ptr>, clang::BackendConsumer*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x46af3a8)\r\n#27 0x000056057764462c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4dab62c)\r\n#28 0x000056057951629c clang::ParseAST(clang::Sema&, bool, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x6c7d29c)\r\n#29 0x0000560577644a48 clang::CodeGenAction::ExecuteAction() (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4daba48)\r\n#30 0x000056057790d3d9 clang::FrontendAction::Execute() (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x50743d9)\r\n#31 0x00005605778895ce clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4ff05ce)\r\n#32 0x00005605779f9f26 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5160f26)\r\n#33 0x0000560573cd1fe5 cc1_main(llvm::ArrayRef, char const*, void*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x1438fe5)\r\n#34 0x0000560573cc9afa ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&) driver.cpp:0:0\r\n#35 0x0000560573cce52e clang_main(int, char**, llvm::ToolContext const&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x143552e)\r\n#36 0x0000560573bba67b main (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x132167b)\r\n#37 0x00007f462363f083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\r\n#38 0x0000560573cc958e _start (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x143058e)\r\nclangtk: error: unable to execute command: Aborted\r\nclangtk: error: clang frontend command failed due to signal (use -v to see invocation)\r\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git df8b785838a2db01b4d056e603f7317209accefb)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /local/suz-local/software/local/clang-trunk/bin\r\nBuild config: +assertions\r\nclangtk: note: diagnostic msg: \r\n********************\r\n\r\nPLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:\r\nPreprocessed source(s) and associated run script(s) are located at:\r\nclangtk: note: diagnostic msg: /tmp/small-d99d4e.c\r\nclangtk: note: diagnostic msg: /tmp/small-d99d4e.sh\r\nclangtk: note: diagnostic msg: \r\n\r\n********************\r\n[525] % \r\n[525] % cat small.c\r\nint a, b, c, d, e, f;\r\nint main() {\r\n for (f = 0; f < 4; f++) {\r\n d &= (((a > 0) != b) != c) && b;\r\n for (b = 0; b < 1; b++)\r\n if (e)\r\n break;\r\n }\r\n return 0;\r\n}\r\n```\r\n\r\n", "author": "zhendongsu", "labels": ["llvm:SLPVectorizer", "crash-on-valid"], "comments": []}, "verified": true} {"bug_id": "114082", "issue_url": "https://github.com/llvm/llvm-project/issues/114082", "bug_type": "crash", "base_commit": "0f040433d325aa68ec6840aa179f3f314c26153a", "knowledge_cutoff": "2024-10-29T16:26:31Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "77bec78878762e34150fe23734fa43df796c873c", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[13398, 13404]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["BoUpSLP::getLastInstructionInBundle"]}}, "patch": "commit 77bec78878762e34150fe23734fa43df796c873c\nAuthor: Alexey Bataev \nDate: Fri Nov 8 04:16:01 2024 -0800\n\n [SLP]Do not look for last instruction in schedule block for buildvectors\n \n If looking for the insertion point for the node and the node is\n a buildvector node, the compiler should not use scheduling info for such\n nodes, they may contain only partial info, which is not fully correct\n and may cause compiler crash.\n \n Fixes #114082\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex b2f677fb84f9..c5b3537bc57b 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -13398,7 +13398,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {\n // scheduled, and the last instruction is VL.back(). So we start with\n // VL.back() and iterate over schedule data until we reach the end of the\n // bundle. The end of the bundle is marked by null ScheduleData.\n- if (BlocksSchedules.count(BB)) {\n+ if (BlocksSchedules.count(BB) && !E->isGather()) {\n Value *V = E->isOneOf(E->Scalars.back());\n if (doesNotNeedToBeScheduled(V))\n V = *find_if_not(E->Scalars, doesNotNeedToBeScheduled);\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/X86/buildvector-schedule-for-subvector.ll", "commands": ["opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -slp-threshold=-99999 < %s"], "tests": [{"test_name": "test", "test_body": "define void @test() {\nbb:\n %icmp = icmp samesign ult i32 0, 0\n %select = select i1 %icmp, i32 0, i32 0\n %zext = zext i32 %select to i64\n %getelementptr = getelementptr ptr addrspace(1), ptr addrspace(1) null, i64 %zext\n store ptr addrspace(1) null, ptr addrspace(1) %getelementptr, align 8\n %icmp1 = icmp eq i32 0, 0\n %icmp2 = icmp eq i32 0, 0\n %icmp3 = icmp samesign ult i32 0, 0\n %icmp4 = icmp eq i32 0, 0\n %add = add i32 1, 0\n %icmp5 = icmp samesign ult i32 %add, 0\n store volatile i32 0, ptr addrspace(1) null, align 4\n %call = call i32 null(<2 x double> zeroinitializer)\n %icmp6 = icmp eq i32 %call, 0\n %icmp7 = icmp samesign ult i32 0, 0\n ret void\n}\n"}]}], "issue": {"title": "[SLPVectorizer] Instruction does not dominate all uses! LLVM ERROR: Broken module found, compilation aborted!", "body": "To reproduce run opt with the test below with -passes=slp-vectorizer -slp-threshold=-99999\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() #0 gc \"statepoint-example\" {\r\nbb:\r\n %icmp = icmp samesign ult i32 0, 0\r\n %select = select i1 %icmp, i32 0, i32 0\r\n %zext = zext i32 %select to i64\r\n %getelementptr = getelementptr ptr addrspace(1), ptr addrspace(1) null, i64 %zext\r\n store ptr addrspace(1) null, ptr addrspace(1) %getelementptr, align 8\r\n %icmp1 = icmp eq i32 0, 0\r\n %icmp2 = icmp eq i32 0, 0\r\n %icmp3 = icmp samesign ult i32 0, 0\r\n %icmp4 = icmp eq i32 0, 0\r\n %add = add i32 1, 0\r\n %icmp5 = icmp samesign ult i32 %add, 0\r\n store volatile i32 0, ptr addrspace(1) null, align 4\r\n %call = call i32 @llvm.x86.sse2.cvttsd2si(<2 x double> zeroinitializer)\r\n %icmp6 = icmp eq i32 %call, 0\r\n %icmp7 = icmp samesign ult i32 0, 0\r\n ret void\r\n}\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)\r\ndeclare i32 @llvm.x86.sse2.cvttsd2si(<2 x double>) #1\r\n\r\nattributes #0 = { \"target-features\"=\"+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,-avx10.2-256,-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,-avx10.2-512,-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\nattributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) \"target-features\"=\"+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,-avx10.2-256,-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,-avx10.2-512,-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\nReproducer: https://godbolt.org/z/nTE84xq7n\r\n\r\nStack dump\r\n```\r\nInstruction does not dominate all uses!\r\n %5 = icmp eq <4 x i32> %4, zeroinitializer\r\n %2 = call <8 x i1> @llvm.vector.insert.v8i1.v4i1(<8 x i1> poison, <4 x i1> %5, i64 0)\r\nLLVM ERROR: Broken module found, compilation aborted!\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=slp-vectorizer -slp-threshold=-99999 \r\n1.\tRunning pass \"verify\" on module \"\"\r\n #0 0x00000000050e7a98 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x50e7a98)\r\n #1 0x00000000050e548c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x000078c8a0042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000078c8a00969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x000078c8a0042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x000078c8a00287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00000000007d7d7b llvm::json::operator==(llvm::json::Value const&, llvm::json::Value const&) (.cold) JSON.cpp:0:0\r\n #7 0x00000000050265b8 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x50265b8)\r\n #8 0x0000000004f24790 llvm::VerifierPass::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f24790)\r\n #9 0x00000000009015ce llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9015ce)\r\n#10 0x0000000004ee5440 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4ee5440)\r\n#11 0x000000000090c1ea llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::ArrayRef>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x90c1ea)\r\n#12 0x00000000008ff258 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ff258)\r\n#13 0x000078c8a0029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#14 0x000078c8a0029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#15 0x00000000008f6d2e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f6d2e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "TatyanaDoubts", "labels": ["llvm:SLPVectorizer", "crash-on-valid"], "comments": []}, "verified": true} @@ -45,6 +46,9 @@ {"bug_id": "112076", "issue_url": "https://github.com/llvm/llvm-project/issues/112076", "bug_type": "miscompilation", "base_commit": "8c56dd3040f295874e3d5742b5dfc109adf1f728", "knowledge_cutoff": "2024-10-12T03:31:00Z", "lit_test_dir": ["llvm/test/Transforms/InstCombine"], "hints": {"fix_commit": "2c094ac761912eea0d7e8ccb140bc647b5378bdf", "components": ["InstCombine"], "bug_location_lineno": {"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [[3466, 3472], [3501, 3506], [4148, 4154]]}, "bug_location_funcname": {"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": ["InstCombinerImpl::visitSelectInst", "foldBitCeil"]}}, "patch": "commit 2c094ac761912eea0d7e8ccb140bc647b5378bdf\nAuthor: Yingwei Zheng \nDate: Wed Nov 20 21:15:26 2024 +0800\n\n [InstCombine] Drop range attributes in `foldBitCeil` (#116641)\n \n Closes https://github.com/llvm/llvm-project/issues/112076\n\ndiff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp\nindex 28dbca027037..2526ce7704ab 100644\n--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp\n+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp\n@@ -3466,7 +3466,8 @@ static bool isSafeToRemoveBitCeilSelect(ICmpInst::Predicate Pred, Value *Cond0,\n // Note that the select is optimized away while the shift count is masked with\n // 31. We handle some variations of the input operand like std::bit_ceil(X +\n // 1).\n-static Instruction *foldBitCeil(SelectInst &SI, IRBuilderBase &Builder) {\n+static Instruction *foldBitCeil(SelectInst &SI, IRBuilderBase &Builder,\n+ InstCombinerImpl &IC) {\n Type *SelType = SI.getType();\n unsigned BitWidth = SelType->getScalarSizeInBits();\n \n@@ -3501,6 +3502,10 @@ static Instruction *foldBitCeil(SelectInst &SI, IRBuilderBase &Builder) {\n // single hardware instruction as opposed to BitWidth - CTLZ, where BitWidth\n // is an integer constant. Masking with BitWidth-1 comes free on some\n // hardware as part of the shift instruction.\n+\n+ // Drop range attributes and re-infer them in the next iteration.\n+ cast(Ctlz)->dropPoisonGeneratingAnnotations();\n+ IC.addToWorklist(cast(Ctlz));\n Value *Neg = Builder.CreateNeg(Ctlz);\n Value *Masked =\n Builder.CreateAnd(Neg, ConstantInt::get(SelType, BitWidth - 1));\n@@ -4148,7 +4153,7 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {\n if (sinkNotIntoOtherHandOfLogicalOp(SI))\n return &SI;\n \n- if (Instruction *I = foldBitCeil(SI, Builder))\n+ if (Instruction *I = foldBitCeil(SI, Builder, *this))\n return I;\n \n if (Instruction *I = foldSelectToCmp(SI))\n", "tests": [{"file": "llvm/test/Transforms/InstCombine/bit_ceil.ll", "commands": ["opt < %s -passes=instcombine -S"], "tests": [{"test_name": "test_drop_range_attr", "test_body": "define i32 @test_drop_range_attr(i32 %x) {\n %ctlz = call range(i32 1, 33) i32 @llvm.ctlz.i32(i32 %x, i1 false)\n %sub = sub i32 32, %ctlz\n %shl = shl i32 1, %sub\n %dec = add i32 %x, -1\n %ult = icmp ult i32 %dec, -2\n %sel = select i1 %ult, i32 %shl, i32 1\n ret i32 %sel\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctlz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "pr91691_keep_nsw", "test_body": "define i32 @pr91691_keep_nsw(i32 %0) {\n %2 = sub nsw i32 -2, %0\n %3 = tail call i32 @llvm.ctlz.i32(i32 %2, i1 false)\n %4 = sub i32 32, %3\n %5 = shl i32 1, %4\n %6 = icmp ult i32 %0, -2\n %7 = select i1 %6, i32 %5, i32 1\n ret i32 %7\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctlz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}]}], "issue": {"title": "[InstCombine] `range` attribute should be dropped in `foldBitCeil`", "body": "Reproducer: https://alive2.llvm.org/ce/z/NQTmkh (Please use latest alive2 with https://github.com/AliveToolkit/alive2/pull/1097)\r\n```\r\ndefine i32 @src(i32 %x) {\r\n %ctlz = call range(i32 1, 33) i32 @llvm.ctlz.i32(i32 %x, i1 false)\r\n %sub = sub i32 32, %ctlz\r\n %shl = shl i32 1, %sub\r\n %dec = add i32 %x, -1\r\n %ult = icmp ult i32 %dec, -2\r\n %sel = select i1 %ult, i32 %shl, i32 1\r\n ret i32 %sel\r\n}\r\n\r\ndefine i32 @tgt(i32 %x) {\r\n %ctlz = call range(i32 1, 33) i32 @llvm.ctlz.i32(i32 %x, i1 false)\r\n %1 = sub nsw i32 0, %ctlz\r\n %2 = and i32 %1, 31\r\n %sel = shl nuw i32 1, %2\r\n ret i32 %sel\r\n}\r\n```\r\n```\r\n----------------------------------------\r\ndefine i32 @src(i32 %x) {\r\n#0:\r\n %ctlz = ctlz i32 %x, 0\r\n %#range_0_%ctlz = !range i32 %ctlz, i32 1, i32 33\r\n %sub = sub i32 32, %#range_0_%ctlz\r\n %shl = shl i32 1, %sub\r\n %dec = add i32 %x, 4294967295\r\n %ult = icmp ult i32 %dec, 4294967294\r\n %sel = select i1 %ult, i32 %shl, i32 1\r\n ret i32 %sel\r\n}\r\n=>\r\ndefine i32 @tgt(i32 %x) {\r\n#0:\r\n %ctlz = ctlz i32 %x, 0\r\n %#range_0_%ctlz = !range i32 %ctlz, i32 1, i32 33\r\n %#1 = sub nsw i32 0, %#range_0_%ctlz\r\n %#2 = and i32 %#1, 31\r\n %sel = shl nuw i32 1, %#2\r\n ret i32 %sel\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Target is more poisonous than source\r\n\r\nExample:\r\ni32 %x = #xffffffff (4294967295, -1)\r\n\r\nSource:\r\ni32 %ctlz = #x00000000 (0)\r\ni32 %#range_0_%ctlz = poison\r\ni32 %sub = poison\r\ni32 %shl = poison\r\ni32 %dec = #xfffffffe (4294967294, -2)\r\ni1 %ult = #x0 (0)\r\ni32 %sel = #x00000001 (1)\r\n\r\nTarget:\r\ni32 %ctlz = #x00000000 (0)\r\ni32 %#range_0_%ctlz = poison\r\ni32 %#1 = poison\r\ni32 %#2 = poison\r\ni32 %sel = poison\r\nSource value: #x00000001 (1)\r\nTarget value: poison\r\n```\r\n", "author": "dtcxzyw", "labels": ["miscompilation", "llvm:instcombine"], "comments": []}, "verified": true} {"bug_id": "101213", "issue_url": "https://github.com/llvm/llvm-project/issues/101213", "bug_type": "crash", "base_commit": "8364a6e108faea1a6f05f7bb53720a6fc101fed2", "knowledge_cutoff": "2024-07-30T18:00:09Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "f70f1228035c9610de38e0e376afdacb647c4ad9", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[13909, 13919]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["BoUpSLP::vectorizeTree"]}}, "patch": "commit f70f1228035c9610de38e0e376afdacb647c4ad9\nAuthor: Alexey Bataev \nDate: Tue Jul 30 14:02:51 2024 -0700\n\n [SLP]Fix PR101213: Reuse extractelement, only if its vector operand comes before new vector value.\n \n When trying to reuse extractelement instruction, need to check that it\n is inserted into proper position. Its original vector operand should\n come before new vector value, otherwise new extractelement instruction\n must be generated.\n \n Fixes https://github.com/llvm/llvm-project/issues/101213\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex 6501a14d8778..cf87b8621027 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -13909,11 +13909,16 @@ Value *BoUpSLP::vectorizeTree(\n }\n if (!Ex) {\n // \"Reuse\" the existing extract to improve final codegen.\n- if (auto *ES = dyn_cast(Scalar)) {\n+ if (auto *ES = dyn_cast(Scalar);\n+ ES && isa(Vec)) {\n Value *V = ES->getVectorOperand();\n if (const TreeEntry *ETE = getTreeEntry(V))\n V = ETE->VectorizedValue;\n- Ex = Builder.CreateExtractElement(V, ES->getIndexOperand());\n+ if (auto *IV = dyn_cast(V);\n+ !IV || IV == Vec || IV->comesBefore(cast(Vec)))\n+ Ex = Builder.CreateExtractElement(V, ES->getIndexOperand());\n+ else\n+ Ex = Builder.CreateExtractElement(Vec, Lane);\n } else if (ReplaceGEP) {\n // Leave the GEPs as is, they are free in most cases and better to\n // keep them as GEPs.\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/X86/extract-vectorized-operand.ll", "commands": ["opt -S --passes=slp-vectorizer -slp-threshold=-99999 < %s -mtriple=x86_64-unknown-linux-gnu"], "tests": [{"test_name": "test", "test_body": "define void @test() {\nbb:\n %0 = shufflevector <2 x ptr addrspace(1)> zeroinitializer, <2 x ptr addrspace(1)> zeroinitializer, <2 x i32> \n %1 = extractelement <2 x ptr addrspace(1)> %0, i32 0\n %2 = extractelement <2 x ptr addrspace(1)> %0, i32 1\n br label %bb43\n\nbb20: ; No predecessors!\n br label %bb105\n\nbb43: ; preds = %bb51, %bb\n %phi441 = phi ptr addrspace(1) [ %4, %bb51 ], [ %2, %bb ]\n %phi452 = phi ptr addrspace(1) [ %5, %bb51 ], [ %1, %bb ]\n br i1 false, label %bb105, label %bb51\n\nbb51: ; preds = %bb54, %bb43\n %3 = phi <2 x ptr addrspace(1)> [ poison, %bb54 ], [ zeroinitializer, %bb43 ]\n %4 = extractelement <2 x ptr addrspace(1)> %3, i32 0\n %5 = extractelement <2 x ptr addrspace(1)> %3, i32 1\n br label %bb43\n\nbb54: ; No predecessors!\n br label %bb51\n\nbb105: ; preds = %bb43, %bb20\n %phi106 = phi ptr addrspace(1) [ %1, %bb20 ], [ null, %bb43 ]\n ret void\n}\n"}]}], "issue": {"title": "[SLPVectorizer] Instruction does not dominate all uses! LLVM ERROR: Broken module found, compilation aborted!", "body": "To reproduce run the following test with -passes slp-vectorizer -slp-threshold=-99999\r\n[Test.ll.tgz](https://github.com/user-attachments/files/16431764/Test.ll.tgz)\r\n\r\nReproducer : https://godbolt.org/z/GW41a7WP6\r\n\r\nStack dump:\r\n```\r\nInstruction does not dominate all uses!\r\n %2 = shufflevector <2 x ptr addrspace(1)> %0, <2 x ptr addrspace(1)> poison, <2 x i32> \r\n %1 = extractelement <2 x ptr addrspace(1)> %2, i32 0\r\nLLVM ERROR: Broken module found, compilation aborted!\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes slp-vectorizer -slp-threshold=-99999 \r\n1.\tRunning pass \"verify\" on module \"\"\r\n #0 0x0000000004eff778 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4eff778)\r\n #1 0x0000000004efceec SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007c0269e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007c0269e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007c0269e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007c0269e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00000000007b3ff7 llvm::json::operator==(llvm::json::Value const&, llvm::json::Value const&) (.cold) JSON.cpp:0:0\r\n #7 0x0000000004e396a8 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e396a8)\r\n #8 0x0000000004d360f0 llvm::VerifierPass::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d360f0)\r\n #9 0x00000000008d865e llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d865e)\r\n#10 0x0000000004cf9c90 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4cf9c90)\r\n#11 0x00000000008e33d2 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::ArrayRef>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8e33d2)\r\n#12 0x00000000008d62fc optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d62fc)\r\n#13 0x00007c0269e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#14 0x00007c0269e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#15 0x00000000008cd75e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8cd75e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```\r\n", "author": "TatyanaDoubts", "labels": ["llvm:SLPVectorizer", "llvm:crash"], "comments": [{"author": "Zentrik", "body": "@alexey-bataev Hi, is there a way to backport this fix for llvm 19, I tried just cherry picking f70f1228035c9610de38e0e376afdacb647c4ad9 but I ended up getting assertion failures of the form `/workspace/srcdir/llvm-project/llvm/lib/IR/Instruction.cpp:321: bool llvm::Instruction::comesBefore(const llvm::Instruction*) const: Assertion 'getParent() == Other->getParent() && \"cross-BB instruction order comparison\"' failed.'`. \r\nI can create an IR reproducer for that failure if need be.\r\nThank you.\r\n\r\nEDIT: Would just adding a check that they're in the same basic block work?"}, {"author": "alexey-bataev", "body": "> @alexey-bataev Hi, is there a way to backport this fix for llvm 19, I tried just cherry picking [f70f122](https://github.com/llvm/llvm-project/commit/f70f1228035c9610de38e0e376afdacb647c4ad9) but I ended up getting assertion failures of the form `/workspace/srcdir/llvm-project/llvm/lib/IR/Instruction.cpp:321: bool llvm::Instruction::comesBefore(const llvm::Instruction*) const: Assertion 'getParent() == Other->getParent() && \"cross-BB instruction order comparison\"' failed.'`. I can create an IR reproducer for that failure if need be. Thank you.\r\n> \r\n> EDIT: Would just adding a check that they're in the same basic block work?\r\n\r\nYes, check for the same parent should fix it"}]}, "verified": true} {"bug_id": "106239", "issue_url": "https://github.com/llvm/llvm-project/issues/106239", "bug_type": "crash", "base_commit": "15405b32b1cdbefab9ce1b1f301a51ae25404037", "knowledge_cutoff": "2024-08-27T15:51:29Z", "lit_test_dir": ["llvm/test/Transforms/IndVarSimplify"], "hints": {"fix_commit": "c9a5e1b665dbba898e9981fd7d48881947e6560e", "components": ["SimplifyIndVar"], "bug_location_lineno": {"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": [[1928, 1945]]}, "bug_location_funcname": {"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": ["WidenIV::widenIVUse"]}}, "patch": "commit c9a5e1b665dbba898e9981fd7d48881947e6560e\nAuthor: Nikita Popov \nDate: Wed Aug 28 12:54:14 2024 +0200\n\n [IndVars] Check if WideInc available before trying to use it\n \n WideInc/WideIncExpr can be null. Previously this worked out\n because the comparison with WideIncExpr would fail. Now we have\n accesses to WideInc prior to that. Avoid the issue with an\n explicit check.\n \n Fixes https://github.com/llvm/llvm-project/issues/106239.\n\ndiff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp\nindex 8e3a14bb4f6d..a950a4f57ef4 100644\n--- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp\n+++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp\n@@ -1928,18 +1928,24 @@ Instruction *WidenIV::widenIVUse(WidenIV::NarrowIVDefUse DU,\n if (!WideAddRec.first)\n return nullptr;\n \n- // Reuse the IV increment that SCEVExpander created. Recompute flags, unless\n- // the flags for both increments agree and it is safe to use the ones from\n- // the original inc. In that case, the new use of the wide increment won't\n- // be more poisonous.\n- bool NeedToRecomputeFlags =\n- !SCEVExpander::canReuseFlagsFromOriginalIVInc(OrigPhi, WidePhi,\n- DU.NarrowUse, WideInc) ||\n- DU.NarrowUse->hasNoUnsignedWrap() != WideInc->hasNoUnsignedWrap() ||\n- DU.NarrowUse->hasNoSignedWrap() != WideInc->hasNoSignedWrap();\n+ auto CanUseWideInc = [&]() {\n+ if (!WideInc)\n+ return false;\n+ // Reuse the IV increment that SCEVExpander created. Recompute flags,\n+ // unless the flags for both increments agree and it is safe to use the\n+ // ones from the original inc. In that case, the new use of the wide\n+ // increment won't be more poisonous.\n+ bool NeedToRecomputeFlags =\n+ !SCEVExpander::canReuseFlagsFromOriginalIVInc(\n+ OrigPhi, WidePhi, DU.NarrowUse, WideInc) ||\n+ DU.NarrowUse->hasNoUnsignedWrap() != WideInc->hasNoUnsignedWrap() ||\n+ DU.NarrowUse->hasNoSignedWrap() != WideInc->hasNoSignedWrap();\n+ return WideAddRec.first == WideIncExpr &&\n+ Rewriter.hoistIVInc(WideInc, DU.NarrowUse, NeedToRecomputeFlags);\n+ };\n+\n Instruction *WideUse = nullptr;\n- if (WideAddRec.first == WideIncExpr &&\n- Rewriter.hoistIVInc(WideInc, DU.NarrowUse, NeedToRecomputeFlags))\n+ if (CanUseWideInc())\n WideUse = WideInc;\n else {\n WideUse = cloneIVUser(DU, WideAddRec.first);\n", "tests": [{"file": "llvm/test/Transforms/IndVarSimplify/pr106239.ll", "commands": ["opt -S -passes=indvars < %s"], "tests": [{"test_name": "m", "test_body": "target datalayout = \"n8:16:32:64\"\n\ndefine i32 @m() {\nentry:\n %div.i4 = sdiv i32 1, 0\n br label %for.body.i6\n\nfor.body.i6: ; preds = %if.end.i, %entry\n %add57.i = phi i32 [ %add.i7, %if.end.i ], [ 0, %entry ]\n br i1 true, label %i.exit, label %if.end.i\n\nif.end.i: ; preds = %for.body.i6\n %add.i7 = add i32 %add57.i, %div.i4\n %conv.i = zext i32 %add57.i to i64\n store i64 %conv.i, ptr null, align 8\n br label %for.body.i6\n\ni.exit: ; preds = %for.body.i6\n ret i32 0\n}\n"}]}], "issue": {"title": "[clang] Crash with O2 optimization flag", "body": "I compiled this code with -O2 flag and it crashed. The code is:\r\n\r\n```c\r\n#include \r\nlong a, c;\r\nunsigned d;\r\nint32_t g;\r\nuint8_t h[];\r\nlong b(long p1, long k) {\r\n long e = k;\r\n int b = 0;\r\n while (e) {\r\n e /= 10;\r\n b++;\r\n }\r\n for (int f = 0; f < b; f++)\r\n p1 *= 10;\r\n a = p1 + k;\r\n return a;\r\n}\r\nlong i(int p1, int, int l) {\r\n int j = l / p1;\r\n for (int f = 0; f < p1; f++) {\r\n if (d > l)\r\n break;\r\n c = d += j;\r\n }\r\n}\r\nuint32_t m() {\r\n for (g = 8; b(35, 46) - 3546 + g >= 0; g--)\r\n ;\r\n h[i(g + 1, 0, -4294967221)];\r\n}\r\n```\r\n\r\nThe crash is: clang: /root/llvm-project/llvm/include/llvm/Support/Casting.h:662: decltype(auto) llvm::dyn_cast(From*) [with To = llvm::BinaryOperator; From = llvm::Instruction]: Assertion `detail::isPresent(Val) && \"dyn_cast on a non-existent value\"' failed.\r\n\r\n\r\nThe details can be found here: https://godbolt.org/z/37WsGxMcv", "author": "cardigan1008", "labels": ["regression", "release:backport", "confirmed", "crash", "llvm:transforms"], "comments": [{"author": "shafik", "body": "Looks like a regression, does not crash in clang-18: https://godbolt.org/z/1zYqs3sbz"}, {"author": "dtcxzyw", "body": "Reproducer: https://godbolt.org/z/bbdhPxx5E\r\n\r\n```\r\n; bin/opt -passes=indvars reduced.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\n\r\ndefine i32 @m() {\r\nentry:\r\n %div.i4 = sdiv i32 1, 0\r\n br label %for.body.i6\r\n\r\nfor.body.i6: ; preds = %if.end.i, %entry\r\n %add57.i = phi i32 [ %add.i7, %if.end.i ], [ 0, %entry ]\r\n br i1 true, label %i.exit, label %if.end.i\r\n\r\nif.end.i: ; preds = %for.body.i6\r\n %add.i7 = add i32 %add57.i, %div.i4\r\n %conv.i = zext i32 %add57.i to i64\r\n store i64 %conv.i, ptr null, align 8\r\n br label %for.body.i6\r\n\r\ni.exit: ; preds = %for.body.i6\r\n ret i32 0\r\n}\r\n```\r\ncc @nikic"}, {"author": "DimitryAndric", "body": "This regressed with `llvmorg-19-init-02822-g`4db93e5d564 (\"[IndVars] Recompute flags if needed in widenIVUse of IV increment. (#82352)\") by @fhahn."}]}, "verified": true} +{"bug_id": "131195", "issue_url": "https://github.com/llvm/llvm-project/issues/131195", "bug_type": "crash", "base_commit": "8413f4d837a96458104f63bab72c751b8285a458", "knowledge_cutoff": "2025-03-13T19:24:54Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "605a9f590d91a42ae652c2ab13487b5ad57c58a5", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[14081, 14086], [14121, 14126]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["BoUpSLP::isGatherShuffledSingleRegisterEntry"]}}, "patch": "commit 605a9f590d91a42ae652c2ab13487b5ad57c58a5\nAuthor: Alexey Bataev \nDate: Fri Mar 14 13:40:15 2025 -0700\n\n [SLP]Check if user node is same as other node and check operand order\n \n Need to check if the user node is same as other node and check operand\n order to prevent a compiler crash when trying to find matching gather\n node with user nodes, having the same last instruction.\n \n Fixes #131195\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex 9c3992b4a713..708dda9bd7f8 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -14081,6 +14081,17 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry(\n }\n return true;\n };\n+ auto CheckParentNodes = [&](const TreeEntry *User1, const TreeEntry *User2,\n+ unsigned EdgeIdx) {\n+ const TreeEntry *Ptr1 = User1;\n+ while (Ptr1) {\n+ unsigned Idx = Ptr1->UserTreeIndex.EdgeIdx;\n+ Ptr1 = Ptr1->UserTreeIndex.UserTE;\n+ if (Ptr1 == User2)\n+ return Idx < EdgeIdx;\n+ }\n+ return false;\n+ };\n for (Value *V : VL) {\n if (isConstant(V) || !VisitedValue.insert(V).second)\n continue;\n@@ -14121,6 +14132,9 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry(\n (TEUseEI.UserTE->Idx < UseEI.UserTE->Idx ||\n HasGatherUser(TEUseEI.UserTE)))\n continue;\n+ // If the user node is the operand of the other user node - skip.\n+ if (CheckParentNodes(TEUseEI.UserTE, UseEI.UserTE, UseEI.EdgeIdx))\n+ continue;\n }\n \n // Check if the user node of the TE comes after user node of TEPtr,\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/X86/user-node-with-same-last-instr.ll", "commands": ["opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -slp-threshold=-99999 < %s"], "tests": [{"test_name": "", "test_body": "\ndefine void @wombat(i32 %arg) {\n;\nbb:\n br label %bb1\n\nbb1:\n br i1 false, label %bb2, label %bb5\n\nbb2:\n %phi = phi i32 [ %or, %bb4 ], [ 0, %bb1 ]\n %phi3 = phi i32 [ %sub, %bb4 ], [ 0, %bb1 ]\n %or = or i32 %phi, 1\n %and = and i32 0, %phi\n %sub = sub i32 %phi3, %arg\n br label %bb4\n\nbb4:\n br i1 false, label %bb2, label %bb5\n\nbb5:\n %phi6 = phi i32 [ 0, %bb1 ], [ %and, %bb4 ]\n %phi7 = phi i32 [ 0, %bb1 ], [ %sub, %bb4 ]\n ret void\n}"}]}], "issue": {"title": "[SLPVectorizer] Instruction does not dominate all uses! ...LLVM ERROR: Broken module found, compilation aborted!", "body": "To reproduce run opt with the test below with -passes=slp-vectorizer -slp-threshold=-99999:\n```\n; ModuleID = './reduced.ll'\nsource_filename = \"./reduced.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-ni:1-p2:32:8:8:32-ni:2\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine void @wombat(i32 %arg) #0 gc \"statepoint-example\" {\nbb:\n br label %bb1\n\nbb1: ; preds = %bb\n br i1 false, label %bb2, label %bb5\n\nbb2: ; preds = %bb4, %bb1\n %phi = phi i32 [ %or, %bb4 ], [ 0, %bb1 ]\n %phi3 = phi i32 [ %sub, %bb4 ], [ 0, %bb1 ]\n %or = or i32 %phi, 1\n %and = and i32 0, %phi\n %sub = sub i32 %phi3, %arg\n br label %bb4\n\nbb4: ; preds = %bb2\n br i1 false, label %bb2, label %bb5\n\nbb5: ; preds = %bb4, %bb1\n %phi6 = phi i32 [ 0, %bb1 ], [ %and, %bb4 ]\n %phi7 = phi i32 [ 0, %bb1 ], [ %sub, %bb4 ]\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+prfchw,-cldemote,+avx,+aes,+sahf,+pclmul,-xop,+crc32,-amx-fp8,+xsaves,-avx512fp16,-usermsr,-sm4,-egpr,+sse4.1,-avx512ifma,+xsave,+sse4.2,-tsxldtrk,-sm3,-ptwrite,-widekl,-movrs,+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,-avx10.2-256,-gfni,-avxvnniint16,-amx-fp16,-zu,-ndd,+xsaveopt,+rdrnd,+avx512f,-amx-bf16,-avx512bf16,-avx512vnni,-push2pop2,+cx8,+avx512bw,+sse3,+pku,-nf,-amx-tf32,-amx-avx512,+fsgsbase,-clzero,-mwaitx,-lwp,+lzcnt,-sha,-movdir64b,-ppx,-wbnoinvd,-enqcmd,-amx-transpose,-avx10.2-512,-avxneconvert,-tbm,-pconfig,-amx-complex,+ssse3,+cx16,+bmi2,+fma,+popcnt,-avxifma,+f16c,-avx512bitalg,-rdpru,+clwb,+mmx,+sse2,+rdseed,-avx512vbmi2,-prefetchi,-amx-movrs,-rdpid,-fma4,-avx512vbmi,-shstk,-vaes,-waitpkg,-sgx,+fxsr,+avx512dq,-sse4a,-avx512f\" }\n```\nReproducer: https://godbolt.org/z/Pfa9ca1o9\n\n\n\nStack dump:\n```\nInstruction does not dominate all uses!\n %5 = insertelement <2 x i32> , i32 %arg, i32 0\n %1 = shufflevector <2 x i32> %5, <2 x i32> , <2 x i32> \nLLVM ERROR: Broken module found, compilation aborted!\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 -slp-threshold=-99999 \n1.\tRunning pass \"verify\" on module \"\"\n #0 0x0000000005480a38 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5480a38)\n #1 0x000000000547e3f4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x000072fce1242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x000072fce12969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x000072fce1242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x000072fce12287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x00000000008074fd llvm::json::operator==(llvm::json::Value const&, llvm::json::Value const&) (.cold) JSON.cpp:0:0\n #7 0x00000000053bec18 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x53bec18)\n #8 0x00000000052bb868 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x52bb868)\n #9 0x000000000093768e llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x93768e)\n#10 0x000000000527a030 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x527a030)\n#11 0x0000000000941b4a llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::ArrayRef>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x941b4a)\n#12 0x000000000093522c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x93522c)\n#13 0x000072fce1229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#14 0x000072fce1229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#15 0x000000000092cd35 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x92cd35)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```", "author": "TatyanaDoubts", "labels": ["llvm:SLPVectorizer", "crash"], "comments": []}, "verified": true} +{"bug_id": "131281", "issue_url": "https://github.com/llvm/llvm-project/issues/131281", "bug_type": "crash", "base_commit": "887cf1f8cea240cd50fb80bc9487b22f67d74263", "knowledge_cutoff": "2025-03-14T05:50:22Z", "lit_test_dir": ["llvm/test/Transforms/LoopVectorize"], "hints": {"fix_commit": "166937b49dac0919fae362c0deecb723b03be764", "components": ["LoopVectorize"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [[1912, 1917]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": ["create"]}}, "patch": "commit 166937b49dac0919fae362c0deecb723b03be764\nAuthor: Florian Hahn \nDate: Mon Mar 17 18:41:34 2025 +0000\n\n [LV] Cleanup after expanding SCEV predicate to constant.\n \n In some cases, SCEV isn't able to prove that no wrap checks are needed,\n while constant folding in SCEVExpander can. In those cases, we may leave\n around IR for computing the trip count, which is unused at this point\n but may be re-used later, triggering an assertion when trying to clean\n up SCEVExp after vectorization.\n \n Directly run the cleaner after expanding to a constant predicate to\n prevent any generated code from being re-used.\n \n Fixes https://github.com/llvm/llvm-project/issues/131281.\n\ndiff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\nindex 0e38ccc565ea..cbfccaab01e2 100644\n--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n@@ -1912,6 +1912,12 @@ public:\n \n SCEVCheckCond = SCEVExp.expandCodeForPredicate(\n &UnionPred, SCEVCheckBlock->getTerminator());\n+ if (isa(SCEVCheckCond)) {\n+ // Clean up directly after expanding the predicate to a constant, to\n+ // avoid further expansions re-using anything left over from SCEVExp.\n+ SCEVExpanderCleaner SCEVCleaner(SCEVExp);\n+ SCEVCleaner.cleanup();\n+ }\n }\n \n const auto &RtPtrChecking = *LAI.getRuntimePointerChecking();\n", "tests": [{"file": "llvm/test/Transforms/LoopVectorize/scev-predicate-reasoning.ll", "commands": ["opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -lv-strided-pointer-ivs=true -S %s"], "tests": [{"test_name": "no_signed_wrap_iv_via_btc", "test_body": "declare i1 @cond()\n\n; Function Attrs: mustprogress\ndefine void @no_signed_wrap_iv_via_btc(ptr %dst, i32 %N) #0 {\nentry:\n %sub = add i32 %N, -100\n %sub4 = add i32 %N, -99\n br label %outer\n\nouter: ; preds = %loop, %entry\n %c = call i1 @cond()\n br i1 %c, label %loop, label %exit\n\nloop: ; preds = %loop, %outer\n %iv = phi i32 [ 0, %outer ], [ %inc, %loop ]\n %add2 = add i32 %sub4, %iv\n %add.ext = sext i32 %add2 to i64\n %gep.dst = getelementptr i32, ptr %dst, i64 %add.ext\n store i32 0, ptr %gep.dst, align 4\n %inc = add i32 %iv, 1\n %add = add i32 %sub, %inc\n %ec = icmp sgt i32 %add, %N\n br i1 %ec, label %outer, label %loop\n\nexit: ; preds = %outer\n ret void\n}\n\nattributes #0 = { mustprogress }\n"}]}], "issue": {"title": "[clang] Crash at -O2: Assertion `all_of(I->users()... \"during expansion\"' failed.", "body": "This code crashes at `-O2`:\n\n```c\nint a, b, c, d;\nvoid e() {\n int *f = 0;\n for (;;)\n for (; c - 100 + d <= b; d++) {\n f[d + a] = 1;\n a = 1 + c - 100;\n }\n}\nvoid main() {}\n```\n\nCompiler Explorer: https://godbolt.org/z/P3f6ef98P\n\nBisected to https://github.com/llvm/llvm-project/commit/ddffb74afd870d284ba07f1cf6c67117a8ab8b33, which was committed by @artagnon \n\nCrash:\n\n```console\nclang: /root/llvm-project/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp:2402: void llvm::SCEVExpanderCleaner::cleanup(): Assertion `all_of(I->users(), [&InsertedSet](Value *U) { return InsertedSet.contains(cast(U)); }) && \"removed instruction should only be used by instructions inserted \" \"during expansion\"' failed.\n```\n\nBacktrace:\n\n```c\nStack dump:\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O2 -Wall -Wextra \n1.\t parser at end of file\n2.\tOptimizer\n3.\tRunning pass \"function(float2int,lower-constant-intrinsics,loop(loop-rotate,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize,infer-alignment,loop-load-elim,instcombine,simplifycfg,slp-vectorizer,vector-combine,instcombine,loop-unroll,transform-warning,sroa,infer-alignment,instcombine,loop-mssa(licm),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg)\" on module \"\"\n4.\tRunning pass \"loop-vectorize\" on function \"e\"\n #0 0x0000000003e7dc08 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3e7dc08)\n #1 0x0000000003e7b8c4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3e7b8c4)\n #2 0x0000000003dc0618 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\n #3 0x00007507d4042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #4 0x00007507d40969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #5 0x00007507d4042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #6 0x00007507d40287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #7 0x00007507d402871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #8 0x00007507d4039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #9 0x0000000003fea367 llvm::SCEVExpanderCleaner::cleanup() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fea367)\n#10 0x000000000597bc1f (anonymous namespace)::GeneratedRTChecks::~GeneratedRTChecks() LoopVectorize.cpp:0:0\n#11 0x00000000059d28c8 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x59d28c8)\n#12 0x00000000059d4e29 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x59d4e29)\n#13 0x00000000059d54a3 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x59d54a3)\n#14 0x00000000055481fe llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x55481fe)\n#15 0x000000000381c880 llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x381c880)\n#16 0x00000000011a852e llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x11a852e)\n#17 0x000000000381b19b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x381b19b)\n#18 0x00000000011a764e llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x11a764e)\n#19 0x000000000381aba0 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x381aba0)\n#20 0x000000000412e684 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr>&, std::unique_ptr>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\n#21 0x0000000004132031 clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr, std::unique_ptr>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4132031)\n#22 0x0000000004837120 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4837120)\n#23 0x000000000643be7c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x643be7c)\n#24 0x0000000004837528 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4837528)\n#25 0x0000000004b00005 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4b00005)\n#26 0x0000000004a8398e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4a8398e)\n#27 0x0000000004bedf9e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4bedf9e)\n#28 0x0000000000d5391f cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd5391f)\n#29 0x0000000000d4b2da ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&) driver.cpp:0:0\n#30 0x000000000487fa49 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0\n#31 0x0000000003dc0ac4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3dc0ac4)\n#32 0x000000000488003f clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0\n#33 0x00000000048426fd clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48426fd)\n#34 0x000000000484377e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x484377e)\n#35 0x000000000484b695 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x484b695)\n#36 0x0000000000d5076c clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd5076c)\n#37 0x0000000000c17ff4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc17ff4)\n#38 0x00007507d4029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#39 0x00007507d4029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#40 0x0000000000d4ad85 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd4ad85)\n```", "author": "cardigan1008", "labels": ["vectorizers", "crash-on-valid", "generated by fuzzer"], "comments": [{"author": "artagnon", "body": "@fhahn Could you kindly look into this? I'm on vacation until the 24th."}, {"author": "dtcxzyw", "body": "Reduced: https://godbolt.org/z/Wbvj9fExo\n```\n; bin/opt -passes=loop-vectorize 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\ndefine void @e(i32 %0) {\nentry:\n %sub = add i32 %0, -100\n %sub4 = add i32 %0, -99\n br label %for.cond\n\nfor.cond: ; preds = %for.body, %entry\n br label %for.body\n\nfor.body: ; preds = %for.body, %for.cond\n %inc510 = phi i32 [ %inc, %for.body ], [ 0, %for.cond ]\n %add2 = add i32 %sub4, %inc510\n %idxprom = sext i32 %add2 to i64\n %arrayidx = getelementptr i32, ptr null, i64 %idxprom\n store i32 0, ptr %arrayidx, align 4\n %inc = add i32 %inc510, 1\n %add = add i32 %sub, %inc\n %cmp.not = icmp sgt i32 %add, %0\n br i1 %cmp.not, label %for.cond, label %for.body, !llvm.loop !0\n}\n\n!0 = distinct !{!0, !1, !2}\n!1 = !{!\"llvm.loop.mustprogress\"}\n!2 = !{!\"llvm.loop.peeled.count\", i32 1}\n\n```"}, {"author": "fhahn", "body": "@artagnon sure, it looks like the underlying issue existed before, but with https://github.com/llvm/llvm-project/commit/ddffb74afd870d284ba07f1cf6c67117a8ab8b33 we now crash.\n\nSCEVExpansion can prove that the AddRec never wraps via constant folding the runtime check, but really SCEV should be able to prove that: https://github.com/llvm/llvm-project/pull/131538"}]}, "verified": true} +{"bug_id": "131465", "issue_url": "https://github.com/llvm/llvm-project/issues/131465", "bug_type": "miscompilation", "base_commit": "baab447aadd59b34bd838584b16d11475329853f", "knowledge_cutoff": "2025-03-15T18:15:27Z", "lit_test_dir": ["llvm/test/Analysis/ScalarEvolution", "llvm/test/Transforms/LoopUnroll"], "hints": {"fix_commit": "c5a491e9ea22014b65664b6e09134b4f055933e2", "components": ["ScalarEvolution"], "bug_location_lineno": {"llvm/lib/Analysis/ScalarEvolution.cpp": [[10635, 10644]]}, "bug_location_funcname": {"llvm/lib/Analysis/ScalarEvolution.cpp": ["ScalarEvolution::howFarToZero"]}}, "patch": "commit c5a491e9ea22014b65664b6e09134b4f055933e2\nAuthor: Yingwei Zheng \nDate: Mon Mar 17 13:59:16 2025 +0800\n\n [SCEV] Check whether the start is non-zero in `ScalarEvolution::howFarToZero` (#131522)\n \n https://github.com/llvm/llvm-project/pull/94525 assumes that the loop\n will be infinite when the stride is zero. However, it doesn't hold when\n the start value of addrec is also zero.\n \n Closes https://github.com/llvm/llvm-project/issues/131465.\n\ndiff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp\nindex 8f74c1c398ce..314baa7c7aee 100644\n--- a/llvm/lib/Analysis/ScalarEvolution.cpp\n+++ b/llvm/lib/Analysis/ScalarEvolution.cpp\n@@ -10635,10 +10635,11 @@ ScalarEvolution::ExitLimit ScalarEvolution::howFarToZero(const SCEV *V,\n if (ControlsOnlyExit && AddRec->hasNoSelfWrap() &&\n loopHasNoAbnormalExits(AddRec->getLoop())) {\n \n- // If the stride is zero, the loop must be infinite. In C++, most loops\n- // are finite by assumption, in which case the step being zero implies\n- // UB must execute if the loop is entered.\n- if (!loopIsFiniteByAssumption(L) && !isKnownNonZero(StepWLG))\n+ // If the stride is zero and the start is non-zero, the loop must be\n+ // infinite. In C++, most loops are finite by assumption, in which case the\n+ // step being zero implies UB must execute if the loop is entered.\n+ if (!(loopIsFiniteByAssumption(L) && isKnownNonZero(Start)) &&\n+ !isKnownNonZero(StepWLG))\n return getCouldNotCompute();\n \n const SCEV *Exact =\n", "tests": [{"file": "llvm/test/Analysis/ScalarEvolution/trip-count-unknown-stride.ll", "commands": ["opt < %s -disable-output \"-passes=print\" -scalar-evolution-classify-expressions=0 2>&1"], "tests": [{"test_name": "ne_nuw_nonneg_step", "test_body": "target datalayout = \"e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128\"\n\n; Function Attrs: mustprogress\ndefine void @ne_nuw_nonneg_step(ptr captures(none) %A, i32 %n, i32 %s) #0 {\nentry:\n %nonneg_step = icmp sge i32 %s, 0\n call void @llvm.assume(i1 %nonneg_step)\n %cmp4 = icmp sgt i32 %n, 0\n br i1 %cmp4, label %for.body, label %for.end\n\nfor.body: ; preds = %for.body, %entry\n %i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]\n %arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05\n %0 = load i32, ptr %arrayidx, align 4\n %inc = add nuw i32 %0, 1\n store i32 %inc, ptr %arrayidx, align 4\n %add = add nuw i32 %i.05, %s\n %cmp = icmp ne i32 %add, %n\n br i1 %cmp, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body, %entry\n ret void\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #1\n\nattributes #0 = { mustprogress }\nattributes #1 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n"}, {"test_name": "pr131465", "test_body": "target datalayout = \"e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128\"\n\n; Function Attrs: mustprogress\ndefine i32 @pr131465(i1 %x) #0 {\nentry:\n %inc = zext i1 %x to i32\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %indvar = phi i32 [ 2, %entry ], [ %next, %for.body ]\n %next = add nsw i32 %indvar, %inc\n %exitcond = icmp eq i32 %next, 2\n br i1 %exitcond, label %for.end, label %for.body\n\nfor.end: ; preds = %for.body\n ret i32 0\n}\n\nattributes #0 = { mustprogress }\n"}, {"test_name": "ne_nsw_nonneg_step", "test_body": "target datalayout = \"e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128\"\n\n; Function Attrs: mustprogress\ndefine void @ne_nsw_nonneg_step(ptr captures(none) %A, i32 %n, i32 %s) #0 {\nentry:\n %nonneg_step = icmp sge i32 %s, 0\n call void @llvm.assume(i1 %nonneg_step)\n %cmp4 = icmp sgt i32 %n, 0\n br i1 %cmp4, label %for.body, label %for.end\n\nfor.body: ; preds = %for.body, %entry\n %i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]\n %arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05\n %0 = load i32, ptr %arrayidx, align 4\n %inc = add nsw i32 %0, 1\n store i32 %inc, ptr %arrayidx, align 4\n %add = add nsw i32 %i.05, %s\n %cmp = icmp ne i32 %add, %n\n br i1 %cmp, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body, %entry\n ret void\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #1\n\nattributes #0 = { mustprogress }\nattributes #1 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n"}]}, {"file": "llvm/test/Transforms/LoopUnroll/pr131465.ll", "commands": ["opt -S -passes=loop-unroll -unroll-runtime %s"], "tests": [{"test_name": "pr131465", "test_body": "; Function Attrs: mustprogress\ndefine i32 @pr131465(i1 %x) #0 {\nentry:\n %inc = zext i1 %x to i32\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %indvar = phi i32 [ 2, %entry ], [ %next, %for.body ]\n %next = add nsw i32 %indvar, %inc\n %exitcond = icmp eq i32 %next, 2\n br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !0\n\nfor.end: ; preds = %for.body\n ret i32 0\n}\n\nattributes #0 = { mustprogress }\n\n!0 = distinct !{!0, !1}\n!1 = !{!\"llvm.loop.unroll.count\", i32 2}\n"}]}], "issue": {"title": "[clang] Miscompilation at -O2/3", "body": "This code prints 80 at `-O2/3` and 0 at `-O0/1`:\n\n```c\nint printf(const char *, ...);\nint a, b;\nvoid c(char d) { a = d; }\nint main() {\n int e = 82, f = 20;\n for (; 85 + 20 + e - 187 + f; f = 65535 + 20 + e - 65637)\n if (b)\n e++;\n c(e >> 24);\n printf(\"%X\\n\", a);\n}\n```\n\nCompiler Explorer: https://godbolt.org/z/6WP1aT6ba\n\nBisected to https://github.com/llvm/llvm-project/commit/04cd06906288dcb148de37d7c3e6c009c3e3b726, which was committed by @preames ", "author": "cardigan1008", "labels": ["miscompilation", "llvm:SCEV"], "comments": [{"author": "dtcxzyw", "body": "Reduced reproducer: https://godbolt.org/z/bvhdjdMc7 https://alive2.llvm.org/ce/z/sSLNUX\n```\n; bin/opt -passes=loop-unroll 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\ndefine i32 @main(i1 %tobool2.not) #0 {\nentry:\n %inc = zext i1 %tobool2.not to i32\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %e.08 = phi i32 [ 2, %entry ], [ %spec.select, %for.body ]\n %spec.select = add nsw i32 %e.08, %inc\n %tobool.not = icmp eq i32 %spec.select, 2\n br i1 %tobool.not, label %for.end, label %for.body, !llvm.loop !0\n\nfor.end: ; preds = %for.body\n ret i32 0\n}\n\nattributes #0 = { \"target-cpu\"=\"x86-64\" }\n\n!0 = distinct !{!0, !1}\n!1 = !{!\"llvm.loop.mustprogress\"}\n\n```"}, {"author": "antoniofrighetto", "body": "@dtcxzyw May I ask whether llubi was used to get such a reduced reproducer? Having a hard time reducing this one, this time: am using [test.sh](https://github.com/dtcxzyw/llvm-ub-aware-interpreter?tab=readme-ov-file#automatic-ub-free-test-case-reduction-for-middle-end-miscompilation-bugs) with:\n1) Custom pipelines & O2 in order to have some proper interestingness test;\n2) `--ir-passes` with the default one, fine-tuning the pipeline by adjusting/removing passes.\n\nHowever, by the time I obtain the reduced IR, it looks already invalid (i.e., unreachable). Any suggestions / idea what I may be missing?"}, {"author": "dtcxzyw", "body": "1. Manually bisect\n```\n#!/usr/bin/bash\n\nFILE=$1\nBISECT=$2\n../../LLVM/llvm-build/bin/clang -O3 -mllvm -inline-threshold=1000000 $FILE -mllvm -opt-bisect-limit=$BISECT -DNDEBUG -g0 -w -emit-llvm -S -I/home/dtcxzyw/WorkSpace/Projects/compilers/csmith/install/include -o test.ll -mllvm -print-changed -mllvm -print-module-scope 2>log\n# ../../LLVM/llvm-build/bin/lli test.ll\n./llubi --max-steps 1000000 test.ll\n# ../../LLVM/llvm-build/bin/opt -O3 $FILE -o out.ll -S -opt-bisect-limit=$BISECT -print-changed -print-module-scope 2>log\n# ./llubi out.ll\n```\n```\n# Correct one\n./bisect.sh test.c 175\n# Miscompilation\n./bisect.sh test.c 174\n```\nAfter the bisection, we got a single-pass reproducer:\n```\n; bin/opt -passes=loop-unroll test.ll -S\n; ModuleID = 'test.c'\nsource_filename = \"test.c\"\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@a = dso_local local_unnamed_addr global i32 0, align 4\n@b = dso_local local_unnamed_addr global i32 0, align 4\n@.str = private unnamed_addr constant [4 x i8] c\"%X\\0A\\00\", align 1\n\n; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) uwtable\ndefine dso_local void @c(i8 noundef signext %d) local_unnamed_addr #0 {\nentry:\n %conv = sext i8 %d to i32\n store i32 %conv, ptr @a, align 4, !tbaa !5\n ret void\n}\n\n; Function Attrs: nofree nounwind uwtable\ndefine dso_local noundef i32 @main() local_unnamed_addr #1 {\nentry:\n %0 = load i32, ptr @b, align 4, !tbaa !5\n %tobool2.not = icmp ne i32 %0, 0\n %inc = zext i1 %tobool2.not to i32\n br label %for.body\n\nfor.body: ; preds = %entry, %for.body\n %e.08 = phi i32 [ 82, %entry ], [ %spec.select, %for.body ]\n %spec.select = add nuw nsw i32 %e.08, %inc\n %sub = add nsw i32 %spec.select, -82\n %add1 = sub nsw i32 82, %spec.select\n %tobool.not = icmp eq i32 %sub, %add1\n br i1 %tobool.not, label %for.end, label %for.body, !llvm.loop !9\n\nfor.end: ; preds = %for.body\n %shr = lshr i32 %spec.select, 24\n store i32 %shr, ptr @a, align 4, !tbaa !5\n %call = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %shr)\n ret i32 0\n}\n\n; Function Attrs: nofree nounwind\ndeclare noundef i32 @printf(ptr noundef readonly captures(none), ...) local_unnamed_addr #2\n\nattributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) uwtable \"min-legal-vector-width\"=\"0\" \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"x86-64\" \"target-features\"=\"+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87\" \"tune-cpu\"=\"generic\" }\nattributes #1 = { nofree nounwind uwtable \"min-legal-vector-width\"=\"0\" \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"x86-64\" \"target-features\"=\"+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87\" \"tune-cpu\"=\"generic\" }\nattributes #2 = { nofree nounwind \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"x86-64\" \"target-features\"=\"+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87\" \"tune-cpu\"=\"generic\" }\n\n!llvm.module.flags = !{!0, !1, !2, !3}\n!llvm.ident = !{!4}\n\n!0 = !{i32 1, !\"wchar_size\", i32 4}\n!1 = !{i32 8, !\"PIC Level\", i32 2}\n!2 = !{i32 7, !\"PIE Level\", i32 2}\n!3 = !{i32 7, !\"uwtable\", i32 2}\n!4 = !{!\"clang version 21.0.0git\"}\n!5 = !{!6, !6, i64 0}\n!6 = !{!\"int\", !7, i64 0}\n!7 = !{!\"omnipotent char\", !8, i64 0}\n!8 = !{!\"Simple C/C++ TBAA\"}\n!9 = distinct !{!9, !10}\n!10 = !{!\"llvm.loop.mustprogress\"}\n```\n2. reduce\n```\n#!/usr/bin/bash\n# /home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/clang -Os -Xclang -disable-llvm-passes -emit-llvm -S test.c -o test.ll -I/home/dtcxzyw/WorkSpace/Projects/compilers/csmith/install/include -w\n# llvm-reduce --test=ubi_reduce.sh --ir-passes=\"function(sroa,instcombine,gvn,simplifycfg,infer-address-spaces),inline\" test.ll\n\na=$(/home/dtcxzyw/WorkSpace/Projects/compilers/llvm-ub-aware-interpreter/build/llubi --max-steps 1000000 --reduce-mode $1)\nif [ $? -ne 0 ]; then\n exit 1\nfi\n/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/opt -passes=loop-unroll $1 -o $1.tmp -S\nif [ $? -ne 0 ]; then\n exit 1\nfi\nb=$(/home/dtcxzyw/WorkSpace/Projects/compilers/llvm-ub-aware-interpreter/build/llubi --max-steps 1000000 --reduce-mode $1.tmp)\nif [ $? -ne 0 ]; then\n exit 0\n # exit 1\nfi\nif [[ \"$a\" == \"$b\" ]]; then\n exit 2\nfi\n# echo $a\n# echo $b\nexit 0\n```\n```\nllvm-reduce --test=ubi_reduce.sh test.ll\n```\nThen we got the final reproducer.\n\nIn general, I will run `creduce w/ sanitizers` and the bisection first to avoid falling into some long-outstanding undef bugs.\n\nBTW, an automatic reproducer reduction pipeline will be available soon :)\n"}, {"author": "antoniofrighetto", "body": "@dtcxzyw Thanks a lot for clarifying that :)"}]}, "verified": true} {"bug_id": "76986", "issue_url": "https://github.com/llvm/llvm-project/issues/76986", "bug_type": "crash", "base_commit": "71c17424b5d5c22c0ce6b4c41acaa0401515baca", "knowledge_cutoff": "2024-01-04T18:14:09Z", "lit_test_dir": ["llvm/test/Transforms/LoopVectorize"], "hints": {"fix_commit": "2ab5c47c8752b444885d6bfaf6f570a482fb4cdf", "components": ["LoopVectorize"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": [[829, 843]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": ["simplifyRecipe"]}}, "patch": "commit 2ab5c47c8752b444885d6bfaf6f570a482fb4cdf\nAuthor: Florian Hahn \nDate: Thu Jan 4 20:39:44 2024 +0000\n\n [VPlan] Don't replace scalarizing recipe with VPWidenCastRecipe.\n \n Don't replace a scalarizing recipe with a VPWidenCastRecipe. This would\n introduce wide (vectorizing) recipes when interleaving only.\n \n Fixes https://github.com/llvm/llvm-project/issues/76986\n\ndiff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp\nindex 33132880d5a4..5c430620a2dc 100644\n--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp\n+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp\n@@ -829,15 +829,20 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {\n Type *ATy = TypeInfo.inferScalarType(A);\n if (TruncTy == ATy) {\n Trunc->replaceAllUsesWith(A);\n- } else if (ATy->getScalarSizeInBits() < TruncTy->getScalarSizeInBits()) {\n- auto *VPC =\n- new VPWidenCastRecipe(Instruction::CastOps(ExtOpcode), A, TruncTy);\n- VPC->insertBefore(&R);\n- Trunc->replaceAllUsesWith(VPC);\n- } else if (ATy->getScalarSizeInBits() > TruncTy->getScalarSizeInBits()) {\n- auto *VPC = new VPWidenCastRecipe(Instruction::Trunc, A, TruncTy);\n- VPC->insertBefore(&R);\n- Trunc->replaceAllUsesWith(VPC);\n+ } else {\n+ // Don't replace a scalarizing recipe with a widened cast.\n+ if (isa(&R))\n+ break;\n+ if (ATy->getScalarSizeInBits() < TruncTy->getScalarSizeInBits()) {\n+ auto *VPC =\n+ new VPWidenCastRecipe(Instruction::CastOps(ExtOpcode), A, TruncTy);\n+ VPC->insertBefore(&R);\n+ Trunc->replaceAllUsesWith(VPC);\n+ } else if (ATy->getScalarSizeInBits() > TruncTy->getScalarSizeInBits()) {\n+ auto *VPC = new VPWidenCastRecipe(Instruction::Trunc, A, TruncTy);\n+ VPC->insertBefore(&R);\n+ Trunc->replaceAllUsesWith(VPC);\n+ }\n }\n #ifndef NDEBUG\n // Verify that the cached type info is for both A and its users is still\n", "tests": [{"file": "llvm/test/Transforms/LoopVectorize/interleave-and-scalarize-only.ll", "commands": ["opt -passes=loop-vectorize -force-vector-width=1 -force-vector-interleave=2 -debug -disable-output %s 2>&1", "opt -passes=loop-vectorize -force-vector-width=1 -force-vector-interleave=2 -S %s"], "tests": [{"test_name": "test_scalarize_call", "test_body": "define void @test_scalarize_call(i32 %start, ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ %start, %entry ], [ %iv.next, %loop ]\n %min = tail call i32 @llvm.smin.i32(i32 %iv, i32 65535)\n %arrayidx = getelementptr inbounds i32, ptr %dst, i32 %iv\n store i32 %min, ptr %arrayidx, align 8\n %iv.next = add nsw i32 %iv, 1\n %tobool.not = icmp eq i32 %iv.next, 1000\n br i1 %tobool.not, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.smin.i32(i32, i32) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "scalarize_ptrtoint", "test_body": "define void @scalarize_ptrtoint(ptr %src, ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep = getelementptr ptr, ptr %src, i64 %iv\n %l = load ptr, ptr %gep, align 8\n %cast = ptrtoint ptr %l to i64\n %add = add i64 %cast, 10\n %cast.2 = inttoptr i64 %add to ptr\n store ptr %cast.2, ptr %dst, align 8\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 0\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n"}, {"test_name": "first_order_recurrence_using_induction", "test_body": "define void @first_order_recurrence_using_induction(i32 %n, ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %for = phi i32 [ 0, %entry ], [ %iv.trunc, %loop ]\n %iv.trunc = trunc i64 %iv to i32\n store i32 %for, ptr %dst, align 4\n %iv.next = add nuw nsw i64 %iv, 1\n %iv.next.trunc = trunc i64 %iv.next to i32\n %ec = icmp slt i32 %iv.next.trunc, %n\n br i1 %ec, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n"}, {"test_name": "reduction_with_casts", "test_body": "define i16 @reduction_with_casts() {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %count.0.in1 = phi i32 [ 0, %entry ], [ %add, %loop ]\n %iv = phi i16 [ 1, %entry ], [ %iv.next, %loop ]\n %conv1 = and i32 %count.0.in1, 65535\n %add = add nuw nsw i32 %conv1, 1\n %iv.next = add i16 %iv, 1\n %cmp = icmp eq i16 %iv.next, 10000\n br i1 %cmp, label %exit, label %loop\n\nexit: ; preds = %loop\n %add.lcssa = phi i32 [ %add, %loop ]\n %count.0 = trunc i32 %add.lcssa to i16\n ret i16 %count.0\n}\n"}, {"test_name": "pr76986_trunc_sext_interleaving_only", "test_body": "define void @pr76986_trunc_sext_interleaving_only(i16 %arg, ptr noalias %src, ptr noalias %dst) {\nbb:\n br label %loop\n\nloop: ; preds = %loop, %bb\n %iv = phi i64 [ 0, %bb ], [ %iv.next, %loop ]\n %gep.src = getelementptr inbounds i8, ptr %src, i64 %iv\n %l = load i8, ptr %gep.src, align 1\n %sext = sext i8 %l to i32\n %trunc = trunc i32 %sext to i16\n %sdiv = sdiv i16 %trunc, %arg\n %gep.dst = getelementptr inbounds i16, ptr %dst, i64 %iv\n store i16 %sdiv, ptr %gep.dst, align 2\n %iv.next = add i64 %iv, 1\n %icmp = icmp ult i64 %iv, 14933\n br i1 %icmp, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n"}, {"test_name": "test_scalarize_with_branch_cond", "test_body": "define void @test_scalarize_with_branch_cond(ptr %src, ptr %dst) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %d = phi i1 [ false, %entry ], [ %d.next, %loop.latch ]\n %d.next = xor i1 %d, true\n br i1 %d, label %cond.false, label %loop.latch\n\ncond.false: ; preds = %loop.header\n %gep.src = getelementptr inbounds i32, ptr %src, i64 %iv\n %gep.dst = getelementptr inbounds i32, ptr %dst, i64 %iv\n %l = load i32, ptr %gep.src, align 4\n store i32 %l, ptr %gep.dst, align 4\n br label %loop.latch\n\nloop.latch: ; preds = %cond.false, %loop.header\n %iv.next = add nsw i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 1000\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret void\n}\n"}]}], "issue": {"title": "Assertion `State.VF.isVector() && \"Not vectorizing?\"' failed.", "body": "Run opt with -passes=loop-vectorize\r\n\r\nhttps://godbolt.org/z/xdrTfEddx\r\n\r\nTest.ll\r\n```\r\n; ModuleID = './reduced.ll'\r\nsource_filename = \"./reduced.ll\"\r\ntarget datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-ni:1-p2:32:8:8:32-ni:2\"\r\ntarget triple = \"aarch64-none-linux-gnu\"\r\n\r\ndefine void @wombat(i16 %arg) gc \"statepoint-example\" {\r\nbb:\r\n br label %bb1\r\n\r\nbb1: ; preds = %bb1, %bb\r\n %phi = phi i64 [ 0, %bb ], [ %add, %bb1 ]\r\n %sext = sext i8 0 to i32\r\n %add = add i64 %phi, 1\r\n %trunc = trunc i32 %sext to i16\r\n %sdiv = sdiv i16 0, %arg\r\n %sext2 = sext i16 %trunc to i32\r\n %sext3 = sext i32 %sext2 to i64\r\n %icmp = icmp ult i64 %phi, 14933\r\n br i1 %icmp, label %bb1, label %bb4\r\n\r\nbb4: ; preds = %bb1\r\n %phi5 = phi i64 [ %sext3, %bb1 ]\r\n ret void\r\n}\r\n```", "author": "TatyanaDoubts", "labels": ["vectorizers", "crash"], "comments": [{"author": "fhahn", "body": "Taking a look now!"}]}, "verified": true} {"bug_id": "99899", "issue_url": "https://github.com/llvm/llvm-project/issues/99899", "bug_type": "crash", "base_commit": "9a8b0407fc16af4ca6f79a2583297318a645d88a", "knowledge_cutoff": "2024-07-22T17:02:03Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "3cb82f49dc990dc20a765856c0e126193992fe44", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[9699, 9705]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["BoUpSLP::getEntryCost"]}}, "patch": "commit 3cb82f49dc990dc20a765856c0e126193992fe44\nAuthor: Alexey Bataev \nDate: Mon Jul 22 12:45:28 2024 -0700\n\n [SLP]Fix PR99899: Use canonical type instead of original vector of ptr.\n \n Use adjusted canonical integer type instead of the original ptr type to\n fix the crash in the TTI.\n Fixes https://github.com/llvm/llvm-project/issues/99899\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex 667c4eb311c2..cca9eeebaa53 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -9699,7 +9699,8 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef VectorizedVals,\n CanonicalType = CanonicalType->getWithNewType(IntegerType::get(\n CanonicalType->getContext(),\n DL->getTypeSizeInBits(CanonicalType->getScalarType())));\n- IntrinsicCostAttributes CostAttrs(MinMaxID, VecTy, {VecTy, VecTy});\n+ IntrinsicCostAttributes CostAttrs(MinMaxID, CanonicalType,\n+ {CanonicalType, CanonicalType});\n InstructionCost IntrinsicCost =\n TTI->getIntrinsicInstrCost(CostAttrs, CostKind);\n // If the selects are the only uses of the compares, they will be\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/SystemZ/cmp-ptr-minmax.ll", "commands": ["opt -S --passes=slp-vectorizer -mtriple=s390x-unknown-linux-gnu -mcpu=z16 -slp-threshold=-10 < %s"], "tests": [{"test_name": "", "test_body": "\ndefine i1 @test(i64 %0, i64 %1, ptr %2) {\n;\nentry:\n %gep44 = getelementptr i8, ptr null, i64 %0\n %gep45 = getelementptr i8, ptr null, i64 %1\n %4 = icmp ult ptr %gep44, %gep45\n %umin = select i1 %4, ptr %gep44, ptr %gep45\n %gep48 = getelementptr i8, ptr null, i64 %0\n %gep49 = getelementptr i8, ptr null, i64 %1\n %5 = icmp ult ptr %gep48, %gep49\n %umin50 = select i1 %5, ptr %gep48, ptr %gep49\n %b095 = icmp ult ptr %umin, %2\n %b196 = icmp ult ptr %umin50, %2\n %res = and i1 %b095, %b196\n ret i1 %res\n}"}]}], "issue": {"title": "[SLP] crash after 8ff233f", "body": "8ff233f \"[SLP]Correctly detect minnum/maxnum patterns for select/cmp operations on floats.\" seems to have introduced a problem when building SPEC on SystemZ.\r\n\r\nopt -mtriple=s390x-linux-gnu -mcpu=z16 -O3 ./tc_slp.ll -o /dev/null\r\nopt: /home/ijonpan/llvm-project/llvm/include/llvm/IR/DerivedTypes.h:704: llvm::Type* llvm::Type::getWithNewBitWidth(unsigned int) const: Assertion `isIntOrIntVectorTy() && \"Original type expected to be a vector of integers or a scalar integer.\"' failed.\r\n...\r\n#15 0x000000000519c8f8 llvm::slpvectorizer::BoUpSLP::getEntryCost\r\n\r\n[tc_slp.ll.tar.gz](https://github.com/user-attachments/files/16337301/tc_slp.ll.tar.gz)\r\n", "author": "JonPsson1", "labels": ["llvm:SLPVectorizer", "crash-on-valid"], "comments": []}, "verified": true} {"bug_id": "99411", "issue_url": "https://github.com/llvm/llvm-project/issues/99411", "bug_type": "crash", "base_commit": "cb3de24b5c0a662ba4a03c6c06a2d765d558bf62", "knowledge_cutoff": "2024-07-18T00:03:03Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "b634e057ddecc41dce046887d0f0854fed305374", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[11852, 11859]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["castToScalarTyElem"]}}, "patch": "commit b634e057ddecc41dce046887d0f0854fed305374\nAuthor: Han-Kuan Chen \nDate: Thu Jul 18 19:54:46 2024 +0800\n\n [SLP][REVEC] Fix false assumption of the source for castToScalarTyElem. (#99424)\n \n The argument V may come from adjustExtracts, which is the vector operand\n of ExtractElementInst. In addition, it is not existed in getTreeEntry.\n \n The vector operand of ExtractElementInst may have a type of <1 x Ty>,\n ensuring that the number of elements in ScalarTy and VecTy are equal.\n \n reference: https://github.com/llvm/llvm-project/issues/99411\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex d88c6307b994..b994645cece6 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -11852,8 +11852,7 @@ class BoUpSLP::ShuffleInstructionBuilder final : public BaseShuffleAnalysis {\n Value *castToScalarTyElem(Value *V,\n std::optional IsSigned = std::nullopt) {\n auto *VecTy = cast(V->getType());\n- assert(getNumElements(ScalarTy) < getNumElements(VecTy) &&\n- (getNumElements(VecTy) % getNumElements(ScalarTy) == 0));\n+ assert(getNumElements(VecTy) % getNumElements(ScalarTy) == 0);\n if (VecTy->getElementType() == ScalarTy->getScalarType())\n return V;\n return Builder.CreateIntCast(\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/revec-fix-99411.ll", "commands": ["opt -mtriple x86_64-unknown-linux-gnu -passes=slp-vectorizer -S %s"], "tests": [{"test_name": "", "test_body": "\ndefine void @e() {\n;\nentry:\n %0 = extractelement <1 x i64> zeroinitializer, i64 0\n %bf.value = and i64 %0, 0\n %bf.set = or i64 0, %bf.value\n store i64 %bf.set, ptr getelementptr inbounds (i8, ptr null, i64 8), align 8\n %bf.value2 = and i64 0, 0\n %bf.set4 = or i64 0, %bf.value2\n store i64 %bf.set4, ptr null, align 8\n ret void\n}"}]}], "issue": {"title": "A/F: `getNumElements(ScalarTy) < getNumElements(VecTy) && (getNumElements(VecTy) % getNumElements(ScalarTy) == 0)' failed after 1813ffd", "body": "Several of our internal tests started hitting an assertion failure while building, one of which I bisected back to commit 1813ffd. Consider the following code:\r\n```c++\r\ntypedef long long __m64 __attribute__((__vector_size__(8), __aligned__(8)));\r\nstatic __inline__ long long foo(__m64 m) { return (long long) m; }\r\nstruct c {\r\n long a : 43;\r\n long b : 61;\r\n} d;\r\nvoid e() {\r\n volatile __m64 f;\r\n long g, i = d.b = g = foo(f);\r\n d.a = i;\r\n}\r\n```\r\nWhen compiled with optimizations with a compiler that includes 1813ffd, it hits an assertion failure:\r\n```\r\n$ ~/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang -c -O2 repro.cpp \r\nclang: /home/dyung/src/upstream/llvm_clean_git/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:11853: llvm::Value* llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::castToScalarTyElem(llvm::Value*, std::optional): Assertion `getNumElements(ScalarTy) < getNumElements(VecTy) && (getNumElements(VecTy) % getNumElements(ScalarTy) == 0)' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.\r\nStack dump:\r\n0. Program arguments: /home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang -c -O2 repro.cpp\r\n1. parser at end of file\r\n2. Optimizer\r\n3. Running pass \"function(float2int,lower-constant-intrinsics,loop(loop-rotate,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize,infer-alignment,loop-load-elim,instcombine,simplifycfg,slp-vectorizer,vector-combine,instcombine,loop-unroll,transform-warning,sroa,infer-alignment,instcombine,loop-mssa(licm),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg)\" on module \"repro.cpp\" \r\n4. Running pass \"slp-vectorizer\" on function \"_Z7test119v\"\r\n #0 0x00005650f775179f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x41a279f) \r\n #1 0x00005650f774f2fc llvm::sys::CleanupOnSignal(unsigned long) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x41a02fc) \r\n #2 0x00005650f76947e8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0 \r\n #3 0x00007ff89a3f9420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420) \r\n #4 0x00007ff899ec600b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1 \r\n #5 0x00007ff899ea5859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7 \r\n #6 0x00007ff899ea5729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8 \r\n #7 0x00007ff899ea5729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34 \r\n #8 0x00007ff899eb6fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6) \r\n #9 0x00005650f903005c llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::castToScalarTyElem(llvm::Value*, std::optional) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5a8105c)\r\n#10 0x00005650f9071f00 llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::adjustExtracts(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::MutableArrayRef, llvm::ArrayRef>, unsigned int, bool&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5ac2f00) \r\n#11 0x00005650f909dfdd llvm::Value* llvm::slpvectorizer::BoUpSLP::processBuildVector, llvm::slpvectorizer::BoUpSLP>(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::Type*, llvm::IRBuilder&, llvm::slpvectorizer::BoUpSLP&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5aeefdd)\r\n#12 0x00005650f90a941a llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5afa41a)\r\n#13 0x00005650f90a80e3 llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5af90e3)\r\n#14 0x00005650f90a9484 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5afa484)\r\n#15 0x00005650f90a7cdf llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5af8cdf)\r\n#16 0x00005650f90ac099 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5afd099)\r\n#17 0x00005650f90a7cdf llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5af8cdf)\r\n#18 0x00005650f90a9e6c llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5afae6c)\r\n#19 0x00005650f90c7263 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::MapVector, llvm::DenseMap, llvm::detail::DenseMapPair>, llvm::SmallVector>, 0u>> const&, llvm::SmallVectorImpl>&, llvm::Instruction*) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5b18263)\r\n#20 0x00005650f90cacbc llvm::slpvectorizer::BoUpSLP::vectorizeTree() (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5b1bcbc)\r\n#21 0x00005650f90e045b llvm::SLPVectorizerPass::vectorizeStoreChain(llvm::ArrayRef, llvm::slpvectorizer::BoUpSLP&, unsigned int, unsigned int, unsigned int&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5b3145b) \r\n#22 0x00005650f90e1a5e llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet, llvm::DenseMapInfo, void>>&)::'lambda'(std::set, llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet, llvm::DenseMapInfo, void>>&)::StoreDistCompare, std::allocator>> const&)::operator()(std::set, llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet, llvm::DenseMapInfo, void>>&)::StoreDistCompare, std::allocator>> const&) const SLPVectorizer.cpp:0:0\r\n#23 0x00005650f90e39a0 llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet, llvm::DenseMapInfo, void>>&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5b349a0)\r\n#24 0x00005650f90e42c3 llvm::SLPVectorizerPass::vectorizeStoreChains(llvm::slpvectorizer::BoUpSLP&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5b352c3)\r\n#25 0x00005650f90e57dd 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#26 0x00005650f90e6253 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5b37253)\r\n#27 0x00005650f8baedb6 llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x55ffdb6)\r\n#28 0x00005650f70f6421 llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x3b47421)\r\n#29 0x00005650f4cb9ca6 llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x170aca6)\r\n#30 0x00005650f70f4ded llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x3b45ded)\r\n#31 0x00005650f4cbac56 llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x170bc56)\r\n#32 0x00005650f70f2f31 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x3b43f31)\r\n#33 0x00005650f7a062c8 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr>&, std::unique_ptr>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\r\n#34 0x00005650f7a09645 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr>, clang::BackendConsumer*) BackendUtil.cpp:0:0\r\n#35 0x00005650f7a09ce6 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr, std::unique_ptr>, clang::BackendConsumer*) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x445ace6)\r\n#36 0x00005650f808091c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x4ad191c)\r\n#37 0x00005650f9e7fe6c clang::ParseAST(clang::Sema&, bool, bool) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x68d0e6c)\r\n#38 0x00005650f8080d28 clang::CodeGenAction::ExecuteAction() (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x4ad1d28)\r\n#39 0x00005650f8318339 clang::FrontendAction::Execute() (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x4d69339)\r\n#40 0x00005650f829a98e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x4ceb98e)\r\n#41 0x00005650f8403dc6 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x4e54dc6)\r\n#42 0x00005650f489f105 cc1_main(llvm::ArrayRef, char const*, void*) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x12f0105)\r\n#43 0x00005650f489811a ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&) driver.cpp:0:0\r\n#44 0x00005650f80c610d void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0\r\n#45 0x00005650f7694cf0 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x40e5cf0)\r\n#46 0x00005650f80c672f clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0\r\n#47 0x00005650f808aa6c clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x4adba6c)\r\n#48 0x00005650f808b4fd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x4adc4fd)\r\n#49 0x00005650f80935d5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x4ae45d5)\r\n#50 0x00005650f489c37b clang_main(int, char**, llvm::ToolContext const&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x12ed37b)\r\n#51 0x00005650f478ee1b main (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x11dfe1b)\r\n#52 0x00007ff899ea7083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\r\n#53 0x00005650f4897bae _start (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x12e8bae)\r\nclang: error: clang frontend command failed with exit code 134 (use -v to see invocation)\r\nclang version 19.0.0 (https://github.com/llvm/llvm-project.git 1813ffd6b2eb04ee2c296a4399a18748740a439d)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin\r\nBuild config: +assertions\r\n```\r\nIf built using the a compiler built from fa0e529 (the parent commit of 1813ffd), the compilation succeeds:\r\n```\r\n$ ~/src/upstream/fa0e52995929ab67dfb468d71fe793be5e1c7f03-linux/bin/clang -c -O2 repro.cpp\r\n$\r\n```\r\n", "author": "dyung", "labels": ["llvm:SLPVectorizer", "crash"], "comments": [{"author": "madhur13490", "body": "@dyung https://godbolt.org/z/ofneqo6zK I don't see here. Am I missing anything?"}, {"author": "dyung", "body": "> @dyung https://godbolt.org/z/ofneqo6zK I don't see here. Am I missing anything?\r\n\r\nI don't know if it reproduces on an ARM targeting compiler, I used an x86-64 targeting x86-64 compiler. Also the compiler currently used by godbolt was built from commit f56cdd4a45b7bbe84be5d4ba9442eb7071605efc which does not include 1813ffd6b2eb04ee2c296a4399a18748740a439d which introduced the issue."}, {"author": "HanKuanChen", "body": "Close the issue since https://github.com/llvm/llvm-project/commit/b634e057ddecc41dce046887d0f0854fed305374 is merged."}]}, "verified": true} @@ -108,6 +112,8 @@ {"bug_id": "91369", "issue_url": "https://github.com/llvm/llvm-project/issues/91369", "bug_type": "miscompilation", "base_commit": "9a28814f59e8f52cc63ae3d17023cee8348d9b53", "knowledge_cutoff": "2024-05-07T18:12:26Z", "lit_test_dir": ["llvm/test/Transforms/LoopVectorize"], "hints": {"fix_commit": "082c81ae4ab9db6bb0acd52098288223dd58501a", "components": ["LoopVectorize"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [[8841, 8848]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": ["LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes"]}}, "patch": "commit 082c81ae4ab9db6bb0acd52098288223dd58501a\nAuthor: Florian Hahn \nDate: Tue May 7 21:31:40 2024 +0100\n\n [LV] Properly extend versioned constant strides.\n \n We only version unknown strides to 1. If the original type is i1, then\n the sign of the extension matters. Properly extend the stride value\n before replacing it.\n \n Fixes https://github.com/llvm/llvm-project/issues/91369.\n\ndiff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\nindex 3be0102bea3e..261933966b74 100644\n--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n@@ -8841,8 +8841,10 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {\n VPValue *StrideVPV = Plan->getLiveIn(U);\n if (!StrideVPV)\n continue;\n- VPValue *CI = Plan->getOrAddLiveIn(ConstantInt::get(\n- U->getType(), ScevStride->getAPInt().getSExtValue()));\n+ unsigned BW = U->getType()->getScalarSizeInBits();\n+ APInt C = isa(U) ? ScevStride->getAPInt().sext(BW)\n+ : ScevStride->getAPInt().zext(BW);\n+ VPValue *CI = Plan->getOrAddLiveIn(ConstantInt::get(U->getType(), C));\n StrideVPV->replaceAllUsesWith(CI);\n }\n }\n", "tests": [{"file": "llvm/test/Transforms/LoopVectorize/version-stride-with-integer-casts.ll", "commands": ["opt -passes=loop-vectorize -force-vector-width=4 -S %s"], "tests": [{"test_name": "zext_of_i1_stride", "test_body": "target datalayout = \"p:8:8:8\"\n\n; Function Attrs: mustprogress\ndefine void @zext_of_i1_stride(i1 %g, ptr %dst) #0 {\nentry:\n %g.16 = zext i1 %g to i16\n %g.64 = zext i1 %g to i64\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep = getelementptr inbounds i16, ptr %dst, i64 %iv\n store i16 %g.16, ptr %gep, align 2\n %iv.next = add nuw nsw i64 %iv, %g.64\n %cmp = icmp ult i64 %iv.next, 16\n br i1 %cmp, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { mustprogress }\n", "additional_args": "-src-unroll=32 -tgt-unroll=32"}]}], "issue": {"title": "[LoopVectorize] Sign-extension miscompile", "body": "C Testcase:\r\n```c\r\nlong a, d;\r\nshort b[20];\r\nshort c[20];\r\n_Bool e[20];\r\nint f(_Bool g) {\r\n for (long h = 0; h < 16; h += g)\r\n b[h] = (short) g;\r\n for (int i = 0; i < 12; i++)\r\n for (int j = d; j; j++)\r\n c[i] = (short) a < e[i];\r\n return (int) b[0];\r\n}\r\nint main() {\r\n __builtin_printf(\"%X\\n\", f(1));\r\n}\r\n```\r\nGodbolt: https://godbolt.org/z/3E8frs1Me\r\n\r\nWith loop-vectorize: `FFFFFFFF`\r\nWithout loop-vectorize: `1`\r\n\r\nReduced LLVM IR:\r\n```llvm ir\r\n; ModuleID = 'red.ll'\r\nsource_filename = \"red.c\"\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@b = global [20 x i16] zeroinitializer, align 2\r\n@.str = constant [4 x i8] c\"%X\\0A\\00\"\r\n\r\n; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable vscale_range(2,1024)\r\ndefine i32 @f(i1 %g) #0 {\r\nentry:\r\n %conv = zext i1 %g to i16\r\n %zext.g.i64 = zext i1 %g to i64\r\n br label %for.body\r\n\r\nfor.cond3.preheader: ; preds = %for.body\r\n %0 = load i64, ptr @b, align 2\r\n %zero = and i64 %0, 0\r\n %true = icmp eq i64 %zero, 0\r\n %2 = load i16, ptr @b, align 2\r\n %conv26 = sext i16 %2 to i32\r\n ret i32 %conv26\r\n\r\nfor.body: ; preds = %for.body, %entry\r\n %phi.0 = phi i64 [ 0, %entry ], [ %add, %for.body ]\r\n %idx.0 = getelementptr inbounds [20 x i16], ptr @b, i64 0, i64 %phi.0\r\n store i16 %conv, ptr %idx.0, align 2\r\n %add = add nuw nsw i64 %phi.0, %zext.g.i64\r\n %cmp = icmp ult i64 %add, 16\r\n br i1 %cmp, label %for.body, label %for.cond3.preheader, !llvm.loop !0\r\n}\r\n\r\n; Function Attrs: nofree nounwind uwtable vscale_range(2,1024)\r\ndefine noundef signext i32 @main() #1 {\r\nentry:\r\n %call = tail call signext i32 @f(i1 noundef zeroext true)\r\n %call1 = tail call signext i32 (ptr, ...) @printf(ptr noundef nonnull @.str, i32 noundef signext %call) #3\r\n ret i32 0\r\n}\r\n\r\n; Function Attrs: nofree nounwind\r\ndeclare noundef signext i32 @printf(ptr nocapture noundef readonly, ...) #2\r\n\r\nattributes #0 = { nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable vscale_range(2,1024) \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"generic-rv64\" \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-e,-experimental-smmpm,-experimental-smnpm,-experimental-ssnpm,-experimental-sspm,-experimental-ssqosid,-experimental-supm,-experimental-zaamo,-experimental-zabha,-experimental-zalasr,-experimental-zalrsc,-experimental-zfbfmin,-experimental-zicfilp,-experimental-zicfiss,-experimental-ztso,-experimental-zvfbfmin,-experimental-zvfbfwma,-h,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smepmp,-smstateen,-ssaia,-ssccptr,-sscofpmf,-sscounterenw,-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,-za128rs,-za64rs,-zacas,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-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,-zmmul,-zvbb,-zvbc,-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\nattributes #1 = { nofree nounwind uwtable vscale_range(2,1024) \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"generic-rv64\" \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-e,-experimental-smmpm,-experimental-smnpm,-experimental-ssnpm,-experimental-sspm,-experimental-ssqosid,-experimental-supm,-experimental-zaamo,-experimental-zabha,-experimental-zalasr,-experimental-zalrsc,-experimental-zfbfmin,-experimental-zicfilp,-experimental-zicfiss,-experimental-ztso,-experimental-zvfbfmin,-experimental-zvfbfwma,-h,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smepmp,-smstateen,-ssaia,-ssccptr,-sscofpmf,-sscounterenw,-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,-za128rs,-za64rs,-zacas,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-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,-zmmul,-zvbb,-zvbc,-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\nattributes #2 = { nofree nounwind \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"generic-rv64\" \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-e,-experimental-smmpm,-experimental-smnpm,-experimental-ssnpm,-experimental-sspm,-experimental-ssqosid,-experimental-supm,-experimental-zaamo,-experimental-zabha,-experimental-zalasr,-experimental-zalrsc,-experimental-zfbfmin,-experimental-zicfilp,-experimental-zicfiss,-experimental-ztso,-experimental-zvfbfmin,-experimental-zvfbfwma,-h,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smepmp,-smstateen,-ssaia,-ssccptr,-sscofpmf,-sscounterenw,-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,-za128rs,-za64rs,-zacas,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-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,-zmmul,-zvbb,-zvbc,-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\nattributes #3 = { nounwind }\r\n\r\n!0 = distinct !{!0, !1}\r\n!1 = !{!\"llvm.loop.mustprogress\"}\r\n```\r\nLoopVectorize pass.\r\n\r\nLooks like a sext/zext related issue.", "author": "patrick-rivos", "labels": ["miscompilation", "vectorizers"], "comments": []}, "verified": true} {"bug_id": "121110", "issue_url": "https://github.com/llvm/llvm-project/issues/121110", "bug_type": "miscompilation", "base_commit": "f68dbbbd57dd0947730300d1e827ad16c2dfffb5", "knowledge_cutoff": "2024-12-25T13:57:11Z", "lit_test_dir": ["llvm/test/Transforms/VectorCombine"], "hints": {"fix_commit": "f2f02b21cd581057e3c9b4a7a27e0014eeb9ba15", "components": ["VectorCombine"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": [[1669, 1675], [1677, 1684], [1727, 1740], [1750, 1759]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": ["VectorCombine::foldShuffleOfBinops"]}}, "patch": "commit f2f02b21cd581057e3c9b4a7a27e0014eeb9ba15\nAuthor: Simon Pilgrim \nDate: Sat Dec 28 09:21:22 2024 +0000\n\n [VectorCombine] foldShuffleOfBinops - only accept exact matching cmp predicates\n \n m_SpecificCmp allowed equivalent predicate+flags which don't necessarily work after being folded from \"shuffle (cmpop), (cmpop)\" into \"cmpop (shuffle), (shuffle)\"\n \n Fixes #121110\n\ndiff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp\nindex ecbc13d489eb..2460ccc61d84 100644\n--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp\n+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp\n@@ -1669,7 +1669,8 @@ bool VectorCombine::foldShuffleOfBinops(Instruction &I) {\n \n Value *X, *Y, *Z, *W;\n bool IsCommutative = false;\n- CmpPredicate Pred = CmpInst::BAD_ICMP_PREDICATE;\n+ CmpPredicate PredLHS = CmpInst::BAD_ICMP_PREDICATE;\n+ CmpPredicate PredRHS = CmpInst::BAD_ICMP_PREDICATE;\n if (match(LHS, m_BinOp(m_Value(X), m_Value(Y))) &&\n match(RHS, m_BinOp(m_Value(Z), m_Value(W)))) {\n auto *BO = cast(LHS);\n@@ -1677,8 +1678,9 @@ bool VectorCombine::foldShuffleOfBinops(Instruction &I) {\n if (llvm::is_contained(OldMask, PoisonMaskElem) && BO->isIntDivRem())\n return false;\n IsCommutative = BinaryOperator::isCommutative(BO->getOpcode());\n- } else if (match(LHS, m_Cmp(Pred, m_Value(X), m_Value(Y))) &&\n- match(RHS, m_SpecificCmp(Pred, m_Value(Z), m_Value(W)))) {\n+ } else if (match(LHS, m_Cmp(PredLHS, m_Value(X), m_Value(Y))) &&\n+ match(RHS, m_Cmp(PredRHS, m_Value(Z), m_Value(W))) &&\n+ (CmpInst::Predicate)PredLHS == (CmpInst::Predicate)PredRHS) {\n IsCommutative = cast(LHS)->isCommutative();\n } else\n return false;\n@@ -1727,14 +1729,14 @@ bool VectorCombine::foldShuffleOfBinops(Instruction &I) {\n TTI.getShuffleCost(SK0, BinOpTy, NewMask0, CostKind, 0, nullptr, {X, Z}) +\n TTI.getShuffleCost(SK1, BinOpTy, NewMask1, CostKind, 0, nullptr, {Y, W});\n \n- if (Pred == CmpInst::BAD_ICMP_PREDICATE) {\n+ if (PredLHS == CmpInst::BAD_ICMP_PREDICATE) {\n NewCost +=\n TTI.getArithmeticInstrCost(LHS->getOpcode(), ShuffleDstTy, CostKind);\n } else {\n auto *ShuffleCmpTy =\n FixedVectorType::get(BinOpTy->getElementType(), ShuffleDstTy);\n NewCost += TTI.getCmpSelInstrCost(LHS->getOpcode(), ShuffleCmpTy,\n- ShuffleDstTy, Pred, CostKind);\n+ ShuffleDstTy, PredLHS, CostKind);\n }\n \n LLVM_DEBUG(dbgs() << \"Found a shuffle feeding two binops: \" << I\n@@ -1750,10 +1752,10 @@ bool VectorCombine::foldShuffleOfBinops(Instruction &I) {\n \n Value *Shuf0 = Builder.CreateShuffleVector(X, Z, NewMask0);\n Value *Shuf1 = Builder.CreateShuffleVector(Y, W, NewMask1);\n- Value *NewBO = Pred == CmpInst::BAD_ICMP_PREDICATE\n+ Value *NewBO = PredLHS == CmpInst::BAD_ICMP_PREDICATE\n ? Builder.CreateBinOp(\n cast(LHS)->getOpcode(), Shuf0, Shuf1)\n- : Builder.CreateCmp(Pred, Shuf0, Shuf1);\n+ : Builder.CreateCmp(PredLHS, Shuf0, Shuf1);\n \n // Intersect flags from the old binops.\n if (auto *NewInst = dyn_cast(NewBO)) {\n", "tests": [{"file": "llvm/test/Transforms/VectorCombine/X86/shuffle-of-cmps.ll", "commands": ["opt < %s -passes=vector-combine -S -mtriple=x86_64-- -mattr=sse2", "opt < %s -passes=vector-combine -S -mtriple=x86_64-- -mattr=sse4.2", "opt < %s -passes=vector-combine -S -mtriple=x86_64-- -mattr=avx2", "opt < %s -passes=vector-combine -S -mtriple=x86_64-- -mattr=avx512vl"], "tests": [{"test_name": "shuf_icmp_ugt_v4i32_use", "test_body": "declare void @use(<4 x i1>)\n\ndefine <4 x i32> @shuf_icmp_ugt_v4i32_use(<4 x i32> %x, <4 x i32> %y, <4 x i32> %z, <4 x i32> %w) {\n %c0 = icmp ugt <4 x i32> %x, %y\n %c1 = icmp ugt <4 x i32> %z, %w\n call void @use(<4 x i1> %c0)\n %s = shufflevector <4 x i1> %c0, <4 x i1> %c1, <4 x i32> \n %r = sext <4 x i1> %s to <4 x i32>\n ret <4 x i32> %r\n}\n"}, {"test_name": "PR121110", "test_body": "define <2 x i1> @PR121110() {\n %ugt = icmp samesign ugt <2 x i32> zeroinitializer, zeroinitializer\n %sgt = icmp sgt <2 x i32> zeroinitializer, \n %res = shufflevector <2 x i1> %ugt, <2 x i1> %sgt, <2 x i32> \n ret <2 x i1> %res\n}\n"}]}], "issue": {"title": "[clang] Miscompilation at -Os", "body": "This code prints 9 at `-Os` and 0 at `-O0/1/2/3`:\n\n```c\nint printf(const char *, ...);\nchar a = 9, c, d;\nint b, e;\nunsigned short f;\nchar *g = &a;\nvoid h(int i) {\n for (; b; b++)\n c &= 0 <= i;\n}\nstatic short j(unsigned long i) {\n int k;\n for (; e + d + 4 > 0;) {\n k = i + 49;\n h(k + i - 52 + i);\n *g = 0;\n return 0;\n }\n return 0;\n}\nint main() {\n j(6 < (unsigned short)(f - 7) + f);\n printf(\"%d\\n\", a);\n}\n```\n\nCompiler Explorer: https://godbolt.org/z/Mo5TEKh8r\n\nBisected to https://github.com/llvm/llvm-project/commit/5287299f8809ae927a0acafb179c4b37ce9ff21d, which was committed by @RKSimon ", "author": "cardigan1008", "labels": ["miscompilation", "vectorizers"], "comments": [{"author": "RKSimon", "body": "I'm not convinced the patch is responsible, it's more likely exposed something else. I'll take a look after the Christmas break."}, {"author": "dtcxzyw", "body": "Reproducer: https://alive2.llvm.org/ce/z/jdkwFh\n```\n; bin/opt -passes=vector-combine test.ll -S\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine <2 x i1> @src() {\nentry:\n %0 = icmp samesign ugt <2 x i32> zeroinitializer, zeroinitializer\n %1 = icmp sgt <2 x i32> zeroinitializer, \n %2 = shufflevector <2 x i1> %0, <2 x i1> %1, <2 x i32> \n ret <2 x i1> %2\n}\n```\n```\ndefine <2 x i1> @tgt() {\nentry:\n ret <2 x i1> zeroinitializer\n}\n```\n```\n\n----------------------------------------\ndefine <2 x i1> @src() {\nentry:\n %#0 = icmp samesign ugt <2 x i32> { 0, 0 }, { 0, 0 }\n %#1 = icmp sgt <2 x i32> { 0, 0 }, { 6, 4294967292 }\n %#2 = shufflevector <2 x i1> %#0, <2 x i1> %#1, 0, 3\n ret <2 x i1> %#2\n}\n=>\ndefine <2 x i1> @tgt() {\nentry:\n ret <2 x i1> { 0, 0 }\n}\nTransformation doesn't verify!\n\nERROR: Value mismatch\n\nExample:\n\nSource:\n<2 x i1> %#0 = < #x0 (0), #x0 (0) >\n<2 x i1> %#1 = < #x0 (0), #x1 (1) >\n<2 x i1> %#2 = < #x0 (0), #x1 (1) >\n\nTarget:\nSource value: < #x0 (0), #x1 (1) >\nTarget value: < #x0 (0), #x0 (0) >\n```\n"}]}, "verified": true} {"bug_id": "77468", "issue_url": "https://github.com/llvm/llvm-project/issues/77468", "bug_type": "crash", "base_commit": "39b2104b4a4e0990eddc763eab99b28e8deab953", "knowledge_cutoff": "2024-01-09T13:19:28Z", "lit_test_dir": ["llvm/test/Transforms/LoopVectorize"], "hints": {"fix_commit": "59d6f033a25d161e494457e8bb6e30375eb7f40f", "components": ["LoopVectorize"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": [[895, 901], [948, 953], [979, 995]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": ["VPlanTransforms::truncateToMinimalBitwidths"]}}, "patch": "commit 59d6f033a25d161e494457e8bb6e30375eb7f40f\nAuthor: Florian Hahn \nDate: Fri Jan 12 13:14:13 2024 +0000\n\n [VPlan] Support narrowing widened loads in truncateToMinimimalBitwidths.\n \n MinBWs may also contain widened load instructions, handle them by only\n narrowing their result.\n \n Fixes https://github.com/llvm/llvm-project/issues/77468\n\ndiff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp\nindex 5c430620a2dc..b3694e74a385 100644\n--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp\n+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp\n@@ -895,7 +895,10 @@ void VPlanTransforms::truncateToMinimalBitwidths(\n vp_depth_first_deep(Plan.getVectorLoopRegion()))) {\n for (VPRecipeBase &R : make_early_inc_range(*VPBB)) {\n if (!isa(&R))\n+ VPWidenSelectRecipe, VPWidenMemoryInstructionRecipe>(&R))\n+ continue;\n+ if (isa(&R) &&\n+ cast(&R)->isStore())\n continue;\n \n VPValue *ResultVPV = R.getVPSingleValue();\n@@ -948,6 +951,23 @@ void VPlanTransforms::truncateToMinimalBitwidths(\n \n auto *NewResTy = IntegerType::get(Ctx, NewResSizeInBits);\n \n+ // Any wrapping introduced by shrinking this operation shouldn't be\n+ // considered undefined behavior. So, we can't unconditionally copy\n+ // arithmetic wrapping flags to VPW.\n+ if (auto *VPW = dyn_cast(&R))\n+ VPW->dropPoisonGeneratingFlags();\n+\n+ // Extend result to original width.\n+ auto *Ext = new VPWidenCastRecipe(Instruction::ZExt, ResultVPV, OldResTy);\n+ Ext->insertAfter(&R);\n+ ResultVPV->replaceAllUsesWith(Ext);\n+ Ext->setOperand(0, ResultVPV);\n+\n+ if (isa(&R)) {\n+ assert(!cast(&R)->isStore() && \"stores cannot be narrowed\");\n+ continue;\n+ }\n+\n // Shrink operands by introducing truncates as needed.\n unsigned StartIdx = isa(&R) ? 1 : 0;\n for (unsigned Idx = StartIdx; Idx != R.getNumOperands(); ++Idx) {\n@@ -979,17 +999,6 @@ void VPlanTransforms::truncateToMinimalBitwidths(\n }\n }\n \n- // Any wrapping introduced by shrinking this operation shouldn't be\n- // considered undefined behavior. So, we can't unconditionally copy\n- // arithmetic wrapping flags to VPW.\n- if (auto *VPW = dyn_cast(&R))\n- VPW->dropPoisonGeneratingFlags();\n-\n- // Extend result to original width.\n- auto *Ext = new VPWidenCastRecipe(Instruction::ZExt, ResultVPV, OldResTy);\n- Ext->insertAfter(&R);\n- ResultVPV->replaceAllUsesWith(Ext);\n- Ext->setOperand(0, ResultVPV);\n }\n }\n \n", "tests": [{"file": "llvm/test/Transforms/LoopVectorize/trunc-loads-p16.ll", "commands": ["opt -p loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S %s"], "tests": [{"test_name": "pr77468", "test_body": "target datalayout = \"p:16:16\"\n\ndefine void @pr77468(ptr noalias %src, ptr noalias %dst, i1 %x) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i16 [ 0, %entry ], [ %iv.next, %loop ]\n %gep.src = getelementptr i32, ptr %src, i16 %iv\n %l = load i32, ptr %gep.src, align 1\n %x.ext = zext i1 %x to i32\n %and = and i32 %x.ext, %l\n %gep.dst = getelementptr i16, ptr %dst, i16 %iv\n %t = trunc i32 %and to i16\n store i16 %t, ptr %gep.dst, align 2\n %iv.next = add i16 %iv, 1\n %exitcond.not = icmp eq i16 %iv.next, 100\n br i1 %exitcond.not, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n"}]}], "issue": {"title": "Assertion `MinBWs.size() == NumProcessedRecipes && \"some entries in MinBWs haven't been processed\"' failed. for opt -passes=loop-vectorize", "body": "llvm commit: c1ed45a271145\r\nReproduce with: ```opt -passes=\"loop-vectorize\" bbi-90681_2.ll -S -o /dev/null -mtriple=x86_64```\r\nResult:\r\n```\r\nopt: ../lib/Transforms/Vectorize/VPlanTransforms.cpp:997: static void llvm::VPlanTransforms::truncateToMinimalBitwidths(llvm::VPlan &, const MapVector &, llvm::LLVMContext &): Assertion `MinBWs.size() == NumProcessedRecipes && \"some entries in MinBWs haven't been processed\"' 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: ../../main-github/llvm/build-all/bin/opt -passes=loop-vectorize bbi-90681_2.ll -S -o /dev/null -mtriple=x86_64\r\n #0 0x0000563bdd2b15d7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (../../main-github/llvm/build-all/bin/opt+0x63c95d7)\r\n #1 0x0000563bdd2af12e llvm::sys::RunSignalHandlers() (../../main-github/llvm/build-all/bin/opt+0x63c712e)\r\n #2 0x0000563bdd2b1c9f SignalHandler(int) (../../main-github/llvm/build-all/bin/opt+0x63c9c9f)\r\n #3 0x00007f87a7de7630 __restore_rt (/lib64/libpthread.so.0+0xf630)\r\n #4 0x00007f87a552e387 raise (/lib64/libc.so.6+0x36387)\r\n #5 0x00007f87a552fa78 abort (/lib64/libc.so.6+0x37a78)\r\n #6 0x00007f87a55271a6 __assert_fail_base (/lib64/libc.so.6+0x2f1a6)\r\n #7 0x00007f87a5527252 (/lib64/libc.so.6+0x2f252)\r\n #8 0x0000563bdd584d86 (../../main-github/llvm/build-all/bin/opt+0x669cd86)\r\n #9 0x0000563bdd50f875 llvm::LoopVectorizationPlanner::buildVPlansWithVPRecipes(llvm::ElementCount, llvm::ElementCount) (../../main-github/llvm/build-all/bin/opt+0x6627875)\r\n#10 0x0000563bdd50eeec llvm::LoopVectorizationPlanner::plan(llvm::ElementCount, unsigned int) (../../main-github/llvm/build-all/bin/opt+0x6626eec)\r\n#11 0x0000563bdd522bc9 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (../../main-github/llvm/build-all/bin/opt+0x663abc9)\r\n#12 0x0000563bdd5289b3 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*) (../../main-github/llvm/build-all/bin/opt+0x66409b3)\r\n#13 0x0000563bdd529318 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager&) (../../main-github/llvm/build-all/bin/opt+0x6641318)\r\n#14 0x0000563bdd4cafad llvm::detail::PassModel >::run(llvm::Function&, llvm::AnalysisManager&) (../../main-github/llvm/build-all/bin/opt+0x65e2fad)\r\n#15 0x0000563bdcce36d4 llvm::PassManager >::run(llvm::Function&, llvm::AnalysisManager&) (../../main-github/llvm/build-all/bin/opt+0x5dfb6d4)\r\n#16 0x0000563bdb09c87d llvm::detail::PassModel >, llvm::PreservedAnalyses, llvm::AnalysisManager >::run(llvm::Function&, llvm::AnalysisManager&) (../../main-github/llvm/build-all/bin/opt+0x41b487d)\r\n#17 0x0000563bdcce7abe llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (../../main-github/llvm/build-all/bin/opt+0x5dffabe)\r\n#18 0x0000563bdb09c61d llvm::detail::PassModel >::run(llvm::Module&, llvm::AnalysisManager&) (../../main-github/llvm/build-all/bin/opt+0x41b461d)\r\n#19 0x0000563bdcce27f6 llvm::PassManager >::run(llvm::Module&, llvm::AnalysisManager&) (../../main-github/llvm/build-all/bin/opt+0x5dfa7f6)\r\n#20 0x0000563bdabb7143 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (../../main-github/llvm/build-all/bin/opt+0x3ccf143)\r\n#21 0x0000563bdabc5844 main (../../main-github/llvm/build-all/bin/opt+0x3cdd844)\r\n#22 0x00007f87a551a555 __libc_start_main (/lib64/libc.so.6+0x22555)\r\n#23 0x0000563bdabb12e9 _start (../../main-github/llvm/build-all/bin/opt+0x3cc92e9)\r\nAbort (core dumped)\r\n```\r\n[bbi-90681_2.ll.gz](https://github.com/llvm/llvm-project/files/13874170/bbi-90681_2.ll.gz)\r\n", "author": "mikaelholmen", "labels": ["vectorizers", "crash"], "comments": [{"author": "mikaelholmen", "body": "This starts happening with 70535f5e609f747c28\r\n```\r\n[VPlan] Replace IR based truncateToMinimalBitwidths with VPlan version.\r\n```\r\nPing @fhahn \r\n"}, {"author": "mikaelholmen", "body": "Thanks!"}]}, "verified": true} +{"bug_id": "121518", "issue_url": "https://github.com/llvm/llvm-project/issues/121518", "bug_type": "crash", "base_commit": "2a5050aa5ef56b01cf4a8f73e0d0eddd6d9ce2a9", "knowledge_cutoff": "2025-01-02T20:14:01Z", "lit_test_dir": ["llvm/test/Transforms/LoopVectorize"], "hints": {"fix_commit": "e258bca9505f35e0a22cb213a305eea9b76d11ea", "components": ["LoopVectorize", "ScalarEvolution"], "bug_location_lineno": {"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": [[1451, 1457]], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": [[3404, 3410]], "llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": [[30, 40]]}, "bug_location_funcname": {"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": ["SCEVExpander::expandCodeFor"], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": ["VPExpandSCEVRecipe::execute"], "llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": ["vputils::getOrCreateVPValueForSCEVExpr"]}}, "patch": "commit e258bca9505f35e0a22cb213a305eea9b76d11ea\nAuthor: Florian Hahn \nDate: Tue Feb 11 13:03:12 2025 +0100\n\n [VPlan] Only skip expansion for SCEVUnknown if it isn't an instruction. (#125235)\n \n Update getOrCreateVPValueForSCEVExpr to only skip expansion of\n SCEVUnknown if the underlying value isn't an instruction. Instructions\n may be defined in a loop and using them without expansion may break\n LCSSA form. SCEVExpander will take care of preserving LCSSA if needed.\n \n We could also try to pass LoopInfo, but there are some users of the\n function where it won't be available and main benefit from skipping\n expansion is slightly more concise VPlans.\n \n Note that SCEVExpander is now used to expand SCEVUnknown with floats.\n Adjust the check in expandCodeFor to only check the types and casts if\n the type of the value is different to the requested type. Otherwise we\n crash when trying to expand a float and requesting a float type.\n \n Fixes https://github.com/llvm/llvm-project/issues/121518.\n \n PR: https://github.com/llvm/llvm-project/pull/125235\n\ndiff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp\nindex 3a761bc4e811..d429fe96f9be 100644\n--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp\n+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp\n@@ -1451,7 +1451,7 @@ Value *SCEVExpander::expandCodeFor(const SCEV *SH, Type *Ty) {\n // Expand the code for this SCEV.\n Value *V = expand(SH);\n \n- if (Ty) {\n+ if (Ty && Ty != V->getType()) {\n assert(SE.getTypeSizeInBits(Ty) == SE.getTypeSizeInBits(SH->getType()) &&\n \"non-trivial casts should be done with the SCEVs directly!\");\n V = InsertNoopCastOfTo(V, Ty);\ndiff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp\nindex 618c8aef3840..1855fb67aa54 100644\n--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp\n+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp\n@@ -3404,7 +3404,7 @@ void VPExpandSCEVRecipe::execute(VPTransformState &State) {\n }\n \n const DataLayout &DL = State.CFG.PrevBB->getDataLayout();\n- SCEVExpander Exp(SE, DL, \"induction\");\n+ SCEVExpander Exp(SE, DL, \"induction\", /*PreserveLCSSA=*/true);\n \n Value *Res = Exp.expandCodeFor(Expr, Expr->getType(),\n &*State.Builder.GetInsertPoint());\ndiff --git a/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp b/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp\nindex e40af3e2e3d3..1a7322ec0aff 100644\n--- a/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp\n+++ b/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp\n@@ -30,11 +30,18 @@ VPValue *vputils::getOrCreateVPValueForSCEVExpr(VPlan &Plan, const SCEV *Expr,\n VPValue *Expanded = nullptr;\n if (auto *E = dyn_cast(Expr))\n Expanded = Plan.getOrAddLiveIn(E->getValue());\n- else if (auto *E = dyn_cast(Expr))\n- Expanded = Plan.getOrAddLiveIn(E->getValue());\n else {\n- Expanded = new VPExpandSCEVRecipe(Expr, SE);\n- Plan.getEntry()->appendRecipe(Expanded->getDefiningRecipe());\n+ auto *U = dyn_cast(Expr);\n+ // Skip SCEV expansion if Expr is a SCEVUnknown wrapping a non-instruction\n+ // value. Otherwise the value may be defined in a loop and using it directly\n+ // will break LCSSA form. The SCEV expansion takes care of preserving LCSSA\n+ // form.\n+ if (U && !isa(U->getValue())) {\n+ Expanded = Plan.getOrAddLiveIn(U->getValue());\n+ } else {\n+ Expanded = new VPExpandSCEVRecipe(Expr, SE);\n+ Plan.getEntry()->appendRecipe(Expanded->getDefiningRecipe());\n+ }\n }\n Plan.addSCEVExpansion(Expr, Expanded);\n return Expanded;\n", "tests": [{"file": "llvm/test/Transforms/LoopVectorize/X86/scev-checks-unprofitable.ll", "commands": ["opt -p loop-vectorize -vectorizer-min-trip-count=8 -mcpu=skylake-avx512 -S %s"], "tests": [{"test_name": "", "test_body": "\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n; Test case for https://github.com/llvm/llvm-project/issues/121518. Make sure\n; that we preserve LCSSA form when using %iv.1 from loop.1 in the trip count\n; expression when vectorizing loop.2\ndefine void @value_defined_in_loop1_used_for_trip_counts(i32 %start, i1 %c, ptr %dst) {\n;\nentry:\n %select = select i1 %c, i32 0, i32 7\n %zext = zext i32 %select to i64\n br label %loop.1\n\nloop.1:\n %iv.1 = phi i64 [ 0, %entry ], [ %zext, %loop.1 ]\n br i1 false, label %loop.1.exit, label %loop.1\n\nloop.1.exit:\n br i1 %c, label %loop.2, label %loop.3\n\nloop.2:\n %iv.2 = phi i64 [ 0, %loop.1.exit ], [ %iv.2.next, %loop.2 ]\n %iv.3 = phi i32 [ %start, %loop.1.exit ], [ %iv.3.next, %loop.2 ]\n %iv.3.next = add i32 %iv.3, 1\n %iv.2.next = add i64 %iv.2, 1\n %shl = shl i32 %iv.3, 1\n %zext8 = zext i32 %shl to i64\n %gep.dst = getelementptr i8, ptr %dst, i64 %zext8\n store i16 0, ptr %gep.dst, align 2\n %ec.2 = icmp ult i64 %iv.2, %iv.1\n br i1 %ec.2, label %loop.2, label %exit.1\n\nloop.3:\n %iv.4 = phi i64 [ 0, %loop.1.exit ], [ %iv.4.next, %loop.3 ]\n %gep.dst.2 = getelementptr i8, ptr %dst, i64 %iv.4\n store i8 0, ptr %gep.dst.2, align 1\n %iv.4.next = add i64 %iv.4, 1\n %ec.3 = icmp ult i64 %iv.4.next, %iv.1\n br i1 %ec.3, label %loop.3, label %exit.1\n\nexit.1:\n ret void\n}\n;.\n;."}]}, {"file": "llvm/test/Transforms/LoopVectorize/float-induction.ll", "commands": ["opt < %s -passes=loop-vectorize,dce,instcombine -force-vector-interleave=1 -force-vector-width=4 -S", "opt < %s -passes=loop-vectorize,dce,instcombine -force-vector-interleave=2 -force-vector-width=4 -S", "opt < %s -passes=loop-vectorize,dce,instcombine -force-vector-interleave=2 -force-vector-width=1 -S", "opt < %s -passes=loop-vectorize,dce,simplifycfg,instcombine,simplifycfg -force-vector-interleave=1 -force-vector-width=2 -simplifycfg-require-and-preserve-domtree=1 -keep-loops=false -S"], "tests": [{"test_name": "fp_iv_loop3", "test_body": "@fp_inc = external global float, align 4\n\ndefine void @fp_iv_loop3(float %init, ptr noalias captures(none) %A, ptr noalias captures(none) %B, ptr noalias captures(none) %C, i32 %N) {\nentry:\n %cmp9 = icmp sgt i32 %N, 0\n br i1 %cmp9, label %for.body.lr.ph, label %for.end\n\nfor.body.lr.ph: ; preds = %entry\n %0 = load float, ptr @fp_inc, align 4\n br label %for.body\n\nfor.body: ; preds = %for.body, %for.body.lr.ph\n %indvars.iv = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next, %for.body ]\n %y.012 = phi float [ 0x3FB99999A0000000, %for.body.lr.ph ], [ %conv1, %for.body ]\n %x.011 = phi float [ %init, %for.body.lr.ph ], [ %add, %for.body ]\n %arrayidx = getelementptr inbounds float, ptr %A, i64 %indvars.iv\n store float %x.011, ptr %arrayidx, align 4\n %add = fadd fast float %x.011, %0\n %conv1 = fadd fast float %y.012, -5.000000e-01\n %add2 = fadd fast float %conv1, %add\n %arrayidx4 = getelementptr inbounds float, ptr %B, i64 %indvars.iv\n store float %add2, ptr %arrayidx4, align 4\n %arrayidx6 = getelementptr inbounds float, ptr %C, i64 %indvars.iv\n store float %conv1, ptr %arrayidx6, align 4\n %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1\n %lftr.wideiv = trunc i64 %indvars.iv.next to i32\n %exitcond = icmp eq i32 %lftr.wideiv, %N\n br i1 %exitcond, label %for.end.loopexit, label %for.body\n\nfor.end.loopexit: ; preds = %for.body\n br label %for.end\n\nfor.end: ; preds = %for.end.loopexit, %entry\n ret void\n}\n\n!llvm.module.flags = !{!0}\n\n!0 = !{i32 2, !\"Debug Info Version\", i32 3}\n"}]}], "issue": {"title": "Assertion `all_of(I->users(), [&InsertedSet](Value *U) { return InsertedSet.contains(cast(U)); }) && \"removed instruction should only be used by instructions inserted \" \"during expansion\"' failed.", "body": "To reproduce run opt with the test below (-passes=loop-vectorize ):\n```\n; ModuleID = './reduced.ll'\nsource_filename = \"./reduced.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-ni:1-p2:32:8:8:32-ni:2\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine ptr addrspace(1) @wombat(i32 %arg) gc \"statepoint-example\" {\nbb:\n %select = select i1 false, i32 0, i32 8\n br label %bb3\n\nbb1: ; preds = %bb3\n br i1 false, label %bb4, label %bb9\n\nbb2: ; No predecessors!\n %zext = zext i32 %select to i64\n br label %bb3\n\nbb3: ; preds = %bb3, %bb2, %bb\n %phi = phi i64 [ %zext, %bb2 ], [ 0, %bb3 ], [ 0, %bb ]\n br i1 false, label %bb1, label %bb3\n\nbb4: ; preds = %bb4, %bb1\n %phi5 = phi i64 [ %add7, %bb4 ], [ 0, %bb1 ]\n %phi6 = phi i32 [ %add, %bb4 ], [ %arg, %bb1 ]\n %add = add i32 %phi6, 1\n %add7 = add i64 %phi5, 1\n %shl = shl i32 %phi6, 1\n %zext8 = zext i32 %shl to i64\n %getelementptr = getelementptr i8, ptr addrspace(1) null, i64 %zext8\n store i16 0, ptr addrspace(1) %getelementptr, align 2\n %icmp = icmp ult i64 %phi5, %phi\n br i1 %icmp, label %bb4, label %bb15\n\nbb9: ; preds = %bb9, %bb1\n %phi10 = phi i64 [ %add12, %bb9 ], [ 0, %bb1 ]\n %getelementptr11 = getelementptr i8, ptr addrspace(1) null, i64 %phi10\n store i8 0, ptr addrspace(1) %getelementptr11, align 1\n %add12 = add i64 %phi10, 1\n %icmp13 = icmp ult i64 %add12, %phi\n br i1 %icmp13, label %bb9, label %bb14\n\nbb14: ; preds = %bb9\n ret ptr addrspace(1) null\n\nbb15: ; preds = %bb4\n ret ptr addrspace(1) null\n}\n```\nReproducer: https://godbolt.org/z/67vadzMbr\nStack dump:\n```\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=loop-vectorize \n1.\tRunning pass \"function(loop-vectorize)\" on module \"\"\n2.\tRunning pass \"loop-vectorize\" on function \"wombat\"\n #0 0x000000000525d5d8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x525d5d8)\n #1 0x000000000525afdc SignalHandler(int) Signals.cpp:0:0\n #2 0x00007cf6f6042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x00007cf6f60969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x00007cf6f6042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x00007cf6f60287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x00007cf6f602871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #7 0x00007cf6f6039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #8 0x00000000045a6237 llvm::SCEVExpanderCleaner::cleanup() (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x45a6237)\n #9 0x00000000041cf7df (anonymous namespace)::GeneratedRTChecks::~GeneratedRTChecks() LoopVectorize.cpp:0:0\n#10 0x0000000004227f36 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4227f36)\n#11 0x0000000004229cc9 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4229cc9)\n#12 0x000000000422a303 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x422a303)\n#13 0x0000000003029e0e llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3029e0e)\n#14 0x000000000505b4d0 llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x505b4d0)\n#15 0x0000000000e6bc0e llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe6bc0e)\n#16 0x0000000005059deb llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5059deb)\n#17 0x0000000000e6b29e llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe6b29e)\n#18 0x00000000050597f0 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x50597f0)\n#19 0x0000000000941fba llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::ArrayRef>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x941fba)\n#20 0x0000000000934559 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x934559)\n#21 0x00007cf6f6029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#22 0x00007cf6f6029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#23 0x000000000092be35 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x92be35)\nProgram terminated with signal: SIGSEGV\n```", "author": "TatyanaDoubts", "labels": ["release:backport", "vectorizers", "llvm:SCEV", "crash"], "comments": [{"author": "TatyanaDoubts", "body": "Triage on our side found the fault commit\n\ncommit 6dc23b70097e4135ecde33f49550b1f473a5c385\n\nAuthor: Nikita Popov <[npopov@redhat.com](mailto:npopov@redhat.com)>\n\nDate: Mon Nov 11 12:36:29 2024 +0100\n\n \n\n [SCEVExpander] Don't try to reuse SCEVUnknown values (#115141)\n\n \n\n The expansion of a SCEVUnknown is trivial (it's just the wrapped value).\n\n If we try to reuse an existing value it might be a more complex\n\n expression that simplifies to the SCEVUnknown.\n\n \n\n This is inspired by [WRONG code: GVN? Loop opts? · Issue #114879 · llvm/llvm-project](https://github.com/llvm/llvm-project/issues/114879) ,\n\n because SCEVExpander replacing a constant with a phi node is just silly.\n\n (I don't consider this a fix for that issue though.)\n\n@nikic , could you please have a look? Thank you!"}, {"author": "danilaml", "body": "Looks like when `FindValueInExprValueMap` returns a `nullptr` (like it does for a phi in reproducer after `SCEVUnknown` changes) the code runs `fixupLCSSAFormFor`. This function runs `llvm::formLCSSAForInstructions` that can insert a new LCSSA phi and more importantly can rewrite the uses of instructions in the worklist. So what happens is this function is run, new phi is added, some old phi uses are replaced with this new phi, then the changes are \"rolled back\", i.e. the cleanup is called on SCEVExpander, it tries to remove the inserted lcssa phi but it doesn't know how to rewrite the uses back so it just asserts (since those users were not inserted by the expander itself, they were already there - they just had their arguments replaced to use instruction from expander).\n\n@nikic this looks like an old issue, although I wasn't yet able to figure out how to trigger it before `SCEVUnknown` changes (and if it even practically possible or just theoretically)."}, {"author": "danilaml", "body": "`fixupLCSSAFormFor` was introduced by @fhahn so perhaps they have a better understanding where the issue lies."}, {"author": "nikic", "body": "I think there are two issues here:\n1. It looks like LV is generating references to the TC that break LCSSA form.\n2. SCEVExpander cleanup can't handle the case where LCSSA formation modified existing uses."}, {"author": "nikic", "body": "This is a possible fix for the SCEVExpander issue: https://github.com/nikic/llvm-project/commit/3217b044ce2b153621f91f8edaaa90984c0998e7\n\nBut after thinking about this, I'm not convinced that SCEVExpander really needs fixing. It is being invoked in PreserveLCSSA mode, so it should be able to rely on the original IR being in LCSSA form.\n\nNote that the `[[N_RND_UP:%.*]] = add i64 [[PHI]], 15` in https://github.com/nikic/llvm-project/commit/3217b044ce2b153621f91f8edaaa90984c0998e7#diff-9e3a00a1cffe1764ee50ab6c79bdea53cd1847cf7b77810a4cdc6835bfc79a52R44 doesn't satisfy LCSSA form, it should be using `PHI_LCSSA`.\n\nMaybe @fhahn could take a look at the LoopVectorize issue?\n\nI could also be convinced to land the SCEVExpander change, as it seems harmless even if LV is fixed..."}, {"author": "fhahn", "body": "Yep, I'll take a look in the next few days"}, {"author": "fhahn", "body": "https://github.com/llvm/llvm-project/pull/125235 should fix the place where LCSSA is broken"}]}, "verified": true} +{"bug_id": "131360", "issue_url": "https://github.com/llvm/llvm-project/issues/131360", "bug_type": "crash", "base_commit": "dccc0a836c20914549fa375905615db49d2f813b", "knowledge_cutoff": "2025-03-14T17:22:16Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "fbf0276b6a7a7a4508c373cf87fc349569652659", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[6665, 6670]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["BoUpSLP::reorderBottomToTop"]}}, "patch": "commit fbf0276b6a7a7a4508c373cf87fc349569652659\nAuthor: Alexey Bataev \nDate: Fri Mar 14 14:07:01 2025 -0700\n\n [SLP] Reorder reuses mask, if it is not empty, for subvector operands\n \n If the subvector operands has reuses mask, need to reorder the mask, not\n the scalars, to prevent compiler crash due to mask/scalars size\n mismatch.\n \n Fixes #131360\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex 708dda9bd7f8..d450336cbc3c 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -6665,6 +6665,8 @@ void BoUpSLP::reorderBottomToTop(bool IgnoreReorder) {\n // Clear ordering of the operand.\n if (!OpTE.ReorderIndices.empty()) {\n OpTE.ReorderIndices.clear();\n+ } else if (!OpTE.ReuseShuffleIndices.empty()) {\n+ reorderReuses(OpTE.ReuseShuffleIndices, Mask);\n } else {\n assert(OpTE.isGather() && \"Expected only gather/buildvector node.\");\n reorderScalars(OpTE.Scalars, Mask);\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/X86/reorder-reused-subvector.ll", "commands": ["opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -slp-threshold=-100 < %s"], "tests": [{"test_name": "", "test_body": "\ndefine void @test(i32 %j.6, i32 %m.4, i8 %v.5, ptr %a, i1 %tobool14.not) {\n;\nentry:\n br label %n\n\nentry.o_crit_edge:\n br label %o\n\nn:\n %i.0 = phi i32 [ 0, %entry ], [ 1, %if.end18 ]\n %j.0 = phi i32 [ 0, %entry ], [ %j.6, %if.end18 ]\n %m.0 = phi i32 [ 0, %entry ], [ %m.4, %if.end18 ]\n %l.0 = phi i8 [ 0, %entry ], [ %l.4, %if.end18 ]\n %u.0 = phi i32 [ 0, %entry ], [ %u.5, %if.end18 ]\n store i32 %j.0, ptr %a, align 4\n %cmp.not.not = icmp eq i8 %l.0, 0\n br i1 %cmp.not.not, label %o.sink.split, label %p\n\np:\n %0 = phi i32 [ %r.3, %if.end18 ], [ 0, %n ]\n %i.1 = phi i32 [ %s.3, %if.end18 ], [ 1, %n ]\n %j.1 = phi i32 [ %j.65, %if.end18 ], [ %j.0, %n ]\n %k.1 = phi i32 [ %t.3, %if.end18 ], [ %i.0, %n ]\n %m.1 = phi i32 [ %m.46, %if.end18 ], [ %m.0, %n ]\n %l.1 = phi i8 [ 1, %if.end18 ], [ 0, %n ]\n %s.1 = phi i32 [ %s.3, %if.end18 ], [ 0, %n ]\n %t.1 = phi i32 [ %t.3, %if.end18 ], [ 0, %n ]\n %u.12 = phi i32 [ %u.5, %if.end18 ], [ 0, %n ]\n %v.1 = phi i8 [ 0, %if.end18 ], [ %v.5, %n ]\n %tobool4.not = icmp eq i32 %m.1, 0\n %spec.select = select i1 %tobool4.not, i32 %j.1, i32 0\n %tobool7.not = icmp eq i32 %0, 0\n br i1 %tobool7.not, label %o.sink.split, label %q\n\no.sink.split:\n %spec.select.sink = phi i32 [ %j.0, %n ], [ %spec.select, %p ]\n %i.3.ph = phi i32 [ 0, %n ], [ %i.1, %p ]\n %k.3.ph = phi i32 [ %i.0, %n ], [ %k.1, %p ]\n %m.3.ph = phi i32 [ %m.0, %n ], [ 0, %p ]\n %l.3.ph = phi i8 [ 0, %n ], [ %l.1, %p ]\n %u.3.ph = phi i32 [ %u.0, %n ], [ 1, %p ]\n %conv10 = zext i32 %spec.select.sink to i64\n %call11 = tail call i32 (ptr, ...) @printf(ptr null, i64 %conv10)\n br label %o\n\no:\n %j.4 = phi i32 [ 0, %entry.o_crit_edge ], [ %spec.select.sink, %o.sink.split ]\n %k.3 = phi i32 [ 0, %entry.o_crit_edge ], [ %k.3.ph, %o.sink.split ]\n %m.3 = phi i32 [ 0, %entry.o_crit_edge ], [ %m.3.ph, %o.sink.split ]\n %u.3 = phi i32 [ 0, %entry.o_crit_edge ], [ %u.3.ph, %o.sink.split ]\n %sub = sub i32 0, %j.6\n %div = sdiv i32 %sub, %i.3.ph\n %sub13 = sub i32 0, %div\n br i1 %tobool14.not, label %if.end18, label %q\n\nq:\n %s.2 = phi i32 [ %s.1, %p ], [ 0, %o ]\n %t.2 = phi i32 [ %t.1, %p ], [ %k.3, %o ]\n %u.4 = phi i32 [ %u.12, %p ], [ 0, %o ]\n %v.44 = phi i8 [ %v.1, %p ], [ 0, %o ]\n %conv17 = sext i8 %v.44 to i32\n %rem = mul i32 %u.4, %conv17\n br label %if.end18\n\nif.end18:\n %j.65 = phi i32 [ 0, %q ], [ %j.4, %o ]\n %m.46 = phi i32 [ %rem, %q ], [ %m.3, %o ]\n %l.4 = phi i8 [ 0, %q ], [ %l.3.ph, %o ]\n %r.3 = phi i32 [ 0, %q ], [ %k.3, %o ]\n %s.3 = phi i32 [ %s.2, %q ], [ %sub, %o ]\n %t.3 = phi i32 [ %t.2, %q ], [ %sub13, %o ]\n %u.5 = phi i32 [ 0, %q ], [ %u.3, %o ]\n br i1 %tobool14.not, label %n, label %p\n\n}\ndeclare i32 @printf(ptr, ...)"}]}], "issue": {"title": "clang crashes at -O{s,2,3} on x86_64-linux-gnu: Assertion `idx < size()' failed", "body": "It appears to be a recent regression as it doesn't reproduce with 20.1.0. \n\nCompiler Explorer: https://godbolt.org/z/31z58Pqnf\n\n```\n[507] % clangtk -v\nclang version 21.0.0git (https://github.com/llvm/llvm-project.git da3ee9763266f9adedaac1b1b3162d14f951fc55)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\nCandidate multilib: .;@m64\nSelected multilib: .;@m64\n[508] % \n[508] % clangtk -Os small.c\nclang-21: /local/suz-local/software/clangbuild/llvm-project/llvm/include/llvm/ADT/SmallVector.h:291: T& llvm::SmallVectorTemplateCommon >::operator[](llvm::SmallVectorTemplateCommon >::size_type) [with T = llvm::Value*; = void; llvm::SmallVectorTemplateCommon >::reference = llvm::Value*&; llvm::SmallVectorTemplateCommon >::size_type = long unsigned int]: Assertion `idx < size()' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.\nStack dump:\n0.\tProgram arguments: /local/suz-local/software/local/clang-trunk/bin/clang-21 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name small.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/local/suz-local/software/emitesting/bugs/20250314-clangtk-m64-O3-build-143933/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/20250314-clangtk-m64-O3-build-143933/delta -resource-dir /local/suz-local/software/local/clang-trunk/lib/clang/21 -I /usr/local/include -I /local/suz-local/software/local/include -internal-isystem /local/suz-local/software/local/clang-trunk/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Os -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/small-fb79f4.o -x c small.c\n1.\t parser at end of file\n2.\tOptimizer\n3.\tRunning pass \"function(float2int,lower-constant-intrinsics,loop(loop-rotate,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize,infer-alignment,loop-load-elim,instcombine,simplifycfg,slp-vectorizer,vector-combine,instcombine,loop-unroll,transform-warning,sroa,infer-alignment,instcombine,loop-mssa(licm),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg)\" on module \"small.c\"\n4.\tRunning pass \"slp-vectorizer\" on function \"g\"\n #0 0x0000559c00edefcf llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x4577fcf)\n #1 0x0000559c00edc7a4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x00007f26a38b4420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\n #3 0x00007f26a32eb00b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\n #4 0x00007f26a32ca859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\n #5 0x00007f26a32ca729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\n #6 0x00007f26a32ca729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\n #7 0x00007f26a32dbfd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\n #8 0x0000559c0296f55e llvm::reorderScalars(llvm::SmallVectorImpl&, llvm::ArrayRef) SLPVectorizer.cpp:0:0\n #9 0x0000559c02a36719 llvm::slpvectorizer::BoUpSLP::reorderBottomToTop(bool) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x60cf719)\n#10 0x0000559c02a41c60 llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef, llvm::slpvectorizer::BoUpSLP&, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x60dac60)\n#11 0x0000559c02a4712d bool tryToVectorizeSequence(llvm::SmallVectorImpl&, llvm::function_ref, llvm::function_ref, llvm::function_ref, bool)>, bool, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0\n#12 0x0000559c02a48b21 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x60e1b21)\n#13 0x0000559c02a50b66 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#14 0x0000559c02a51733 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x60ea733)\n#15 0x0000559c024c7cf6 llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x5b60cf6)\n#16 0x0000559c0084f7c9 llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x3ee87c9)\n#17 0x0000559bfe1397a6 llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x17d27a6)\n#18 0x0000559c0084e032 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x3ee7032)\n#19 0x0000559bfe1373b6 llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x17d03b6)\n#20 0x0000559c0084da51 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x3ee6a51)\n#21 0x0000559c0119ce4a (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr>&, std::unique_ptr>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\n#22 0x0000559c011a08a1 clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr, std::unique_ptr>, clang::BackendConsumer*) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x48398a1)\n#23 0x0000559c018e0d91 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x4f79d91)\n#24 0x0000559c0326e6dc clang::ParseAST(clang::Sema&, bool, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x69076dc)\n#25 0x0000559c018e11b8 clang::CodeGenAction::ExecuteAction() (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x4f7a1b8)\n#26 0x0000559c01bb7bc9 clang::FrontendAction::Execute() (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x5250bc9)\n#27 0x0000559c01b38ece clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x51d1ece)\n#28 0x0000559c01cac996 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x5345996)\n#29 0x0000559bfdccc9ed cc1_main(llvm::ArrayRef, char const*, void*) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x13659ed)\n#30 0x0000559bfdcc415a ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&) driver.cpp:0:0\n#31 0x0000559bfdcc83c7 clang_main(int, char**, llvm::ToolContext const&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x13613c7)\n#32 0x0000559bfdbad0db main (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x12460db)\n#33 0x00007f26a32cc083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\n#34 0x0000559bfdcc3bee _start (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x135cbee)\nclangtk: error: unable to execute command: Aborted\nclangtk: error: clang frontend command failed due to signal (use -v to see invocation)\nclang version 21.0.0git (https://github.com/llvm/llvm-project.git da3ee9763266f9adedaac1b1b3162d14f951fc55)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nclangtk: note: diagnostic msg: \n********************\n\nPLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:\nPreprocessed source(s) and associated run script(s) are located at:\nclangtk: note: diagnostic msg: /tmp/small-d812eb.c\nclangtk: note: diagnostic msg: /tmp/small-d812eb.sh\nclangtk: note: diagnostic msg: \n\n********************\n[509] % \n[509] % cat small.c\nint printf(const char *, ...);\nint a, b, c, d, e, f;\nvoid g() {\n int i = 1, j = 0, k = 0, m;\n char l = 1;\n if (d)\n n : {\n a = j;\n if (e >= l) {\n printf(\"%ld\", (long) j);\n goto o;\n }\n p:\n if (m)\n j = 1;\n if (b)\n goto q;\n printf(\"%ld\", (long) j);\n }\n o : ;\n int r = k, s = -f, t = -(s / i);\n if (c) {\n t = k;\n int u = a;\n char v = u;\n q:\n m = u % v;\n l = 0;\n }\n i = s;\n k = t;\n b = r;\n if (a)\n goto p;\n goto n;\n}\n```\n", "author": "zhendongsu", "labels": ["llvm:SLPVectorizer", "crash"], "comments": []}, "verified": true} {"bug_id": "108620", "issue_url": "https://github.com/llvm/llvm-project/issues/108620", "bug_type": "crash", "base_commit": "03618ceabd003be94190b068db11b607fd1108ef", "knowledge_cutoff": "2024-09-13T18:15:02Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "1e3536ef3141d6429f3616af624b81b6d6ab2959", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[1283, 1293], [14222, 14235], [14373, 14378], [14426, 14436], [14530, 14537], [14757, 14762], [17660, 17666], [17956, 17961], [18024, 18031]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["BoUpSLP::vectorizeTree", "tryToReduce"]}}, "patch": "commit 1e3536ef3141d6429f3616af624b81b6d6ab2959\nAuthor: Alexey Bataev \nDate: Fri Sep 13 15:40:22 2024 -0700\n\n [SLP]Fix PR108620: Need to check, if the reduced value was transformed\n \n Before trying to include the scalar into the list of\n ExternallyUsedValues, need to check, if it was transformed in previous\n iteration and use the transformed value, not the original one, to avoid\n compiler crash when building external uses.\n \n Fixes https://github.com/llvm/llvm-project/issues/108620\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex 0afe02fc08ff..5f2bf082fb87 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -1283,11 +1283,8 @@ public:\n /// Vectorize the tree but with the list of externally used values \\p\n /// ExternallyUsedValues. Values in this MapVector can be replaced but the\n /// generated extractvalue instructions.\n- /// \\param ReplacedExternals containd list of replaced external values\n- /// {scalar, replace} after emitting extractelement for external uses.\n Value *\n vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues,\n- SmallVectorImpl> &ReplacedExternals,\n Instruction *ReductionRoot = nullptr);\n \n /// \\returns the cost incurred by unwanted spills and fills, caused by\n@@ -14222,14 +14219,12 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {\n \n Value *BoUpSLP::vectorizeTree() {\n ExtraValueToDebugLocsMap ExternallyUsedValues;\n- SmallVector> ReplacedExternals;\n- return vectorizeTree(ExternallyUsedValues, ReplacedExternals);\n+ return vectorizeTree(ExternallyUsedValues);\n }\n \n-Value *BoUpSLP::vectorizeTree(\n- const ExtraValueToDebugLocsMap &ExternallyUsedValues,\n- SmallVectorImpl> &ReplacedExternals,\n- Instruction *ReductionRoot) {\n+Value *\n+BoUpSLP::vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues,\n+ Instruction *ReductionRoot) {\n // All blocks must be scheduled before any instructions are inserted.\n for (auto &BSIter : BlocksSchedules) {\n scheduleBlock(BSIter.second.get());\n@@ -14373,6 +14368,7 @@ Value *BoUpSLP::vectorizeTree(\n SmallDenseSet UsedInserts;\n DenseMap, Value *> VectorCasts;\n SmallDenseSet ScalarsWithNullptrUser;\n+ SmallDenseSet IgnoredExtracts;\n // Extract all of the elements with the external uses.\n for (const auto &ExternalUse : ExternalUses) {\n Value *Scalar = ExternalUse.Scalar;\n@@ -14426,11 +14422,16 @@ Value *BoUpSLP::vectorizeTree(\n if (ReplaceInst) {\n // Leave the instruction as is, if it cheaper extracts and all\n // operands are scalar.\n- auto *CloneInst = Inst->clone();\n- CloneInst->insertBefore(Inst);\n- if (Inst->hasName())\n- CloneInst->takeName(Inst);\n- Ex = CloneInst;\n+ if (auto *EE = dyn_cast(Inst)) {\n+ IgnoredExtracts.insert(EE);\n+ Ex = EE;\n+ } else {\n+ auto *CloneInst = Inst->clone();\n+ CloneInst->insertBefore(Inst);\n+ if (Inst->hasName())\n+ CloneInst->takeName(Inst);\n+ Ex = CloneInst;\n+ }\n } else if (auto *ES = dyn_cast(Scalar);\n ES && isa(Vec)) {\n Value *V = ES->getVectorOperand();\n@@ -14530,8 +14531,12 @@ Value *BoUpSLP::vectorizeTree(\n }\n Value *NewInst = ExtractAndExtendIfNeeded(Vec);\n // Required to update internally referenced instructions.\n- Scalar->replaceAllUsesWith(NewInst);\n- ReplacedExternals.emplace_back(Scalar, NewInst);\n+ if (Scalar != NewInst) {\n+ assert((!isa(Scalar) ||\n+ !IgnoredExtracts.contains(cast(Scalar))) &&\n+ \"Extractelements should not be replaced.\");\n+ Scalar->replaceAllUsesWith(NewInst);\n+ }\n continue;\n }\n \n@@ -14757,6 +14762,9 @@ Value *BoUpSLP::vectorizeTree(\n if (Entry->getOpcode() == Instruction::GetElementPtr &&\n !isa(Scalar))\n continue;\n+ if (auto *EE = dyn_cast(Scalar);\n+ EE && IgnoredExtracts.contains(EE))\n+ continue;\n #ifndef NDEBUG\n Type *Ty = Scalar->getType();\n if (!Ty->isVoidTy()) {\n@@ -17660,7 +17668,6 @@ public:\n // because of the vectorization.\n DenseMap TrackedVals(ReducedVals.size() *\n ReducedVals.front().size());\n- SmallVector> ReplacedExternals;\n \n // The compare instruction of a min/max is the insertion point for new\n // instructions and may be replaced with a new compare instruction.\n@@ -17956,6 +17963,8 @@ public:\n if (Cnt >= Pos && Cnt < Pos + ReduxWidth)\n continue;\n Value *RdxVal = Candidates[Cnt];\n+ if (auto It = TrackedVals.find(RdxVal); It != TrackedVals.end())\n+ RdxVal = It->second;\n if (!Visited.insert(RdxVal).second)\n continue;\n // Check if the scalar was vectorized as part of the vectorization\n@@ -18024,8 +18033,8 @@ public:\n InsertPt = GetCmpForMinMaxReduction(RdxRootInst);\n \n // Vectorize a tree.\n- Value *VectorizedRoot = V.vectorizeTree(LocalExternallyUsedValues,\n- ReplacedExternals, InsertPt);\n+ Value *VectorizedRoot =\n+ V.vectorizeTree(LocalExternallyUsedValues, InsertPt);\n \n Builder.SetInsertPoint(InsertPt);\n \n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/X86/reduced-val-extracted-and-externally-used.ll", "commands": ["opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s"], "tests": [{"test_name": "test", "test_body": "define void @test(i32 %arg) {\nbb:\n br label %bb1\n\nbb1: ; preds = %bb1, %bb\n %phi = phi i32 [ 0, %bb ], [ %add27, %bb1 ]\n %phi2 = phi i32 [ 0, %bb ], [ %add24, %bb1 ]\n %phi3 = phi i32 [ 0, %bb ], [ %xor26, %bb1 ]\n %add = add i32 %phi2, 0\n %add4 = add i32 %phi2, 0\n %xor = xor i32 %add, %add4\n %add5 = add i32 %phi, 0\n %add6 = add i32 %phi2, 0\n %add7 = add i32 %phi2, 0\n %xor8 = xor i32 %add6, %xor\n %xor9 = xor i32 %xor8, %add5\n %xor10 = xor i32 %xor9, %add7\n %add11 = add i32 %phi, 0\n %add12 = add i32 %phi2, 0\n %add13 = add i32 %phi2, 0\n %xor14 = xor i32 %add12, %xor10\n %xor15 = xor i32 %xor14, %add11\n %xor16 = xor i32 %xor15, %add13\n %add17 = add i32 %phi, 0\n %add18 = add i32 %phi2, 0\n %add19 = add i32 %phi2, 0\n %xor20 = xor i32 %add18, %xor16\n %xor21 = xor i32 %xor20, %add17\n %xor22 = xor i32 %xor21, %add19\n %add23 = add i32 %phi2, 0\n %add24 = add i32 %arg, 0\n %xor25 = xor i32 %add23, %xor22\n %xor26 = xor i32 %xor25, %add24\n %add27 = add i32 1, 0\n %icmp = icmp ult i32 %add27, 0\n br label %bb1\n}\n"}]}], "issue": {"title": "Assertion `(I->use_empty() || all_of(I->uses(), [&](Use &U) { return isDeleted( cast(U.getUser())); })) && \"trying to erase instruction with users.\"' failed.", "body": "To reproduce run the following test with -passes=slp-vectorizer\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) gc \"statepoint-example\" {\r\nbb:\r\n br label %bb1\r\n\r\nbb1: ; preds = %bb1, %bb\r\n %phi = phi i32 [ 0, %bb ], [ %add27, %bb1 ]\r\n %phi2 = phi i32 [ 0, %bb ], [ %add24, %bb1 ]\r\n %phi3 = phi i32 [ 0, %bb ], [ %xor26, %bb1 ]\r\n %add = add i32 %phi2, 0\r\n %add4 = add i32 %phi2, 0\r\n %xor = xor i32 %add, %add4\r\n %add5 = add i32 %phi, 0\r\n %add6 = add i32 %phi2, 0\r\n %add7 = add i32 %phi2, 0\r\n %xor8 = xor i32 %add6, %xor\r\n %xor9 = xor i32 %xor8, %add5\r\n %xor10 = xor i32 %xor9, %add7\r\n %add11 = add i32 %phi, 0\r\n %add12 = add i32 %phi2, 0\r\n %add13 = add i32 %phi2, 0\r\n %xor14 = xor i32 %add12, %xor10\r\n %xor15 = xor i32 %xor14, %add11\r\n %xor16 = xor i32 %xor15, %add13\r\n %add17 = add i32 %phi, 0\r\n %add18 = add i32 %phi2, 0\r\n %add19 = add i32 %phi2, 0\r\n %xor20 = xor i32 %add18, %xor16\r\n %xor21 = xor i32 %xor20, %add17\r\n %xor22 = xor i32 %xor21, %add19\r\n %add23 = add i32 %phi2, 0\r\n %add24 = add i32 %arg, 0\r\n %xor25 = xor i32 %add23, %xor22\r\n %xor26 = xor i32 %xor25, %add24\r\n %add27 = add i32 1, 0\r\n %icmp = icmp ult i32 %add27, 0\r\n br label %bb1\r\n}\r\n```\r\nReproducer: https://godbolt.org/z/77hKre61P\r\n\r\nStack dump:\r\n```\r\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:2663: void llvm::slpvectorizer::BoUpSLP::removeInstructionsAndOperands(llvm::ArrayRef) [with T = llvm::Instruction]: Assertion `(I->use_empty() || all_of(I->uses(), [&](Use &U) { return isDeleted( cast(U.getUser())); })) && \"trying to erase instruction with users.\"' 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 \r\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"\"\r\n2.\tRunning pass \"slp-vectorizer\" on function \"wombat\"\r\n #0 0x00000000050106b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x50106b8)\r\n #1 0x000000000500ddfc SignalHandler(int) Signals.cpp:0:0\r\n #2 0x0000737fffa42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x0000737fffa969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x0000737fffa42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x0000737fffa287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x0000737fffa2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x0000737fffa39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x00000000040b91cf void llvm::slpvectorizer::BoUpSLP::removeInstructionsAndOperands(llvm::ArrayRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40b91cf)\r\n #9 0x000000000410b80a llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::MapVector, llvm::DenseMap, llvm::detail::DenseMapPair>, llvm::SmallVector>, 0u>> const&, llvm::SmallVectorImpl>&, llvm::Instruction*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x410b80a)\r\n#10 0x0000000004115bed (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\r\n#11 0x0000000004118321 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::SmallVectorImpl&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4118321)\r\n#12 0x000000000411cb18 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x411cb18)\r\n#13 0x00000000041212fa llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41212fa)\r\n#14 0x0000000004127719 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#15 0x00000000041283cb llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41283cb)\r\n#16 0x0000000002efda4e llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2efda4e)\r\n#17 0x0000000004e12948 llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e12948)\r\n#18 0x0000000000e06f8e llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe06f8e)\r\n#19 0x0000000004e1136e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e1136e)\r\n#20 0x0000000000e0679e llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe0679e)\r\n#21 0x0000000004e10da0 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e10da0)\r\n#22 0x00000000008fb642 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::ArrayRef>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8fb642)\r\n#23 0x00000000008ee4cc optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ee4cc)\r\n#24 0x0000737fffa29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#25 0x0000737fffa29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#26 0x00000000008e5f9e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8e5f9e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "TatyanaDoubts", "labels": ["llvm:SLPVectorizer", "crash"], "comments": []}, "verified": true} {"bug_id": "117133", "issue_url": "https://github.com/llvm/llvm-project/issues/117133", "bug_type": "miscompilation", "base_commit": "94df95de6bab20930c1a77bc785221ff2f670dba", "knowledge_cutoff": "2024-11-21T09:18:16Z", "lit_test_dir": ["llvm/test/Analysis/ScalarEvolution", "llvm/test/Transforms/IndVarSimplify"], "hints": {"fix_commit": "f7ef0721d60f85e1f699f8d1b83d4402ae19b122", "components": ["ScalarEvolution"], "bug_location_lineno": {"llvm/include/llvm/Analysis/ScalarEvolution.h": [[2187, 2192]], "llvm/lib/Analysis/ScalarEvolution.cpp": [[4307, 4321], [5933, 5950], [7324, 7329]]}, "bug_location_funcname": {"llvm/lib/Analysis/ScalarEvolution.cpp": ["ScalarEvolution::createAddRecFromPHI", "ScalarEvolution::getSequentialMinMaxExpr", "ScalarEvolution::isGuaranteedNotToBePoison", "ScalarEvolution::isSCEVExprNeverPoison"]}}, "patch": "commit f7ef0721d60f85e1f699f8d1b83d4402ae19b122\nAuthor: Yingwei Zheng \nDate: Sun Dec 1 20:11:09 2024 +0800\n\n [SCEV] Do not allow refinement in the rewriting of BEValue (#117152)\n \n See the following case:\n ```\n ; bin/opt -passes=\"print\" test.ll --disable-output\n define i32 @widget() {\n b:\n br label %b1\n \n b1: ; preds = %b5, %b\n %phi = phi i32 [ 0, %b ], [ %udiv6, %b5 ]\n %phi2 = phi i32 [ 1, %b ], [ %add, %b5 ]\n %icmp = icmp eq i32 %phi, 0\n br i1 %icmp, label %b3, label %b8\n \n b3: ; preds = %b1\n %udiv = udiv i32 10, %phi2\n %urem = urem i32 %udiv, 10\n %icmp4 = icmp eq i32 %urem, 0\n br i1 %icmp4, label %b7, label %b5\n \n b5: ; preds = %b3\n %udiv6 = udiv i32 %phi2, 0\n %add = add i32 %phi2, 1\n br label %b1\n \n b7: ; preds = %b3\n ret i32 5\n \n b8: ; preds = %b1\n ret i32 7\n }\n ```\n ```\n %phi2 = phi i32 [ 1, %b ], [ %add, %b5 ] --> {1,+,1}<%b1>\n %udiv6 = udiv i32 %phi2, 0 --> ({1,+,1}<%b1> /u 0)\n %phi = phi i32 [ 0, %b ], [ %udiv6, %b5 ] --> ({0,+,1}<%b1> /u 0)\n ```\n `ScalarEvolution::createAddRecFromPHI` gives a wrong SCEV result for\n `%phi`:\n \n https://github.com/llvm/llvm-project/blob/d7d6fb1804415b0f3e7f1cc9290bfb3d711cb707/llvm/lib/Analysis/ScalarEvolution.cpp#L5926-L5950\n It converts `phi(0, ({1,+,1}<%b1> /u 0))` into `phi(0 / 0,\n ({1,+,1}<%b1> /u 0))`. Then it simplifies the expr into\n `{0,+,1}<%b1> /u 0`.\n \n As we did in\n https://github.com/llvm/llvm-project/commit/acd700a24b6f767413db3d525e06d03e4245aa40,\n this patch disallows udiv simplification if we cannot prove that the\n denominator is a well-defined non-zero value.\n \n Fixes https://github.com/llvm/llvm-project/issues/117133.\n\ndiff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h\nindex 885c5985f9d2..b20c6a13cb6b 100644\n--- a/llvm/include/llvm/Analysis/ScalarEvolution.h\n+++ b/llvm/include/llvm/Analysis/ScalarEvolution.h\n@@ -2187,6 +2187,9 @@ private:\n bool isGuaranteedToTransferExecutionTo(const Instruction *A,\n const Instruction *B);\n \n+ /// Returns true if \\p Op is guaranteed not to cause immediate UB.\n+ bool isGuaranteedNotToCauseUB(const SCEV *Op);\n+\n /// Returns true if \\p Op is guaranteed to not be poison.\n static bool isGuaranteedNotToBePoison(const SCEV *Op);\n \ndiff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp\nindex c3f296b9ff33..882e938e69c0 100644\n--- a/llvm/lib/Analysis/ScalarEvolution.cpp\n+++ b/llvm/lib/Analysis/ScalarEvolution.cpp\n@@ -4307,15 +4307,7 @@ ScalarEvolution::getSequentialMinMaxExpr(SCEVTypes Kind,\n }\n \n for (unsigned i = 1, e = Ops.size(); i != e; ++i) {\n- bool MayBeUB = SCEVExprContains(Ops[i], [this](const SCEV *S) {\n- auto *UDiv = dyn_cast(S);\n- // The UDiv may be UB if the divisor is poison or zero. Unless the divisor\n- // is a non-zero constant, we have to assume the UDiv may be UB.\n- return UDiv && (!isKnownNonZero(UDiv->getOperand(1)) ||\n- !isGuaranteedNotToBePoison(UDiv->getOperand(1)));\n- });\n-\n- if (MayBeUB)\n+ if (!isGuaranteedNotToCauseUB(Ops[i]))\n continue;\n // We can replace %x umin_seq %y with %x umin %y if either:\n // * %y being poison implies %x is also poison.\n@@ -5933,18 +5925,22 @@ const SCEV *ScalarEvolution::createAddRecFromPHI(PHINode *PN) {\n // We can generalize this saying that i is the shifted value of BEValue\n // by one iteration:\n // PHI(f(0), f({1,+,1})) --> f({0,+,1})\n- const SCEV *Shifted = SCEVShiftRewriter::rewrite(BEValue, L, *this);\n- const SCEV *Start = SCEVInitRewriter::rewrite(Shifted, L, *this, false);\n- if (Shifted != getCouldNotCompute() &&\n- Start != getCouldNotCompute()) {\n- const SCEV *StartVal = getSCEV(StartValueV);\n- if (Start == StartVal) {\n- // Okay, for the entire analysis of this edge we assumed the PHI\n- // to be symbolic. We now need to go back and purge all of the\n- // entries for the scalars that use the symbolic expression.\n- forgetMemoizedResults(SymbolicName);\n- insertValueToMap(PN, Shifted);\n- return Shifted;\n+\n+ // Do not allow refinement in rewriting of BEValue.\n+ if (isGuaranteedNotToCauseUB(BEValue)) {\n+ const SCEV *Shifted = SCEVShiftRewriter::rewrite(BEValue, L, *this);\n+ const SCEV *Start = SCEVInitRewriter::rewrite(Shifted, L, *this, false);\n+ if (Shifted != getCouldNotCompute() && Start != getCouldNotCompute() &&\n+ ::impliesPoison(BEValue, Start)) {\n+ const SCEV *StartVal = getSCEV(StartValueV);\n+ if (Start == StartVal) {\n+ // Okay, for the entire analysis of this edge we assumed the PHI\n+ // to be symbolic. We now need to go back and purge all of the\n+ // entries for the scalars that use the symbolic expression.\n+ forgetMemoizedResults(SymbolicName);\n+ insertValueToMap(PN, Shifted);\n+ return Shifted;\n+ }\n }\n }\n }\n@@ -7324,6 +7320,16 @@ bool ScalarEvolution::isGuaranteedNotToBePoison(const SCEV *Op) {\n return PC.MaybePoison.empty();\n }\n \n+bool ScalarEvolution::isGuaranteedNotToCauseUB(const SCEV *Op) {\n+ return !SCEVExprContains(Op, [this](const SCEV *S) {\n+ auto *UDiv = dyn_cast(S);\n+ // The UDiv may be UB if the divisor is poison or zero. Unless the divisor\n+ // is a non-zero constant, we have to assume the UDiv may be UB.\n+ return UDiv && (!isKnownNonZero(UDiv->getOperand(1)) ||\n+ !isGuaranteedNotToBePoison(UDiv->getOperand(1)));\n+ });\n+}\n+\n bool ScalarEvolution::isSCEVExprNeverPoison(const Instruction *I) {\n // Only proceed if we can prove that I does not yield poison.\n if (!programUndefinedIfPoison(I))\n", "tests": [{"file": "llvm/test/Analysis/ScalarEvolution/pr117133.ll", "commands": ["opt -S -disable-output \"-passes=print\" < %s 2>&1"], "tests": [{"test_name": "test_poisonous", "test_body": "define i64 @test_poisonous(i64 %a, i32 %n) {\nentry:\n br label %loop.body\n\nloop.body: ; preds = %loop.body, %entry\n %indvar1 = phi i32 [ 0, %entry ], [ %indvar1.next, %loop.body ]\n %indvar2 = phi i64 [ 0, %entry ], [ %mul, %loop.body ]\n %indvar1.next = add i32 %indvar1, 1\n %ext = zext i32 %indvar1.next to i64\n %mul = mul i64 %ext, %a\n %exitcond = icmp sgt i32 %indvar1.next, %n\n br i1 %exitcond, label %loop.exit, label %loop.body\n\nloop.exit: ; preds = %loop.body\n ret i64 %mul\n}\n"}, {"test_name": "widget", "test_body": "define i32 @widget() {\nb:\n br label %b1\n\nb1: ; preds = %b5, %b\n %phi = phi i32 [ 0, %b ], [ %udiv6, %b5 ]\n %phi2 = phi i32 [ 1, %b ], [ %add, %b5 ]\n %icmp = icmp eq i32 %phi, 0\n br i1 %icmp, label %b3, label %b8\n\nb3: ; preds = %b1\n %udiv = udiv i32 10, %phi2\n %urem = urem i32 %udiv, 10\n %icmp4 = icmp eq i32 %urem, 0\n br i1 %icmp4, label %b7, label %b5\n\nb5: ; preds = %b3\n %udiv6 = udiv i32 %phi2, 0\n %add = add i32 %phi2, 1\n br label %b1\n\nb7: ; preds = %b3\n ret i32 5\n\nb8: ; preds = %b1\n ret i32 7\n}\n"}]}, {"file": "llvm/test/Transforms/IndVarSimplify/pr117133.ll", "commands": ["opt -S -passes=indvars < %s"], "tests": [{"test_name": "widget", "test_body": "define i32 @widget() {\nb:\n br label %b1\n\nb1: ; preds = %b5, %b\n %phi = phi i32 [ 0, %b ], [ %udiv6, %b5 ]\n %phi2 = phi i32 [ 1, %b ], [ %add, %b5 ]\n %icmp = icmp eq i32 %phi, 0\n br i1 %icmp, label %b3, label %b8\n\nb3: ; preds = %b1\n %udiv = udiv i32 10, %phi2\n %urem = urem i32 %udiv, 10\n %icmp4 = icmp eq i32 %urem, 0\n br i1 %icmp4, label %b7, label %b5\n\nb5: ; preds = %b3\n %udiv6 = udiv i32 %phi2, 0\n %add = add i32 %phi2, 1\n br label %b1\n\nb7: ; preds = %b3\n ret i32 5\n\nb8: ; preds = %b1\n ret i32 7\n}\n"}]}], "issue": {"title": "[indvars] Miscompile when loop body has an operation with Undefined Behaviour", "body": "Here is the problematic IR:\r\n```\r\ndefine i32 @widget() {\r\nbb:\r\n br label %bb1\r\n\r\nbb1: ; preds = %bb5, %bb\r\n %phi = phi i32 [ 0, %bb ], [ %udiv6, %bb5 ]\r\n %phi2 = phi i32 [ 1, %bb ], [ %add, %bb5 ]\r\n %icmp = icmp eq i32 %phi, 0\r\n br i1 %icmp, label %bb3, label %bb8\r\n\r\nbb3: ; preds = %bb1\r\n %udiv = udiv i32 10, %phi2\r\n %urem = urem i32 %udiv, 10\r\n %icmp4 = icmp eq i32 %urem, 0\r\n br i1 %icmp4, label %bb7, label %bb5\r\n\r\nbb5: ; preds = %bb3\r\n %udiv6 = udiv i32 %phi2, 0\r\n %add = add i32 %phi2, 1\r\n br label %bb1\r\n\r\nbb7: ; preds = %bb3\r\n ret i32 5\r\n\r\nbb8: ; preds = %bb1\r\n ret i32 7\r\n}\r\n```\r\nproduces incorrect IR when `indvars` pass is run. I suspect this is because of the `%udiv6 = udiv i32 %phi2, 0` divide by zero operation. \r\nLook at the indvars transformation here: https://godbolt.org/z/cz1r5178h\r\nThe original IR must return 5, while the transformed IR returns 7\r\n\r\nProof of wrong transformation: https://alive2.llvm.org/ce/z/vPFhzg", "author": "Nirhar", "labels": ["miscompilation", "llvm:SCEV"], "comments": [{"author": "nikic", "body": "Is this a fuzzer-generated test case?"}, {"author": "Nirhar", "body": "> Is this a fuzzer-generated test case?\n\nHi @nikic , yes this test was fuzzer-generated."}]}, "verified": true} {"bug_id": "110382", "issue_url": "https://github.com/llvm/llvm-project/issues/110382", "bug_type": "crash", "base_commit": "72a957ba4c8ef059f1572f6d4ee0cba8dc615268", "knowledge_cutoff": "2024-09-28T19:00:52Z", "lit_test_dir": ["llvm/test/Transforms/VectorCombine"], "hints": {"fix_commit": "c136d3237a3c6230cfe1ab3f0f6790f903c54a27", "components": ["VectorCombine"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": [[1984, 2016], [2038, 2044]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": ["VectorCombine::foldShuffleToIdentity"]}}, "patch": "commit c136d3237a3c6230cfe1ab3f0f6790f903c54a27\nAuthor: David Green \nDate: Wed Oct 9 16:20:03 2024 +0100\n\n [VectorCombine] Do not try to operate on OperandBundles. (#111635)\n \n This bails out if we see an intrinsic with an operand bundle on it, to\n make sure we don't process the bundles incorrectly.\n \n Fixes #110382.\n\ndiff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp\nindex a2ab5d966640..627edb680dfa 100644\n--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp\n+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp\n@@ -1984,33 +1984,35 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) {\n \n // We need each element to be the same type of value, and check that each\n // element has a single use.\n- if (all_of(drop_begin(Item), [Item](InstLane IL) {\n- Value *FrontV = Item.front().first->get();\n- if (!IL.first)\n- return true;\n- Value *V = IL.first->get();\n- if (auto *I = dyn_cast(V); I && !I->hasOneUse())\n- return false;\n- if (V->getValueID() != FrontV->getValueID())\n- return false;\n- if (auto *CI = dyn_cast(V))\n- if (CI->getPredicate() != cast(FrontV)->getPredicate())\n- return false;\n- if (auto *CI = dyn_cast(V))\n- if (CI->getSrcTy() != cast(FrontV)->getSrcTy())\n- return false;\n- if (auto *SI = dyn_cast(V))\n- if (!isa(SI->getOperand(0)->getType()) ||\n- SI->getOperand(0)->getType() !=\n- cast(FrontV)->getOperand(0)->getType())\n- return false;\n- if (isa(V) && !isa(V))\n- return false;\n- auto *II = dyn_cast(V);\n- return !II || (isa(FrontV) &&\n- II->getIntrinsicID() ==\n- cast(FrontV)->getIntrinsicID());\n- })) {\n+ auto CheckLaneIsEquivalentToFirst = [Item](InstLane IL) {\n+ Value *FrontV = Item.front().first->get();\n+ if (!IL.first)\n+ return true;\n+ Value *V = IL.first->get();\n+ if (auto *I = dyn_cast(V); I && !I->hasOneUse())\n+ return false;\n+ if (V->getValueID() != FrontV->getValueID())\n+ return false;\n+ if (auto *CI = dyn_cast(V))\n+ if (CI->getPredicate() != cast(FrontV)->getPredicate())\n+ return false;\n+ if (auto *CI = dyn_cast(V))\n+ if (CI->getSrcTy() != cast(FrontV)->getSrcTy())\n+ return false;\n+ if (auto *SI = dyn_cast(V))\n+ if (!isa(SI->getOperand(0)->getType()) ||\n+ SI->getOperand(0)->getType() !=\n+ cast(FrontV)->getOperand(0)->getType())\n+ return false;\n+ if (isa(V) && !isa(V))\n+ return false;\n+ auto *II = dyn_cast(V);\n+ return !II || (isa(FrontV) &&\n+ II->getIntrinsicID() ==\n+ cast(FrontV)->getIntrinsicID() &&\n+ !II->hasOperandBundles());\n+ };\n+ if (all_of(drop_begin(Item), CheckLaneIsEquivalentToFirst)) {\n // Check the operator is one that we support.\n if (isa(FrontU)) {\n // We exclude div/rem in case they hit UB from poison lanes.\n@@ -2038,7 +2040,8 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) {\n Worklist.push_back(generateInstLaneVectorFromOperand(Item, 2));\n continue;\n } else if (auto *II = dyn_cast(FrontU);\n- II && isTriviallyVectorizable(II->getIntrinsicID())) {\n+ II && isTriviallyVectorizable(II->getIntrinsicID()) &&\n+ !II->hasOperandBundles()) {\n for (unsigned Op = 0, E = II->getNumOperands() - 1; Op < E; Op++) {\n if (isVectorIntrinsicWithScalarOpAtArg(II->getIntrinsicID(), Op)) {\n if (!all_of(drop_begin(Item), [Item, Op](InstLane &IL) {\n", "tests": [{"file": "llvm/test/Transforms/VectorCombine/AArch64/shuffletoidentity.ll", "commands": ["opt -passes=vector-combine -S %s"], "tests": [{"test_name": "add_same_operands", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i32> @add_same_operands(<4 x i32> %x) {\n %shuf = shufflevector <4 x i32> %x, <4 x i32> poison, <4 x i32> \n %add = add <4 x i32> %shuf, %shuf\n %revshuf = shufflevector <4 x i32> %add, <4 x i32> poison, <4 x i32> \n ret <4 x i32> %revshuf\n}\n"}, {"test_name": "extrause_add_same_operands", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i32> @extrause_add_same_operands(<4 x i32> %x) {\n %shuf = shufflevector <4 x i32> %x, <4 x i32> poison, <4 x i32> \n %add = add <4 x i32> %shuf, %shuf\n %revshuf = shufflevector <4 x i32> %add, <4 x i32> poison, <4 x i32> \n %add2 = add <4 x i32> %shuf, %revshuf\n ret <4 x i32> %add2\n}\n"}, {"test_name": "callinst2", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @callinst2(<8 x half> %a) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> \n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> \n %abt = call <4 x half> @llvm.fabs.v4f16(<4 x half> %at)\n %abb = call <4 x half> @othercall(<4 x half> %ab)\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> \n ret <8 x half> %r\n}\n\ndeclare <4 x half> @othercall(<4 x half>)\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x half> @llvm.fabs.v4f16(<4 x half>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "poison_intrinsic", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i32> @poison_intrinsic(<2 x i16> %l256) {\n %l266 = call <2 x i16> @llvm.abs.v2i16(<2 x i16> %l256, i1 false)\n %l267 = zext <2 x i16> %l266 to <2 x i32>\n %l271 = shufflevector <2 x i32> %l267, <2 x i32> poison, <4 x i32> \n ret <4 x i32> %l271\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <2 x i16> @llvm.abs.v2i16(<2 x i16>, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "splattwice", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @splattwice(<8 x half> %a, <8 x half> %b) {\n %as = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> zeroinitializer\n %bs = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> zeroinitializer\n %ab1 = fadd <4 x half> %as, %bs\n %ab2 = fadd <4 x half> %as, %bs\n %r = shufflevector <4 x half> %ab1, <4 x half> %ab2, <8 x i32> \n ret <8 x half> %r\n}\n"}, {"test_name": "fadd_mismatched_types", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x float> @fadd_mismatched_types(<4 x float> %x, <4 x float> %y) {\n %shuf.x = shufflevector <4 x float> %x, <4 x float> poison, <2 x i32> \n %shuf.y = shufflevector <4 x float> %y, <4 x float> poison, <2 x i32> \n %fadd = fadd fast <2 x float> %shuf.x, %shuf.y\n %extshuf = shufflevector <2 x float> %fadd, <2 x float> poison, <4 x i32> \n ret <4 x float> %extshuf\n}\n"}, {"test_name": "intrinsics_minmax", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @intrinsics_minmax(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> \n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> \n %abt = call <4 x i8> @llvm.smin.v4i8(<4 x i8> %at, <4 x i8> %bt)\n %abb = call <4 x i8> @llvm.smin.v4i8(<4 x i8> %ab, <4 x i8> %bb)\n %abt1 = call <4 x i8> @llvm.smax.v4i8(<4 x i8> %abt, <4 x i8> %bt)\n %abb1 = call <4 x i8> @llvm.smax.v4i8(<4 x i8> %abb, <4 x i8> %bb)\n %abt2 = call <4 x i8> @llvm.umin.v4i8(<4 x i8> %abt1, <4 x i8> %bt)\n %abb2 = call <4 x i8> @llvm.umin.v4i8(<4 x i8> %abb1, <4 x i8> %bb)\n %abt3 = call <4 x i8> @llvm.umax.v4i8(<4 x i8> %abt2, <4 x i8> %bt)\n %abb3 = call <4 x i8> @llvm.umax.v4i8(<4 x i8> %abb2, <4 x i8> %bb)\n %r = shufflevector <4 x i8> %abt3, <4 x i8> %abb3, <8 x i32> \n ret <8 x i8> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.smax.v4i8(<4 x i8>, <4 x i8>) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.smin.v4i8(<4 x i8>, <4 x i8>) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.umax.v4i8(<4 x i8>, <4 x i8>) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.umin.v4i8(<4 x i8>, <4 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "constantdiff2", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @constantdiff2(<8 x i8> %a) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %abt = add <4 x i8> %at, \n %abb = add <4 x i8> %ab, \n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> \n ret <8 x i8> %r\n}\n"}, {"test_name": "fcmpsel", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @fcmpsel(<8 x half> %a, <8 x half> %b, <8 x i8> %c, <8 x i8> %d) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> \n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> \n %bb = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> \n %bt = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> \n %cb = shufflevector <8 x i8> %c, <8 x i8> poison, <4 x i32> \n %ct = shufflevector <8 x i8> %c, <8 x i8> poison, <4 x i32> \n %db = shufflevector <8 x i8> %d, <8 x i8> poison, <4 x i32> \n %dt = shufflevector <8 x i8> %d, <8 x i8> poison, <4 x i32> \n %abt1 = fcmp olt <4 x half> %at, %bt\n %abb1 = fcmp olt <4 x half> %ab, %bb\n %abt = select <4 x i1> %abt1, <4 x i8> %ct, <4 x i8> %dt\n %abb = select <4 x i1> %abb1, <4 x i8> %cb, <4 x i8> %db\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> \n ret <8 x i8> %r\n}\n"}, {"test_name": "inner_shuffle", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @inner_shuffle(<8 x i8> %a, <8 x i8> %b, <8 x i8> %c) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> \n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> \n %cs = shufflevector <8 x i8> %c, <8 x i8> poison, <4 x i32> zeroinitializer\n %abt = mul <4 x i8> %at, %bt\n %abb = mul <4 x i8> %ab, %bb\n %abt2 = shufflevector <4 x i8> %abt, <4 x i8> poison, <4 x i32> \n %abb2 = shufflevector <4 x i8> %abb, <4 x i8> poison, <4 x i32> \n %abt3 = add <4 x i8> %abt2, %cs\n %abb3 = add <4 x i8> %abb2, %cs\n %r = shufflevector <4 x i8> %abt3, <4 x i8> %abb3, <8 x i32> \n ret <8 x i8> %r\n}\n"}, {"test_name": "zext_types", "test_body": "target triple = \"aarch64\"\n\ndefine void @zext_types(<8 x i16> %a, <8 x i32> %b, ptr %p) {\n %ab = shufflevector <8 x i16> %a, <8 x i16> poison, <4 x i32> \n %at = shufflevector <8 x i32> %b, <8 x i32> poison, <4 x i32> \n %ab1 = zext <4 x i16> %ab to <4 x i64>\n %at1 = zext <4 x i32> %at to <4 x i64>\n %r = shufflevector <4 x i64> %ab1, <4 x i64> %at1, <8 x i32> \n store <8 x i64> %r, ptr %p, align 64\n ret void\n}\n"}, {"test_name": "add_different_operands", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @add_different_operands(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> \n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> \n %abt = add <4 x i8> %at, %bt\n %abb = add <4 x i8> %ab, %bb\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> \n ret <8 x i8> %r\n}\n"}, {"test_name": "constantdiff", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @constantdiff(<8 x i8> %a) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %abt = add <4 x i8> %at, \n %abb = add <4 x i8> %ab, \n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> \n ret <8 x i8> %r\n}\n"}, {"test_name": "extrause_add_different_operands", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @extrause_add_different_operands(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> \n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> \n %abt = add <4 x i8> %at, %bt\n %abb = add <4 x i8> %ab, %bb\n call void @use(<4 x i8> %abb)\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> \n ret <8 x i8> %r\n}\n\ndeclare void @use(<4 x i8>)\n"}, {"test_name": "icmpsel_diffentcond", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @icmpsel_diffentcond(<8 x i8> %a, <8 x i8> %b, <8 x i8> %c, <8 x i8> %d) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> \n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> \n %cb = shufflevector <8 x i8> %c, <8 x i8> poison, <4 x i32> \n %ct = shufflevector <8 x i8> %c, <8 x i8> poison, <4 x i32> \n %db = shufflevector <8 x i8> %d, <8 x i8> poison, <4 x i32> \n %dt = shufflevector <8 x i8> %d, <8 x i8> poison, <4 x i32> \n %abt1 = icmp slt <4 x i8> %at, %bt\n %abb1 = icmp ult <4 x i8> %ab, %bb\n %abt = select <4 x i1> %abt1, <4 x i8> %ct, <4 x i8> %dt\n %abb = select <4 x i1> %abb1, <4 x i8> %cb, <4 x i8> %db\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> \n ret <8 x i8> %r\n}\n"}, {"test_name": "exttrunc", "test_body": "target triple = \"aarch64\"\n\ndefine void @exttrunc(<8 x i32> %a, <8 x i32> %b, ptr %p) {\n %ab = shufflevector <8 x i32> %a, <8 x i32> poison, <4 x i32> \n %at = shufflevector <8 x i32> %a, <8 x i32> poison, <4 x i32> \n %bb = shufflevector <8 x i32> %b, <8 x i32> poison, <4 x i32> \n %bt = shufflevector <8 x i32> %b, <8 x i32> poison, <4 x i32> \n %ab1 = zext <4 x i32> %ab to <4 x i64>\n %at1 = zext <4 x i32> %at to <4 x i64>\n %bb1 = sext <4 x i32> %bb to <4 x i64>\n %bt1 = sext <4 x i32> %bt to <4 x i64>\n %abb = add <4 x i64> %ab1, %bb1\n %abt = add <4 x i64> %at1, %bt1\n %abb1 = trunc <4 x i64> %abb to <4 x i32>\n %abt1 = trunc <4 x i64> %abt to <4 x i32>\n %r = shufflevector <4 x i32> %abb1, <4 x i32> %abt1, <8 x i32> \n store <8 x i32> %r, ptr %p, align 32\n ret void\n}\n"}, {"test_name": "lrint", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i32> @lrint(<8 x half> %a) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> \n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> \n %abt = call <4 x i32> @llvm.lrint.v4i32.v4f16(<4 x half> %at)\n %abb = call <4 x i32> @llvm.lrint.v4i32.v4f16(<4 x half> %ab)\n %r = shufflevector <4 x i32> %abt, <4 x i32> %abb, <8 x i32> \n ret <8 x i32> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i32> @llvm.lrint.v4i32.v4f16(<4 x half>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "fadd", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @fadd(<8 x half> %a, <8 x half> %b) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> \n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> \n %bb = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> \n %bt = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> \n %abt = fadd <4 x half> %at, %bt\n %abb = fadd <4 x half> %ab, %bb\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> \n ret <8 x half> %r\n}\n"}, {"test_name": "abs_different", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @abs_different(<8 x i8> %a) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %abt = call <4 x i8> @llvm.abs.v4i8(<4 x i8> %at, i1 true)\n %abb = call <4 x i8> @llvm.abs.v4i8(<4 x i8> %ab, i1 false)\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> \n ret <8 x i8> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.abs.v4i8(<4 x i8>, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "wrong_addsub", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @wrong_addsub(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> \n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> \n %abt = add <4 x i8> %at, %bt\n %abb = sub <4 x i8> %ab, %bb\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> \n ret <8 x i8> %r\n}\n"}, {"test_name": "single_zext", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i64> @single_zext(<4 x i32> %x) {\n %shuf = shufflevector <4 x i32> %x, <4 x i32> poison, <4 x i32> \n %zext = zext <4 x i32> %shuf to <4 x i64>\n %revshuf = shufflevector <4 x i64> %zext, <4 x i64> poison, <4 x i32> \n ret <4 x i64> %revshuf\n}\n"}, {"test_name": "v8f64interleave", "test_body": "target triple = \"aarch64\"\n\ndefine void @v8f64interleave(i64 %0, ptr %1, ptr %x, double %z) {\nentry:\n %broadcast.splatinsert = insertelement <2 x double> poison, double %z, i64 0\n %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer\n %wide.vec = load <16 x double>, ptr %1, align 8\n %strided.vec = shufflevector <16 x double> %wide.vec, <16 x double> poison, <2 x i32> \n %strided.vec27 = shufflevector <16 x double> %wide.vec, <16 x double> poison, <2 x i32> \n %strided.vec28 = shufflevector <16 x double> %wide.vec, <16 x double> poison, <2 x i32> \n %strided.vec29 = shufflevector <16 x double> %wide.vec, <16 x double> poison, <2 x i32> \n %strided.vec30 = shufflevector <16 x double> %wide.vec, <16 x double> poison, <2 x i32> \n %strided.vec31 = shufflevector <16 x double> %wide.vec, <16 x double> poison, <2 x i32> \n %strided.vec32 = shufflevector <16 x double> %wide.vec, <16 x double> poison, <2 x i32> \n %strided.vec33 = shufflevector <16 x double> %wide.vec, <16 x double> poison, <2 x i32> \n %2 = fmul fast <2 x double> %strided.vec, %broadcast.splat\n %3 = getelementptr inbounds double, ptr %x, i64 %0\n %wide.vec34 = load <16 x double>, ptr %3, align 8\n %strided.vec35 = shufflevector <16 x double> %wide.vec34, <16 x double> poison, <2 x i32> \n %strided.vec36 = shufflevector <16 x double> %wide.vec34, <16 x double> poison, <2 x i32> \n %strided.vec37 = shufflevector <16 x double> %wide.vec34, <16 x double> poison, <2 x i32> \n %strided.vec38 = shufflevector <16 x double> %wide.vec34, <16 x double> poison, <2 x i32> \n %strided.vec39 = shufflevector <16 x double> %wide.vec34, <16 x double> poison, <2 x i32> \n %strided.vec40 = shufflevector <16 x double> %wide.vec34, <16 x double> poison, <2 x i32> \n %strided.vec41 = shufflevector <16 x double> %wide.vec34, <16 x double> poison, <2 x i32> \n %strided.vec42 = shufflevector <16 x double> %wide.vec34, <16 x double> poison, <2 x i32> \n %4 = fadd fast <2 x double> %strided.vec35, %2\n %5 = fmul fast <2 x double> %strided.vec27, %broadcast.splat\n %6 = fadd fast <2 x double> %strided.vec36, %5\n %7 = fmul fast <2 x double> %strided.vec28, %broadcast.splat\n %8 = fadd fast <2 x double> %strided.vec37, %7\n %9 = fmul fast <2 x double> %strided.vec29, %broadcast.splat\n %10 = fadd fast <2 x double> %strided.vec38, %9\n %11 = fmul fast <2 x double> %strided.vec30, %broadcast.splat\n %12 = fadd fast <2 x double> %strided.vec39, %11\n %13 = fmul fast <2 x double> %strided.vec31, %broadcast.splat\n %14 = fadd fast <2 x double> %strided.vec40, %13\n %15 = fmul fast <2 x double> %strided.vec32, %broadcast.splat\n %16 = fadd fast <2 x double> %strided.vec41, %15\n %17 = or disjoint i64 %0, 7\n %18 = fmul fast <2 x double> %strided.vec33, %broadcast.splat\n %19 = getelementptr inbounds double, ptr %x, i64 %17\n %20 = fadd fast <2 x double> %strided.vec42, %18\n %21 = getelementptr inbounds i8, ptr %19, i64 -56\n %22 = shufflevector <2 x double> %4, <2 x double> %6, <4 x i32> \n %23 = shufflevector <2 x double> %8, <2 x double> %10, <4 x i32> \n %24 = shufflevector <2 x double> %12, <2 x double> %14, <4 x i32> \n %25 = shufflevector <2 x double> %16, <2 x double> %20, <4 x i32> \n %26 = shufflevector <4 x double> %22, <4 x double> %23, <8 x i32> \n %27 = shufflevector <4 x double> %24, <4 x double> %25, <8 x i32> \n %interleaved.vec = shufflevector <8 x double> %26, <8 x double> %27, <16 x i32> \n store <16 x double> %interleaved.vec, ptr %21, align 8\n ret void\n}\n"}, {"test_name": "singleop", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i8> @singleop(<4 x i8> %a, <4 x i8> %b) {\n %a1 = shufflevector <4 x i8> %a, <4 x i8> poison, <4 x i32> \n %b1 = shufflevector <4 x i8> %b, <4 x i8> poison, <4 x i32> zeroinitializer\n %a2 = zext <4 x i8> %a1 to <4 x i16>\n %b2 = zext <4 x i8> %b1 to <4 x i16>\n %ab = add <4 x i16> %a2, %b2\n %t = trunc <4 x i16> %ab to <4 x i8>\n %r = shufflevector <4 x i8> %t, <4 x i8> poison, <4 x i32> \n ret <4 x i8> %r\n}\n"}, {"test_name": "not_bitcast", "test_body": "target triple = \"aarch64\"\n\ndefine i32 @not_bitcast(<4 x i8> %x) {\n %shuf = shufflevector <4 x i8> %x, <4 x i8> poison, <4 x i32> \n %bitcast = bitcast <4 x i8> %shuf to i32\n ret i32 %bitcast\n}\n"}, {"test_name": "zext_chain", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i64> @zext_chain(<4 x i16> %x) {\n %shuf = shufflevector <4 x i16> %x, <4 x i16> poison, <4 x i32> \n %zext = zext <4 x i16> %shuf to <4 x i32>\n %sext = sext <4 x i32> %zext to <4 x i64>\n %revshuf = shufflevector <4 x i64> %sext, <4 x i64> poison, <4 x i32> \n ret <4 x i64> %revshuf\n}\n"}, {"test_name": "intrinsics_different", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @intrinsics_different(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> \n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> \n %abt = call <4 x i8> @llvm.smin.v4i8(<4 x i8> %at, <4 x i8> %bt)\n %abb = call <4 x i8> @llvm.umin.v4i8(<4 x i8> %ab, <4 x i8> %bb)\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> \n ret <8 x i8> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.smin.v4i8(<4 x i8>, <4 x i8>) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.umin.v4i8(<4 x i8>, <4 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "operandbundles_second", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @operandbundles_second(<8 x i8> %a) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %abt = call <4 x i8> @llvm.abs.v4i8(<4 x i8> %at, i1 false)\n %abb = call <4 x i8> @llvm.abs.v4i8(<4 x i8> %ab, i1 false) [ \"jl_roots\"(ptr addrspace(10) null, ptr addrspace(10) null) ]\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> \n ret <8 x i8> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.abs.v4i8(<4 x i8>, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "cast_mismatched_types", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i64> @cast_mismatched_types(<4 x i32> %x) {\n %shuf = shufflevector <4 x i32> %x, <4 x i32> poison, <2 x i32> \n %zext = zext <2 x i32> %shuf to <2 x i64>\n %extshuf = shufflevector <2 x i64> %zext, <2 x i64> poison, <4 x i32> \n ret <4 x i64> %extshuf\n}\n"}, {"test_name": "operandbundles_first", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @operandbundles_first(<8 x i8> %a) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %abt = call <4 x i8> @llvm.abs.v4i8(<4 x i8> %at, i1 false) [ \"jl_roots\"(ptr addrspace(10) null, ptr addrspace(10) null) ]\n %abb = call <4 x i8> @llvm.abs.v4i8(<4 x i8> %ab, i1 false)\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> \n ret <8 x i8> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.abs.v4i8(<4 x i8>, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "wrong_lanes", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @wrong_lanes(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> \n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> \n %abt = add <4 x i8> %at, %bt\n %abb = add <4 x i8> %ab, %bb\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> \n ret <8 x i8> %r\n}\n"}, {"test_name": "first_scalar_select", "test_body": "target triple = \"aarch64\"\n\ndefine <2 x float> @first_scalar_select(<2 x float> %0, <2 x float> %1, float %x) {\nentry:\n %cmp.i903 = fcmp ogt float %x, 0.000000e+00\n %sel1639 = select i1 %cmp.i903, <2 x float> %0, <2 x float> %1\n %2 = fcmp ogt <2 x float> %0, zeroinitializer\n %sel48.i913 = select <2 x i1> %2, <2 x float> %0, <2 x float> %1\n %3 = shufflevector <2 x float> %sel1639, <2 x float> %sel48.i913, <2 x i32> \n ret <2 x float> %3\n}\n"}, {"test_name": "splat0", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @splat0(<8 x half> %a, <8 x half> %b) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> \n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> \n %bs = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> zeroinitializer\n %abt = fadd <4 x half> %at, %bs\n %abb = fadd <4 x half> %ab, %bs\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> \n ret <8 x half> %r\n}\n"}, {"test_name": "splatandidentity", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @splatandidentity(<8 x half> %a, <8 x half> %b) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> \n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> \n %bs = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> zeroinitializer\n %abt = fadd <4 x half> %at, %bs\n %abb = fadd <4 x half> %ab, %bs\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> \n ret <8 x half> %r\n}\n"}, {"test_name": "trivial", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @trivial(<8 x i8> %a) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %r = shufflevector <4 x i8> %at, <4 x i8> %ab, <8 x i32> \n ret <8 x i8> %r\n}\n"}, {"test_name": "constantsplat", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @constantsplat(<8 x i8> %a) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %abt = add <4 x i8> %at, splat (i8 10)\n %abb = add <4 x i8> %ab, splat (i8 10)\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> \n ret <8 x i8> %r\n}\n"}, {"test_name": "bitcast_srcty_mismatch", "test_body": "target triple = \"aarch64\"\n\ndefine void @bitcast_srcty_mismatch() {\nentry:\n %shuffle.i.i = shufflevector <2 x i64> zeroinitializer, <2 x i64> zeroinitializer, <2 x i32> \n %0 = bitcast <4 x i32> zeroinitializer to <4 x float>\n %1 = bitcast <2 x i64> %shuffle.i.i to <4 x float>\n %shufp.i196 = shufflevector <4 x float> %0, <4 x float> %1, <4 x i32> \n store <4 x float> %shufp.i196, ptr null, align 16\n ret void\n}\n"}, {"test_name": "zext_add_chain", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i64> @zext_add_chain(<4 x i32> %x) {\n %shuf = shufflevector <4 x i32> %x, <4 x i32> poison, <4 x i32> \n %zext = zext <4 x i32> %shuf to <4 x i64>\n %add = add <4 x i64> %zext, %zext\n %revshuf = shufflevector <4 x i64> %add, <4 x i64> poison, <4 x i32> \n ret <4 x i64> %revshuf\n}\n"}, {"test_name": "add_chain", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i32> @add_chain(<4 x i32> %x) {\n %shuf = shufflevector <4 x i32> %x, <4 x i32> poison, <4 x i32> \n %add = add <4 x i32> %shuf, %shuf\n %add2 = add <4 x i32> %add, %add\n %revshuf = shufflevector <4 x i32> %add2, <4 x i32> poison, <4 x i32> \n ret <4 x i32> %revshuf\n}\n"}, {"test_name": "splat2", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @splat2(<8 x half> %a, <8 x half> %b) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> \n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> \n %bs = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> \n %abt = fadd <4 x half> %at, %bs\n %abb = fadd <4 x half> %ab, %bs\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> \n ret <8 x half> %r\n}\n"}, {"test_name": "trunc", "test_body": "target triple = \"aarch64\"\n\ndefine void @trunc(<8 x i64> %a, <8 x i64> %b, ptr %p) {\n %ab = shufflevector <8 x i64> %a, <8 x i64> poison, <4 x i32> \n %at = shufflevector <8 x i64> %a, <8 x i64> poison, <4 x i32> \n %abb1 = trunc <4 x i64> %ab to <4 x i32>\n %abt1 = trunc <4 x i64> %at to <4 x i32>\n %r = shufflevector <4 x i32> %abb1, <4 x i32> %abt1, <8 x i32> \n store <8 x i32> %r, ptr %p, align 32\n ret void\n}\n"}, {"test_name": "sext", "test_body": "target triple = \"aarch64\"\n\ndefine void @sext(<8 x i16> %a, <8 x i16> %b, ptr %p) {\n %ab = shufflevector <8 x i16> %a, <8 x i16> poison, <4 x i32> \n %at = shufflevector <8 x i16> %a, <8 x i16> poison, <4 x i32> \n %bb = shufflevector <8 x i16> %b, <8 x i16> poison, <4 x i32> \n %bt = shufflevector <8 x i16> %b, <8 x i16> poison, <4 x i32> \n %ab1 = sext <4 x i16> %ab to <4 x i32>\n %at1 = sext <4 x i16> %at to <4 x i32>\n %bb1 = sext <4 x i16> %bb to <4 x i32>\n %bt1 = sext <4 x i16> %bt to <4 x i32>\n %abb = add <4 x i32> %ab1, %bb1\n %abt = add <4 x i32> %at1, %bt1\n %r = shufflevector <4 x i32> %abb, <4 x i32> %abt, <8 x i32> \n store <8 x i32> %r, ptr %p, align 32\n ret void\n}\n"}, {"test_name": "powi", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @powi(<8 x half> %a) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> \n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> \n %abt = call <4 x half> @llvm.powi.v4f16.i32(<4 x half> %at, i32 10)\n %abb = call <4 x half> @llvm.powi.v4f16.i32(<4 x half> %ab, i32 10)\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> \n ret <8 x half> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x half> @llvm.powi.v4f16.i32(<4 x half>, i32) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "callinst", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @callinst(<8 x half> %a) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> \n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> \n %abt = call <4 x half> @othercall(<4 x half> %at)\n %abb = call <4 x half> @llvm.fabs.v4f16(<4 x half> %ab)\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> \n ret <8 x half> %r\n}\n\ndeclare <4 x half> @othercall(<4 x half>)\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x half> @llvm.fabs.v4f16(<4 x half>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "fma", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @fma(<8 x half> %a, <8 x half> %b, <8 x half> %c) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> \n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> \n %bb = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> \n %bt = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> \n %cb = shufflevector <8 x half> %c, <8 x half> poison, <4 x i32> \n %ct = shufflevector <8 x half> %c, <8 x half> poison, <4 x i32> \n %abb = call <4 x half> @llvm.fma.v4f16(<4 x half> %ab, <4 x half> %bb, <4 x half> %cb)\n %abt = call <4 x half> @llvm.fma.v4f16(<4 x half> %at, <4 x half> %bt, <4 x half> %ct)\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> \n ret <8 x half> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x half> @llvm.fma.v4f16(<4 x half>, <4 x half>, <4 x half>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "extrause_shuffle", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @extrause_shuffle(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> \n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> \n call void @use(<4 x i8> %bt)\n %abt = add <4 x i8> %at, %bt\n %abb = add <4 x i8> %ab, %bb\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> \n ret <8 x i8> %r\n}\n\ndeclare void @use(<4 x i8>)\n"}, {"test_name": "intrinsics_addsat", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @intrinsics_addsat(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> \n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> \n %abt = call <4 x i8> @llvm.sadd.sat.v4i8(<4 x i8> %at, <4 x i8> %bt)\n %abb = call <4 x i8> @llvm.sadd.sat.v4i8(<4 x i8> %ab, <4 x i8> %bb)\n %abt1 = call <4 x i8> @llvm.ssub.sat.v4i8(<4 x i8> %abt, <4 x i8> %bt)\n %abb1 = call <4 x i8> @llvm.ssub.sat.v4i8(<4 x i8> %abb, <4 x i8> %bb)\n %abt2 = call <4 x i8> @llvm.uadd.sat.v4i8(<4 x i8> %abt1, <4 x i8> %bt)\n %abb2 = call <4 x i8> @llvm.uadd.sat.v4i8(<4 x i8> %abb1, <4 x i8> %bb)\n %abt3 = call <4 x i8> @llvm.usub.sat.v4i8(<4 x i8> %abt2, <4 x i8> %bt)\n %abb3 = call <4 x i8> @llvm.usub.sat.v4i8(<4 x i8> %abb2, <4 x i8> %bb)\n %r = shufflevector <4 x i8> %abt3, <4 x i8> %abb3, <8 x i32> \n ret <8 x i8> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.sadd.sat.v4i8(<4 x i8>, <4 x i8>) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.ssub.sat.v4i8(<4 x i8>, <4 x i8>) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.uadd.sat.v4i8(<4 x i8>, <4 x i8>) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.usub.sat.v4i8(<4 x i8>, <4 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "zext", "test_body": "target triple = \"aarch64\"\n\ndefine void @zext(<8 x i16> %a, <8 x i16> %b, ptr %p) {\n %ab = shufflevector <8 x i16> %a, <8 x i16> poison, <4 x i32> \n %at = shufflevector <8 x i16> %a, <8 x i16> poison, <4 x i32> \n %bb = shufflevector <8 x i16> %b, <8 x i16> poison, <4 x i32> \n %bt = shufflevector <8 x i16> %b, <8 x i16> poison, <4 x i32> \n %ab1 = zext <4 x i16> %ab to <4 x i32>\n %at1 = zext <4 x i16> %at to <4 x i32>\n %bb1 = zext <4 x i16> %bb to <4 x i32>\n %bt1 = zext <4 x i16> %bt to <4 x i32>\n %abb = add <4 x i32> %ab1, %bb1\n %abt = add <4 x i32> %at1, %bt1\n %r = shufflevector <4 x i32> %abb, <4 x i32> %abt, <8 x i32> \n store <8 x i32> %r, ptr %p, align 32\n ret void\n}\n"}, {"test_name": "div", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @div(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> \n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> \n %abt = udiv <4 x i8> %at, %bt\n %abb = udiv <4 x i8> %ab, %bb\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> \n ret <8 x i8> %r\n}\n"}, {"test_name": "bitcast_smax_v8i32_v4i32", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i64> @bitcast_smax_v8i32_v4i32(<4 x i64> %a, <4 x i64> %b) {\n %a.bc0 = bitcast <4 x i64> %a to <8 x i32>\n %b.bc0 = bitcast <4 x i64> %b to <8 x i32>\n %cmp = icmp slt <8 x i32> %a.bc0, %b.bc0\n %cmp.lo = shufflevector <8 x i1> %cmp, <8 x i1> poison, <4 x i32> \n %cmp.hi = shufflevector <8 x i1> %cmp, <8 x i1> poison, <4 x i32> \n %a.bc1 = bitcast <4 x i64> %a to <8 x i32>\n %b.bc1 = bitcast <4 x i64> %b to <8 x i32>\n %a.lo = shufflevector <8 x i32> %a.bc1, <8 x i32> poison, <4 x i32> \n %b.lo = shufflevector <8 x i32> %b.bc1, <8 x i32> poison, <4 x i32> \n %lo = select <4 x i1> %cmp.lo, <4 x i32> %b.lo, <4 x i32> %a.lo\n %a.bc2 = bitcast <4 x i64> %a to <8 x i32>\n %b.bc2 = bitcast <4 x i64> %b to <8 x i32>\n %a.hi = shufflevector <8 x i32> %a.bc2, <8 x i32> poison, <4 x i32> \n %b.hi = shufflevector <8 x i32> %b.bc2, <8 x i32> poison, <4 x i32> \n %hi = select <4 x i1> %cmp.hi, <4 x i32> %b.hi, <4 x i32> %a.hi\n %concat = shufflevector <4 x i32> %lo, <4 x i32> %hi, <8 x i32> \n %res = bitcast <8 x i32> %concat to <4 x i64>\n ret <4 x i64> %res\n}\n"}, {"test_name": "not_bitcast2", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i16> @not_bitcast2(<4 x i32> %x, <8 x i16> %y) {\n %cast = bitcast <4 x i32> %x to <8 x i16>\n %out = shufflevector <8 x i16> %y, <8 x i16> %cast, <8 x i32> \n ret <8 x i16> %out\n}\n"}, {"test_name": "abs", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @abs(<8 x i8> %a) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %abt = call <4 x i8> @llvm.abs.v4i8(<4 x i8> %at, i1 false)\n %abb = call <4 x i8> @llvm.abs.v4i8(<4 x i8> %ab, i1 false)\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> \n ret <8 x i8> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.abs.v4i8(<4 x i8>, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "maximal_legal_fpmath", "test_body": "target triple = \"aarch64\"\n\ndefine void @maximal_legal_fpmath(ptr %addr1, ptr %addr2, ptr %result, float %val) {\n %splatinsert = insertelement <4 x float> poison, float %val, i64 0\n %incoming.vec = shufflevector <4 x float> %splatinsert, <4 x float> poison, <4 x i32> zeroinitializer\n %vec1 = load <16 x float>, ptr %addr1, align 4\n %strided.vec1 = shufflevector <16 x float> %vec1, <16 x float> poison, <4 x i32> \n %strided.vec2 = shufflevector <16 x float> %vec1, <16 x float> poison, <4 x i32> \n %strided.vec3 = shufflevector <16 x float> %vec1, <16 x float> poison, <4 x i32> \n %strided.vec4 = shufflevector <16 x float> %vec1, <16 x float> poison, <4 x i32> \n %vec2 = load <16 x float>, ptr %addr2, align 4\n %strided.vec6 = shufflevector <16 x float> %vec2, <16 x float> poison, <4 x i32> \n %strided.vec7 = shufflevector <16 x float> %vec2, <16 x float> poison, <4 x i32> \n %strided.vec8 = shufflevector <16 x float> %vec2, <16 x float> poison, <4 x i32> \n %strided.vec9 = shufflevector <16 x float> %vec2, <16 x float> poison, <4 x i32> \n %1 = fmul fast <4 x float> %incoming.vec, %strided.vec6\n %2 = fadd fast <4 x float> %strided.vec1, %1\n %3 = fmul contract <4 x float> %incoming.vec, %strided.vec7\n %4 = fadd fast <4 x float> %strided.vec2, %3\n %5 = fmul reassoc contract <4 x float> %incoming.vec, %strided.vec8\n %6 = fadd fast <4 x float> %strided.vec3, %5\n %7 = fmul reassoc contract <4 x float> %incoming.vec, %strided.vec9\n %8 = fadd reassoc contract <4 x float> %strided.vec4, %7\n %9 = shufflevector <4 x float> %2, <4 x float> %4, <8 x i32> \n %10 = shufflevector <4 x float> %6, <4 x float> %8, <8 x i32> \n %interleaved.vec = shufflevector <8 x float> %9, <8 x float> %10, <16 x i32> \n store <16 x float> %interleaved.vec, ptr %result, align 4\n ret void\n}\n"}, {"test_name": "not_zext", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i64> @not_zext(<4 x i32> %x) {\n %zext = zext <4 x i32> %x to <4 x i64>\n %revshuf = shufflevector <4 x i64> %zext, <4 x i64> poison, <4 x i32> \n ret <4 x i64> %revshuf\n}\n"}, {"test_name": "undeflane", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @undeflane(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> \n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> \n %abt = add <4 x i8> %at, %bt\n %abb = add <4 x i8> %ab, %bb\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> \n ret <8 x i8> %r\n}\n"}, {"test_name": "operandbundles", "test_body": "target triple = \"aarch64\"\n\ndefine <16 x i64> @operandbundles(<4 x i64> %a, <4 x i64> %b, <4 x i64> %c) {\n %call = call <4 x i64> @llvm.fshl.v4i64(<4 x i64> %a, <4 x i64> %b, <4 x i64> %c) [ \"jl_roots\"(ptr addrspace(10) null, ptr addrspace(10) null) ]\n %shufflevector = shufflevector <4 x i64> %call, <4 x i64> poison, <16 x i32> \n %shufflevector1 = shufflevector <16 x i64> %shufflevector, <16 x i64> undef, <16 x i32> \n ret <16 x i64> %shufflevector1\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i64> @llvm.fshl.v4i64(<4 x i64>, <4 x i64>, <4 x i64>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "fneg", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @fneg(<8 x half> %a, <8 x half> %b) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> \n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> \n %abt = fneg <4 x half> %at\n %abb = fneg <4 x half> %ab\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> \n ret <8 x half> %r\n}\n"}, {"test_name": "icmpsel", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @icmpsel(<8 x i8> %a, <8 x i8> %b, <8 x i8> %c, <8 x i8> %d) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> \n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> \n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> \n %cb = shufflevector <8 x i8> %c, <8 x i8> poison, <4 x i32> \n %ct = shufflevector <8 x i8> %c, <8 x i8> poison, <4 x i32> \n %db = shufflevector <8 x i8> %d, <8 x i8> poison, <4 x i32> \n %dt = shufflevector <8 x i8> %d, <8 x i8> poison, <4 x i32> \n %abt1 = icmp slt <4 x i8> %at, %bt\n %abb1 = icmp slt <4 x i8> %ab, %bb\n %abt = select <4 x i1> %abt1, <4 x i8> %ct, <4 x i8> %dt\n %abb = select <4 x i1> %abb1, <4 x i8> %cb, <4 x i8> %db\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> \n ret <8 x i8> %r\n}\n"}, {"test_name": "szext", "test_body": "target triple = \"aarch64\"\n\ndefine void @szext(<8 x i32> %a, <8 x i32> %b, ptr %p) {\n %ab = shufflevector <8 x i32> %a, <8 x i32> poison, <4 x i32> \n %at = shufflevector <8 x i32> %a, <8 x i32> poison, <4 x i32> \n %ab1 = sext <4 x i32> %ab to <4 x i64>\n %at1 = zext <4 x i32> %at to <4 x i64>\n %r = shufflevector <4 x i64> %ab1, <4 x i64> %at1, <8 x i32> \n store <8 x i64> %r, ptr %p, align 64\n ret void\n}\n"}, {"test_name": "constantsplatf", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @constantsplatf(<8 x half> %a) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> \n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> \n %abt = fadd <4 x half> %at, splat (half 0xH4900)\n %abb = fadd <4 x half> %ab, splat (half 0xH4900)\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> \n ret <8 x half> %r\n}\n"}, {"test_name": "not_zext2", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i64> @not_zext2(<4 x i32> %x) {\n %shuf = shufflevector <4 x i32> %x, <4 x i32> poison, <4 x i32> \n %zext = zext <4 x i32> %shuf to <4 x i64>\n ret <4 x i64> %zext\n}\n"}]}], "issue": {"title": "Assertion Failure in Vector Combine", "body": "Runnning vector-combine pass on \r\n```llvm\r\nsource_filename = \"text\"\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:10:11:12:13\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine nonnull ptr addrspace(10) @wombat() {\r\n %call = call <4 x i64> @llvm.fshl.v4i64(<4 x i64> zeroinitializer, <4 x i64> zeroinitializer, <4 x i64> ) [ \"jl_roots\"(ptr addrspace(10) null, ptr addrspace(10) null) ]\r\n %shufflevector = shufflevector <4 x i64> %call, <4 x i64> poison, <16 x i32> \r\n %shufflevector1 = shufflevector <16 x i64> %shufflevector, <16 x i64> undef, <16 x i32> \r\n ret ptr addrspace(10) null\r\n}\r\n\r\ndeclare <4 x i64> @llvm.fshl.v4i64(<4 x i64>, <4 x i64>, <4 x i64>)\r\n```\r\nproduces\r\n```\r\nopt: /root/llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = llvm::FixedVectorType; From = llvm::Type]: Assertion `isa(Val) && \"cast() argument of incompatible type!\"' 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=vector-combine \r\n1.\tRunning pass \"function(vector-combine)\" on module \"\"\r\n2.\tRunning pass \"vector-combine\" on function \"wombat\"\r\n #0 0x0000000005079b38 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5079b38)\r\n #1 0x00000000050774ec SignalHandler(int) Signals.cpp:0:0\r\n #2 0x000074d0dce42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000074d0dce969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x000074d0dce42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x000074d0dce287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x000074d0dce2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x000074d0dce39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x0000000004186458 (anonymous namespace)::VectorCombine::foldShuffleToIdentity(llvm::Instruction&) VectorCombine.cpp:0:0\r\n #9 0x0000000004190f01 (anonymous namespace)::VectorCombine::run()::'lambda'(llvm::Instruction&)::operator()(llvm::Instruction&) const (.isra.0) VectorCombine.cpp:0:0\r\n#10 0x0000000004191c25 llvm::VectorCombinePass::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4191c25)\r\n#11 0x0000000002f2defe llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2f2defe)\r\n#12 0x0000000004e7c978 llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e7c978)\r\n#13 0x0000000000e157ce llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe157ce)\r\n#14 0x0000000004e7b39e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e7b39e)\r\n#15 0x0000000000e14f7e llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe14f7e)\r\n#16 0x0000000004e7add0 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e7add0)\r\n#17 0x0000000000904cc2 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::ArrayRef>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x904cc2)\r\n#18 0x00000000008f7b4c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f7b4c)\r\n#19 0x000074d0dce29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#20 0x000074d0dce29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#21 0x00000000008ef61e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ef61e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```\r\nGodbolt: https://godbolt.org/z/MGefYs3M5", "author": "Zentrik", "labels": ["release:backport", "vectorizers", "crash"], "comments": [{"author": "Heresh83", "body": "> Runnning vector-combine pass on \n> ```llvm\n> source_filename = \"text\"\n> target 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:10:11:12:13\"\n> target triple = \"x86_64-unknown-linux-gnu\"\n> \n> define nonnull ptr addrspace(10) @wombat() {\n> %call = call <4 x i64> @llvm.fshl.v4i64(<4 x i64> zeroinitializer, <4 x i64> zeroinitializer, <4 x i64> ) [ \"jl_roots\"(ptr addrspace(10) null, ptr addrspace(10) null) ]\n> %shufflevector = shufflevector <4 x i64> %call, <4 x i64> poison, <16 x i32> \n> %shufflevector1 = shufflevector <16 x i64> %shufflevector, <16 x i64> undef, <16 x i32> \n> ret ptr addrspace(10) null\n> }\n> \n> declare <4 x i64> @llvm.fshl.v4i64(<4 x i64>, <4 x i64>, <4 x i64>)\n> ```\n> produces\n> ```\n> opt: /root/llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = llvm::FixedVectorType; From = llvm::Type]: Assertion `isa(Val) && \"cast() argument of incompatible type!\"' failed.\n> PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\n> Stack dump:\n> 0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=vector-combine \n> 1.\tRunning pass \"function(vector-combine)\" on module \"\"\n> 2.\tRunning pass \"vector-combine\" on function \"wombat\"\n> #0 0x0000000005079b38 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5079b38)\n> #1 0x00000000050774ec SignalHandler(int) Signals.cpp:0:0\n> #2 0x000074d0dce42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n> #3 0x000074d0dce969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n> #4 0x000074d0dce42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n> #5 0x000074d0dce287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n> #6 0x000074d0dce2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n> #7 0x000074d0dce39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n> #8 0x0000000004186458 (anonymous namespace)::VectorCombine::foldShuffleToIdentity(llvm::Instruction&) VectorCombine.cpp:0:0\n> #9 0x0000000004190f01 (anonymous namespace)::VectorCombine::run()::'lambda'(llvm::Instruction&)::operator()(llvm::Instruction&) const (.isra.0) VectorCombine.cpp:0:0\n> #10 0x0000000004191c25 llvm::VectorCombinePass::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4191c25)\n> #11 0x0000000002f2defe llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2f2defe)\n> #12 0x0000000004e7c978 llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e7c978)\n> #13 0x0000000000e157ce llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe157ce)\n> #14 0x0000000004e7b39e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e7b39e)\n> #15 0x0000000000e14f7e llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe14f7e)\n> #16 0x0000000004e7add0 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e7add0)\n> #17 0x0000000000904cc2 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::ArrayRef>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x904cc2)\n> #18 0x00000000008f7b4c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f7b4c)\n> #19 0x000074d0dce29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n> #20 0x000074d0dce29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n> #21 0x00000000008ef61e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ef61e)\n> Program terminated with signal: SIGSEGV\n> Compiler returned: 139\n> ```\n> Godbolt: https://godbolt.org/z/MGefYs3M5\n\n"}, {"author": "RKSimon", "body": "Looks like foldShuffleToIdentity is attempting to fold the operand bundle on the fshl call"}]}, "verified": true} @@ -121,9 +127,11 @@ {"bug_id": "104422", "issue_url": "https://github.com/llvm/llvm-project/issues/104422", "bug_type": "miscompilation", "base_commit": "13a6a7975256ebdbce85f1174ae2eec735fa0d7a", "knowledge_cutoff": "2024-08-15T09:29:27Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "56140a8258a3498cfcd9f0f05c182457d43cbfd2", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[15663, 15669]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["BoUpSLP::collectValuesToDemote"]}}, "patch": "commit 56140a8258a3498cfcd9f0f05c182457d43cbfd2\nAuthor: Alexey Bataev \nDate: Thu Aug 15 07:57:37 2024 -0700\n\n [SLP]Fix PR104422: Wrong value truncation\n \n The minbitwidth restrictions can be skipped only for immediate reduced\n values, for other nodes still need to check if external users allow\n bitwidth reduction.\n \n Fixes https://github.com/llvm/llvm-project/issues/104422\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex 81841a8f6928..87b4ed599b5b 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -15663,7 +15663,8 @@ bool BoUpSLP::collectValuesToDemote(\n if (any_of(E.Scalars, [&](Value *V) {\n return !all_of(V->users(), [=](User *U) {\n return getTreeEntry(U) ||\n- (UserIgnoreList && UserIgnoreList->contains(U)) ||\n+ (E.Idx == 0 && UserIgnoreList &&\n+ UserIgnoreList->contains(U)) ||\n (!isa(U) && U->getType()->isSized() &&\n !U->getType()->isScalableTy() &&\n DL->getTypeSizeInBits(U->getType()) <= BitWidth);\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/X86/operand-is-reduced-val.ll", "commands": ["opt -S --passes=slp-vectorizer < %s -slp-threshold=-10"], "tests": [{"test_name": "src", "test_body": "define i64 @src(i32 %a) {\nentry:\n %0 = sext i32 %a to i64\n %1 = add nsw i64 %0, 4294967297\n %2 = sext i32 %a to i64\n %3 = add nsw i64 %2, 4294967297\n %4 = add i64 %3, %1\n %5 = and i64 %3, 1\n %6 = add i64 %4, %5\n %7 = sext i32 %a to i64\n %8 = add nsw i64 %7, 4294967297\n %9 = add i64 %8, %6\n %10 = and i64 %8, 1\n %11 = add i64 %9, %10\n %12 = sext i32 %a to i64\n %13 = add nsw i64 %12, 4294967297\n %14 = add i64 %13, %11\n %15 = and i64 %13, 1\n %16 = add i64 %14, %15\n %17 = sext i32 %a to i64\n %18 = add nsw i64 %17, 4294967297\n %19 = add i64 %18, %16\n %20 = and i64 %18, 1\n %21 = add i64 %19, %20\n ret i64 %21\n}\n"}]}], "issue": {"title": "[SLPVectorizer] Wrong value truncation ", "body": "- There seems to be an issue with SLPVectorizer. In the following example, a 2-byte wide value is incorrectly truncated:\r\n\r\n```\r\ndefine i64 @test(ptr addrspace(1) %arr, i32 %a) {\r\nentry:\r\n br label %loop\r\n\r\nloop:\r\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\r\n %local_1_7 = phi i64 [ 0, %entry ], [ %4, %loop ]\r\n %0 = sext i32 %a to i64\r\n %1 = add nsw i64 %0, 4294967297\r\n %2 = add i64 %1, %local_1_7\r\n %3 = and i64 %1, 1\r\n %4 = add i64 %2, %3\r\n %iv.next = add nuw nsw i64 %iv, 1\r\n %5 = icmp ugt i64 %iv, 355\r\n br i1 %5, label %exit, label %loop\r\n\r\nexit:\r\n ret i64 %4\r\n}\r\n```\r\n- In the loop we summarize the constant 4294967297 (`0x1'0000'0001`), but after running SLPVectorizer over the unrolled loop, the constant is truncated to `1`:\r\n```\r\nloop: \r\n %iv = phi i64 [ 0, %entry ], [ %iv.next.16, %loop ]\r\n %local_1_7 = phi i64 [ 0, %entry ], [ %op.rdx3, %loop ]\r\n %2 = add <16 x i32> %1, \r\n %3 = sext <16 x i32> %2 to <16 x i64>\r\n...\r\n```\r\n- Command to reproduce: `opt -passes=loop-unroll,slp-vectorizer -unroll-count=17`\r\n- https://godbolt.org/z/zcPefTPzW\r\n- Looks like the issue was caused by the https://github.com/llvm/llvm-project/commit/7f2167868d8c1cedd3915883412b9c787a2f01db\r\n\r\n@alexey-bataev Could you please take a look?\r\n", "author": "aleks-tmb", "labels": ["miscompilation", "release:backport", "llvm:SLPVectorizer"], "comments": [{"author": "nikic", "body": "This probably needs an LLVM 19 backport?\r\n\r\n/cherry-pick 65ac12d3c9877ecf5b97552364e7eead887d94eb 56140a8258a3498cfcd9f0f05c182457d43cbfd2"}]}, "verified": true} {"bug_id": "112078", "issue_url": "https://github.com/llvm/llvm-project/issues/112078", "bug_type": "miscompilation", "base_commit": "39aae575744de7ae77e755142e0746a5b473b3ed", "knowledge_cutoff": "2024-10-12T04:08:35Z", "lit_test_dir": ["llvm/test/Transforms/InstCombine"], "hints": {"fix_commit": "9edc454ee601e04500529c98b753d3bd8f427d01", "components": ["InstCombine"], "bug_location_lineno": {"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": [[935, 943], [945, 955], [3362, 3370]]}, "bug_location_funcname": {"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": ["InstCombinerImpl::foldAndOrOfICmps", "foldIsPowerOf2OrZero"]}}, "patch": "commit 9edc454ee601e04500529c98b753d3bd8f427d01\nAuthor: Yingwei Zheng \nDate: Mon Oct 14 20:52:55 2024 +0800\n\n [InstCombine] Drop range attributes in `foldIsPowerOf2OrZero` (#112178)\n \n Closes https://github.com/llvm/llvm-project/issues/112078.\n\ndiff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp\nindex 453071f3f982..64bee4ab974e 100644\n--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp\n+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp\n@@ -935,9 +935,11 @@ static Value *foldSignedTruncationCheck(ICmpInst *ICmp0, ICmpInst *ICmp1,\n \n /// Fold (icmp eq ctpop(X) 1) | (icmp eq X 0) into (icmp ult ctpop(X) 2) and\n /// fold (icmp ne ctpop(X) 1) & (icmp ne X 0) into (icmp ugt ctpop(X) 1).\n-/// Also used for logical and/or, must be poison safe.\n+/// Also used for logical and/or, must be poison safe if range attributes are\n+/// dropped.\n static Value *foldIsPowerOf2OrZero(ICmpInst *Cmp0, ICmpInst *Cmp1, bool IsAnd,\n- InstCombiner::BuilderTy &Builder) {\n+ InstCombiner::BuilderTy &Builder,\n+ InstCombinerImpl &IC) {\n CmpInst::Predicate Pred0, Pred1;\n Value *X;\n if (!match(Cmp0, m_ICmp(Pred0, m_Intrinsic(m_Value(X)),\n@@ -945,11 +947,19 @@ static Value *foldIsPowerOf2OrZero(ICmpInst *Cmp0, ICmpInst *Cmp1, bool IsAnd,\n !match(Cmp1, m_ICmp(Pred1, m_Specific(X), m_ZeroInt())))\n return nullptr;\n \n- Value *CtPop = Cmp0->getOperand(0);\n- if (IsAnd && Pred0 == ICmpInst::ICMP_NE && Pred1 == ICmpInst::ICMP_NE)\n+ auto *CtPop = cast(Cmp0->getOperand(0));\n+ if (IsAnd && Pred0 == ICmpInst::ICMP_NE && Pred1 == ICmpInst::ICMP_NE) {\n+ // Drop range attributes and re-infer them in the next iteration.\n+ CtPop->dropPoisonGeneratingAnnotations();\n+ IC.addToWorklist(CtPop);\n return Builder.CreateICmpUGT(CtPop, ConstantInt::get(CtPop->getType(), 1));\n- if (!IsAnd && Pred0 == ICmpInst::ICMP_EQ && Pred1 == ICmpInst::ICMP_EQ)\n+ }\n+ if (!IsAnd && Pred0 == ICmpInst::ICMP_EQ && Pred1 == ICmpInst::ICMP_EQ) {\n+ // Drop range attributes and re-infer them in the next iteration.\n+ CtPop->dropPoisonGeneratingAnnotations();\n+ IC.addToWorklist(CtPop);\n return Builder.CreateICmpULT(CtPop, ConstantInt::get(CtPop->getType(), 2));\n+ }\n \n return nullptr;\n }\n@@ -3362,9 +3372,9 @@ Value *InstCombinerImpl::foldAndOrOfICmps(ICmpInst *LHS, ICmpInst *RHS,\n /*IsLogical*/ false, Builder, Q))\n return V;\n \n- if (Value *V = foldIsPowerOf2OrZero(LHS, RHS, IsAnd, Builder))\n+ if (Value *V = foldIsPowerOf2OrZero(LHS, RHS, IsAnd, Builder, *this))\n return V;\n- if (Value *V = foldIsPowerOf2OrZero(RHS, LHS, IsAnd, Builder))\n+ if (Value *V = foldIsPowerOf2OrZero(RHS, LHS, IsAnd, Builder, *this))\n return V;\n \n // TODO: One of these directions is fine with logical and/or, the other could\n", "tests": [{"file": "llvm/test/Transforms/InstCombine/ispow2.ll", "commands": ["opt < %s -passes=instcombine -S"], "tests": [{"test_name": "is_pow2or0_decrement_op", "test_body": "define i1 @is_pow2or0_decrement_op(i8 %x) {\n %dec = add i8 %x, -1\n %and = and i8 %dec, %x\n %cmp = icmp eq i8 %and, 0\n ret i1 %cmp\n}\n"}, {"test_name": "is_pow2_negate_op_vec", "test_body": "define <2 x i1> @is_pow2_negate_op_vec(<2 x i32> %x) {\n %neg = sub <2 x i32> zeroinitializer, %x\n %and = and <2 x i32> %neg, %x\n %cmp = icmp eq <2 x i32> %and, %x\n %notzero = icmp ne <2 x i32> %x, zeroinitializer\n %r = and <2 x i1> %cmp, %notzero\n ret <2 x i1> %r\n}\n"}, {"test_name": "is_pow2_ctpop_wrong_cmp_op1_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2_ctpop_wrong_cmp_op1_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ult i32 %t0, 3\n %notzero = icmp ne i32 %x, 0\n %r = select i1 %notzero, i1 %cmp, i1 false\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_pow2_negate_op", "test_body": "define i1 @is_pow2_negate_op(i32 %x) {\n %neg = sub i32 0, %x\n %and = and i32 %neg, %x\n %cmp = icmp eq i32 %and, %x\n %notzero = icmp ne i32 %x, 0\n %r = and i1 %notzero, %cmp\n ret i1 %r\n}\n"}, {"test_name": "not_pow2_nz_known_bits", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @not_pow2_nz_known_bits(i32 %xin) {\n %x = or i32 %xin, 1\n %cnt = call i32 @llvm.ctpop.i32(i32 %x)\n %r = icmp ne i32 %cnt, 1\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_pow2_nz_known_bits", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2_nz_known_bits(i32 %xin) {\n %x = or i32 %xin, 64\n %cnt = call i32 @llvm.ctpop.i32(i32 %x)\n %r = icmp eq i32 %cnt, 1\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_power2_or_zero_with_range", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_power2_or_zero_with_range(i32 %x) {\n %ctpop = call range(i32 1, 33) i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp eq i32 %ctpop, 1\n %notzero = icmp eq i32 %x, 0\n %res = select i1 %notzero, i1 true, i1 %cmp\n ret i1 %res\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "blsmsk_is_p2_or_z", "test_body": "define i1 @blsmsk_is_p2_or_z(i32 %xx, i32 %yy) {\n %x = or i32 %xx, %yy\n %xm1 = add i32 %x, -1\n %y = xor i32 %x, %xm1\n %r = icmp uge i32 %x, %y\n ret i1 %r\n}\n"}, {"test_name": "isnot_pow2nor0_ctpop_commute_vec", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <2 x i8> @llvm.ctpop.v2i8(<2 x i8>) #0\n\ndefine <2 x i1> @isnot_pow2nor0_ctpop_commute_vec(<2 x i8> %x) {\n %t0 = tail call <2 x i8> @llvm.ctpop.v2i8(<2 x i8> %x)\n %cmp = icmp ne <2 x i8> %t0, splat (i8 1)\n %notzero = icmp ne <2 x i8> %x, zeroinitializer\n %r = and <2 x i1> %notzero, %cmp\n ret <2 x i1> %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_pow2or0_ctpop_wrong_pred1", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2or0_ctpop_wrong_pred1(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ne i32 %t0, 1\n %iszero = icmp eq i32 %x, 0\n %r = or i1 %iszero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_pow2_non_zero_ne_1", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #1\n\ndefine i1 @is_pow2_non_zero_ne_1(i32 %x) {\n %notzero = icmp ne i32 %x, 0\n call void @llvm.assume(i1 %notzero)\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ne i32 %t0, 1\n ret i1 %cmp\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\nattributes #1 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n"}, {"test_name": "blsmsk_is_p2_or_z_fail", "test_body": "define i1 @blsmsk_is_p2_or_z_fail(i32 %xx, i32 %yy) {\n %x = or i32 %xx, %yy\n %xm1 = add i32 %x, -1\n %y = xor i32 %x, %xm1\n %r = icmp ugt i32 %x, %y\n ret i1 %r\n}\n"}, {"test_name": "blsmsk_is_p2_or_z_uge_xy_fail", "test_body": "define i1 @blsmsk_is_p2_or_z_uge_xy_fail(i8 %xx, i8 %yy) {\n %x = or i8 %xx, %yy\n %xm1 = add i8 %x, -1\n %y = xor i8 %x, %xm1\n %r = icmp uge i8 %x, %y\n ret i1 %r\n}\n"}, {"test_name": "is_pow2or0_ctpop_logical_extra_uses", "test_body": "declare void @use(i32)\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndeclare void @use_i1(i1)\n\ndefine i1 @is_pow2or0_ctpop_logical_extra_uses(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n call void @use(i32 %t0)\n %cmp = icmp eq i32 %t0, 1\n call void @use_i1(i1 %cmp)\n %iszero = icmp eq i32 %x, 0\n call void @use_i1(i1 %iszero)\n %r = select i1 %iszero, i1 true, i1 %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "isnot_pow2_ctpop_commute_vec", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <2 x i8> @llvm.ctpop.v2i8(<2 x i8>) #0\n\ndefine <2 x i1> @isnot_pow2_ctpop_commute_vec(<2 x i8> %x) {\n %t0 = tail call <2 x i8> @llvm.ctpop.v2i8(<2 x i8> %x)\n %cmp = icmp ugt <2 x i8> %t0, splat (i8 1)\n %iszero = icmp eq <2 x i8> %x, zeroinitializer\n %r = or <2 x i1> %cmp, %iszero\n ret <2 x i1> %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "blsmsk_isnt_p2_or_z_fail_wrong_add", "test_body": "define i1 @blsmsk_isnt_p2_or_z_fail_wrong_add(i32 %x, i32 %z) {\n %xm1 = add i32 %z, -1\n %y = xor i32 %x, %xm1\n %r = icmp ult i32 %y, %x\n ret i1 %r\n}\n"}, {"test_name": "is_pow2_ctpop_wrong_pred2", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2_ctpop_wrong_pred2(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ult i32 %t0, 2\n %cmp2 = icmp sgt i32 %x, 0\n %r = and i1 %cmp2, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_pow2or0_ctpop_swap_cmp", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2or0_ctpop_swap_cmp(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp eq i32 %t0, 1\n %iszero = icmp eq i32 %x, 0\n %r = or i1 %cmp, %iszero\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_pow2or0_ctpop_commute_vec_wrong_pred3", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <2 x i8> @llvm.ctpop.v2i8(<2 x i8>) #0\n\ndefine <2 x i1> @is_pow2or0_ctpop_commute_vec_wrong_pred3(<2 x i8> %x) {\n %t0 = tail call <2 x i8> @llvm.ctpop.v2i8(<2 x i8> %x)\n %cmp = icmp eq <2 x i8> %t0, splat (i8 1)\n %iszero = icmp eq <2 x i8> %x, zeroinitializer\n %r = and <2 x i1> %cmp, %iszero\n ret <2 x i1> %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_pow2_decrement_op_logical", "test_body": "define i1 @is_pow2_decrement_op_logical(i8 %x) {\n %dec = add i8 %x, -1\n %and = and i8 %dec, %x\n %cmp = icmp eq i8 %and, 0\n %notzero = icmp ne i8 %x, 0\n %r = select i1 %cmp, i1 %notzero, i1 false\n ret i1 %r\n}\n"}, {"test_name": "isnot_pow2or0_negate_op_vec", "test_body": "define <2 x i1> @isnot_pow2or0_negate_op_vec(<2 x i32> %x) {\n %neg = sub <2 x i32> zeroinitializer, %x\n %and = and <2 x i32> %neg, %x\n %cmp = icmp ne <2 x i32> %and, %x\n ret <2 x i1> %cmp\n}\n"}, {"test_name": "is_pow2or0_ctpop_commute_vec", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <2 x i8> @llvm.ctpop.v2i8(<2 x i8>) #0\n\ndefine <2 x i1> @is_pow2or0_ctpop_commute_vec(<2 x i8> %x) {\n %t0 = tail call <2 x i8> @llvm.ctpop.v2i8(<2 x i8> %x)\n %cmp = icmp eq <2 x i8> %t0, splat (i8 1)\n %iszero = icmp eq <2 x i8> %x, zeroinitializer\n %r = or <2 x i1> %iszero, %cmp\n ret <2 x i1> %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_pow2_negate_op_logical", "test_body": "define i1 @is_pow2_negate_op_logical(i32 %x) {\n %neg = sub i32 0, %x\n %and = and i32 %neg, %x\n %cmp = icmp eq i32 %and, %x\n %notzero = icmp ne i32 %x, 0\n %r = select i1 %notzero, i1 %cmp, i1 false\n ret i1 %r\n}\n"}, {"test_name": "isnot_pow2nor0_ctpop", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2nor0_ctpop(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ne i32 %t0, 1\n %notzero = icmp ne i32 %x, 0\n %r = and i1 %notzero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "blsmsk_isnt_p2_or_z_ult_xy_fail", "test_body": "define i1 @blsmsk_isnt_p2_or_z_ult_xy_fail(i8 %xx, i8 %yy) {\n %x = or i8 %xx, %yy\n %xm1 = add i8 %x, -1\n %y = xor i8 %x, %xm1\n %r = icmp ult i8 %x, %y\n ret i1 %r\n}\n"}, {"test_name": "isnot_pow2nor0_wrong_pred3_ctpop_commute_vec", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <2 x i8> @llvm.ctpop.v2i8(<2 x i8>) #0\n\ndefine <2 x i1> @isnot_pow2nor0_wrong_pred3_ctpop_commute_vec(<2 x i8> %x) {\n %t0 = tail call <2 x i8> @llvm.ctpop.v2i8(<2 x i8> %x)\n %cmp = icmp ne <2 x i8> %t0, splat (i8 1)\n %notzero = icmp ne <2 x i8> %x, zeroinitializer\n %r = or <2 x i1> %cmp, %notzero\n ret <2 x i1> %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_pow2or0_negate_op_vec", "test_body": "define <2 x i1> @is_pow2or0_negate_op_vec(<2 x i32> %x) {\n %neg = sub <2 x i32> zeroinitializer, %x\n %and = and <2 x i32> %neg, %x\n %cmp = icmp eq <2 x i32> %and, %x\n ret <2 x i1> %cmp\n}\n"}, {"test_name": "isnot_pow2or0_negate_op", "test_body": "define i1 @isnot_pow2or0_negate_op(i32 %x) {\n %neg = sub i32 0, %x\n %and = and i32 %neg, %x\n %cmp = icmp ne i32 %and, %x\n ret i1 %cmp\n}\n"}, {"test_name": "not_pow2_or_z_known_bits_fail_wrong_cmp", "test_body": "define <2 x i1> @not_pow2_or_z_known_bits_fail_wrong_cmp(<2 x i32> %xin) {\n %x = or <2 x i32> %xin, splat (i32 64)\n %cnt = call <2 x i32> @llvm.ctpop.v2i32(<2 x i32> %x)\n %r = icmp ugt <2 x i32> %cnt, splat (i32 2)\n ret <2 x i1> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <2 x i32> @llvm.ctpop.v2i32(<2 x i32>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_pow2_ctpop_wrong_cmp_op2", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2_ctpop_wrong_cmp_op2(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ult i32 %t0, 2\n %notzero = icmp ne i32 %x, 1\n %r = and i1 %notzero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_pow2_ctpop_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2_ctpop_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ult i32 %t0, 2\n %notzero = icmp ne i32 %x, 0\n %r = select i1 %notzero, i1 %cmp, i1 false\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "isnot_pow2_decrement_op_logical", "test_body": "define i1 @isnot_pow2_decrement_op_logical(i8 %x) {\n %dec = add i8 %x, -1\n %and = and i8 %dec, %x\n %cmp = icmp ne i8 %and, 0\n %iszero = icmp eq i8 %x, 0\n %r = select i1 %iszero, i1 true, i1 %cmp\n ret i1 %r\n}\n"}, {"test_name": "isnot_pow2_negate_op_logical", "test_body": "define i1 @isnot_pow2_negate_op_logical(i32 %x) {\n %neg = sub i32 0, %x\n %and = and i32 %neg, %x\n %cmp = icmp ne i32 %and, %x\n %iszero = icmp eq i32 %x, 0\n %r = select i1 %cmp, i1 true, i1 %iszero\n ret i1 %r\n}\n"}, {"test_name": "is_pow2or0_ctpop", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2or0_ctpop(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp eq i32 %t0, 1\n %iszero = icmp eq i32 %x, 0\n %r = or i1 %iszero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "blsmsk_is_p2_or_z_uge_yx", "test_body": "define i1 @blsmsk_is_p2_or_z_uge_yx(i8 %xx, i8 %yy) {\n %x = or i8 %xx, %yy\n %xm1 = add i8 %x, -1\n %y = xor i8 %x, %xm1\n %r = icmp uge i8 %y, %x\n ret i1 %r\n}\n"}, {"test_name": "has_single_bit_inv", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @has_single_bit_inv(i32 %x) {\nentry:\n %cmp1 = icmp eq i32 %x, 0\n %popcnt = call range(i32 1, 33) i32 @llvm.ctpop.i32(i32 %x)\n %cmp2 = icmp ugt i32 %popcnt, 1\n %sel = select i1 %cmp1, i1 true, i1 %cmp2\n ret i1 %sel\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_pow2or0_negate_op", "test_body": "define i1 @is_pow2or0_negate_op(i32 %x) {\n %neg = sub i32 0, %x\n %and = and i32 %neg, %x\n %cmp = icmp eq i32 %and, %x\n ret i1 %cmp\n}\n"}, {"test_name": "blsmsk_isnt_p2_or_z_ugt_yx_fail", "test_body": "define i1 @blsmsk_isnt_p2_or_z_ugt_yx_fail(i8 %xx, i8 %yy) {\n %x = or i8 %xx, %yy\n %xm1 = add i8 %x, -1\n %y = xor i8 %x, %xm1\n %r = icmp ugt i8 %y, %x\n ret i1 %r\n}\n"}, {"test_name": "blsmsk_isnt_p2_or_z_fail", "test_body": "define i1 @blsmsk_isnt_p2_or_z_fail(i32 %x) {\n %xm1 = add i32 %x, -1\n %y = xor i32 %x, %xm1\n %r = icmp ule i32 %y, %x\n ret i1 %r\n}\n"}, {"test_name": "is_pow2_decrement_op_vec", "test_body": "define <2 x i1> @is_pow2_decrement_op_vec(<2 x i8> %x) {\n %dec = add <2 x i8> %x, splat (i8 -1)\n %and = and <2 x i8> %dec, %x\n %cmp = icmp eq <2 x i8> %and, zeroinitializer\n %notzero = icmp ne <2 x i8> %x, zeroinitializer\n %r = and <2 x i1> %notzero, %cmp\n ret <2 x i1> %r\n}\n"}, {"test_name": "isnot_pow2nor0_ctpop_extra_uses", "test_body": "declare void @use(i32)\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndeclare void @use_i1(i1)\n\ndefine i1 @isnot_pow2nor0_ctpop_extra_uses(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n call void @use(i32 %t0)\n %cmp = icmp ne i32 %t0, 1\n call void @use_i1(i1 %cmp)\n %notzero = icmp ne i32 %x, 0\n call void @use_i1(i1 %notzero)\n %r = and i1 %notzero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "isnot_pow2nor0_ctpop_wrong_pred1", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2nor0_ctpop_wrong_pred1(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp eq i32 %t0, 1\n %notzero = icmp ne i32 %x, 0\n %r = and i1 %notzero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "isnot_pow2_ctpop", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2_ctpop(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ugt i32 %t0, 1\n %iszero = icmp eq i32 %x, 0\n %r = or i1 %iszero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "blsmsk_isnt_p2_or_z_fail_multiuse", "test_body": "declare void @use.i32(i32)\n\ndefine i1 @blsmsk_isnt_p2_or_z_fail_multiuse(i32 %x) {\n %xm1 = add i32 %x, -1\n %y = xor i32 %x, %xm1\n call void @use.i32(i32 %y)\n %r = icmp ult i32 %y, %x\n ret i1 %r\n}\n"}, {"test_name": "is_pow2or0_ctpop_wrong_pred2_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2or0_ctpop_wrong_pred2_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ne i32 %t0, 1\n %iszero = icmp ne i32 %x, 0\n %r = select i1 %iszero, i1 true, i1 %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_pow2_ctpop_extra_uses", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndeclare void @use_i1(i1)\n\ndefine i1 @is_pow2_ctpop_extra_uses(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ult i32 %t0, 2\n call void @use_i1(i1 %cmp)\n %notzero = icmp ne i32 %x, 0\n call void @use_i1(i1 %notzero)\n %r = and i1 %notzero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "blsmsk_isnt_p2_or_z_ult_yx", "test_body": "define i1 @blsmsk_isnt_p2_or_z_ult_yx(i8 %xx, i8 %yy) {\n %x = or i8 %xx, %yy\n %xm1 = add i8 %x, -1\n %y = xor i8 %x, %xm1\n %r = icmp ult i8 %y, %x\n ret i1 %r\n}\n"}, {"test_name": "is_pow2or0_ctpop_wrong_cmp_op1_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2or0_ctpop_wrong_cmp_op1_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp eq i32 %t0, 3\n %iszero = icmp eq i32 %x, 0\n %r = select i1 %iszero, i1 true, i1 %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "blsmsk_isnt_p2_or_z_fail_bad_xor", "test_body": "define i1 @blsmsk_isnt_p2_or_z_fail_bad_xor(i32 %x, i32 %z) {\n %xm1 = add i32 %x, -1\n %y = xor i32 %z, %xm1\n %r = icmp ult i32 %y, %x\n ret i1 %r\n}\n"}, {"test_name": "is_pow2or0_negate_op_extra_use2", "test_body": "declare void @use(i32)\n\ndefine i1 @is_pow2or0_negate_op_extra_use2(i32 %x) {\n %neg = sub i32 0, %x\n %and = and i32 %neg, %x\n call void @use(i32 %and)\n %cmp = icmp eq i32 %and, %x\n ret i1 %cmp\n}\n"}, {"test_name": "isnot_pow2_negate_op", "test_body": "define i1 @isnot_pow2_negate_op(i32 %x) {\n %neg = sub i32 0, %x\n %and = and i32 %neg, %x\n %cmp = icmp ne i32 %and, %x\n %iszero = icmp eq i32 %x, 0\n %r = or i1 %cmp, %iszero\n ret i1 %r\n}\n"}, {"test_name": "is_pow2or0_negate_op_extra_use1", "test_body": "declare void @use(i32)\n\ndefine i1 @is_pow2or0_negate_op_extra_use1(i32 %x) {\n %neg = sub i32 0, %x\n call void @use(i32 %neg)\n %and = and i32 %neg, %x\n %cmp = icmp eq i32 %and, %x\n ret i1 %cmp\n}\n"}, {"test_name": "isnot_pow2_ctpop_wrong_cmp_op1_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2_ctpop_wrong_cmp_op1_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ugt i32 %t0, 2\n %iszero = icmp eq i32 %x, 0\n %r = select i1 %iszero, i1 true, i1 %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "isnot_pow2_ctpop_wrong_cmp_op2_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2_ctpop_wrong_cmp_op2_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ugt i32 %t0, 1\n %iszero = icmp eq i32 %x, 1\n %r = select i1 %iszero, i1 true, i1 %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_pow2_ctpop_wrong_cmp_op1", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2_ctpop_wrong_cmp_op1(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ult i32 %t0, 3\n %notzero = icmp ne i32 %x, 0\n %r = and i1 %notzero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_pow2or0_ctpop_commute_vec_wrong_cmp_op1", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <2 x i8> @llvm.ctpop.v2i8(<2 x i8>) #0\n\ndefine <2 x i1> @is_pow2or0_ctpop_commute_vec_wrong_cmp_op1(<2 x i8> %x) {\n %t0 = tail call <2 x i8> @llvm.ctpop.v2i8(<2 x i8> %x)\n %cmp = icmp eq <2 x i8> %t0, \n %iszero = icmp eq <2 x i8> %x, zeroinitializer\n %r = or <2 x i1> %cmp, %iszero\n ret <2 x i1> %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "isnot_pow2_ctpop_wrong_pred2_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2_ctpop_wrong_pred2_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ugt i32 %t0, 1\n %cmp2 = icmp slt i32 %x, 0\n %r = select i1 %cmp2, i1 true, i1 %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_pow2_ctpop_extra_uses_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndeclare void @use_i1(i1)\n\ndefine i1 @is_pow2_ctpop_extra_uses_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ult i32 %t0, 2\n call void @use_i1(i1 %cmp)\n %notzero = icmp ne i32 %x, 0\n call void @use_i1(i1 %notzero)\n %r = select i1 %notzero, i1 %cmp, i1 false\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "isnot_pow2or0_negate_op_commute3", "test_body": "define i1 @isnot_pow2or0_negate_op_commute3(i32 %p) {\n %x = urem i32 42, %p\n %neg = sub i32 0, %x\n %and = and i32 %x, %neg\n %cmp = icmp ne i32 %x, %and\n ret i1 %cmp\n}\n"}, {"test_name": "is_pow2_ctpop_wrong_cmp_op2_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2_ctpop_wrong_cmp_op2_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ult i32 %t0, 2\n %notzero = icmp ne i32 %x, 1\n %r = select i1 %notzero, i1 %cmp, i1 false\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_pow2_non_zero_eq_1", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #1\n\ndefine i1 @is_pow2_non_zero_eq_1(i32 %x) {\n %notzero = icmp ne i32 %x, 0\n call void @llvm.assume(i1 %notzero)\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp eq i32 %t0, 1\n ret i1 %cmp\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\nattributes #1 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n"}, {"test_name": "isnot_pow2nor0_ctpop_logical_extra_uses", "test_body": "declare void @use(i32)\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndeclare void @use_i1(i1)\n\ndefine i1 @isnot_pow2nor0_ctpop_logical_extra_uses(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n call void @use(i32 %t0)\n %cmp = icmp ne i32 %t0, 1\n call void @use_i1(i1 %cmp)\n %notzero = icmp ne i32 %x, 0\n call void @use_i1(i1 %notzero)\n %r = select i1 %notzero, i1 %cmp, i1 false\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_pow2or0_ctpop_wrong_pred2", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2or0_ctpop_wrong_pred2(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ne i32 %t0, 1\n %iszero = icmp ne i32 %x, 0\n %r = or i1 %iszero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "isnot_pow2_ctpop_wrong_cmp_op2", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2_ctpop_wrong_cmp_op2(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ugt i32 %t0, 1\n %iszero = icmp eq i32 %x, 1\n %r = or i1 %iszero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_pow2_ctpop_wrong_pred1", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2_ctpop_wrong_pred1(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ugt i32 %t0, 2\n %notzero = icmp ne i32 %x, 0\n %r = and i1 %notzero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "isnot_pow2_ctpop_extra_uses_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndeclare void @use_i1(i1)\n\ndefine i1 @isnot_pow2_ctpop_extra_uses_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ugt i32 %t0, 1\n call void @use_i1(i1 %cmp)\n %iszero = icmp eq i32 %x, 0\n call void @use_i1(i1 %iszero)\n %r = select i1 %iszero, i1 true, i1 %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_pow2or0_ctpop_extra_uses", "test_body": "declare void @use(i32)\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndeclare void @use_i1(i1)\n\ndefine i1 @is_pow2or0_ctpop_extra_uses(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n call void @use(i32 %t0)\n %cmp = icmp eq i32 %t0, 1\n call void @use_i1(i1 %cmp)\n %iszero = icmp eq i32 %x, 0\n call void @use_i1(i1 %iszero)\n %r = or i1 %iszero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_pow2_non_zero_ult_2", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #1\n\ndefine i1 @is_pow2_non_zero_ult_2(i32 %x) {\n %notzero = icmp ne i32 %x, 0\n call void @llvm.assume(i1 %notzero)\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ult i32 %t0, 2\n ret i1 %cmp\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\nattributes #1 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n"}, {"test_name": "is_pow2_ctpop_commute_vec", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <2 x i8> @llvm.ctpop.v2i8(<2 x i8>) #0\n\ndefine <2 x i1> @is_pow2_ctpop_commute_vec(<2 x i8> %x) {\n %t0 = tail call <2 x i8> @llvm.ctpop.v2i8(<2 x i8> %x)\n %cmp = icmp ult <2 x i8> %t0, splat (i8 2)\n %notzero = icmp ne <2 x i8> %x, zeroinitializer\n %r = and <2 x i1> %cmp, %notzero\n ret <2 x i1> %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "isnot_pow2_decrement_op", "test_body": "define i1 @isnot_pow2_decrement_op(i8 %x) {\n %dec = add i8 %x, -1\n %and = and i8 %dec, %x\n %cmp = icmp ne i8 %and, 0\n %iszero = icmp eq i8 %x, 0\n %r = or i1 %iszero, %cmp\n ret i1 %r\n}\n"}, {"test_name": "isnot_pow2nor0_ctpop_wrong_cmp_op1_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2nor0_ctpop_wrong_cmp_op1_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ne i32 %t0, 5\n %notzero = icmp ne i32 %x, 0\n %r = select i1 %notzero, i1 %cmp, i1 false\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_pow2_ctpop_wrong_pred1_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2_ctpop_wrong_pred1_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ugt i32 %t0, 2\n %notzero = icmp ne i32 %x, 0\n %r = select i1 %notzero, i1 %cmp, i1 false\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "isnot_pow2or0_decrement_op_vec", "test_body": "define <2 x i1> @isnot_pow2or0_decrement_op_vec(<2 x i8> %x) {\n %dec = add <2 x i8> %x, splat (i8 -1)\n %and = and <2 x i8> %dec, %x\n %cmp = icmp ne <2 x i8> %and, zeroinitializer\n ret <2 x i1> %cmp\n}\n"}, {"test_name": "is_pow2_ctpop_wrong_pred2_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2_ctpop_wrong_pred2_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ult i32 %t0, 2\n %cmp2 = icmp sgt i32 %x, 0\n %r = select i1 %cmp2, i1 %cmp, i1 false\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "blsmsk_isnt_p2_or_z_ugt_xy", "test_body": "define i1 @blsmsk_isnt_p2_or_z_ugt_xy(i8 %xx, i8 %yy) {\n %x = or i8 %xx, %yy\n %xm1 = add i8 %x, -1\n %y = xor i8 %x, %xm1\n %r = icmp ugt i8 %x, %y\n ret i1 %r\n}\n"}, {"test_name": "isnot_pow2nor0_ctpop_commute_vec_wrong_cmp_op1", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <2 x i8> @llvm.ctpop.v2i8(<2 x i8>) #0\n\ndefine <2 x i1> @isnot_pow2nor0_ctpop_commute_vec_wrong_cmp_op1(<2 x i8> %x) {\n %t0 = tail call <2 x i8> @llvm.ctpop.v2i8(<2 x i8> %x)\n %cmp = icmp ne <2 x i8> %t0, \n %notzero = icmp ne <2 x i8> %x, zeroinitializer\n %r = and <2 x i1> %cmp, %notzero\n ret <2 x i1> %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "isnot_pow2nor0_ctpop_wrong_pred2_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2nor0_ctpop_wrong_pred2_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp eq i32 %t0, 1\n %notzero = icmp eq i32 %x, 0\n %r = select i1 %notzero, i1 %cmp, i1 false\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_pow2or0_negate_op_commute1", "test_body": "define i1 @is_pow2or0_negate_op_commute1(i32 %p) {\n %x = srem i32 42, %p\n %neg = sub i32 0, %x\n %and = and i32 %x, %neg\n %cmp = icmp eq i32 %and, %x\n ret i1 %cmp\n}\n"}, {"test_name": "is_pow2_or_z_known_bits", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2_or_z_known_bits(i32 %xin) {\n %x = or i32 %xin, -2147483648\n %cnt = call i32 @llvm.ctpop.i32(i32 %x)\n %r = icmp ult i32 %cnt, 2\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_pow2or0_decrement_op_vec", "test_body": "define <2 x i1> @is_pow2or0_decrement_op_vec(<2 x i8> %x) {\n %dec = add <2 x i8> %x, splat (i8 -1)\n %and = and <2 x i8> %dec, %x\n %cmp = icmp eq <2 x i8> %and, zeroinitializer\n ret <2 x i1> %cmp\n}\n"}, {"test_name": "is_pow2_decrement_op", "test_body": "define i1 @is_pow2_decrement_op(i8 %x) {\n %dec = add i8 %x, -1\n %and = and i8 %dec, %x\n %cmp = icmp eq i8 %and, 0\n %notzero = icmp ne i8 %x, 0\n %r = and i1 %cmp, %notzero\n ret i1 %r\n}\n"}, {"test_name": "isnot_pow2_ctpop_wrong_pred2", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2_ctpop_wrong_pred2(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ugt i32 %t0, 1\n %cmp2 = icmp slt i32 %x, 0\n %r = or i1 %cmp2, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "isnot_pow2_ctpop_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2_ctpop_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ugt i32 %t0, 1\n %iszero = icmp eq i32 %x, 0\n %r = select i1 %iszero, i1 true, i1 %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "isnot_pow2or0_negate_op_commute2", "test_body": "define i1 @isnot_pow2or0_negate_op_commute2(i32 %p) {\n %x = urem i32 42, %p\n %neg = sub i32 0, %x\n %and = and i32 %neg, %x\n %cmp = icmp ne i32 %x, %and\n ret i1 %cmp\n}\n"}, {"test_name": "blsmsk_is_p2_or_z_fail_bad_cmp", "test_body": "define i1 @blsmsk_is_p2_or_z_fail_bad_cmp(i32 %x, i32 %z) {\n %xm1 = add i32 %x, -1\n %y = xor i32 %x, %xm1\n %r = icmp uge i32 %y, %z\n ret i1 %r\n}\n"}, {"test_name": "isnot_pow2_decrement_op_vec", "test_body": "define <2 x i1> @isnot_pow2_decrement_op_vec(<2 x i8> %x) {\n %dec = add <2 x i8> %x, splat (i8 -1)\n %and = and <2 x i8> %dec, %x\n %cmp = icmp ne <2 x i8> %and, zeroinitializer\n %iszero = icmp eq <2 x i8> %x, zeroinitializer\n %r = or <2 x i1> %cmp, %iszero\n ret <2 x i1> %r\n}\n"}, {"test_name": "is_pow2or0_ctpop_wrong_cmp_op1", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2or0_ctpop_wrong_cmp_op1(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp eq i32 %t0, 2\n %iszero = icmp eq i32 %x, 0\n %r = or i1 %iszero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "blsmsk_is_p2_or_z_ule_yx_fail", "test_body": "define i1 @blsmsk_is_p2_or_z_ule_yx_fail(i8 %xx, i8 %yy) {\n %x = or i8 %xx, %yy\n %xm1 = add i8 %x, -1\n %y = xor i8 %x, %xm1\n %r = icmp ule i8 %y, %x\n ret i1 %r\n}\n"}, {"test_name": "not_pow2_or_z_known_bits", "test_body": "define <2 x i1> @not_pow2_or_z_known_bits(<2 x i32> %xin) {\n %x = or <2 x i32> %xin, splat (i32 64)\n %cnt = call <2 x i32> @llvm.ctpop.v2i32(<2 x i32> %x)\n %r = icmp ugt <2 x i32> %cnt, splat (i32 1)\n ret <2 x i1> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <2 x i32> @llvm.ctpop.v2i32(<2 x i32>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "isnot_pow2_negate_op_vec", "test_body": "define <2 x i1> @isnot_pow2_negate_op_vec(<2 x i32> %x) {\n %neg = sub <2 x i32> zeroinitializer, %x\n %and = and <2 x i32> %neg, %x\n %cmp = icmp ne <2 x i32> %and, %x\n %iszero = icmp eq <2 x i32> %x, zeroinitializer\n %r = or <2 x i1> %iszero, %cmp\n ret <2 x i1> %r\n}\n"}, {"test_name": "is_pow2or0_ctpop_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2or0_ctpop_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp eq i32 %t0, 1\n %iszero = icmp eq i32 %x, 0\n %r = select i1 %iszero, i1 true, i1 %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "isnot_pow2_ctpop_extra_uses", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndeclare void @use_i1(i1)\n\ndefine i1 @isnot_pow2_ctpop_extra_uses(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ugt i32 %t0, 1\n call void @use_i1(i1 %cmp)\n %iszero = icmp eq i32 %x, 0\n call void @use_i1(i1 %iszero)\n %r = or i1 %iszero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_power2_or_zero_inv_with_range", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_power2_or_zero_inv_with_range(i32 %x) {\n %ctpop = call range(i32 1, 33) i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ne i32 %ctpop, 1\n %notzero = icmp ne i32 %x, 0\n %res = select i1 %notzero, i1 %cmp, i1 false\n ret i1 %res\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "isnot_pow2nor0_ctpop_wrong_pred2", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2nor0_ctpop_wrong_pred2(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp eq i32 %t0, 1\n %notzero = icmp eq i32 %x, 0\n %r = and i1 %notzero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "has_single_bit", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @has_single_bit(i32 %x) {\nentry:\n %cmp1 = icmp ne i32 %x, 0\n %popcnt = call range(i32 1, 33) i32 @llvm.ctpop.i32(i32 %x)\n %cmp2 = icmp ult i32 %popcnt, 2\n %sel = select i1 %cmp1, i1 %cmp2, i1 false\n ret i1 %sel\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_pow2_fail_pr63327", "test_body": "define i1 @is_pow2_fail_pr63327(i32 %x) {\n %nx = sub i32 0, %x\n %x_and_nx = and i32 %x, %nx\n %r = icmp sge i32 %x_and_nx, %x\n ret i1 %r\n}\n"}, {"test_name": "is_pow2_ctpop", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2_ctpop(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ult i32 %t0, 2\n %notzero = icmp ne i32 %x, 0\n %r = and i1 %notzero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "is_pow2_nz_known_bits_fail_multiuse", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndeclare void @use.i32(i32)\n\ndefine i1 @is_pow2_nz_known_bits_fail_multiuse(i32 %xin) {\n %x = or i32 %xin, 64\n %cnt = call i32 @llvm.ctpop.i32(i32 %x)\n call void @use.i32(i32 %cnt)\n %r = icmp eq i32 %cnt, 1\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "blsmsk_isnt_p2_or_z", "test_body": "define i1 @blsmsk_isnt_p2_or_z(i32 %x) {\n %xm1 = add i32 %x, -1\n %y = xor i32 %x, %xm1\n %r = icmp ult i32 %y, %x\n ret i1 %r\n}\n"}, {"test_name": "isnot_pow2or0_decrement_op", "test_body": "define i1 @isnot_pow2or0_decrement_op(i8 %x) {\n %dec = add i8 %x, -1\n %and = and i8 %dec, %x\n %cmp = icmp ne i8 %and, 0\n ret i1 %cmp\n}\n"}, {"test_name": "not_pow2_nz_known_bits_fail_not_p2_test", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @not_pow2_nz_known_bits_fail_not_p2_test(i32 %xin) {\n %x = or i32 %xin, 1\n %cnt = call i32 @llvm.ctpop.i32(i32 %x)\n %r = icmp ne i32 %cnt, 2\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "isnot_pow2_ctpop_wrong_cmp_op1", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2_ctpop_wrong_cmp_op1(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ugt i32 %t0, 2\n %iszero = icmp eq i32 %x, 0\n %r = or i1 %iszero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "blsmsk_is_p2_or_z_ule_xy", "test_body": "define i1 @blsmsk_is_p2_or_z_ule_xy(i8 %xx, i8 %yy) {\n %x = or i8 %xx, %yy\n %xm1 = add i8 %x, -1\n %y = xor i8 %x, %xm1\n %r = icmp ule i8 %x, %y\n ret i1 %r\n}\n"}, {"test_name": "is_pow2_non_zero_ugt_1", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #1\n\ndefine i1 @is_pow2_non_zero_ugt_1(i32 %x) {\n %notzero = icmp ne i32 %x, 0\n call void @llvm.assume(i1 %notzero)\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ugt i32 %t0, 1\n ret i1 %cmp\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\nattributes #1 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n"}, {"test_name": "isnot_pow2nor0_ctpop_swap_cmp", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2nor0_ctpop_swap_cmp(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ne i32 %t0, 1\n %notzero = icmp ne i32 %x, 0\n %r = and i1 %cmp, %notzero\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "isnot_pow2nor0_ctpop_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2nor0_ctpop_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ne i32 %t0, 1\n %notzero = icmp ne i32 %x, 0\n %r = select i1 %notzero, i1 %cmp, i1 false\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}, {"test_name": "isnot_pow2nor0_ctpop_wrong_cmp_op1", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2nor0_ctpop_wrong_cmp_op1(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ne i32 %t0, 4\n %notzero = icmp ne i32 %x, 0\n %r = and i1 %notzero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}]}], "issue": {"title": "[InstCombine] `range` attribute should be dropped in `foldIsPowerOf2OrZero`", "body": "Reproducer: https://alive2.llvm.org/ce/z/u62KKP (Please use latest alive2 with https://github.com/AliveToolkit/alive2/pull/1097)\r\n```\r\ndefine i1 @src(i32 %x) {\r\n %t0 = tail call range(i32 1, 33) i32 @llvm.ctpop.i32(i32 %x)\r\n %cmp = icmp ne i32 %t0, 1\r\n %notzero = icmp ne i32 %x, 0\r\n %r = select i1 %notzero, i1 %cmp, i1 false\r\n ret i1 %r\r\n}\r\n\r\ndefine i1 @tgt(i32 %x) {\r\n %t0 = tail call range(i32 1, 33) i32 @llvm.ctpop.i32(i32 %x)\r\n %r = icmp ugt i32 %t0, 1\r\n ret i1 %r\r\n}\r\n```\r\n```\r\n----------------------------------------\r\ndefine i1 @src(i32 %x) {\r\n#0:\r\n %t0 = ctpop i32 %x\r\n %#range_0_%t0 = !range i32 %t0, i32 1, i32 33\r\n %cmp = icmp ne i32 %#range_0_%t0, 1\r\n %notzero = icmp ne i32 %x, 0\r\n %r = select i1 %notzero, i1 %cmp, i1 0\r\n ret i1 %r\r\n}\r\n=>\r\ndefine i1 @tgt(i32 %x) {\r\n#0:\r\n %t0 = ctpop i32 %x\r\n %#range_0_%t0 = !range i32 %t0, i32 1, i32 33\r\n %r = icmp ugt i32 %#range_0_%t0, 1\r\n ret i1 %r\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Target is more poisonous than source\r\n\r\nExample:\r\ni32 %x = #x00000000 (0)\r\n\r\nSource:\r\ni32 %t0 = #x00000000 (0)\r\ni32 %#range_0_%t0 = poison\r\ni1 %cmp = poison\r\ni1 %notzero = #x0 (0)\r\ni1 %r = #x0 (0)\r\n\r\nTarget:\r\ni32 %t0 = #x00000000 (0)\r\ni32 %#range_0_%t0 = poison\r\ni1 %r = poison\r\nSource value: #x0 (0)\r\nTarget value: poison\r\n```", "author": "dtcxzyw", "labels": ["miscompilation", "llvm:instcombine"], "comments": []}, "verified": true} {"bug_id": "95520", "issue_url": "https://github.com/llvm/llvm-project/issues/95520", "bug_type": "crash", "base_commit": "e7acb3792b8ba971bda2c9564ed26c2a60a2ddbc", "knowledge_cutoff": "2024-06-14T09:26:34Z", "lit_test_dir": ["llvm/test/Transforms/LoopVectorize"], "hints": {"fix_commit": "40a72f8cc414726a8be234a260650fd62354da21", "components": ["LoopVectorize"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/VPlan.cpp": [[231, 236]], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": [[577, 583]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/VPlan.cpp": ["VPTransformState::get"], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": ["VPInstruction::generatePerPart"]}}, "patch": "commit 40a72f8cc414726a8be234a260650fd62354da21\nAuthor: Florian Hahn \nDate: Fri Jun 14 22:16:51 2024 +0100\n\n [VPlan] Support extracting any lane of uniform value.\n \n If the value we are extracting a lane from is uniform, only the first\n lane will be set. Return lane 0 for any requested lane.\n \n This fixes a crash when trying to extract the last lane for a\n first-order recurrence resume value.\n \n Fixes https://github.com/llvm/llvm-project/issues/95520.\n\ndiff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp\nindex f17be451e684..348a2be5072b 100644\n--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp\n+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp\n@@ -231,6 +231,11 @@ Value *VPTransformState::get(VPValue *Def, const VPIteration &Instance) {\n return Data\n .PerPartScalars[Def][Instance.Part][Instance.Lane.mapToCacheIndex(VF)];\n }\n+ if (!Instance.Lane.isFirstLane() &&\n+ vputils::isUniformAfterVectorization(Def) &&\n+ hasScalarValue(Def, {Instance.Part, VPLane::getFirstLane()})) {\n+ return Data.PerPartScalars[Def][Instance.Part][0];\n+ }\n \n assert(hasVectorValue(Def, Instance.Part));\n auto *VecPart = Data.PerPartOutput[Def][Instance.Part];\ndiff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp\nindex 7a482455473e..a3ff6395bb39 100644\n--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp\n+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp\n@@ -577,7 +577,8 @@ Value *VPInstruction::generatePerPart(VPTransformState &State, unsigned Part) {\n // When loop is unrolled without vectorizing, retrieve UF - Offset.\n Res = State.get(getOperand(0), State.UF - Offset);\n }\n- Res->setName(Name);\n+ if (isa(Res))\n+ Res->setName(Name);\n return Res;\n }\n case VPInstruction::LogicalAnd: {\n", "tests": [{"file": "llvm/test/Transforms/LoopVectorize/AArch64/reduction-recurrence-costs-sve.ll", "commands": ["opt -p loop-vectorize -S %s", "opt -p loop-vectorize -prefer-predicate-over-epilogue=predicate-else-scalar-epilogue -S %s"], "tests": [{"test_name": "chained_recurrences", "test_body": "target datalayout = \"e-m:o-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"arm64-apple-macosx14.0.0\"\n\ndefine i32 @chained_recurrences(i32 %x, i64 %y, ptr %src.1, i32 %z, ptr %src.2) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %0 = phi i32 [ 0, %entry ], [ %3, %loop ]\n %1 = phi i32 [ 0, %entry ], [ %0, %loop ]\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %sum.red = phi i32 [ 0, %entry ], [ %red.2, %loop ]\n %2 = add i64 %y, 1\n %gep.1 = getelementptr i32, ptr %src.1, i64 %2\n %3 = load i32, ptr %gep.1, align 4\n %or3 = or i32 %1, %x\n %iv.next = add i64 %iv, 1\n %shr = lshr i32 %x, 1\n %4 = shl i32 %or3, 1\n %5 = or i32 %4, 2\n %shl19 = shl i32 %x, 1\n %6 = or i32 %shr, %shl19\n %7 = or i32 %6, %5\n %8 = or i32 %7, %x\n %or20 = or i32 %z, %x\n %not = and i32 %or20, 1\n %and = xor i32 %not, 1\n %idx.ext.1 = zext i32 %and to i64\n %gep.2 = getelementptr i32, ptr %src.2, i64 %idx.ext.1\n %9 = load i32, ptr %gep.2, align 4\n %shr24 = lshr i32 %8, 1\n %idx.ext.2 = zext i32 %shr24 to i64\n %gep.3 = getelementptr i32, ptr %src.2, i64 %idx.ext.2\n %10 = load i32, ptr %gep.3, align 4\n %red.1 = or i32 %9, %sum.red\n %red.2 = or i32 %red.1, %10\n %ec = icmp eq i64 %iv, %y\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i32 %red.2\n}\n\nattributes #0 = { \"target-features\"=\"+sve\" }\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/first-order-recurrence-chains.ll", "commands": ["opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S %s"], "tests": [{"test_name": "test_resinking_required", "test_body": "define double @test_resinking_required(ptr %p, ptr noalias %a, ptr noalias %b) {\nEntry:\n br label %Loop\n\nLoop: ; preds = %Loop, %Entry\n %for.1 = phi double [ %l1, %Loop ], [ 0.000000e+00, %Entry ]\n %for.2 = phi double [ %l2, %Loop ], [ 0.000000e+00, %Entry ]\n %for.3 = phi double [ %for.2, %Loop ], [ 0.000000e+00, %Entry ]\n %iv = phi i64 [ %iv.next, %Loop ], [ 0, %Entry ]\n %USE_2_FORS = fdiv double %for.3, %for.1\n %div = fdiv double 0.000000e+00, %for.1\n %l1 = load double, ptr %a, align 8\n %iv.next = add nuw nsw i64 %iv, 1\n %l2 = load double, ptr %b, align 8\n store double %div, ptr %p, align 8\n %cond = icmp eq i64 %iv.next, 0\n br i1 %cond, label %End, label %Loop\n\nEnd: ; preds = %Loop\n %res.1 = fadd double %for.1, %for.2\n %res.2 = fadd double %res.1, %for.3\n ret double %res.2\n}\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/first-order-recurrence-complex.ll", "commands": ["opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S %s"], "tests": [{"test_name": "instruction_with_2_FOR_operands_and_multiple_other_uses_chain", "test_body": "define void @instruction_with_2_FOR_operands_and_multiple_other_uses_chain(ptr noalias %dst.1, ptr noalias %dst.2, ptr noalias %dst.3, ptr noalias %for.ptr.1, ptr noalias %for.ptr.2) {\nbb:\n br label %loop\n\nloop: ; preds = %loop, %bb\n %for.1 = phi float [ 0.000000e+00, %bb ], [ %for.1.next, %loop ]\n %for.2 = phi float [ 0.000000e+00, %bb ], [ %for.2.next, %loop ]\n %iv = phi i64 [ 0, %bb ], [ %iv.next, %loop ]\n %for.1.use.1 = fmul fast float %for.1, 2.000000e+00\n %for.1.use.c = fmul fast float %for.1.use.1, 2.000000e+00\n %used.by.both = fmul fast float %for.1.use.c, %for.2\n %for.2.next = load float, ptr %for.ptr.2, align 4\n %for.1.use.3 = fadd fast float %for.1, 1.000000e+00\n %iv.next = add nuw nsw i64 %iv, 1\n %for.1.next = load float, ptr %for.ptr.1, align 4\n %gep.dst.1 = getelementptr inbounds float, ptr %dst.1, i64 %iv\n store float %used.by.both, ptr %gep.dst.1, align 4\n %gep.dst.2 = getelementptr inbounds float, ptr %dst.2, i64 %iv\n store float %for.1.use.1, ptr %gep.dst.2, align 4\n %gep.dst.3 = getelementptr inbounds float, ptr %dst.3, i64 %iv\n store float %for.1.use.3, ptr %gep.dst.3, align 4\n %ec = icmp slt i64 %iv, 1000\n br i1 %ec, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n"}, {"test_name": "instruction_with_2_FOR_operands_and_multiple_other_uses", "test_body": "define void @instruction_with_2_FOR_operands_and_multiple_other_uses(ptr noalias %dst.1, ptr noalias %dst.2, ptr noalias %dst.3, ptr noalias %for.ptr.1, ptr noalias %for.ptr.2) {\nbb:\n br label %loop\n\nloop: ; preds = %loop, %bb\n %for.1 = phi float [ 0.000000e+00, %bb ], [ %for.1.next, %loop ]\n %for.2 = phi float [ 0.000000e+00, %bb ], [ %for.2.next, %loop ]\n %iv = phi i64 [ 0, %bb ], [ %iv.next, %loop ]\n %for.1.use.1 = fmul fast float %for.1, 2.000000e+00\n %used.by.both = fmul fast float %for.1, %for.2\n %for.2.next = load float, ptr %for.ptr.2, align 4\n %for.1.use.3 = fadd fast float %for.1, 1.000000e+00\n %iv.next = add nuw nsw i64 %iv, 1\n %for.1.next = load float, ptr %for.ptr.1, align 4\n %gep.dst.1 = getelementptr inbounds float, ptr %dst.1, i64 %iv\n store float %used.by.both, ptr %gep.dst.1, align 4\n %gep.dst.2 = getelementptr inbounds float, ptr %dst.2, i64 %iv\n store float %for.1.use.1, ptr %gep.dst.2, align 4\n %gep.dst.3 = getelementptr inbounds float, ptr %dst.3, i64 %iv\n store float %for.1.use.3, ptr %gep.dst.3, align 4\n %ec = icmp slt i64 %iv, 1000\n br i1 %ec, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n"}, {"test_name": "instruction_with_2_FOR_operands", "test_body": "define void @instruction_with_2_FOR_operands(ptr noalias %A, ptr noalias %B, ptr noalias %C) {\nbb:\n br label %bb13\n\nbb13: ; preds = %bb13, %bb\n %tmp37 = phi float [ %tmp60, %bb13 ], [ 0.000000e+00, %bb ]\n %tmp27 = phi float [ %tmp49, %bb13 ], [ 1.000000e+00, %bb ]\n %iv = phi i64 [ %iv.next, %bb13 ], [ 0, %bb ]\n %tmp38 = fmul fast float %tmp37, %tmp27\n %iv.next = add nuw nsw i64 %iv, 1\n %gep = getelementptr inbounds float, ptr %C, i64 %iv\n %tmp49 = load float, ptr %A, align 4\n %tmp60 = load float, ptr %B, align 4\n store float %tmp38, ptr %gep, align 4\n %tmp12 = icmp slt i64 %iv, 1000\n br i1 %tmp12, label %bb13, label %bb74\n\nbb74: ; preds = %bb13\n ret void\n}\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/first-order-recurrence-multiply-recurrences.ll", "commands": [], "tests": [{"test_name": "test_pr54233_for_depend_on_each_other", "test_body": "define void @test_pr54233_for_depend_on_each_other(ptr noalias %a, ptr noalias %b) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %for.1 = phi i32 [ 0, %entry ], [ %for.1.next, %loop ]\n %for.2 = phi i32 [ 0, %entry ], [ %for.2.next, %loop ]\n %or = or i32 %for.2, 10\n %shl = shl i32 %for.2, %for.1\n %xor = xor i32 %shl, 255\n %and = and i32 %xor, %or\n %for.1.next = xor i32 12, %for.2\n %for.2.next = load i32, ptr %b, align 4\n %a.gep = getelementptr inbounds i32, ptr %a, i64 %iv\n store i32 %and, ptr %a.gep, align 4\n %iv.next = add nuw i64 %iv, 1\n %exitcond = icmp eq i64 %iv, 1000\n br i1 %exitcond, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n"}, {"test_name": "test_pr54223_sink_after_insertion_order", "test_body": "define void @test_pr54223_sink_after_insertion_order(ptr noalias %a, ptr noalias %b, ptr noalias %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %for.1 = phi float [ 0.000000e+00, %entry ], [ %for.1.next, %loop ]\n %for.2 = phi float [ 0.000000e+00, %entry ], [ %for.2.next, %loop ]\n %neg = fneg float %for.2\n %muladd = call float @llvm.fmuladd.f32(float %for.1, float %neg, float 0.000000e+00)\n %dst.gep = getelementptr inbounds float, ptr %dst, i64 %iv\n %iv.next = add nuw nsw i64 %iv, 1\n %for.1.next = load float, ptr %a, align 4\n %for.2.next = load float, ptr %b, align 4\n store float %muladd, ptr %dst.gep, align 4\n %exitcond.not = icmp eq i64 %iv.next, 10000\n br i1 %exitcond.not, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare float @llvm.fmuladd.f32(float, float, float) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/first-order-recurrence.ll", "commands": ["opt < %s -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=2 -force-widen-divrem-via-safe-divisor=0 -S", "opt < %s -passes=loop-vectorize -force-vector-width=1 -force-vector-interleave=2 -force-widen-divrem-via-safe-divisor=0 -S", "opt < %s -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -force-widen-divrem-via-safe-divisor=0 -S"], "tests": [{"test_name": "recurence_uniform_load", "test_body": "target datalayout = \"e-m:e-i64:64-i128:128-n32:64-S128\"\n\ndefine i32 @recurence_uniform_load(ptr %src, ptr noalias %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %phi = phi i64 [ 0, %entry ], [ %add, %loop ]\n %recur = phi i32 [ 0, %entry ], [ %load, %loop ]\n %add = add i64 %phi, 1\n %load = load i32, ptr %src, align 4\n %icmp = icmp ult i64 %phi, 1\n br i1 %icmp, label %loop, label %exit\n\nexit: ; preds = %loop\n ret i32 0\n}\n"}]}], "issue": {"title": "Assertion `hasVectorValue(Def, Instance.Part)' failed.", "body": "To reproduce run the following test opt with -passes loop-vectorize:\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 i32 @wombat() gc \"statepoint-example\" {\r\nbb:\r\n br label %bb2\r\n\r\nbb1: ; preds = %bb2\r\n ret i32 0\r\n\r\nbb2: ; preds = %bb2, %bb\r\n %phi = phi i64 [ 0, %bb ], [ %add, %bb2 ]\r\n %phi3 = phi i32 [ 0, %bb ], [ %load, %bb2 ]\r\n %add = add i64 %phi, 1\r\n %load = load i32, ptr addrspace(1) null, align 4\r\n %icmp = icmp ult i64 %phi, 1\r\n br i1 %icmp, label %bb2, label %bb1\r\n}\r\n```\r\nReproducer: https://godbolt.org/z/cv7Tf3vba\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 \r\n #0 0x0000000004e41688 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e41688)\r\n #1 0x0000000004e3eddc SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007ec2abe42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007ec2abe969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007ec2abe42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007ec2abe287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00007ec2abe2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x00007ec2abe39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x0000000003fecdce (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3fecdce)\r\n #9 0x0000000004008abe llvm::VPInstruction::generatePerPart(llvm::VPTransformState&, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4008abe)\r\n#10 0x000000000400ae5e llvm::VPInstruction::execute(llvm::VPTransformState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x400ae5e)\r\n#11 0x0000000003fe5fbf llvm::VPBasicBlock::executeRecipes(llvm::VPTransformState*, llvm::BasicBlock*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3fe5fbf)\r\n#12 0x0000000003fe9cb0 llvm::VPBasicBlock::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3fe9cb0)\r\n#13 0x0000000003feda3e llvm::VPlan::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3feda3e)\r\n#14 0x0000000003eda4e5 llvm::LoopVectorizationPlanner::executePlan(llvm::ElementCount, unsigned int, llvm::VPlan&, llvm::InnerLoopVectorizer&, llvm::DominatorTree*, bool, llvm::DenseMap, llvm::detail::DenseMapPair> const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3eda4e5)\r\n#15 0x0000000003eef18b llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3eef18b)\r\n#16 0x0000000003ef1a4d 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+0x3ef1a4d)\r\n#17 0x0000000003ef2c5b llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3ef2c5b)\r\n#18 0x0000000002e0679e llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2e0679e)\r\n#19 0x0000000004c49a6c llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4c49a6c)\r\n#20 0x0000000000dbabee llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xdbabee)\r\n#21 0x0000000004c483ae llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4c483ae)\r\n#22 0x0000000000dbc65e llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xdbc65e)\r\n#23 0x0000000004c462bc llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4c462bc)\r\n#24 0x00000000008db912 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::ArrayRef>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8db912)\r\n#25 0x00000000008ceabc optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ceabc)\r\n#26 0x00007ec2abe29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#27 0x00007ec2abe29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#28 0x00000000008c5f0e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8c5f0e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```\r\n\r\n", "author": "TatyanaDoubts", "labels": ["vectorizers", "crash-on-valid"], "comments": [{"author": "dtcxzyw", "body": "cc @fhahn "}]}, "verified": true} +{"bug_id": "126581", "issue_url": "https://github.com/llvm/llvm-project/issues/126581", "bug_type": "crash", "base_commit": "c81139f417a209dbd2a4e06465483d4b0951a9ac", "knowledge_cutoff": "2025-02-10T19:26:42Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "d18b1ebef5f5e355d6cee2b2f48789a159a5d616", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[18467, 18474]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["BoUpSLP::computeMinimumValueSizes"]}}, "patch": "commit d18b1ebef5f5e355d6cee2b2f48789a159a5d616\nAuthor: Alexey Bataev \nDate: Thu Feb 13 09:39:56 2025 -0800\n\n [SLP]Check if vector user exist before accessing it\n \n Need to check if vector user exist before accessing it to avoid compiler\n crash.\n Fixes #126581\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex a337ab7410f7..fb72a112b9ac 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -18467,8 +18467,8 @@ void BoUpSLP::computeMinimumValueSizes() {\n any_of(\n VectorizableTree[NodeIdx]->UserTreeIndices,\n [&](const EdgeInfo &EI) {\n- return (EI.UserTE->hasState() &&\n- EI.UserTE->getOpcode() == Instruction::ICmp) &&\n+ return EI.UserTE && EI.UserTE->hasState() &&\n+ EI.UserTE->getOpcode() == Instruction::ICmp &&\n any_of(EI.UserTE->Scalars, [&](Value *V) {\n auto *IC = dyn_cast(V);\n return IC &&\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/RISCV/check-node-without-vector-user.ll", "commands": ["opt -S --passes=slp-vectorizer -mtriple=riscv64-unknown-linux-gnu -mattr=+v < %s"], "tests": [{"test_name": "", "test_body": "\n@r = external global [8 x i8]\n\ndefine void @test(i64 %0, ptr %1) {\n;\n %3 = load i8, ptr @r, align 1\n %4 = trunc i8 %3 to i1\n %5 = select i1 %4, i64 %0, i64 0\n %6 = getelementptr i8, ptr @r, i64 %5\n %7 = load i8, ptr %6, align 1\n %8 = icmp ule i8 %3, %7\n %9 = sext i1 %8 to i32\n %10 = load i8, ptr getelementptr (i8, ptr @r, i64 -8049), align 1\n %11 = trunc i8 %10 to i1\n %12 = select i1 %11, i64 %0, i64 0\n %13 = getelementptr i8, ptr @r, i64 %12\n %14 = load i8, ptr %13, align 1\n %15 = icmp ule i8 %10, %14\n %16 = sext i1 %15 to i32\n %17 = add i32 %9, %16\n %18 = load i8, ptr getelementptr (i8, ptr @r, i64 -16098), align 1\n %19 = trunc i8 %18 to i1\n %20 = select i1 %19, i64 %0, i64 0\n %21 = getelementptr i8, ptr @r, i64 %20\n %22 = load i8, ptr %21, align 1\n %23 = icmp ule i8 %18, %22\n %24 = sext i1 %23 to i32\n %25 = add i32 %17, %24\n %26 = load i8, ptr getelementptr (i8, ptr @r, i64 -24147), align 1\n %27 = trunc i8 %26 to i1\n %28 = select i1 %27, i64 %0, i64 0\n %29 = getelementptr i8, ptr @r, i64 %28\n %30 = load i8, ptr %29, align 1\n %31 = icmp ule i8 %26, %30\n %32 = sext i1 %31 to i32\n %33 = add i32 %25, %32\n store i32 %33, ptr %1, align 4\n ret void\n}"}]}], "issue": {"title": "[SLPVectorizer] Segmentation Fault using opt \"-passes=lto\"", "body": "Testcase:\n```llvm ir\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\n@a = external global i32\n@g = internal global i16 -8049\n@r = external global [8 x i8]\n\ndefine internal void @c(i16 %g, ptr %r) #0 {\nentry:\n br label %for.cond16.preheader.us.us.us.us\n\nfor.cond16.preheader.us.us.us.us: ; preds = %for.cond.cleanup20.split.us.us.us.us.us, %entry\n %indvars.iv133 = phi i64 [ %indvars.iv.next134, %for.cond.cleanup20.split.us.us.us.us.us ], [ 0, %entry ]\n br label %for.body21.us.us.us.us.us\n\nfor.body21.us.us.us.us.us: ; preds = %for.body21.us.us.us.us.us, %for.cond16.preheader.us.us.us.us\n %sub74.us.us.us.us124.us = phi i32 [ 0, %for.cond16.preheader.us.us.us.us ], [ %sub74.us.us.us.us.us, %for.body21.us.us.us.us.us ]\n %w.0109.us.us.us.us.us = phi i16 [ 0, %for.cond16.preheader.us.us.us.us ], [ %add77.us.us.us.us.us, %for.body21.us.us.us.us.us ]\n %idxprom38.us.us.us.us.us = sext i16 %w.0109.us.us.us.us.us to i64\n %arrayidx48.us.us.us.us.us = getelementptr i8, ptr %r, i64 %idxprom38.us.us.us.us.us\n %0 = load i8, ptr %arrayidx48.us.us.us.us.us, align 1\n %loadedv49.us.us.us.us.us = trunc i8 %0 to i1\n %cond71.in.in.v.us.us.us.us.us = select i1 %loadedv49.us.us.us.us.us, i64 %indvars.iv133, i64 0\n %cond71.in.in.us.us.us.us.us = getelementptr i8, ptr %r, i64 %cond71.in.in.v.us.us.us.us.us\n %cond71.in.us.us.us.us.us = load i8, ptr %cond71.in.in.us.us.us.us.us, align 1\n %cmp72.us.us.us.us.us = icmp ule i8 %0, %cond71.in.us.us.us.us.us\n %conv73.neg.us.us.us.us.us = sext i1 %cmp72.us.us.us.us.us to i32\n %sub74.us.us.us.us.us = add i32 %sub74.us.us.us.us124.us, %conv73.neg.us.us.us.us.us\n store i32 %sub74.us.us.us.us124.us, ptr @a, align 4\n %add77.us.us.us.us.us = add i16 %w.0109.us.us.us.us.us, %g\n %cmp18.us.us.us.us.us = icmp slt i16 %add77.us.us.us.us.us, 0\n br i1 %cmp18.us.us.us.us.us, label %for.body21.us.us.us.us.us, label %for.cond.cleanup20.split.us.us.us.us.us\n\nfor.cond.cleanup20.split.us.us.us.us.us: ; preds = %for.body21.us.us.us.us.us\n %indvars.iv.next134 = add i64 %indvars.iv133, 1\n %1 = and i64 %indvars.iv133, 2147483648\n %cmp12.us.us.us.us = icmp eq i64 %1, 0\n br i1 %cmp12.us.us.us.us, label %for.cond16.preheader.us.us.us.us, label %for.cond5.loopexit.split.us.us.us.us\n\nfor.cond5.loopexit.split.us.us.us.us: ; preds = %for.cond.cleanup20.split.us.us.us.us.us\n ret void\n}\n\ndefine i32 @main() {\nentry:\n %0 = load i16, ptr @g, align 2\n call void @c(i16 %0, ptr @r)\n ret i32 0\n}\n\nattributes #0 = { \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zaamo,+zalrsc,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl256b,+zvl32b,+zvl64b,-b,-e,-experimental-sdext,-experimental-sdtrig,-experimental-smctr,-experimental-ssctr,-experimental-svukte,-experimental-xqcia,-experimental-xqciac,-experimental-xqcicli,-experimental-xqcicm,-experimental-xqcics,-experimental-xqcicsr,-experimental-xqciint,-experimental-xqcilo,-experimental-xqcilsm,-experimental-xqcisls,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-experimental-zvbc32e,-experimental-zvkgs,-h,-sha,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smdbltrp,-smepmp,-smmpm,-smnpm,-smrnmi,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssdbltrp,-ssnpm,-sspm,-ssqosid,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-supm,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-svvptc,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xmipscmove,-xmipslsp,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zabha,-zacas,-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,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b\" }\n```\n\n\nCommand/backtrace:\n```\n$ /scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt \"-passes=lto\" reduced.ll\nWARNING: You're attempting to print out a bitcode file.\nThis is inadvisable as it may cause display problems. If\nyou REALLY want to taste LLVM bitcode first-hand, you\ncan force output with the `-f' option.\n\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\nStack dump:\n0. Program arguments: /scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt -passes=lto reduced.ll\n1. Running pass \"function(loop-mssa(licm),gvn<>,memcpyopt,dse,move-auto-init,mldst-motion,loop(indvars,loop-deletion,loop-unroll-full),loop-distribute,loop-vectorize,infer-alignment,loop-unroll,transform-warning,sroa,instcombine,simplifycfg,sccp,instcombine,bdce,slp-vectorizer,vector-combine,infer-alignment,instcombine,loop-mssa(licm),alignment-from-assumptions,jump-threading)\" on module \"reduced.ll\"\n2. Running pass \"slp-vectorizer\" on function \"c\"\n #0 0x000064a320d6dd02 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x34a8d02)\n #1 0x000064a320d6ad3f llvm::sys::RunSignalHandlers() (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x34a5d3f)\n #2 0x000064a320d6ae84 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #3 0x00007fe3fee45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)\n #4 0x000064a31fc28b80 llvm::slpvectorizer::BoUpSLP::computeMinimumValueSizes()::'lambda1'(llvm::slpvectorizer::BoUpSLP::EdgeInfo const&)::operator()(llvm::slpvectorizer::BoUpSLP::EdgeInfo const&) const (.isra.0) SLPVectorizer.cpp:0:0\n #5 0x000064a31fcdc0bb llvm::slpvectorizer::BoUpSLP::computeMinimumValueSizes() (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x24170bb)\n #6 0x000064a31fcf9808 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&, llvm::AssumptionCache*) SLPVectorizer.cpp:0:0\n #7 0x000064a31fcfc9ae llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::SmallVectorImpl&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x24379ae)\n #8 0x000064a31fd00c41 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x243bc41)\n #9 0x000064a31fd04e32 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x243fe32)\n#10 0x000064a31fd0c6e0 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x24476e0)\n#11 0x000064a31fd0d336 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x2448336)\n#12 0x000064a31e87b285 llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0xfb6285)\n#13 0x000064a320b5976a llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x329476a)\n#14 0x000064a31e87d0d5 llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0xfb80d5)\n#15 0x000064a320b5807c llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x329307c)\n#16 0x000064a31e879675 llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0xfb4675)\n#17 0x000064a320b5865d llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x329365d)\n#18 0x000064a31e01d465 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::ArrayRef>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x758465)\n#19 0x000064a31e00d6ee optMain (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x7486ee)\n#20 0x00007fe3fee2a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3\n#21 0x00007fe3fee2a28b call_init ./csu/../csu/libc-start.c:128:20\n#22 0x00007fe3fee2a28b __libc_start_main ./csu/../csu/libc-start.c:347:5\n#23 0x000064a31e003f45 _start (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x73ef45)\nSegmentation fault (core dumped)\n```\n\nGodbolt: https://godbolt.org/z/P3sGYsGYc\n\nFound via fuzzer (C program before reduction)", "author": "ewlu", "labels": ["llvm:SLPVectorizer", "crash"], "comments": []}, "verified": true} {"bug_id": "129236", "issue_url": "https://github.com/llvm/llvm-project/issues/129236", "bug_type": "crash", "base_commit": "fa5db05ca36a732bffb8128ff017c575ec6e1201", "knowledge_cutoff": "2025-02-28T12:37:14Z", "lit_test_dir": ["llvm/test/Transforms/LoopVectorize"], "hints": {"fix_commit": "f937b17e8570082d4710b6dca7a91b5c235c1c70", "components": ["LoopVectorize"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [[6673, 6679]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": ["LoopVectorizationCostModel::getInstructionCost"]}}, "patch": "commit f937b17e8570082d4710b6dca7a91b5c235c1c70\nAuthor: Florian Hahn \nDate: Sun Mar 2 10:55:42 2025 +0000\n\n [LV] Don't query SCEV for non-invariant values in cost model.\n \n This fixes a divergence between VPlan and legacy cost model, matching\n behavior further up in getInstructionCost as well.\n \n Fixes https://github.com/llvm/llvm-project/issues/129236.\n\ndiff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\nindex c447fa484359..f3bdc95713af 100644\n--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n@@ -6673,7 +6673,8 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I,\n // Certain instructions can be cheaper to vectorize if they have a constant\n // second vector operand. One example of this are shifts on x86.\n Value *Op2 = I->getOperand(1);\n- if (!isa(Op2) && PSE.getSE()->isSCEVable(Op2->getType()) &&\n+ if (!isa(Op2) && TheLoop->isLoopInvariant(Op2) &&\n+ PSE.getSE()->isSCEVable(Op2->getType()) &&\n isa(PSE.getSCEV(Op2))) {\n Op2 = cast(PSE.getSCEV(Op2))->getValue();\n }\n", "tests": [{"file": "llvm/test/Transforms/LoopVectorize/X86/cost-model.ll", "commands": ["opt < %s -passes=loop-vectorize -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx -S"], "tests": [{"test_name": "cost_ashr_with_op_known_invariant_via_scev", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.8.0\"\n\ndefine i32 @cost_ashr_with_op_known_invariant_via_scev(i8 %a) {\nentry:\n %cmp.i = icmp eq i16 0, 0\n %conv.i = sext i16 0 to i32\n %conv5.i = sext i8 %a to i32\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i8 [ 100, %entry ], [ %iv.next, %loop.latch ]\n br i1 %cmp.i, label %then, label %else\n\nthen: ; preds = %else, %loop.header\n %p.1 = phi i32 [ %rem.i, %else ], [ 0, %loop.header ]\n %shr.i = ashr i32 %conv5.i, %p.1\n %tobool6.not.i = icmp eq i32 %shr.i, 0\n %sext.i = shl i32 %p.1, 24\n %0 = ashr exact i32 %sext.i, 24\n %1 = select i1 %tobool6.not.i, i32 %0, i32 0\n br label %loop.latch\n\nelse: ; preds = %loop.header\n %rem.i = urem i32 -1, %conv.i\n %cmp3.i = icmp sgt i32 %rem.i, 1\n br i1 %cmp3.i, label %loop.latch, label %then\n\nloop.latch: ; preds = %else, %then\n %p.2 = phi i32 [ 0, %else ], [ %1, %then ]\n %iv.next = add i8 %iv, -1\n %ec = icmp eq i8 %iv.next, 0\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret i32 %p.2\n}\n"}]}], "issue": {"title": "[clang] Crash at -O2: Assertion Assertion `(BestFactor.Width == LegacyVF.Width || PlanForEarlyExitLoop...' failed.", "body": "This code crashes at `-O2`:\n\n```c\nchar a;\nstruct b {\n short c;\n char d;\n long e;\n int f;\n} static g;\nint h;\nvoid i(struct b j) {\n char k;\n int l;\n for (; j.d; --j.d) {\n l = g.c == 0 ? 0 : 4294967295U % g.c;\n k = l >= 2 || a >> l ? 0 : l;\n h = k;\n }\n}\nvoid m() { i(g); }\n```\n\nCompiler Explorer: https://godbolt.org/z/WG85qYnc6\n\nBisected to https://github.com/llvm/llvm-project/commit/30f3752e54fa7cd595a434a985efbe9a7abe9b65, which was committed by @fhahn \n\nCrash:\n\n```console\nclang: /root/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7589: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || PlanForEarlyExitLoop || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), CostCtx, OrigLoop) || planContainsAdditionalSimplifications(getPlanFor(LegacyVF.Width), CostCtx, OrigLoop)) && \" VPlan cost model and legacy cost model disagreed\"' failed.\n```\n\nBacktrace:\n\n```console\nStack dump:\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O2 -Wall -Wextra \n1.\t parser at end of file\n2.\tOptimizer\n3.\tRunning pass \"function(float2int,lower-constant-intrinsics,loop(loop-rotate,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize,infer-alignment,loop-load-elim,instcombine,simplifycfg,slp-vectorizer,vector-combine,instcombine,loop-unroll,transform-warning,sroa,infer-alignment,instcombine,loop-mssa(licm),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg)\" on module \"\"\n4.\tRunning pass \"loop-vectorize\" on function \"i\"\n #0 0x0000000003e76828 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3e76828)\n #1 0x0000000003e744e4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3e744e4)\n #2 0x0000000003dc0e18 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\n #3 0x00007e3b78e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #4 0x00007e3b78e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #5 0x00007e3b78e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #6 0x00007e3b78e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #7 0x00007e3b78e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #8 0x00007e3b78e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #9 0x00000000059b6042 llvm::LoopVectorizationPlanner::computeBestVF() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x59b6042)\n#10 0x00000000059cd46c llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x59cd46c)\n#11 0x00000000059cfb19 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x59cfb19)\n#12 0x00000000059d0193 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x59d0193)\n#13 0x0000000005546d4e llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5546d4e)\n#14 0x000000000381d3f0 llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x381d3f0)\n#15 0x000000000119ab8e llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x119ab8e)\n#16 0x000000000381bd0b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x381bd0b)\n#17 0x0000000001199e3e llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x1199e3e)\n#18 0x000000000381b710 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x381b710)\n#19 0x00000000041305e8 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr>&, std::unique_ptr>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\n#20 0x000000000413485e clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr, std::unique_ptr>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x413485e)\n#21 0x0000000004835d60 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4835d60)\n#22 0x000000000642100c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x642100c)\n#23 0x0000000004836168 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4836168)\n#24 0x0000000004afe6e5 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4afe6e5)\n#25 0x0000000004a81dce clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4a81dce)\n#26 0x0000000004bec53e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4bec53e)\n#27 0x0000000000d4401f cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd4401f)\n#28 0x0000000000d3b93a ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&) driver.cpp:0:0\n#29 0x000000000487e099 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0\n#30 0x0000000003dc12c4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3dc12c4)\n#31 0x000000000487e68f clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0\n#32 0x00000000048412ad clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48412ad)\n#33 0x000000000484232e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x484232e)\n#34 0x000000000484a2c5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x484a2c5)\n#35 0x0000000000d40e13 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd40e13)\n#36 0x0000000000c11aa4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc11aa4)\n#37 0x00007e3b78e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#38 0x00007e3b78e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#39 0x0000000000d3b3e5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd3b3e5)\n```", "author": "cardigan1008", "labels": ["regression", "vectorizers", "crash"], "comments": []}, "verified": true} {"bug_id": "79175", "issue_url": "https://github.com/llvm/llvm-project/issues/79175", "bug_type": "miscompilation", "base_commit": "e538486e90539096e7851d0deba4ea9ed94fced2", "knowledge_cutoff": "2024-01-23T17:34:28Z", "lit_test_dir": ["llvm/test/Transforms/JumpThreading"], "hints": {"fix_commit": "4f32f5d5720fbef06672714a62376f236a36aef5", "components": ["JumpThreading", "AliasAnalysis"], "bug_location_lineno": {"llvm/include/llvm/Analysis/AliasAnalysis.h": [[287, 292], [668, 673]], "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": [[43, 62]], "llvm/lib/Analysis/BasicAliasAnalysis.cpp": [[89, 95], [1063, 1068], [1556, 1561], [1735, 1741]], "llvm/lib/Transforms/Scalar/JumpThreading.cpp": [[1261, 1266]]}, "bug_location_funcname": {"llvm/include/llvm/Analysis/AliasAnalysis.h": ["AAQueryInfo", "enableCrossIterationMode"], "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": ["BasicAAResult"], "llvm/lib/Analysis/BasicAliasAnalysis.cpp": ["BasicAAResult::aliasCheck", "BasicAAResult::aliasGEP", "BasicAAResult::invalidate", "BasicAAResult::isValueEqualInPotentialCycles", "BasicAAResult::subtractDecomposedGEPs"], "llvm/lib/Transforms/Scalar/JumpThreading.cpp": ["JumpThreadingPass::simplifyPartiallyRedundantLoad"]}}, "patch": "commit 4f32f5d5720fbef06672714a62376f236a36aef5\nAuthor: Nikita Popov \nDate: Wed Jan 31 15:23:53 2024 +0100\n\n [AA][JumpThreading] Don't use DomTree for AA in JumpThreading (#79294)\n \n JumpThreading may perform AA queries while the dominator tree is not up\n to date, which may result in miscompilations.\n \n Fix this by adding a new AAQI option to disable the use of the dominator\n tree in BasicAA.\n \n Fixes https://github.com/llvm/llvm-project/issues/79175.\n\ndiff --git a/llvm/include/llvm/Analysis/AliasAnalysis.h b/llvm/include/llvm/Analysis/AliasAnalysis.h\nindex d6f732d35fd4..e8e4f491be5a 100644\n--- a/llvm/include/llvm/Analysis/AliasAnalysis.h\n+++ b/llvm/include/llvm/Analysis/AliasAnalysis.h\n@@ -287,6 +287,10 @@ public:\n /// store %l, ...\n bool MayBeCrossIteration = false;\n \n+ /// Whether alias analysis is allowed to use the dominator tree, for use by\n+ /// passes that lazily update the DT while performing AA queries.\n+ bool UseDominatorTree = true;\n+\n AAQueryInfo(AAResults &AAR, CaptureInfo *CI) : AAR(AAR), CI(CI) {}\n };\n \n@@ -668,6 +672,9 @@ public:\n void enableCrossIterationMode() {\n AAQI.MayBeCrossIteration = true;\n }\n+\n+ /// Disable the use of the dominator tree during alias analysis queries.\n+ void disableDominatorTree() { AAQI.UseDominatorTree = false; }\n };\n \n /// Temporary typedef for legacy code that uses a generic \\c AliasAnalysis\ndiff --git a/llvm/include/llvm/Analysis/BasicAliasAnalysis.h b/llvm/include/llvm/Analysis/BasicAliasAnalysis.h\nindex afc1811239f2..7eca82729430 100644\n--- a/llvm/include/llvm/Analysis/BasicAliasAnalysis.h\n+++ b/llvm/include/llvm/Analysis/BasicAliasAnalysis.h\n@@ -43,20 +43,26 @@ class BasicAAResult : public AAResultBase {\n const Function &F;\n const TargetLibraryInfo &TLI;\n AssumptionCache &AC;\n- DominatorTree *DT;\n+ /// Use getDT() instead of accessing this member directly, in order to\n+ /// respect the AAQI.UseDominatorTree option.\n+ DominatorTree *DT_;\n+\n+ DominatorTree *getDT(const AAQueryInfo &AAQI) const {\n+ return AAQI.UseDominatorTree ? DT_ : nullptr;\n+ }\n \n public:\n BasicAAResult(const DataLayout &DL, const Function &F,\n const TargetLibraryInfo &TLI, AssumptionCache &AC,\n DominatorTree *DT = nullptr)\n- : DL(DL), F(F), TLI(TLI), AC(AC), DT(DT) {}\n+ : DL(DL), F(F), TLI(TLI), AC(AC), DT_(DT) {}\n \n BasicAAResult(const BasicAAResult &Arg)\n : AAResultBase(Arg), DL(Arg.DL), F(Arg.F), TLI(Arg.TLI), AC(Arg.AC),\n- DT(Arg.DT) {}\n+ DT_(Arg.DT_) {}\n BasicAAResult(BasicAAResult &&Arg)\n : AAResultBase(std::move(Arg)), DL(Arg.DL), F(Arg.F), TLI(Arg.TLI),\n- AC(Arg.AC), DT(Arg.DT) {}\n+ AC(Arg.AC), DT_(Arg.DT_) {}\n \n /// Handle invalidation events in the new pass manager.\n bool invalidate(Function &Fn, const PreservedAnalyses &PA,\ndiff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp\nindex 3178e2d27816..1028b52a7912 100644\n--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp\n+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp\n@@ -89,7 +89,7 @@ bool BasicAAResult::invalidate(Function &Fn, const PreservedAnalyses &PA,\n // may be created without handles to some analyses and in that case don't\n // depend on them.\n if (Inv.invalidate(Fn, PA) ||\n- (DT && Inv.invalidate(Fn, PA)))\n+ (DT_ && Inv.invalidate(Fn, PA)))\n return true;\n \n // Otherwise this analysis result remains valid.\n@@ -1063,6 +1063,7 @@ AliasResult BasicAAResult::aliasGEP(\n : AliasResult::MayAlias;\n }\n \n+ DominatorTree *DT = getDT(AAQI);\n DecomposedGEP DecompGEP1 = DecomposeGEPExpression(GEP1, DL, &AC, DT);\n DecomposedGEP DecompGEP2 = DecomposeGEPExpression(V2, DL, &AC, DT);\n \n@@ -1556,6 +1557,7 @@ AliasResult BasicAAResult::aliasCheck(const Value *V1, LocationSize V1Size,\n const Value *HintO1 = getUnderlyingObject(Hint1);\n const Value *HintO2 = getUnderlyingObject(Hint2);\n \n+ DominatorTree *DT = getDT(AAQI);\n auto ValidAssumeForPtrContext = [&](const Value *Ptr) {\n if (const Instruction *PtrI = dyn_cast(Ptr)) {\n return isValidAssumeForContext(Assume, PtrI, DT,\n@@ -1735,7 +1737,7 @@ bool BasicAAResult::isValueEqualInPotentialCycles(const Value *V,\n if (!Inst || Inst->getParent()->isEntryBlock())\n return true;\n \n- return isNotInCycle(Inst, DT, /*LI*/ nullptr);\n+ return isNotInCycle(Inst, getDT(AAQI), /*LI*/ nullptr);\n }\n \n /// Computes the symbolic difference between two de-composed GEPs.\ndiff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp\nindex b7cf02489631..bb33a5da288c 100644\n--- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp\n+++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp\n@@ -1261,6 +1261,8 @@ bool JumpThreadingPass::simplifyPartiallyRedundantLoad(LoadInst *LoadI) {\n BasicBlock::iterator BBIt(LoadI);\n bool IsLoadCSE;\n BatchAAResults BatchAA(*AA);\n+ // The dominator tree is updated lazily and may not be valid at this point.\n+ BatchAA.disableDominatorTree();\n if (Value *AvailableVal = FindAvailableLoadedValue(\n LoadI, LoadBB, BBIt, DefMaxInstsToScan, &BatchAA, &IsLoadCSE)) {\n // If the value of the load is locally available within the block, just use\n", "tests": [{"file": "llvm/test/Transforms/JumpThreading/pr79175.ll", "commands": ["opt -S -passes=jump-threading < %s"], "tests": [{"test_name": "test", "test_body": "@f = external global i32\n\ndefine i32 @test(i64 %idx, i32 %val) {\nentry:\n %cmp = icmp slt i64 %idx, 1\n br i1 %cmp, label %for.body, label %return\n\nfor.body: ; preds = %entry\n %f = load i32, ptr @f, align 4\n %cmp1 = icmp eq i32 %f, 0\n br i1 %cmp1, label %cond.end, label %cond.false\n\ncond.false: ; preds = %for.body\n br label %cond.end\n\ncond.end: ; preds = %cond.false, %for.body\n %phi = phi i32 [ %val, %cond.false ], [ 1, %for.body ]\n %cmp.i = icmp sgt i32 %phi, 0\n %sel = select i1 %cmp.i, i32 0, i32 %phi\n %f.idx = getelementptr inbounds i32, ptr @f, i64 %idx\n store i32 %sel, ptr %f.idx, align 4\n %f.reload = load i32, ptr @f, align 4\n %cmp3 = icmp slt i32 %f.reload, 1\n br i1 %cmp3, label %return2, label %return\n\nreturn: ; preds = %cond.end, %entry\n ret i32 0\n\nreturn2: ; preds = %cond.end\n ret i32 1\n}\n"}]}], "issue": {"title": "WRONG code, likely JumpThreadingPass", "body": "[wrong0.tar.gz](https://github.com/llvm/llvm-project/files/14027750/wrong0.tar.gz)\r\n(reduced c test case, should print 0)\r\n\r\nrunline:\r\nclang -O3 -march=arch13 wrong0.i -o a.out -w -mllvm -available-load-scan-limit=12\r\n\r\nThe function n() below is called two times in the reduced test case. The first time f[0] has a value of 0 at the start of the function, and a value of 1 at the end. The second time n() is called, f[0] has a value of 1 at the top, while it is then set to 0 by k().\r\n```\r\nlong k(long l, int m); // returns 0 \r\n\r\nconst int *n() {\r\n for (; C <= 0;) {\r\n A = (f[0] == 0 ? 1 : A % f[0]);\r\n f[C] = k(A, 0);\r\n g = &f[0];\r\n f[C] = 1 > *g;\r\n if (f[C])\r\n return &e;\r\n break;\r\n }\r\n return 0;\r\n}\r\n```\r\nThis is the transformation of jump threading:\r\n\r\n```\r\n > *** IR Dump After JumpThreadingPass on n ***\r\n > ; Function Attrs: nounwind\r\ndefine dso_local ptr @n() local_unnamed_addr #1 { define dso_local ptr @n() local_unnamed_addr #1 {\r\nentry: entry:\r\n %0 = load i64, ptr @C, align 8, !tbaa !4 %0 = load i64, ptr @C, align 8, !tbaa !4\r\n %cmp = icmp slt i64 %0, 1 %cmp = icmp slt i64 %0, 1\r\n br i1 %cmp, label %for.body, label %for.end br i1 %cmp, label %for.body, label %for.end\r\n\r\nfor.body: ; preds = %entry for.body: ; preds = %entry\r\n %1 = load i32, ptr @f, align 4, !tbaa !8 %1 = load i32, ptr @f, align 4, !tbaa !8\r\n %cmp1 = icmp eq i32 %1, 0 %cmp1 = icmp eq i32 %1, 0\r\n br i1 %cmp1, label %cond.end, label %cond.false | br i1 %cmp1, label %cond.end.thread, label %cond.end\r\n\r\ncond.false: ; preds = %for.body | cond.end.thread: ; preds = %for.body\r\n > store i64 1, ptr @A, align 8, !tbaa !4\r\n > br label %3\r\n >\r\n > cond.end: ; preds = %for.body\r\n %2 = load i64, ptr @A, align 8, !tbaa !4 %2 = load i64, ptr @A, align 8, !tbaa !4\r\n %conv = sext i32 %1 to i64 %conv = sext i32 %1 to i64\r\n %rem = srem i64 %2, %conv %rem = srem i64 %2, %conv\r\n br label %cond.end | store i64 %rem, ptr @A, align 8, !tbaa !4\r\n > %cmp.i = icmp sgt i64 %rem, 0\r\n > %cond.fr = freeze i1 %cmp.i\r\n > br i1 %cond.fr, label %3, label %4\r\n >\r\n > 3: ; preds = %cond.end.\r\n > %.pr = load i32, ptr @f, align 4, !tbaa !8\r\n > br label %4\r\n\r\ncond.end: ; preds = %for.body, | 4: ; preds = %cond.end,\r\n %cond = phi i64 [ %rem, %cond.false ], [ 1, %for.body ] | %5 = phi i32 [ %1, %cond.end ], [ %.pr, %3 ]\r\n store i64 %cond, ptr @A, align 8, !tbaa !4 | %6 = phi i64 [ 0, %3 ], [ %rem, %cond.end ]\r\n %cmp.i = icmp sgt i64 %cond, 0 | %conv2 = trunc i64 %6 to i32\r\n %cond.i = select i1 %cmp.i, i64 0, i64 %cond <\r\n %conv2 = trunc i64 %cond.i to i32 <\r\n %arrayidx = getelementptr inbounds [1 x i32], ptr @f, i64 0, i64 %0 %arrayidx = getelementptr inbounds [1 x i32], ptr @f, i64 0, i64 %0\r\n store i32 %conv2, ptr %arrayidx, align 4, !tbaa !8 store i32 %conv2, ptr %arrayidx, align 4, !tbaa !8\r\n store ptr @f, ptr @g, align 8, !tbaa !10 store ptr @f, ptr @g, align 8, !tbaa !10\r\n %3 = load i32, ptr @f, align 4, !tbaa !8 | %cmp3 = icmp slt i32 %5, 1\r\n %cmp3 = icmp slt i32 %3, 1 <\r\n %conv4 = zext i1 %cmp3 to i32 %conv4 = zext i1 %cmp3 to i32\r\n store i32 %conv4, ptr %arrayidx, align 4, !tbaa !8 store i32 %conv4, ptr %arrayidx, align 4, !tbaa !8\r\n br i1 %cmp3, label %return, label %for.end br i1 %cmp3, label %return, label %for.end\r\n\r\nfor.end: ; preds = %cond.end, | for.end: ; preds = %4, %entry\r\n br label %return br label %return\r\n\r\nreturn: ; preds = %cond.end, | return: ; preds = %4, %for.e\r\n %retval.0 = phi ptr [ null, %for.end ], [ @e, %cond.end ] | %retval.0 = phi ptr [ null, %for.end ], [ @e, %4 ]\r\n ret ptr %retval.0 ret ptr %retval.0\r\n} }\r\n~\r\n\r\n```\r\n\r\nBefore (left), `@f `is reloaded for the final icmp in cond.end (%3), which is necessary as the store to %conv2 just above goes to the same address. However, to the right JumpThreading has changed the final icmp to use the %5 value, which does not reflect the stored value of %conv2. This seems wrong and maybe JT has missed the fact that %arrayidx aliases `@f`?\r\n\r\n@jmorse @MatzeB @nikic \r\n", "author": "JonPsson1", "labels": ["miscompilation", "llvm:analysis", "llvm:transforms"], "comments": [{"author": "jmorse", "body": "Here's a godbolt link seemingly showing the same thing: https://godbolt.org/z/dMPaP7161 . I can't replicate this at 6a7abea47 with just `opt --passes=jump-threading`, but can if it's part of clang and inspected with `print-after-all`."}, {"author": "jmorse", "body": "Ah -- because it's sensitive to the `-available-load-scan-limit=12`, which defaults to six and needs to be at least ten for this problem to appear. Stepping through bits of opt, the AA trace believes something that's wrong:\r\n\r\n```\r\nStart %arrayidx = getelementptr inbounds [1 x i32], ptr @f, i64 0, i64 %0 @ LocationSize::precise(4), @f = dso_local global [1 x i32] zeroinitializer, align 4 @ LocationSize::precise(4)\r\n Start @f = dso_local global [1 x i32] zeroinitializer, align 4 @ LocationSize::beforeOrAfterPointer, @f = dso_local global [1 x i32] zeroinitializer, align 4 @ LocationSize::beforeOrAfterPointer\r\n End @f = dso_local global [1 x i32] zeroinitializer, align 4 @ LocationSize::beforeOrAfterPointer, @f = dso_local global [1 x i32] zeroinitializer, align 4 @ LocationSize::beforeOrAfterPointer = MustAlias\r\nEnd %arrayidx = getelementptr inbounds [1 x i32], ptr @f, i64 0, i64 %0 @ LocationSize::precise(4), @f = dso_local global [1 x i32] zeroinitializer, align 4 @ LocationSize::precise(4) = NoAlias\r\n```\r\n\r\nWhich I think is saying that the GEP is believed to not-alias the \"f\" variable, wheras it might alias depending on the value of %0. Stepping through other things during the alias query, I see `isKnownNonNullFromDominatingCondition` returning true for %0, i.e. the load from \"C\". I would imagine this means there's something wrong with the dominator tree that makes this code think it's only executing on a path where %0 is always-zero. (EDIT: actually it means always-non-zero).\r\n\r\n(However this isn't my normal wheelhouse, so that might not be true!)."}, {"author": "nikic", "body": "That sounds about right to me. JumpThreading performs lazy DT updates, so it's not legal to use DT during the transform.\r\n\r\nBasicAA in principle already supports working without DT, but it may be a bit tricky to avoid the DT use just in JumpThreading, given how this is all wired up in the pass manager."}, {"author": "nikic", "body": "Somewhat reduced test case:\r\n```llvm\r\n; RUN: opt -S -passes=jump-threading < %s\r\n@f = external global i32\r\n\r\ndefine void @test(i64 %idx, i32 %val) {\r\nentry:\r\n %cmp = icmp slt i64 %idx, 1\r\n br i1 %cmp, label %for.body, label %return\r\n\r\nfor.body:\r\n %f = load i32, ptr @f, align 4\r\n %cmp1 = icmp eq i32 %f, 0\r\n br i1 %cmp1, label %cond.end, label %cond.false\r\n\r\ncond.false:\r\n br label %cond.end\r\n\r\ncond.end:\r\n %phi = phi i32 [ %val, %cond.false ], [ 1, %for.body ]\r\n %cmp.i = icmp sgt i32 %phi, 0\r\n %sel = select i1 %cmp.i, i32 0, i32 %phi\r\n %f.idx = getelementptr inbounds i32, ptr @f, i64 %idx\r\n store i32 %sel, ptr %f.idx, align 4\r\n %f.reload = load i32, ptr @f, align 4\r\n %cmp3 = icmp slt i32 %f.reload, 1\r\n br i1 %cmp3, label %return, label %return\r\n\r\nreturn:\r\n ret void\r\n}\r\n```"}, {"author": "EugeneZelenko", "body": "Not merged yet."}, {"author": "tstellar", "body": "PR has been created, we will track the status there."}]}, "verified": true} {"bug_id": "91178", "issue_url": "https://github.com/llvm/llvm-project/issues/91178", "bug_type": "miscompilation", "base_commit": "7098cd215b95286794d9e0c822e8323ad0509750", "knowledge_cutoff": "2024-05-06T09:44:48Z", "lit_test_dir": ["llvm/test/Transforms/InstCombine", "llvm/test/Transforms/PGOProfile"], "hints": {"fix_commit": "d085b42cbbefe79a41113abcd2b1e1f2a203acef", "components": ["InstructionSimplify"], "bug_location_lineno": {"llvm/lib/Analysis/InstructionSimplify.cpp": [[4312, 4317]]}, "bug_location_funcname": {"llvm/lib/Analysis/InstructionSimplify.cpp": ["simplifyWithOpReplaced"]}}, "patch": "commit d085b42cbbefe79a41113abcd2b1e1f2a203acef\nAuthor: Yingwei Zheng \nDate: Wed May 8 10:04:09 2024 +0800\n\n [InstSimplify] Do not simplify freeze in `simplifyWithOpReplaced` (#91215)\n \n See the LangRef:\n > All uses of a value returned by the same ‘freeze’ instruction are\n guaranteed to always observe the same value, while different ‘freeze’\n instructions may yield different values.\n \n It is incorrect to replace freezes with the simplified value.\n \n Proof:\n https://alive2.llvm.org/ce/z/3Dn9Cd\n https://alive2.llvm.org/ce/z/Qyh5h6\n \n Fixes https://github.com/llvm/llvm-project/issues/91178\n\ndiff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp\nindex 4061dae83c10..37a7259a5cd0 100644\n--- a/llvm/lib/Analysis/InstructionSimplify.cpp\n+++ b/llvm/lib/Analysis/InstructionSimplify.cpp\n@@ -4312,6 +4312,10 @@ static Value *simplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp,\n if (match(I, m_Intrinsic()))\n return nullptr;\n \n+ // Don't simplify freeze.\n+ if (isa(I))\n+ return nullptr;\n+\n // Replace Op with RepOp in instruction operands.\n SmallVector NewOps;\n bool AnyReplaced = false;\n", "tests": [{"file": "llvm/test/Transforms/InstCombine/icmp.ll", "commands": ["opt < %s -passes=instcombine -S"], "tests": [{"test_name": "icmp_freeze_sext", "test_body": "target datalayout = \"e-p:64:64:64-p1:16:16:16-p2:32:32:32-p3:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\"\n\ndefine i1 @icmp_freeze_sext(i16 %x, i16 %y) {\n %cmp1 = icmp uge i16 %x, %y\n %ext = sext i1 %cmp1 to i16\n %ext.fr = freeze i16 %ext\n %cmp2 = icmp uge i16 %ext.fr, %y\n ret i1 %cmp2\n}\n"}]}, {"file": "llvm/test/Transforms/InstCombine/select.ll", "commands": ["opt < %s -passes=instcombine -S"], "tests": [{"test_name": "test_replace_freeze_oneuse", "test_body": "target datalayout = \"e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64\"\n\ndefine i8 @test_replace_freeze_oneuse(i1 %x, i8 %y) {\n %ext = zext i1 %x to i8\n %shl = shl nuw i8 %ext, %y\n %shl.fr = freeze i8 %shl\n %sel = select i1 %x, i8 0, i8 %shl.fr\n ret i8 %sel\n}\n"}, {"test_name": "sequence_select_with_same_cond_extra_use", "test_body": "target datalayout = \"e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64\"\n\ndeclare void @use32(i32)\n\ndefine i32 @sequence_select_with_same_cond_extra_use(i1 %c1, i1 %c2) {\n %s1 = select i1 %c1, i32 23, i32 45\n call void @use32(i32 %s1)\n %s2 = select i1 %c2, i32 666, i32 %s1\n %s3 = select i1 %c1, i32 789, i32 %s2\n ret i32 %s3\n}\n"}, {"test_name": "test_replace_freeze_multiuse", "test_body": "target datalayout = \"e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64\"\n\ndefine i8 @test_replace_freeze_multiuse(i1 %x, i8 %y) {\n %ext = zext i1 %x to i8\n %shl = shl nuw i8 %ext, %y\n %shl.fr = freeze i8 %shl\n %sel = select i1 %x, i8 0, i8 %shl.fr\n %add = add i8 %shl.fr, %sel\n ret i8 %add\n}\n"}]}], "issue": {"title": "[InstCombine] Miscompilation which simplifies a use of a multi-use freeze", "body": "Reduced test case: https://alive2.llvm.org/ce/z/_JyUGw\r\n```\r\ndefine i8 @func78(i1 %0, i8 %1) {\r\n %3 = zext i1 %0 to i8\r\n %4 = shl i8 %3, %1\r\n %5 = freeze i8 %4\r\n %6 = select i1 %0, i8 0, i8 %5\r\n %7 = call i8 @llvm.fshr.i8(i8 0, i8 %5, i8 %6)\r\n ret i8 %7\r\n}\r\n```\r\n\r\n```\r\n----------------------------------------\r\ndefine i8 @func78(i1 %#0, i8 %#1) {\r\n#2:\r\n %#3 = zext i1 %#0 to i8\r\n %#4 = shl i8 %#3, %#1\r\n %#5 = freeze i8 %#4\r\n %#6 = select i1 %#0, i8 0, i8 %#5\r\n %#7 = fshr i8 0, i8 %#5, i8 %#6\r\n ret i8 %#7\r\n}\r\n=>\r\ndefine i8 @func78(i1 %#0, i8 %#1) nofree noundef willreturn memory(none) {\r\n#2:\r\n %#3 = zext i1 %#0 to i8\r\n %#4 = shl nuw i8 %#3, %#1\r\n %#5 = freeze i8 %#4\r\n ret i8 %#5\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Value mismatch\r\n\r\nExample:\r\ni1 %#0 = #x0 (0)\r\ni8 %#1 = #x08 (8)\r\n\r\nSource:\r\ni8 %#3 = #x00 (0)\r\ni8 %#4 = poison\r\ni8 %#5 = #x00 (0)\r\ni8 %#6 = #x00 (0)\r\ni8 %#7 = #x00 (0)\r\n\r\nTarget:\r\ni8 %#3 = #x00 (0)\r\ni8 %#4 = poison\r\ni8 %#5 = #x9d (157, -99)\r\nSource value: #x00 (0)\r\nTarget value: #x9d (157, -99)\r\n\r\nSummary:\r\n 0 correct transformations\r\n 1 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\n```", "author": "dtcxzyw", "labels": ["miscompilation", "llvm:instcombine"], "comments": []}, "verified": true} +{"bug_id": "126304", "issue_url": "https://github.com/llvm/llvm-project/issues/126304", "bug_type": "crash", "base_commit": "fcbf04e40e66014f455a38b59993be865bc6cdfd", "knowledge_cutoff": "2025-02-07T20:48:01Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "10844fb9b0b78695243391e091e17ec29295872a", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[5596, 5601], [5626, 5632]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["BoUpSLP::getReorderingData"]}}, "patch": "commit 10844fb9b0b78695243391e091e17ec29295872a\nAuthor: Alexey Bataev \nDate: Tue Feb 11 13:23:55 2025 -0800\n\n [SLP]Fix attempt to build the reorder mask for non-adjusted reuse mask\n \n When building the reorder for non-single use reuse mask, need to check\n if the size of the mask is multiple of the number of unique scalars.\n Otherwise, the compiler may crash when trying to reorder nodes.\n \n Fixes #126304\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex e1c08077126d..fb1054ee30aa 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -5596,6 +5596,8 @@ BoUpSLP::getReorderingData(const TreeEntry &TE, bool TopToBottom) {\n ::getNumberOfParts(*TTI, getWidenedType(TE.Scalars.front()->getType(),\n 2 * TE.getVectorFactor())) == 1)\n return std::nullopt;\n+ if (TE.ReuseShuffleIndices.size() % Sz != 0)\n+ return std::nullopt;\n if (!ShuffleVectorInst::isOneUseSingleSourceMask(TE.ReuseShuffleIndices,\n Sz)) {\n SmallVector ReorderMask(Sz, PoisonMaskElem);\n@@ -5626,7 +5628,7 @@ BoUpSLP::getReorderingData(const TreeEntry &TE, bool TopToBottom) {\n UsedVals.set(Val);\n for (unsigned K = 0; K < NumParts; ++K) {\n unsigned Idx = Val + Sz * K;\n- if (Idx < VF)\n+ if (Idx < VF && I + K < VF)\n ResOrder[Idx] = I + K;\n }\n }\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/SystemZ/reuse-non-power-of-2-reorder.ll", "commands": ["opt -S --passes=slp-vectorizer -mtriple=systemz -mcpu=z15 < %s -slp-threshold=-100"], "tests": [{"test_name": "", "test_body": "\ndefine void @test(i32 %0, i64 %1, i32 %2, i32 %3, ptr %4) {\n;\n %6 = trunc i64 %1 to i32\n %7 = xor i32 %6, 1\n %8 = xor i32 %6, 1\n %9 = or i32 %7, %8\n %10 = xor i32 %6, 1\n %11 = or i32 %9, %10\n %12 = xor i32 %6, 1\n %13 = or i32 %11, %12\n %14 = xor i32 %6, 1\n %15 = or i32 %13, %14\n %16 = xor i32 %6, 1\n %17 = or i32 %15, %16\n %18 = xor i32 %6, 1\n %19 = or i32 %17, %18\n %20 = xor i32 %6, 1\n %21 = or i32 %19, %20\n %22 = trunc i64 %1 to i32\n %23 = xor i32 %22, 1\n %24 = or i32 %23, %21\n %25 = xor i32 %22, 1\n %26 = or i32 %24, %25\n %27 = xor i32 %22, 1\n %28 = or i32 %26, %27\n %29 = xor i32 %22, 1\n %30 = or i32 %28, %29\n %31 = xor i32 %22, 1\n %32 = or i32 %30, %31\n %33 = xor i32 %22, 1\n %34 = or i32 %32, %33\n %35 = xor i32 %22, 1\n %36 = or i32 %34, %35\n %37 = xor i32 %22, 1\n %38 = or i32 %36, %37\n %39 = trunc i64 %1 to i32\n %40 = xor i32 %39, 1\n %41 = or i32 %40, %38\n %42 = xor i32 %39, 1\n %43 = or i32 %41, %42\n %44 = xor i32 %39, 1\n %45 = or i32 %43, %44\n %46 = xor i32 %39, 1\n %47 = or i32 %45, %46\n %48 = xor i32 %39, 1\n %49 = or i32 %47, %48\n %50 = xor i32 %39, 1\n %51 = or i32 %49, %50\n %52 = xor i32 %39, 1\n %53 = or i32 %51, %52\n %54 = xor i32 %39, 1\n %55 = or i32 %53, %54\n %56 = trunc i64 %1 to i32\n %57 = xor i32 %56, 1\n %58 = or i32 %57, %55\n %59 = xor i32 %56, 1\n %60 = or i32 %58, %59\n %61 = xor i32 %56, 1\n %62 = or i32 %60, %61\n %63 = xor i32 %56, 1\n %64 = or i32 %62, %63\n %65 = xor i32 %56, 1\n %66 = or i32 %64, %65\n %67 = xor i32 %56, 1\n %68 = or i32 %66, %67\n %69 = xor i32 %56, 1\n %70 = or i32 %68, %69\n %71 = xor i32 %56, 1\n %72 = or i32 %70, %71\n %73 = trunc i64 %1 to i32\n %74 = xor i32 %73, 1\n %75 = or i32 %74, %72\n %76 = xor i32 %73, 1\n %77 = or i32 %75, %76\n %78 = xor i32 %73, 1\n %79 = or i32 %77, %78\n %80 = xor i32 %73, 1\n %81 = or i32 %79, %80\n %82 = xor i32 %73, 1\n %83 = or i32 %81, %82\n %84 = xor i32 %73, 1\n %85 = or i32 %83, %84\n %86 = xor i32 %73, 1\n %87 = or i32 %85, %86\n %88 = xor i32 %0, %73\n %89 = or i32 %87, %88\n %90 = xor i32 %0, %2\n %91 = or i32 %90, %89\n %92 = xor i32 %0, %2\n %93 = or i32 %91, %92\n %94 = xor i32 %0, %2\n %95 = or i32 %93, %94\n %96 = xor i32 %0, %2\n %97 = or i32 %95, %96\n %98 = trunc i64 %1 to i32\n %99 = xor i32 %98, 1\n %100 = xor i32 %98, 1\n %101 = or i32 %99, %100\n %102 = xor i32 %98, 1\n %103 = or i32 %101, %102\n %104 = xor i32 %98, 1\n %105 = or i32 %103, %104\n %106 = xor i32 %98, 1\n %107 = or i32 %105, %106\n %108 = xor i32 %98, 1\n %109 = or i32 %107, %108\n %110 = xor i32 %98, 1\n %111 = or i32 %109, %110\n %112 = xor i32 %0, %98\n %113 = or i32 %111, %112\n %114 = xor i32 %0, %3\n %115 = or i32 %113, %114\n %116 = xor i32 %0, %3\n %117 = or i32 %115, %116\n %118 = xor i32 %0, %3\n %119 = or i32 %117, %118\n %120 = xor i32 %0, %3\n %121 = or i32 %119, %120\n %122 = xor i32 %0, %3\n %123 = or i32 %121, %122\n %124 = xor i32 %0, %3\n %125 = or i32 %123, %124\n %126 = xor i32 %0, %3\n %127 = or i32 %125, %126\n %128 = xor i32 %0, %3\n %129 = or i32 %127, %128\n %130 = or i32 %129, %97\n store i32 %130, ptr %4, align 4\n ret void\n}\n"}]}], "issue": {"title": "[SLP] llvm::BitVector::set(unsigned int): Assertion `Idx < Size && \"access in bound\"' failed.", "body": "[crash41.tar.gz](https://github.com/user-attachments/files/18712696/crash41.tar.gz)\n\nclang -O3 -march=z15 crash41.i -o a.out -w -mllvm -inline-threshold=450\n\nllvm/include/llvm/ADT/BitVector.h:358: llvm::BitVector& llvm::BitVector::set(unsigned int): Assertion `Idx < Size && \"access in bound\"' failed.\n\n#11 0x000002aa03b45768 llvm::SLPVectorizerPass::vectorizeHorReduction\n\n@alexey-bataev \n", "author": "JonPsson1", "labels": ["llvm:SLPVectorizer", "crash"], "comments": []}, "verified": true} {"bug_id": "121584", "issue_url": "https://github.com/llvm/llvm-project/issues/121584", "bug_type": "miscompilation", "base_commit": "4a7c0b8afe6bf616cd6bb4f13b5b706a43c10e74", "knowledge_cutoff": "2025-01-03T17:05:45Z", "lit_test_dir": ["llvm/test/Transforms/InstCombine"], "hints": {"fix_commit": "24c2ba07ce65a5bf7d1113e05c517169d950b663", "components": ["InstCombine"], "bug_location_lineno": {"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": [[2066, 2079], [2095, 2101], [2108, 2114], [2131, 2137]]}, "bug_location_funcname": {"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": ["simplifyIRemMulShl"]}}, "patch": "commit 24c2ba07ce65a5bf7d1113e05c517169d950b663\nAuthor: Yingwei Zheng \nDate: Sun Jan 5 01:20:54 2025 +0800\n\n [InstCombine] Drop NSW when converting `shl X, BW - 1` back into mul (#121633)\n \n `X < bool {\n+ auto MatchShiftOrMulXC = [](Value *Op, Value *&V, APInt &C,\n+ bool &PreserveNSW) -> bool {\n const APInt *Tmp = nullptr;\n if ((!V && match(Op, m_Mul(m_Value(V), m_APInt(Tmp)))) ||\n (V && match(Op, m_Mul(m_Specific(V), m_APInt(Tmp)))))\n C = *Tmp;\n else if ((!V && match(Op, m_Shl(m_Value(V), m_APInt(Tmp)))) ||\n- (V && match(Op, m_Shl(m_Specific(V), m_APInt(Tmp)))))\n+ (V && match(Op, m_Shl(m_Specific(V), m_APInt(Tmp))))) {\n C = APInt(Tmp->getBitWidth(), 1) << *Tmp;\n+ // We cannot preserve NSW when shifting by BW - 1.\n+ PreserveNSW = Tmp->ult(Tmp->getBitWidth() - 1);\n+ }\n if (Tmp != nullptr)\n return true;\n \n@@ -2095,7 +2099,9 @@ static Instruction *simplifyIRemMulShl(BinaryOperator &I,\n return false;\n };\n \n- if (MatchShiftOrMulXC(Op0, X, Y) && MatchShiftOrMulXC(Op1, X, Z)) {\n+ bool Op0PreserveNSW = true, Op1PreserveNSW = true;\n+ if (MatchShiftOrMulXC(Op0, X, Y, Op0PreserveNSW) &&\n+ MatchShiftOrMulXC(Op1, X, Z, Op1PreserveNSW)) {\n // pass\n } else if (MatchShiftCX(Op0, Y, X) && MatchShiftCX(Op1, Z, X)) {\n ShiftByX = true;\n@@ -2108,7 +2114,7 @@ static Instruction *simplifyIRemMulShl(BinaryOperator &I,\n OverflowingBinaryOperator *BO0 = cast(Op0);\n // TODO: We may be able to deduce more about nsw/nuw of BO0/BO1 based on Y >=\n // Z or Z >= Y.\n- bool BO0HasNSW = BO0->hasNoSignedWrap();\n+ bool BO0HasNSW = Op0PreserveNSW && BO0->hasNoSignedWrap();\n bool BO0HasNUW = BO0->hasNoUnsignedWrap();\n bool BO0NoWrap = IsSRem ? BO0HasNSW : BO0HasNUW;\n \n@@ -2131,7 +2137,7 @@ static Instruction *simplifyIRemMulShl(BinaryOperator &I,\n };\n \n OverflowingBinaryOperator *BO1 = cast(Op1);\n- bool BO1HasNSW = BO1->hasNoSignedWrap();\n+ bool BO1HasNSW = Op1PreserveNSW && BO1->hasNoSignedWrap();\n bool BO1HasNUW = BO1->hasNoUnsignedWrap();\n bool BO1NoWrap = IsSRem ? BO1HasNSW : BO1HasNUW;\n // (rem (mul X, Y), (mul nuw/nsw X, Z))\n", "tests": [{"file": "llvm/test/Transforms/InstCombine/rem-mul-shl.ll", "commands": ["opt < %s -passes=instcombine -S"], "tests": [{"test_name": "srem_XY_XZ_with_CY_gt_CZ_no_nuw_out", "test_body": "define <2 x i8> @srem_XY_XZ_with_CY_gt_CZ_no_nuw_out(<2 x i8> %X) {\n %BO0 = mul nsw <2 x i8> %X, splat (i8 10)\n %BO1 = shl nuw nsw <2 x i8> %X, splat (i8 3)\n %r = srem <2 x i8> %BO0, %BO1\n ret <2 x i8> %r\n}\n"}, {"test_name": "srem_XY_XZ_with_CY_gt_CZ_drop_nsw_commuted", "test_body": "define i8 @srem_XY_XZ_with_CY_gt_CZ_drop_nsw_commuted(i8 noundef %X) {\n %BO0 = mul nsw i8 %X, 127\n %BO1 = shl nsw i8 %X, 7\n %r = srem i8 %BO0, %BO1\n ret i8 %r\n}\n"}, {"test_name": "srem_XY_XZ_with_CY_gt_CZ_drop_nsw", "test_body": "define i8 @srem_XY_XZ_with_CY_gt_CZ_drop_nsw(i8 noundef %X) {\n %BO0 = mul nsw i8 %X, 127\n %BO1 = shl nsw i8 %X, 7\n %r = srem i8 %BO1, %BO0\n ret i8 %r\n}\n"}, {"test_name": "srem_XY_XZ_with_CY_gt_CZ_fail_missing_flag1", "test_body": "define i8 @srem_XY_XZ_with_CY_gt_CZ_fail_missing_flag1(i8 %X) {\n %BO0 = mul nuw nsw i8 %X, 10\n %BO1 = mul nuw i8 %X, 6\n %r = srem i8 %BO0, %BO1\n ret i8 %r\n}\n"}]}], "issue": {"title": "[InstCombine] Miscompilation in `simplifyIRemMulShl`", "body": "Alive2: https://alive2.llvm.org/ce/z/rdeehL\n```\n\n----------------------------------------\ndefine i8 @srem_XY_XZ_with_CY_gt_CZ_no_nuw_out1(i8 noundef %X) {\n#0:\n %BO0 = mul nsw i8 noundef %X, 127\n %BO1 = shl nsw i8 noundef %X, 7\n %r = srem i8 %BO1, %BO0\n ret i8 %r\n}\n=>\ndefine i8 @srem_XY_XZ_with_CY_gt_CZ_no_nuw_out1(i8 noundef %X) {\n#0:\n %r = sub nsw i8 0, noundef %X\n ret i8 %r\n}\nTransformation doesn't verify!\n\nERROR: Value mismatch\n\nExample:\ni8 noundef %X = #xff (255, -1)\n\nSource:\ni8 %BO0 = #x81 (129, -127)\ni8 %BO1 = #x80 (128, -128)\ni8 %r = #xff (255, -1)\n\nTarget:\ni8 %r = #x01 (1)\nSource value: #xff (255, -1)\nTarget value: #x01 (1)\n\nSummary:\n 0 correct transformations\n 1 incorrect transformations\n 0 failed-to-prove transformations\n 0 Alive2 errors\n```", "author": "dtcxzyw", "labels": ["miscompilation", "llvm:instcombine"], "comments": []}, "verified": true} {"bug_id": "118798", "issue_url": "https://github.com/llvm/llvm-project/issues/118798", "bug_type": "hang", "base_commit": "8a90b5b31776957cb9cfa4f9547d19544640c5cc", "knowledge_cutoff": "2024-12-05T13:19:25Z", "lit_test_dir": ["llvm/test/Transforms/InstCombine"], "hints": {"fix_commit": "27eaa8a40ef338bea611f693fa8e810b1fc8d78d", "components": ["InstCombine"], "bug_location_lineno": {"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": [[427, 433]]}, "bug_location_funcname": {"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": ["InstCombinerImpl::commonShiftTransforms"]}}, "patch": "commit 27eaa8a40ef338bea611f693fa8e810b1fc8d78d\nAuthor: Maurice Heumann \nDate: Thu Dec 5 16:57:27 2024 +0100\n\n [InstCombine] Prevent infinite loop with two shifts (#118806)\n \n The following pattern: `(C2 << X) << C1` will usually be transformed\n into `(C2 << C1) << X`, essentially swapping `X` and `C1`.\n \n However, this should only be done when `C1` is an immediate constant,\n otherwise thiscan lead to both constants being swapped forever.\n \n This fixes #118798.\n\ndiff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp\nindex 10c3ccdb2243..d511e79e3e48 100644\n--- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp\n+++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp\n@@ -427,7 +427,8 @@ Instruction *InstCombinerImpl::commonShiftTransforms(BinaryOperator &I) {\n if (Instruction *R = FoldOpIntoSelect(I, SI))\n return R;\n \n- if (Constant *CUI = dyn_cast(Op1))\n+ Constant *CUI;\n+ if (match(Op1, m_ImmConstant(CUI)))\n if (Instruction *Res = FoldShiftByConstant(Op0, CUI, I))\n return Res;\n \n", "tests": [{"file": "llvm/test/Transforms/InstCombine/shl-twice-constant.ll", "commands": ["opt < %s -passes=instcombine -S"], "tests": [{"test_name": "testfunc", "test_body": "@c = external constant i8\n@c2 = external constant i8\n\ndefine i64 @testfunc() {\n %shl1 = shl i64 1, ptrtoint (ptr @c2 to i64)\n %shl2 = shl i64 %shl1, ptrtoint (ptr @c to i64)\n ret i64 %shl2\n}\n"}]}], "issue": {"title": "[InstCombine] Infinite loop when combining two `shl` instructions", "body": "The following sample triggers an infinite loop in instcombine:\n\n```\n@c = external constant i8\n@c2 = external constant i8\n\ndefine i16 @testfunc() {\nentry:\n %0 = shl i64 1, ptrtoint (ptr @c2 to i64)\n %1 = shl i64 %0, ptrtoint (ptr @c to i64)\n %2 = inttoptr i64 %1 to ptr\n %3 = load i16, ptr %2, align 1\n ret i16 %3\n}\n```\n\nhttps://godbolt.org/z/WP6YvGjPq\n", "author": "momo5502", "labels": ["llvm:instcombine", "llvm:hang"], "comments": [{"author": "momo5502", "body": "I have a potential fix and will create a PR soon"}]}, "verified": true} {"bug_id": "89390", "issue_url": "https://github.com/llvm/llvm-project/issues/89390", "bug_type": "miscompilation", "base_commit": "d674f45d51bffbba474b12e07f7d57a2390d2f31", "knowledge_cutoff": "2024-04-19T14:44:07Z", "lit_test_dir": ["llvm/test/Transforms/VectorCombine"], "hints": {"fix_commit": "4cc9c6d98dfef90d1ffa69977d13ffa2894a10f7", "components": ["VectorCombine"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": [[1405, 1410]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": ["VectorCombine::foldShuffleOfBinops"]}}, "patch": "commit 4cc9c6d98dfef90d1ffa69977d13ffa2894a10f7\nAuthor: Simon Pilgrim \nDate: Mon Apr 22 09:00:20 2024 +0100\n\n [VectorCombine] foldShuffleOfBinops - don't fold shuffle(divrem(x,y),divrem(z,w)) if mask contains poison\n \n Fixes #89390\n\ndiff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp\nindex 4918cee1fa82..f23b10540338 100644\n--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp\n+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp\n@@ -1405,6 +1405,11 @@ bool VectorCombine::foldShuffleOfBinops(Instruction &I) {\n B0->getOpcode() != B1->getOpcode() || B0->getType() != VecTy)\n return false;\n \n+ // Don't introduce poison into div/rem.\n+ if (any_of(Mask, [](int M) { return M == PoisonMaskElem; }) &&\n+ B0->isIntDivRem())\n+ return false;\n+\n // Try to replace a binop with a shuffle if the shuffle is not costly.\n // The new shuffle will choose from a single, common operand, so it may be\n // cheaper than the existing two-operand shuffle.\n", "tests": [{"file": "llvm/test/Transforms/VectorCombine/X86/shuffle-of-binops.ll", "commands": ["opt < %s -passes=vector-combine -S -mtriple=x86_64-- -mattr=SSE2", "opt < %s -passes=vector-combine -S -mtriple=x86_64-- -mattr=AVX2"], "tests": [{"test_name": "shuf_and_v16i16_yy_expensive_shuf", "test_body": "define <16 x i16> @shuf_and_v16i16_yy_expensive_shuf(<16 x i16> %x, <16 x i16> %y, <16 x i16> %z) {\n %b0 = and <16 x i16> %x, %y\n %b1 = and <16 x i16> %y, %z\n %r = shufflevector <16 x i16> %b0, <16 x i16> %b1, <16 x i32> \n ret <16 x i16> %r\n}\n"}, {"test_name": "shuf_srem_v4i32_poison", "test_body": "define <4 x i32> @shuf_srem_v4i32_poison(<4 x i32> %a0, <4 x i32> %a1) {\n %srem0 = srem <4 x i32> %a1, %a0\n %srem1 = srem <4 x i32> splat (i32 1), %a0\n %r = shufflevector <4 x i32> %srem0, <4 x i32> %srem1, <4 x i32> \n ret <4 x i32> %r\n}\n"}]}], "issue": {"title": "VectorCombine transform leading to srem by poison", "body": "https://alive2.llvm.org/ce/z/HRAkAK\r\n\r\nthis:\r\n```llvm\r\ndefine <4 x i32> @f(<4 x i32> %0, <4 x i32> %1) {\r\n %3 = srem <4 x i32> %1, %0\r\n %4 = srem <4 x i32> , %0\r\n %5 = shufflevector <4 x i32> %3, <4 x i32> %4, <4 x i32> \r\n ret <4 x i32> %5\r\n}\r\n```\r\nis getting vector-combined to this:\r\n```llvm\r\ndefine <4 x i32> @f(<4 x i32> %0, <4 x i32> %1) {\r\n %3 = shufflevector <4 x i32> %1, <4 x i32> , <4 x i32> \r\n %4 = shufflevector <4 x i32> %0, <4 x i32> poison, <4 x i32> \r\n %5 = srem <4 x i32> %3, %4\r\n ret <4 x i32> %5\r\n}\r\n```\r\n\r\nbut that poison in lane 1 is now problematic, this gives us full UB when it hits the srem\r\n\r\ncc @nunoplopes @hatsunespica\r\n", "author": "regehr", "labels": ["miscompilation", "vectorizers"], "comments": [{"author": "RKSimon", "body": "I'll take a look at this"}]}, "verified": true} @@ -137,6 +145,7 @@ {"bug_id": "107198", "issue_url": "https://github.com/llvm/llvm-project/issues/107198", "bug_type": "crash", "base_commit": "c2b92a4250b3f514685676ba8985ea73450f14d3", "knowledge_cutoff": "2024-09-04T08:17:58Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "d65ff3e9364536f9e0bd5f1c1bace626c256a2ad", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[7780, 7785]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["BoUpSLP::canMapToVector"]}}, "patch": "commit d65ff3e9364536f9e0bd5f1c1bace626c256a2ad\nAuthor: Alexey Bataev \nDate: Wed Sep 4 05:12:17 2024 -0700\n\n [SLP]Fix PR107198: add a check for empty complex type\n \n Need to check if the complex type is empty before trying to dig in,\n trying to find vectorizable type\n \n Fixes https://github.com/llvm/llvm-project/issues/107198\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex 19b95cf473e9..a2af7f4e1b01 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -7780,6 +7780,8 @@ unsigned BoUpSLP::canMapToVector(Type *T) const {\n Type *EltTy = T;\n \n while (isa(EltTy)) {\n+ if (EltTy->isEmptyTy())\n+ return 0;\n if (auto *ST = dyn_cast(EltTy)) {\n // Check that struct is homogeneous.\n for (const auto *Ty : ST->elements())\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/empty-struct.ll", "commands": ["opt -S --passes=slp-vectorizer < %s"], "tests": [{"test_name": "test", "test_body": "define { { {}, {}, {}, {}, {}, {}, {} } } @test({ {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, { {}, {}, {}, {}, {}, {}, {} }, { {} } } %0) {\n %2 = extractvalue { {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, { {}, {}, {}, {}, {}, {}, {} }, { {} } } %0, 18\n %3 = insertvalue { { {}, {}, {}, {}, {}, {}, {} } } undef, { {}, {}, {}, {}, {}, {}, {} } %2, 0\n ret { { {}, {}, {}, {}, {}, {}, {} } } %3\n}\n"}]}], "issue": {"title": "Crash on slp-vectorizer", "body": "When running `/opt/llvm-19/bin/opt -O3 -S bug.ll` opt crashes with the following:\r\n\r\n(tested on 19 rc2 and rc4 and 18)\r\n```\r\n/opt/llvm-19/bin/llvm-config --version\r\n19.1.0-rc2\r\n\r\n/opt/llvm-19/bin/opt: WARNING: failed to create target machine for 'arm64-apple-darwin23.6.0': unable to get target for 'arm64-apple-darwin23.6.0', see --version and --triple.\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/llvm-19/bin/opt -O3 -S bug.ll\r\n1.\tRunning pass \"function(float2int,lower-constant-intrinsics,chr,loop(loop-rotate,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize,infer-alignment,loop-load-elim,instcombine,simplifycfg,slp-vectorizer,vector-combine,instcombine,loop-unroll,transform-warning,sroa,infer-alignment,instcombine,loop-mssa(licm),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg)\" on module \"lol.ll\"\r\n2.\tRunning pass \"slp-vectorizer\" on function \"bug\"\r\n #0 0x00005558779163f7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/admin/repos/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:13\r\n #1 0x0000555877914570 llvm::sys::RunSignalHandlers() /home/admin/repos/llvm-project/llvm/lib/Support/Signals.cpp:106:18\r\n #2 0x0000555877916d9a SignalHandler(int) /home/admin/repos/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1\r\n #3 0x00007fb7b7e5b050 (/lib/x86_64-linux-gnu/libc.so.6+0x3c050)\r\n #4 0x0000555878d08ae0 llvm::slpvectorizer::BoUpSLP::canMapToVector(llvm::Type*) const /home/admin/repos/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:0:0\r\n #5 0x0000555878d3ca29 llvm::SLPVectorizerPass::vectorizeInsertValueInst(llvm::InsertValueInst*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, bool) /home/admin/repos/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:18336:8\r\n #6 0x0000555878d3d459 llvm::SLPVectorizerPass::vectorizeInserts(llvm::SmallSetVector&, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) /home/admin/repos/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:0:11\r\n #7 0x0000555878d3e35b llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&)::$_172::operator()(bool) const /home/admin/repos/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:18847:20\r\n #8 0x0000555878d34039 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) /home/admin/repos/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:18963:18\r\n #9 0x0000555878d31968 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) /home/admin/repos/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:15865:13\r\n#10 0x0000555878d31431 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager&) /home/admin/repos/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:15796:18\r\n#11 0x0000555878921dfd llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) /home/admin/repos/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:90:5\r\n#12 0x0000555877ab570d llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) /home/admin/repos/llvm-project/llvm/include/llvm/IR/PassManagerImpl.h:85:8\r\n#13 0x00005558785d887d llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) /home/admin/repos/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:90:5\r\n#14 0x0000555877ab94f0 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) /home/admin/repos/llvm-project/llvm/lib/IR/PassManager.cpp:129:23\r\n#15 0x00005558785d86cd llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) /home/admin/repos/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:90:5\r\n#16 0x0000555877ab44ed llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) /home/admin/repos/llvm-project/llvm/include/llvm/IR/PassManagerImpl.h:85:8\r\n#17 0x00005558788ca8c9 llvm::SmallPtrSetImplBase::isSmall() const /home/admin/repos/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:197:33\r\n#18 0x00005558788ca8c9 llvm::SmallPtrSetImplBase::~SmallPtrSetImplBase() /home/admin/repos/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:84:10\r\n#19 0x00005558788ca8c9 llvm::PreservedAnalyses::~PreservedAnalyses() /home/admin/repos/llvm-project/llvm/include/llvm/IR/Analysis.h:111:7\r\n#20 0x00005558788ca8c9 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::ArrayRef>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) /home/admin/repos/llvm-project/llvm/tools/opt/NewPMDriver.cpp:547:3\r\n#21 0x00005558778e5779 optMain /home/admin/repos/llvm-project/llvm/tools/opt/optdriver.cpp:739:12\r\n#22 0x00007fb7b7e4624a (/lib/x86_64-linux-gnu/libc.so.6+0x2724a)\r\n#23 0x00007fb7b7e46305 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x27305)\r\n#24 0x00005558778dfd21 _start (/opt/llvm-19/bin/opt+0xf17d21)\r\nSegmentation fault\r\n```\r\n\r\n```llvmir\r\n; ModuleID = 'LLVMDialectModule'\r\nsource_filename = \"LLVMDialectModule\"\r\ntarget datalayout = \"e-m:o-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"arm64-apple-darwin23.6.0\"\r\n\r\ndefine { { {}, {}, {}, {}, {}, {}, {} } } @\"bug\"({ {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, { {}, {}, {}, {}, {}, {}, {} }, { {} } } %0) {\r\n %2 = extractvalue { {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, { {}, {}, {}, {}, {}, {}, {} }, { {} } } %0, 18\r\n %3 = insertvalue { { {}, {}, {}, {}, {}, {}, {} } } undef, { {}, {}, {}, {}, {}, {}, {} } %2, 0\r\n ret { { {}, {}, {}, {}, {}, {}, {} } } %3\r\n}\r\n\r\n!llvm.module.flags = !{!0}\r\n\r\n!0 = !{i32 2, !\"Debug Info Version\", i32 3}\r\n```", "author": "edg-l", "labels": ["llvm:SLPVectorizer", "crash"], "comments": [{"author": "edg-l", "body": "one question, will this be included in llvm 19?"}, {"author": "alexey-bataev", "body": "Not sure, it is not an immediate regression from 18 to 19, and it is too late, I think, to include it into 19"}]}, "verified": true} {"bug_id": "127534", "issue_url": "https://github.com/llvm/llvm-project/issues/127534", "bug_type": "crash", "base_commit": "6de5d1e46d1812de2bbbbe8d8d2c811e4d16acbe", "knowledge_cutoff": "2025-02-17T18:29:15Z", "lit_test_dir": ["llvm/test/Transforms/LoopSimplifyCFG"], "hints": {"fix_commit": "41437a6067b2f9dc8e7c458ff6417397796be31c", "components": ["LoopSimplifyCFG"], "bug_location_lineno": {"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": [[369, 375]]}, "bug_location_funcname": {"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": ["handleDeadExits"]}}, "patch": "commit 41437a6067b2f9dc8e7c458ff6417397796be31c\nAuthor: Aleksandr Popov <42888396+aleks-tmb@users.noreply.github.com>\nDate: Fri Feb 21 12:26:39 2025 +0100\n\n [LoopSimplifyCFG] Fix SCEV invalidation after removing dead exit (#127536)\n \n Fixes #127534\n\ndiff --git a/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp b/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp\nindex 765b76e54068..4524446e5947 100644\n--- a/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp\n+++ b/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp\n@@ -369,7 +369,7 @@ private:\n DeadInstructions.emplace_back(LandingPad);\n \n for (Instruction *I : DeadInstructions) {\n- SE.forgetBlockAndLoopDispositions(I);\n+ SE.forgetValue(I);\n I->replaceAllUsesWith(PoisonValue::get(I->getType()));\n I->eraseFromParent();\n }\n", "tests": [{"file": "llvm/test/Transforms/LoopSimplifyCFG/pr117537.ll", "commands": ["opt -S -passes='print,loop-mssa(licm,loop-simplifycfg,loop-predication)' -verify-scev < %s"], "tests": [{"test_name": "", "test_body": "\n; Make sure we don't assert due to insufficient SCEV invalidation.\n\ndefine i64 @\"main\"(ptr addrspace(1) %p, i1 %check) {\n;\nentry:\n br label %loop0.pre\n\nloop0.pre:\n br i1 %check, label %exit, label %loop0\n\nloop0:\n %length = load atomic i32, ptr addrspace(1) %p unordered, align 4\n %28 = icmp ugt i32 %length, 1\n br i1 %28, label %loop0.out, label %loop1.preheader\n\nloop0.out:\n %t = add i32 0, 1\n br i1 false, label %loop1.preheader, label %mid\n\nloop1.preheader:\n %length.lcssa = phi i32 [ %length, %loop0.out ], [ %length, %loop0 ]\n %local = phi i32 [ 0, %loop0 ], [ %t, %loop0.out ]\n br label %loop1\n\nloop1:\n %iv1 = phi i32 [ 4, %loop1.preheader ], [ %iv1.next, %loop1.guarded ]\n %82 = icmp ult i32 %iv1, %length.lcssa\n %wc = call i1 @llvm.experimental.widenable.condition()\n %guard.chk = and i1 %82, %wc\n br i1 %guard.chk, label %loop1.guarded, label %deopt-exit\n\nloop1.guarded:\n %iv1.next = add nuw nsw i32 %iv1, 1\n %chk = icmp ugt i32 %iv1, 310\n br i1 %chk, label %loop1.exit, label %loop1\n\ndeopt-exit:\n %100 = call i64 (...) @llvm.experimental.deoptimize.i64(i32 13) [ \"deopt\"() ]\n ret i64 %100\n\nloop1.exit:\n ret i64 0\n\nmid:\n br label %loop0.pre\n\nexit:\n ret i64 0\n}\n\ndeclare i64 @foo()\n\ndeclare i64 @llvm.experimental.deoptimize.i64(...)\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(inaccessiblemem: readwrite)\ndeclare noundef i1 @llvm.experimental.widenable.condition()"}]}], "issue": {"title": "[SCEV] Assertion `isAvailableAtLoopEntry(RHS, L) && \"RHS is not available at Loop Entry\"' failed", "body": "During our local testing, we encountered the assertion failure `isAvailableAtLoopEntry(RHS, L) && \"RHS is not available at Loop Entry\".\n\nReduced reproducer:\n\n```llvm\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\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i64 @\"main\"(ptr addrspace(1) %p, i1 %check) {\nentry:\n br label %loop0.pre\n\nloop0.pre:\n br i1 %check, label %exit, label %loop0\n\nloop0:\n %length = load atomic i32, ptr addrspace(1) %p unordered, align 4\n %28 = icmp ugt i32 %length, 1\n br i1 %28, label %loop0.out, label %loop1.preheader\n\nloop0.out:\n %t = add i32 0, 1\n br i1 false, label %loop1.preheader, label %mid\n\nloop1.preheader:\n %length.lcssa = phi i32 [ %length, %loop0.out ], [ %length, %loop0 ]\n %local = phi i32 [ 0, %loop0 ], [ %t, %loop0.out ]\n br label %loop1\n\nloop1:\n %iv1 = phi i32 [ 4, %loop1.preheader ], [ %iv1.next, %loop1.guarded ]\n %82 = icmp ult i32 %iv1, %length.lcssa\n %wc = call i1 @llvm.experimental.widenable.condition()\n %guard.chk = and i1 %82, %wc\n br i1 %guard.chk, label %loop1.guarded, label %deopt-exit\n\nloop1.guarded:\n %iv1.next = add nuw nsw i32 %iv1, 1\n %chk = icmp ugt i32 %iv1, 310\n br i1 %chk, label %loop1.exit, label %loop1\n\ndeopt-exit:\n %100 = call i64 (...) @llvm.experimental.deoptimize.i64(i32 13) [ \"deopt\"() ]\n ret i64 %100\n\nloop1.exit:\n ret i64 0\n\nmid:\n br label %loop0.pre\n\nexit:\n ret i64 0\n}\n\ndeclare i64 @foo()\n\ndeclare i64 @llvm.experimental.deoptimize.i64(...)\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(inaccessiblemem: readwrite)\ndeclare noundef i1 @llvm.experimental.widenable.condition()\n```\n\n\nSteps to reproduce:\n`$opt -passes='print,loop-mssa(licm,loop-simplifycfg,loop-predication)'`\n\nProof: https://godbolt.org/z/8hsbahTjq\n\nLooks like `LoopSimplifyCFGPass` is guilty - it doesn’t invalidate SCEV when removing a dead exit:\n\n```c++\n void handleDeadExits() {\n...\n for (Instruction *I : DeadInstructions) {\n SE.forgetBlockAndLoopDispositions(I);\n I->replaceAllUsesWith(PoisonValue::get(I->getType()));\n I->eraseFromParent();\n }\n```\n\n", "author": "aleks-tmb", "labels": ["crash", "llvm:transforms"], "comments": [{"author": "aleks-tmb", "body": "The `LoopSimplifyCFG` pass removes `%length.lcssa.ph`, but later, in the `LoopPredication` pass, we encounter an assertion failure for the `%length.lcssa` SCEV, which remains equal to `%length`\n\n\"Image\"\n\n![Image](https://github.com/user-attachments/assets/49481d3d-102c-42e1-8836-5c970461993d)"}, {"author": "aleks-tmb", "body": "It seems the reason why forgetBlockAndLoopDispositions doesn't cover this case is that `%length.lcssa.ph` doesn't have an existing SCEV, since the instruction was just added by the previous LICM pass."}, {"author": "nikic", "body": "There is some pretty tricky interaction between LCSSA formation and SCEV invalidation, see:\nhttps://github.com/llvm/llvm-project/blob/7f69a399df384c86428d0c97e3afbc8146324226/llvm/lib/Transforms/Utils/LCSSA.cpp#L206-L211\n\nBasically, when forming LCSSA form, we take care not to break the invalidation chain, so that invalidation of the LCSSA phi node is sufficient.\n\nI think the LICM predecessor splitting effectively does manual LCSSA formation and doesn't maintain this special logic.\n\nI think the extra forgetValue() call works around this issue and variants of this might appear elsewhere. But TBH I'm not totally sure."}]}, "verified": true} {"bug_id": "80954", "issue_url": "https://github.com/llvm/llvm-project/issues/80954", "bug_type": "crash", "base_commit": "e60c4b61f8bab25a137a481e4d2d3dbfa656807b", "knowledge_cutoff": "2024-02-07T08:19:15Z", "lit_test_dir": ["llvm/test/Transforms/LoopIdiom"], "hints": {"fix_commit": "bec7181d5b9d1828129d78d440fd9e02d5cb63e8", "components": ["ScalarEvolution"], "bug_location_lineno": {"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": [[795, 801]]}, "bug_location_funcname": {"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": ["SCEVExpander::expandIVInc"]}}, "patch": "commit bec7181d5b9d1828129d78d440fd9e02d5cb63e8\nAuthor: Nikita Popov \nDate: Wed Feb 7 11:06:51 2024 +0100\n\n [SCEVExpander] Don't use recursive expansion for ptr IV inc\n \n Similar to the non-ptr case, directly create the getelementptr\n instruction. Going through expandAddToGEP() no longer makes sense\n with opaque pointers, where generating the necessary instruction\n is trivial.\n \n This avoids recursive expansion of (the SCEV of) StepV while the\n IR is in an inconsistent state, in particular with an incomplete\n IV phi node, which utilities may not be prepared to deal with.\n \n Fixes https://github.com/llvm/llvm-project/issues/80954.\n\ndiff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp\nindex 58dbac0e85fb..3a28909473d9 100644\n--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp\n+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp\n@@ -795,7 +795,8 @@ Value *SCEVExpander::expandIVInc(PHINode *PN, Value *StepV, const Loop *L,\n Value *IncV;\n // If the PHI is a pointer, use a GEP, otherwise use an add or sub.\n if (PN->getType()->isPointerTy()) {\n- IncV = expandAddToGEP(SE.getSCEV(StepV), PN);\n+ // TODO: Change name to IVName.iv.next.\n+ IncV = Builder.CreatePtrAdd(PN, StepV, \"scevgep\");\n } else {\n IncV = useSubtract ?\n Builder.CreateSub(PN, StepV, Twine(IVName) + \".iv.next\") :\n", "tests": [{"file": "llvm/test/Transforms/LoopIdiom/pr80954.ll", "commands": ["opt -S -passes=loop-idiom < %s"], "tests": [{"test_name": "test", "test_body": "define void @test(ptr %p, i8 %arg, i64 %arg1, i32 %arg2) {\nentry:\n %sext = sext i8 %arg to i64\n %add = add i64 %arg1, -1\n br label %loop\n\nloop: ; preds = %latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %latch ]\n %phi = phi i32 [ %arg2, %entry ], [ %add9, %latch ]\n br label %loop2\n\nloop2: ; preds = %loop2, %loop\n %iv2 = phi i64 [ %iv2.next, %loop2 ], [ 0, %loop ]\n %gep = getelementptr [4 x i8], ptr %p, i64 %iv, i64 %iv2\n store i8 0, ptr %gep, align 1\n %iv2.next = add i64 %iv2, 1\n %icmp = icmp eq i64 %iv2.next, 0\n br i1 %icmp, label %latch, label %loop2\n\nlatch: ; preds = %loop2\n %add9 = add nsw i32 %phi, 1\n %sext10 = sext i32 %phi to i64\n %add11 = add i64 %add, %sext10\n %add12 = add i64 %add11, %sext\n %iv.next = add i64 %add12, %iv\n br label %loop\n}\n"}]}], "issue": {"title": "llvm crash: Assertion `Idx >= 0 && \"Invalid basic block argument!\"' failed.", "body": "llvm crashes in `loop-idiom` pass.\r\n\r\nBisected to 1c6e6432ca0b6832e06b93a4bcf22ead1899c14d, which was committed by @nikic \r\n\r\nCompiler explorer: https://godbolt.org/z/nxhnoE1Mb\r\n\r\n**% cat reduced.ll**\r\n```llvm\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine void @m(i8 %0, i64 %1, i32 %a.promoted) {\r\nentry:\r\n %conv13 = sext i8 %0 to i64\r\n %add14 = add i64 %1, -1\r\n br label %for.cond5thread-pre-split.lr.ph.split.us.us\r\n\r\nfor.cond5thread-pre-split.lr.ph.split.us.us: ; preds = %for.cond2.loopexit.us.us, %entry\r\n %inc.i1417.us = phi i32 [ %a.promoted, %entry ], [ %inc.i.us20, %for.cond2.loopexit.us.us ]\r\n %add161516.us = phi i64 [ 0, %entry ], [ %add16.us24, %for.cond2.loopexit.us.us ]\r\n br label %for.body7.us.us\r\n\r\nfor.body7.us.us: ; preds = %for.body7.us.us, %for.cond5thread-pre-split.lr.ph.split.us.us\r\n %2 = phi i64 [ %add9.us.us, %for.body7.us.us ], [ 0, %for.cond5thread-pre-split.lr.ph.split.us.us ]\r\n %arrayidx8.us.us = getelementptr [1 x [5 x i8]], ptr null, i64 0, i64 %add161516.us, i64 %2\r\n store i8 0, ptr %arrayidx8.us.us, align 1\r\n %add9.us.us = add i64 %2, 1\r\n %tobool6.not.us.us = icmp eq i64 %add9.us.us, 0\r\n br i1 %tobool6.not.us.us, label %for.cond2.loopexit.us.us, label %for.body7.us.us\r\n\r\nfor.cond2.loopexit.us.us: ; preds = %for.body7.us.us\r\n %inc.i.us20 = add nsw i32 %inc.i1417.us, 1\r\n %conv.i.us21 = sext i32 %inc.i1417.us to i64\r\n %add15.us22 = add i64 %add14, %conv.i.us21\r\n %sub.us23 = add i64 %add15.us22, %conv13\r\n %add16.us24 = add i64 %sub.us23, %add161516.us\r\n br label %for.cond5thread-pre-split.lr.ph.split.us.us\r\n}\r\n```\r\n\r\n**% opt -disable-output -passes=loop-idiom reduced.ll**\r\n```console\r\nopt: /tmp/tmpxmdtc3mt/tmpn8inmjh2/llvm/include/llvm/IR/Instructions.h:2910: llvm::Value* llvm::PHINode::getIncomingValueForBlock(const llvm::BasicBlock*) const: Assertion `Idx >= 0 && \"Invalid basic block argument!\"' 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: /zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/opt -disable-output -passes=loop-idiom reduced.ll\r\n #0 0x00007fc24b876eaf llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x914eaf)\r\n #1 0x00007fc24b874414 SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007fc24ab77090 (/lib/x86_64-linux-gnu/libc.so.6+0x43090)\r\n #3 0x00007fc24ab7700b raise /build/glibc-wuryBv/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\r\n #4 0x00007fc24ab56859 abort /build/glibc-wuryBv/glibc-2.31/stdlib/abort.c:81:7\r\n #5 0x00007fc24ab56729 get_sysdep_segment_value /build/glibc-wuryBv/glibc-2.31/intl/loadmsgcat.c:509:8\r\n #6 0x00007fc24ab56729 _nl_load_domain /build/glibc-wuryBv/glibc-2.31/intl/loadmsgcat.c:970:34\r\n #7 0x00007fc24ab67fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\r\n #8 0x00007fc24d68155f llvm::Loop::getCanonicalInductionVariable() const (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x271f55f)\r\n #9 0x00007fc24ca39df5 llvm::SCEVExpander::visitAddRecExpr(llvm::SCEVAddRecExpr const*) (.part.0) ScalarEvolutionExpander.cpp:0:0\r\n#10 0x00007fc24ca36745 llvm::SCEVVisitor::visit(llvm::SCEV const*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1ad4745)\r\n#11 0x00007fc24ca3711b llvm::SCEVExpander::expand(llvm::SCEV const*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1ad511b)\r\n#12 0x00007fc24ca37380 llvm::SCEVExpander::expandCodeForImpl(llvm::SCEV const*, llvm::Type*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1ad5380)\r\n#13 0x00007fc24ca399ec llvm::SCEVExpander::expandAddToGEP(llvm::SCEV const*, llvm::Type*, llvm::Value*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1ad79ec)\r\n#14 0x00007fc24ca3ab97 llvm::SCEVExpander::expandIVInc(llvm::PHINode*, llvm::Value*, llvm::Loop const*, llvm::Type*, llvm::Type*, bool) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1ad8b97)\r\n#15 0x00007fc24ca3bb6e llvm::SCEVExpander::getAddRecExprPHILiterally(llvm::SCEVAddRecExpr const*, llvm::Loop const*, llvm::Type*, llvm::Type*, llvm::Type*&, bool&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1ad9b6e)\r\n#16 0x00007fc24ca3c5d4 llvm::SCEVExpander::expandAddRecExprLiterally(llvm::SCEVAddRecExpr const*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1ada5d4)\r\n#17 0x00007fc24ca36745 llvm::SCEVVisitor::visit(llvm::SCEV const*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1ad4745)\r\n#18 0x00007fc24ca3711b llvm::SCEVExpander::expand(llvm::SCEV const*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1ad511b)\r\n#19 0x00007fc24ca37380 llvm::SCEVExpander::expandCodeForImpl(llvm::SCEV const*, llvm::Type*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1ad5380)\r\n#20 0x00007fc24ce4bc8c (anonymous namespace)::LoopIdiomRecognize::processLoopStridedStore(llvm::Value*, llvm::SCEV const*, llvm::MaybeAlign, llvm::Value*, llvm::Instruction*, llvm::SmallPtrSetImpl&, llvm::SCEVAddRecExpr const*, llvm::SCEV const*, bool, bool) LoopIdiomRecognize.cpp:0:0\r\n#21 0x00007fc24ce539b7 (anonymous namespace)::LoopIdiomRecognize::processLoopStores(llvm::SmallVectorImpl&, llvm::SCEV const*, (anonymous namespace)::LoopIdiomRecognize::ForMemset) LoopIdiomRecognize.cpp:0:0\r\n#22 0x00007fc24ce5494c (anonymous namespace)::LoopIdiomRecognize::runOnCountableLoop() LoopIdiomRecognize.cpp:0:0\r\n#23 0x00007fc24ce561fd llvm::LoopIdiomRecognizePass::run(llvm::Loop&, llvm::AnalysisManager&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1ef41fd)\r\n#24 0x00007fc24e6ee6c6 llvm::detail::PassModel, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x378c6c6)\r\n#25 0x00007fc24ce7544f std::optional llvm::PassManager, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::runSinglePass, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>, std::default_delete, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>>>>(llvm::Loop&, std::unique_ptr, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>, std::default_delete, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>>>&, llvm::AnalysisManager&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&, llvm::PassInstrumentation&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1f1344f)\r\n#26 0x00007fc24ce756f6 llvm::PassManager, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::runWithoutLoopNestPasses(llvm::Loop&, llvm::AnalysisManager&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1f136f6)\r\n#27 0x00007fc24ce76b0d llvm::PassManager, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1f14b0d)\r\n#28 0x00007fc24ce77d62 llvm::FunctionToLoopPassAdaptor::run(llvm::Function&, llvm::AnalysisManager&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1f15d62)\r\n#29 0x00007fc24e6eb0c6 llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x37890c6)\r\n#30 0x00007fc24ba8a40d llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0xb2840d)\r\n#31 0x00007fc24e6e41a6 llvm::detail::PassModel>, llvm::PreservedAnalyses, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x37821a6)\r\n#32 0x00007fc24ba88c9d llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0xb26c9d)\r\n#33 0x00007fc24e6eb026 llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x3789026)\r\n#34 0x00007fc24ba86c1d llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0xb24c1d)\r\n#35 0x000055608ac0cc95 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/opt+0x25c95)\r\n#36 0x000055608ac00876 main (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/opt+0x19876)\r\n#37 0x00007fc24ab58083 __libc_start_main /build/glibc-wuryBv/glibc-2.31/csu/../csu/libc-start.c:342:3\r\n#38 0x000055608ac0151e _start (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/opt+0x1a51e)\r\n[1] 1629345 abort -disable-output -passes=loop-idiom reduced.ll\r\n```\r\n\r\nThe IR is reduced from the following C code:\r\n```C\r\nint a, b;\r\nlong d, h, j;\r\nshort e;\r\nchar f;\r\nstatic char *g = &f;\r\nstatic long *i = &d;\r\nchar k[1][5];\r\nlong l() {\r\n long c = a++;\r\n return c;\r\n}\r\nvoid m() {\r\n for (; b;)\r\n for (;; j = l() + *g + *i - 1 + j) {\r\n e = 0;\r\n for (; *i + e; e = 1)\r\n for (; h; h = h + 1)\r\n k[j][h] = 4;\r\n }\r\n}\r\nint main() {}\r\n```", "author": "shao-hua-li", "labels": ["llvm:crash", "llvm:SCEV"], "comments": []}, "verified": true} +{"bug_id": "124759", "issue_url": "https://github.com/llvm/llvm-project/issues/124759", "bug_type": "crash", "base_commit": "b923f6cf8faca82b8df2a936d8ff36a6125aedcc", "knowledge_cutoff": "2025-01-28T14:48:43Z", "lit_test_dir": ["llvm/test/Analysis/LoopAccessAnalysis"], "hints": {"fix_commit": "275baedfde9dcd344bc4f11f552b046a69a4bf3f", "components": ["LoopAccessAnalysis"], "bug_location_lineno": {"llvm/lib/Analysis/LoopAccessAnalysis.cpp": [[1362, 1369], [1443, 1450]]}, "bug_location_funcname": {"llvm/lib/Analysis/LoopAccessAnalysis.cpp": ["AccessAnalysis::processMemAccesses"]}}, "patch": "commit 275baedfde9dcd344bc4f11f552b046a69a4bf3f\nAuthor: Florian Hahn \nDate: Fri Feb 28 20:56:12 2025 +0000\n\n [LAA] Consider accessed addrspace when mapping underlying obj to access. (#129087)\n \n In some cases, it is possible for the same underlying object to be\n accessed via pointers to different address spaces. This could lead to\n pointers from different address spaces ending up in the same dependency\n set, which isn't allowed (and triggers an assertion).\n \n Update the mapping from underlying object -> last access to also include\n the accessing address space.\n \n Fixes https://github.com/llvm/llvm-project/issues/124759.\n \n PR: https://github.com/llvm/llvm-project/pull/129087\n\ndiff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp\nindex cf3bb6a8eae1..38ee82b77a94 100644\n--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp\n+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp\n@@ -1362,8 +1362,10 @@ void AccessAnalysis::processMemAccesses() {\n \n bool SetHasWrite = false;\n \n- // Map of pointers to last access encountered.\n- typedef DenseMap UnderlyingObjToAccessMap;\n+ // Map of (pointer to underlying objects, accessed address space) to last\n+ // access encountered.\n+ typedef DenseMap, MemAccessInfo>\n+ UnderlyingObjToAccessMap;\n UnderlyingObjToAccessMap ObjToLastAccess;\n \n // Set of access to check after all writes have been processed.\n@@ -1443,8 +1445,10 @@ void AccessAnalysis::processMemAccesses() {\n UnderlyingObj->getType()->getPointerAddressSpace()))\n continue;\n \n- auto [It, Inserted] =\n- ObjToLastAccess.try_emplace(UnderlyingObj, Access);\n+ auto [It, Inserted] = ObjToLastAccess.try_emplace(\n+ {UnderlyingObj,\n+ cast(Ptr->getType())->getAddressSpace()},\n+ Access);\n if (!Inserted) {\n DepCands.unionSets(Access, It->second);\n It->second = Access;\n", "tests": [{"file": "llvm/test/Analysis/LoopAccessAnalysis/underlying-object-different-address-spaces.ll", "commands": ["opt -passes='print' -disable-output %s 2>&1"], "tests": [{"test_name": "", "test_body": "\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\"\n\n; Test case for https://github.com/llvm/llvm-project/issues/124759. The same\n; underlying object is access through pointers with different address spaces.\ndefine void @same_underlying_object_different_address_spaces(ptr %dst1.as1, ptr %dst2.as1) {\n;\nentry:\n %alloc = alloca i8, i64 0, align 128\n %as3 = addrspacecast ptr %alloc to ptr addrspace(3)\n %as4 = addrspacecast ptr %alloc to ptr addrspace(4)\n br label %loop\n\nloop:\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n store i32 0, ptr addrspace(4) %as4, align 4\n store i32 0, ptr %dst1.as1, align 4\n %l = load i64, ptr addrspace(3) %as3, align 4\n store i64 %l, ptr %dst2.as1, align 4\n %iv.next = add i64 %iv, 1\n %c = icmp eq i64 %iv.next, 100\n br i1 %c, label %loop, label %exit\n\nexit:\n ret void\n}"}]}], "issue": {"title": "LoopVectorizer `assert(AddressSpace == AS && with addrspacecast` is hit", "body": "The following code produces an assert in RuntimeCheckingPtrGroup::addPointer()\n\n\n``` llvm\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-unknown-elf\"\n\ndefine void @__mux_host_0(ptr addrspace(1) %_arg_resultPtr, ptr addrspace(1) %add.ptr.i.sroa_idx.i.i.i.i) {\nloopIR.i.preheader:\n %0 = alloca i8, i64 0, align 128\n %_arg_localAccessor = addrspacecast ptr %0 to ptr addrspace(3)\n %arrayidx.ascast.i.i.i.i.i.i = addrspacecast ptr %0 to ptr addrspace(4)\n br label %loopIR2.i\n\nloopIR2.i: ; preds = %loopIR2.i, %loopIR.i.preheader\n %1 = phi i64 [ 0, %loopIR.i.preheader ], [ %3, %loopIR2.i ]\n store i32 0, ptr addrspace(4) %arrayidx.ascast.i.i.i.i.i.i, align 4\n store float 0.000000e+00, ptr addrspace(1) %add.ptr.i.sroa_idx.i.i.i.i, align 4\n %2 = load i64, ptr addrspace(3) %_arg_localAccessor, align 4\n store i64 0, ptr addrspace(1) %_arg_resultPtr, align 4\n %3 = add i64 %1, 1\n br i1 false, label %loopIR2.i, label %exitIR.i\n\nexitIR.i: ; preds = %loopIR2.i\n ret void\n}\n```\n\nThis crashes with `opt --passes loop-vectorize /tmp/reduced.ll -S -o -` as follows:\n\n```\n./bin/opt --passes loop-vectorize /tmp/reduced.ll -S -o -\nopt: /home/colin/llvm-project/llvm/lib/Analysis/LoopAccessAnalysis.cpp:423: bool llvm::RuntimeCheckingPtrGroup::addPointer(unsigned int, const llvm::SCEV*, const llvm::SCEV*, unsigned int, bool, llvm::ScalarEvolution&): Assertion `AddressSpace == AS && \"all pointers in a checking group must be in the same address space\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\nStack dump:\n0. Program arguments: ./bin/opt --passes loop-vectorize /tmp/reduced.ll -S -o -\n1. Running pass \"function(loop-vectorize)\" on module \"/tmp/reduced.ll\"\n2. Running pass \"loop-vectorize\" on function \"__mux_host_0\"\n #0 0x00005a58a99c2ddc llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/colin/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:22\n #1 0x00005a58a99c31fd PrintStackTraceSignalHandler(void*) /home/colin/llvm-project/llvm/lib/Support/Unix/Signals.inc:874:1\n #2 0x00005a58a99c0663 llvm::sys::RunSignalHandlers() /home/colin/llvm-project/llvm/lib/Support/Signals.cpp:105:20\n #3 0x00005a58a99c2674 SignalHandler(int) /home/colin/llvm-project/llvm/lib/Support/Unix/Signals.inc:415:1\n #4 0x00007c96b3242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #5 0x00007c96b32969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\n #6 0x00007c96b32969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\n #7 0x00007c96b32969fc pthread_kill ./nptl/pthread_kill.c:89:10\n #8 0x00007c96b3242476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\n #9 0x00007c96b32287f3 abort ./stdlib/abort.c:81:7\n#10 0x00007c96b322871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\n#11 0x00007c96b3239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n#12 0x00005a58a8936a8b llvm::RuntimeCheckingPtrGroup::addPointer(unsigned int, llvm::SCEV const*, llvm::SCEV const*, unsigned int, bool, llvm::ScalarEvolution&) /home/colin/llvm-project/llvm/lib/Analysis/LoopAccessAnalysis.cpp:429:37\n#13 0x00005a58a8936a20 llvm::RuntimeCheckingPtrGroup::addPointer(unsigned int, llvm::RuntimePointerChecking const&) /home/colin/llvm-project/llvm/lib/Analysis/LoopAccessAnalysis.cpp:413:20\n#14 0x00005a58a8936f8d llvm::RuntimePointerChecking::groupChecks(llvm::EquivalenceClasses, llvm::PointerIntPairInfo>>, std::less, llvm::PointerIntPairInfo>>>>&, bool) /home/colin/llvm-project/llvm/lib/Analysis/LoopAccessAnalysis.cpp:554:11\n#15 0x00005a58a893678d llvm::RuntimePointerChecking::generateChecks(llvm::EquivalenceClasses, llvm::PointerIntPairInfo>>, std::less, llvm::PointerIntPairInfo>>>>&, bool) /home/colin/llvm-project/llvm/lib/Analysis/LoopAccessAnalysis.cpp:389:26\n#16 0x00005a58a893a016 (anonymous namespace)::AccessAnalysis::canCheckPtrAtRT(llvm::RuntimePointerChecking&, llvm::ScalarEvolution*, llvm::Loop*, llvm::DenseMap, llvm::detail::DenseMapPair> const&, llvm::Value*&, bool) /home/colin/llvm-project/llvm/lib/Analysis/LoopAccessAnalysis.cpp:1243:3\n#17 0x00005a58a8940750 llvm::LoopAccessInfo::analyzeLoop(llvm::AAResults*, llvm::LoopInfo const*, llvm::TargetLibraryInfo const*, llvm::DominatorTree*) /home/colin/llvm-project/llvm/lib/Analysis/LoopAccessAnalysis.cpp:2638:31\n#18 0x00005a58a89422b3 llvm::LoopAccessInfo::LoopAccessInfo(llvm::Loop*, llvm::ScalarEvolution*, llvm::TargetTransformInfo const*, llvm::TargetLibraryInfo const*, llvm::AAResults*, llvm::DominatorTree*, llvm::LoopInfo*) /home/colin/llvm-project/llvm/lib/Analysis/LoopAccessAnalysis.cpp:3028:15\n#19 0x00005a58a894ae40 std::_MakeUniq::__single_object std::make_unique(llvm::Loop*&&, llvm::ScalarEvolution*&&, llvm::TargetTransformInfo*&, llvm::TargetLibraryInfo const*&, llvm::AAResults*&&, llvm::DominatorTree*&&, llvm::LoopInfo*&&) /usr/include/c++/11/bits/unique_ptr.h:962:30\n#20 0x00005a58a8942883 llvm::LoopAccessInfoManager::getInfo(llvm::Loop&) /home/colin/llvm-project/llvm/lib/Analysis/LoopAccessAnalysis.cpp:3084:41\n#21 0x00005a58a831900e llvm::LoopVectorizationLegality::canVectorizeMemory() /home/colin/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp:1208:7\n#22 0x00005a58a831bc45 llvm::LoopVectorizationLegality::canVectorize(bool) /home/colin/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp:1840:7\n#23 0x00005a58a800b8b5 llvm::LoopVectorizePass::processLoop(llvm::Loop*) /home/colin/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10349:7\n#24 0x00005a58a800dde6 llvm::LoopVectorizePass::runImpl(llvm::Function&) /home/colin/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10779:27\n#25 0x00005a58a800e133 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager&) /home/colin/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10816:39\n#26 0x00005a58a65ef71b llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) /home/colin/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:92:3\n#27 0x00005a58a96e6133 llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) /home/colin/llvm-project/llvm/include/llvm/IR/PassManagerImpl.h:85:18\n#28 0x00005a58a4a21a65 llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) /home/colin/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:92:3\n#29 0x00005a58a96e513e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) /home/colin/llvm-project/llvm/lib/IR/PassManager.cpp:129:23\n#30 0x00005a58a4a21995 llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) /home/colin/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:92:3\n#31 0x00005a58a96e5d5f llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) /home/colin/llvm-project/llvm/include/llvm/IR/PassManagerImpl.h:85:18\n#32 0x00005a58a476e632 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::ArrayRef>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) /home/colin/llvm-project/llvm/tools/opt/NewPMDriver.cpp:541:10\n#33 0x00005a58a473c69f optMain /home/colin/llvm-project/llvm/tools/opt/optdriver.cpp:739:27\n#34 0x00005a58a4739e81 main /home/colin/llvm-project/llvm/tools/opt/opt.cpp:25:64\n#35 0x00007c96b3229d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\n#36 0x00007c96b3229e40 call_init ./csu/../csu/libc-start.c:128:20\n#37 0x00007c96b3229e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\n#38 0x00005a58a4739d65 _start (./bin/opt+0xb93d65)\n```\n\nI've done some debugging and in `RuntimeCheckingPtrGroup::addPointer()` II can see the first two elements if RTCheck have the same dependency set but different address spaces.\n\nI did try removing the dependency set being equal continuing the loop here https://github.com/llvm/llvm-project/blob/main/llvm/lib/Analysis/LoopAccessAnalysis.cpp#L1219\n\n``` cpp\n // Only need to check pointers between two different dependency sets.\n if (RtCheck.Pointers[i].DependencySetId ==\n RtCheck.Pointers[j].DependencySetId)\n continue;\n```\nThis does seem to fix the issue but I was wary on whether this was just another symptom rather than the proper fix.\n", "author": "coldav", "labels": ["release:backport", "release:cherry-pick-failed", "crash", "llvm:analysis"], "comments": [{"author": "coldav", "body": "Since nobody is looking at this, and it shows up as an assert for this, I'll try upstreaming my fix."}, {"author": "fhahn", "body": "@coldav sorry I missed this one. I think skipping the check you mentioned is probably not the right fix. I am looking into avoiding grouping pointers with different address spaces in the same dependency set.\n\nI am not super familiar with address space semantics, I am not sure if it is valid to access the same object with pointers to different address spaces?"}, {"author": "hvdijk", "body": "> I am not super familiar with address space semantics, I am not sure if it is valid to access the same object with pointers to different address spaces?\n\nIt depends on the address spaces. Address spaces may or may not overlap. If they do not overlap, then LLVM can assume that an object accessed from one address space and an object accessed from another do not alias. If the address spaces do overlap, however, that assumption is not valid. For the X86 target, address spaces 1-255 are reserved for user-defined code (https://llvm.org/docs/CodeGenerator.html#x86-address-spaces-supported) and interpreted for codegen purposes as aliases for address space zero, meaning all these address spaces overlap exactly."}, {"author": "fhahn", "body": "Put up https://github.com/llvm/llvm-project/pull/129087 to avoid adding pointers from different addrspaces in the same dependency set"}, {"author": "coldav", "body": "Thanks @fhahn "}, {"author": "fhahn", "body": "Manual PR to pick https://github.com/llvm/llvm-project/pull/129317"}]}, "verified": true} {"bug_id": "79742", "issue_url": "https://github.com/llvm/llvm-project/issues/79742", "bug_type": "crash", "base_commit": "a9689c6029e3078e09e43a4efb2b2ced98e9020f", "knowledge_cutoff": "2024-01-28T09:40:40Z", "lit_test_dir": ["llvm/test/Transforms/LoopVectorize"], "hints": {"fix_commit": "17fb3e82f6c950267bb01cc2fd2a84b0d9e9d0d8", "components": ["LoopVectorize"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": [[1031, 1037], [1040, 1047]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": ["VPlanTransforms::truncateToMinimalBitwidths"]}}, "patch": "commit 17fb3e82f6c950267bb01cc2fd2a84b0d9e9d0d8\nAuthor: Florian Hahn \nDate: Tue Apr 23 11:50:25 2024 +0100\n\n [VPlan] Skip extending ICmp results in trunateToMinimalBitwidth.\n \n Results of icmp don't need extending after truncating their operands, as\n the result will always be i1. Skip them during extending.\n \n Fixes https://github.com/llvm/llvm-project/issues/79742\n Fixes https://github.com/llvm/llvm-project/issues/85185\n\ndiff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp\nindex 007dc3f89b3f..9580dc4a27f6 100644\n--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp\n+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp\n@@ -1031,7 +1031,9 @@ void VPlanTransforms::truncateToMinimalBitwidths(\n if (auto *VPW = dyn_cast(&R))\n VPW->dropPoisonGeneratingFlags();\n \n- if (OldResSizeInBits != NewResSizeInBits) {\n+ using namespace llvm::VPlanPatternMatch;\n+ if (OldResSizeInBits != NewResSizeInBits &&\n+ !match(&R, m_Binary(m_VPValue(), m_VPValue()))) {\n // Extend result to original width.\n auto *Ext =\n new VPWidenCastRecipe(Instruction::ZExt, ResultVPV, OldResTy);\n@@ -1040,8 +1042,9 @@ void VPlanTransforms::truncateToMinimalBitwidths(\n Ext->setOperand(0, ResultVPV);\n assert(OldResSizeInBits > NewResSizeInBits && \"Nothing to shrink?\");\n } else\n- assert(cast(&R)->getOpcode() == Instruction::ICmp &&\n- \"Only ICmps should not need extending the result.\");\n+ assert(\n+ match(&R, m_Binary(m_VPValue(), m_VPValue())) &&\n+ \"Only ICmps should not need extending the result.\");\n \n assert(!isa(&R) && \"stores cannot be narrowed\");\n if (isa(&R))\n", "tests": [{"file": "llvm/test/Transforms/LoopVectorize/trunc-extended-icmps.ll", "commands": ["opt -p loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S %s"], "tests": [{"test_name": "test_icmp_and_op_zext", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine i32 @test_icmp_and_op_zext(ptr %dst, i64 %a) {\nentry:\n %and = and i64 %a, 7304878031173690989\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i16 [ 1, %entry ], [ %iv.next, %loop ]\n %c = icmp ne i64 %and, 0\n %c.ext = zext i1 %c to i64\n %or = or i64 %and, %c.ext\n %or.trunc = trunc i64 %or to i8\n %gep = getelementptr i8, ptr %dst, i16 %iv\n store i8 %or.trunc, ptr %gep, align 1\n %iv.next = add i16 %iv, 1\n %ec = icmp eq i16 %iv.next, 1000\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i32 0\n}\n"}, {"test_name": "ext_cmp", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine void @ext_cmp(ptr %src.1, ptr %src.2, ptr noalias %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep.src.1 = getelementptr inbounds i16, ptr %src.1, i64 %iv\n %i2 = load i16, ptr %gep.src.1, align 2\n %i3 = sext i16 %i2 to i32\n %c.1 = icmp sgt i32 0, %i3\n %gep.src.2 = getelementptr inbounds i8, ptr %src.2, i64 %iv\n %i4 = load i8, ptr %gep.src.2, align 2\n %i5 = zext i8 %i4 to i32\n %i6 = select i1 %c.1, i32 0, i32 %i5\n %i7 = and i32 %i6, 0\n %i8 = trunc nuw nsw i32 %i7 to i16\n %gep.dst = getelementptr inbounds i16, ptr %dst, i64 %iv\n store i16 %i8, ptr %gep.dst, align 2\n %iv.next = add nsw i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 1000\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n"}, {"test_name": "test_icmp_constant_op_zext", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine i32 @test_icmp_constant_op_zext(ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i16 [ 1, %entry ], [ %iv.next, %loop ]\n %c = icmp ne i64 7304878031173690989, 0\n %c.ext = zext i1 %c to i64\n %or = or i64 7304878031173690989, %c.ext\n %or.trunc = trunc i64 %or to i8\n %gep = getelementptr i8, ptr %dst, i16 %iv\n store i8 %or.trunc, ptr %gep, align 1\n %iv.next = add i16 %iv, 1\n %ec = icmp eq i16 %iv.next, 1000\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i32 0\n}\n"}]}], "issue": {"title": "llvm crash on loop-vectorize: Assertion `OldResSizeInBits > NewResSizeInBits && \"Nothing to shrink?\"' failed.", "body": "llvm crashes on the following IR.\r\n\r\nBisected to 822c749aec69ace75bd3923a4c850e2fd2e34fb1, which was committed by @fhahn \r\n\r\nCompiler explorer: https://godbolt.org/z/rWj9dhvPo\r\n\r\n```llvm\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine void @i(i64 %0) {\r\nentry:\r\n %conv = sext i16 1 to i32\r\n br label %for.body\r\n\r\nfor.body: ; preds = %for.body, %entry\r\n %1 = phi i32 [ 0, %entry ], [ %inc, %for.body ]\r\n %tobool.not.i = icmp eq i64 %0, 0\r\n %..i = select i1 %tobool.not.i, i32 0, i32 0\r\n %cmp = icmp eq i32 %..i, 0\r\n %conv1 = zext i1 %tobool.not.i to i32\r\n %or = or i32 %conv1, %conv\r\n %cmp2 = icmp slt i32 %or, 7\r\n %conv4 = zext i1 %cmp2 to i64\r\n store i64 %conv4, ptr null, align 8\r\n %inc = add i32 %1, 1\r\n %tobool.not = icmp eq i32 %inc, 0\r\n br i1 %tobool.not, label %for.cond.for.end_crit_edge, label %for.body\r\n\r\nfor.cond.for.end_crit_edge: ; preds = %for.body\r\n ret void\r\n}\r\n```\r\n\r\n```console\r\n% opt -passes=loop-vectorize reduced.ll\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: /zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/opt -disable-output -passes=loop-vectorize reduced.ll\r\n #0 0x00007f5302fedeff llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/../lib/libLLVM-18git.so+0x902eff)\r\n #1 0x00007f5302feb654 SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007f5302300090 (/lib/x86_64-linux-gnu/libc.so.6+0x43090)\r\n #3 0x00007f5304a458f0 llvm::InnerLoopVectorizer::truncateToMinimalBitwidths(llvm::VPTransformState&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/../lib/libLLVM-18git.so+0x235a8f0)\r\n #4 0x00007f5304a49d95 llvm::InnerLoopVectorizer::fixVectorizedLoop(llvm::VPTransformState&, llvm::VPlan&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/../lib/libLLVM-18git.so+0x235ed95)\r\n #5 0x00007f5304a4abb1 llvm::LoopVectorizationPlanner::executePlan(llvm::ElementCount, unsigned int, llvm::VPlan&, llvm::InnerLoopVectorizer&, llvm::DominatorTree*, bool, llvm::DenseMap, llvm::detail::DenseMapPair>*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/../lib/libLLVM-18git.so+0x235fbb1)\r\n #6 0x00007f5304a4d564 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/../lib/libLLVM-18git.so+0x2362564)\r\n #7 0x00007f5304a4fbdd 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*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/../lib/libLLVM-18git.so+0x2364bdd)\r\n #8 0x00007f5304a50e20 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/../lib/libLLVM-18git.so+0x2365e20)\r\n #9 0x00007f5305e0d916 llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/../lib/libLLVM-18git.so+0x3722916)\r\n#10 0x00007f53031fd3fd llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/../lib/libLLVM-18git.so+0xb123fd)\r\n#11 0x00007f5305e069f6 llvm::detail::PassModel>, llvm::PreservedAnalyses, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/../lib/libLLVM-18git.so+0x371b9f6)\r\n#12 0x00007f53031fbc8d llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/../lib/libLLVM-18git.so+0xb10c8d)\r\n#13 0x00007f5305e0d696 llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/../lib/libLLVM-18git.so+0x3722696)\r\n#14 0x00007f53031f9c0d llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/../lib/libLLVM-18git.so+0xb0ec0d)\r\n#15 0x0000555c5281fcb5 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/opt+0x25cb5)\r\n#16 0x0000555c52813876 main (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/opt+0x19876)\r\n#17 0x00007f53022e1083 __libc_start_main /build/glibc-wuryBv/glibc-2.31/csu/../csu/libc-start.c:342:3\r\n#18 0x0000555c5281451e _start (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/opt+0x1a51e)\r\n[1] 1975861 segmentation fault -disable-output -passes=loop-vectorize reduced.ll\r\n```\r\n\r\n\r\nThis IR is reduced from \r\n```C\r\nlong a, b;\r\nint c, d, f;\r\nstatic long *e = &b;\r\nstatic short g = 5;\r\nint h() {\r\n if (a)\r\n return 0;\r\n return 5;\r\n}\r\nvoid i() {\r\n int j;\r\n long **k = &e;\r\n for (; d; d++) {\r\n j = h();\r\n *e = 6 >= (g | (j + c == 0));\r\n }\r\n j = &k || 1;\r\n short *l[6];\r\n l[f] = &g;\r\n}\r\nint main() {}\r\n```", "author": "shao-hua-li", "labels": ["vectorizers", "crash"], "comments": []}, "verified": true} {"bug_id": "116249", "issue_url": "https://github.com/llvm/llvm-project/issues/116249", "bug_type": "miscompilation", "base_commit": "c1f6cb74634509d0e4204dadd46566185fa33e2b", "knowledge_cutoff": "2024-11-14T15:57:03Z", "lit_test_dir": ["llvm/test/Transforms/IndVarSimplify"], "hints": {"fix_commit": "40a647fc7dc6048c92e2d580b61f5feca0785980", "components": ["IndVarSimplify"], "bug_location_lineno": {"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": [[1530, 1535]]}, "bug_location_funcname": {"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": ["IndVarSimplify::canonicalizeExitCondition"]}}, "patch": "commit 40a647fc7dc6048c92e2d580b61f5feca0785980\nAuthor: Yingwei Zheng \nDate: Fri Nov 15 09:15:37 2024 +0800\n\n [IndVarSimplify] Drop samesign flags after narrowing compares (#116263)\n \n Samesign flag cannot be preserved after narrowing the compare since the\n position of the sign bit is changed.\n \n Closes https://github.com/llvm/llvm-project/issues/116249.\n\ndiff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp\nindex 2b2d516a7079..8a3e0bc3eb97 100644\n--- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp\n+++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp\n@@ -1530,6 +1530,8 @@ bool IndVarSimplify::canonicalizeExitCondition(Loop *L) {\n L->getLoopPreheader()->getTerminator()->getIterator());\n ICmp->setOperand(Swapped ? 1 : 0, LHSOp);\n ICmp->setOperand(Swapped ? 0 : 1, NewRHS);\n+ // Samesign flag cannot be preserved after narrowing the compare.\n+ ICmp->setSameSign(false);\n if (LHS->use_empty())\n DeadInsts.push_back(LHS);\n };\n", "tests": [{"file": "llvm/test/Transforms/IndVarSimplify/finite-exit-comparisons.ll", "commands": ["opt -passes=indvars -S < %s -indvars-predicate-loops=0"], "tests": [{"test_name": "test_drop_icmp_samesign", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\"\n\ndefine i8 @test_drop_icmp_samesign(i1 %cond, i32 range(i32 0, 32) %x) {\nentry:\n br i1 %cond, label %for.body, label %else\n\nelse: ; preds = %entry\n %call1 = call i8 @callee()\n br label %exit\n\nfor.body: ; preds = %for.body, %entry\n %call2 = call i8 @callee()\n %ext = zext i8 %call2 to i32\n %cond2 = icmp samesign ugt i32 %x, %ext\n br i1 %cond2, label %for.body, label %exit\n\nexit: ; preds = %for.body, %else\n %res = phi i8 [ %call1, %else ], [ %call2, %for.body ]\n ret i8 %res\n}\n\ndeclare i8 @callee()\n"}]}], "issue": {"title": "[IndVarSimplify] samesign flag should be dropped after narrowing", "body": "Found with https://github.com/dtcxzyw/llvm-ub-aware-interpreter.\r\nReproducer: https://alive2.llvm.org/ce/z/fcnvLv\r\n```\r\n; bin/opt -passes=indvars test.ll -S\r\ndefine i8 @test(i1 %cond, i32 range(i32 0, 32) %x) {\r\nentry:\r\n br i1 %cond, label %for.body, label %else\r\n\r\nelse:\r\n %call1 = call i8 @callee()\r\n br label %exit\r\n\r\nfor.body:\r\n %call2 = call i8 @callee()\r\n %ext = zext i8 %call2 to i32\r\n %cond2 = icmp samesign ugt i32 %x, %ext\r\n br i1 %cond2, label %for.body, label %exit\r\n\r\nexit:\r\n %res = phi i8 [ %call1, %else ], [ %call2, %for.body ]\r\n ret i8 %res\r\n}\r\n```\r\n```\r\n\r\n----------------------------------------\r\ndeclare i8 @callee()\r\n\r\ndefine i8 @test(i1 %cond, i32 %x) {\r\ninit:\r\n %#range_0_%x = !range i32 %x, i32 0, i32 32\r\n br label %entry\r\n\r\nentry:\r\n br i1 %cond, label %for.body, label %else\r\n\r\nelse:\r\n %call1 = call i8 @callee()\r\n br label %exit\r\n\r\nfor.body:\r\n %call2 = call i8 @callee()\r\n %ext = zext i8 %call2 to i32\r\n %cond2 = icmp samesign ugt i32 %#range_0_%x, %ext\r\n br i1 %cond2, label %for.body, label %exit\r\n\r\nexit:\r\n %res = phi i8 [ %call1, %else ], [ %call2, %for.body ]\r\n ret i8 %res\r\n}\r\n=>\r\ndeclare i8 @callee()\r\n\r\ndefine i8 @test(i1 %cond, i32 %x) {\r\ninit:\r\n %#range_0_%x = !range i32 %x, i32 0, i32 32\r\n br label %entry\r\n\r\nentry:\r\n br i1 %cond, label %for.body.preheader, label %else\r\n\r\nelse:\r\n %call1 = call i8 @callee()\r\n br label %exit\r\n\r\nfor.body.preheader:\r\n %#0 = trunc i32 %#range_0_%x to i8\r\n br label %for.body\r\n\r\nfor.body:\r\n %call2 = call i8 @callee()\r\n %cond2 = icmp samesign ugt i8 %#0, %call2\r\n br i1 %cond2, label %for.body, label %exit.loopexit\r\n\r\nexit.loopexit:\r\n %call2.lcssa = phi i8 [ %call2, %for.body ]\r\n br label %exit\r\n\r\nexit:\r\n %res = phi i8 [ %call1, %else ], [ %call2.lcssa, %exit.loopexit ]\r\n ret i8 %res\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Source is more defined than target\r\n\r\nExample:\r\ni1 %cond = #x1 (1)\r\ni32 %x = #x00000000 (0)\r\n\r\nSource:\r\ni32 %#range_0_%x = #x00000000 (0)\r\n >> Jump to %entry\r\n >> Jump to %for.body\r\ni8 %call2 = #x80 (128, -128)\r\ni32 %ext = #x00000080 (128)\r\ni1 %cond2 = #x0 (0)\r\n >> Jump to %exit\r\ni8 %res = #x80 (128, -128)\r\n\r\nSOURCE MEMORY STATE\r\n===================\r\nNON-LOCAL BLOCKS:\r\nBlock 0 >\tsize: 0\talign: 1\talloc type: 0\talive: false\taddress: 0\r\nBlock 1 >\tsize: 4\talign: 1\talloc type: 0\talive: true\taddress: 1\r\n\r\nTarget:\r\ni32 %#range_0_%x = #x00000000 (0)\r\n >> Jump to %entry\r\n >> Jump to %for.body.preheader\r\ni8 %#0 = #x00 (0)\r\n >> Jump to %for.body\r\ni8 %call2 = #x80 (128, -128)\r\ni1 %cond2 = poison\r\nUB triggered on br\r\n\r\n\r\nSummary:\r\n 0 correct transformations\r\n 1 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\n```", "author": "dtcxzyw", "labels": ["miscompilation", "llvm:transforms"], "comments": []}, "verified": true} {"bug_id": "91127", "issue_url": "https://github.com/llvm/llvm-project/issues/91127", "bug_type": "miscompilation", "base_commit": "30367cb5982dfdab2655401f020711311e7d78b9", "knowledge_cutoff": "2024-05-05T15:35:24Z", "lit_test_dir": ["llvm/test/Transforms/InstCombine"], "hints": {"fix_commit": "d3dad7a74be50d90754bf5c072e1a2330e92712c", "components": ["InstCombine"], "bug_location_lineno": {"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": [[1510, 1515]]}, "bug_location_funcname": {"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": ["InstCombinerImpl::foldICmpTruncWithTruncOrExt"]}}, "patch": "commit d3dad7a74be50d90754bf5c072e1a2330e92712c\nAuthor: Yingwei Zheng \nDate: Mon May 6 16:30:07 2024 +0800\n\n [InstCombine] Fix miscompilation caused by #90436 (#91133)\n \n Proof: https://alive2.llvm.org/ce/z/iRnJ4i\n \n Fixes https://github.com/llvm/llvm-project/issues/91127.\n\ndiff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp\nindex c60a290ce72e..7092fb5e509b 100644\n--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp\n+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp\n@@ -1510,6 +1510,7 @@ InstCombinerImpl::foldICmpTruncWithTruncOrExt(ICmpInst &Cmp,\n std::swap(X, Y);\n Pred = Cmp.getSwappedPredicate(Pred);\n }\n+ YIsSExt = !(NoWrapFlags & TruncInst::NoUnsignedWrap);\n }\n // Try to match icmp (trunc nuw X), (zext Y)\n else if (!Cmp.isSigned() &&\n", "tests": [{"file": "llvm/test/Transforms/InstCombine/icmp-of-trunc-ext.ll", "commands": ["opt -S -passes=instcombine < %s"], "tests": [{"test_name": "trunc_equality_both_sext", "test_body": "define i1 @trunc_equality_both_sext(i32 %x, i8 %y) {\n %xt = trunc nuw nsw i32 %x to i16\n %ye = sext i8 %y to i16\n %c = icmp ne i16 %xt, %ye\n ret i1 %c\n}\n"}, {"test_name": "test_slt_nuw", "test_body": "define i1 @test_slt_nuw(i32 %x, i16 %y) {\n %conv1 = trunc nuw nsw i32 %x to i8\n %conv2 = trunc nuw nsw i16 %y to i8\n %cond = icmp slt i8 %conv1, %conv2\n ret i1 %cond\n}\n"}, {"test_name": "test_slt", "test_body": "define i1 @test_slt(i32 %x, i16 %y) {\n %conv1 = trunc nsw i32 %x to i8\n %conv2 = trunc nsw i16 %y to i8\n %cond = icmp slt i8 %conv1, %conv2\n ret i1 %cond\n}\n"}, {"test_name": "test_ult_nuw", "test_body": "define i1 @test_ult_nuw(i32 %x, i16 %y) {\n %conv1 = trunc nuw nsw i32 %x to i8\n %conv2 = trunc nuw nsw i16 %y to i8\n %cond = icmp ult i8 %conv1, %conv2\n ret i1 %cond\n}\n"}, {"test_name": "test_ult", "test_body": "define i1 @test_ult(i32 %x, i16 %y) {\n %conv1 = trunc nsw i32 %x to i8\n %conv2 = trunc nsw i16 %y to i8\n %cond = icmp ult i8 %conv1, %conv2\n ret i1 %cond\n}\n"}, {"test_name": "test_eq1", "test_body": "define i1 @test_eq1(i32 %x, i16 %y) {\n %conv1 = trunc nsw i32 %x to i8\n %conv2 = trunc nsw i16 %y to i8\n %cond = icmp eq i8 %conv1, %conv2\n ret i1 %cond\n}\n"}, {"test_name": "test_eq2", "test_body": "define i1 @test_eq2(i32 %x, i16 %y) {\n %conv1 = trunc nsw i32 %x to i8\n %conv2 = trunc nsw i16 %y to i8\n %cond = icmp eq i8 %conv2, %conv1\n ret i1 %cond\n}\n"}]}], "issue": {"title": "[InstCombine] Miscompilation which converts `icmp eq (trunc nsw i64 X), (trunc nsw i32 Y)` into `icmp eq (zext i32 Y), X`", "body": "Reduced test case: https://alive2.llvm.org/ce/z/MLgA5x\r\n```\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 i32 @src() {\r\nentry:\r\n br label %for.cond\r\n\r\nfor.cond: ; preds = %if.end, %entry\r\n %storemerge = phi i32 [ 3, %entry ], [ %dec, %if.end ]\r\n %h = phi i32 [ 1, %entry ], [ %hres, %if.end ]\r\n %e = phi i32 [ 0, %entry ], [ -1, %if.end ]\r\n %tobool.not = icmp eq i32 %storemerge, 0\r\n br i1 %tobool.not, label %for.end9, label %for.body\r\n\r\nfor.body: ; preds = %for.cond\r\n %cmp = icmp eq i32 %h, 5\r\n %conv1 = zext i1 %cmp to i64\r\n %conv2 = sext i32 %e to i64\r\n %cond.i = call i64 @llvm.umax.i64(i64 %conv1, i64 %conv2)\r\n %conv3 = trunc nsw i64 %cond.i to i16\r\n %conv4 = trunc nsw i32 %e to i16\r\n %sub.i = sub i16 %conv3, %conv4\r\n %tobool6.not = icmp eq i16 %sub.i, 0\r\n br i1 %tobool6.not, label %if.end, label %if.then\r\n\r\nif.then: ; preds = %for.body\r\n br label %if.end\r\n\r\nif.end: ; preds = %if.then, %for.body\r\n %hres = phi i32 [ 0, %if.then ], [ %h, %for.body ]\r\n %dec = add nsw i32 %storemerge, -1\r\n br label %for.cond\r\n\r\nfor.end9: ; preds = %for.cond\r\n ret i32 %h\r\n}\r\n\r\ndefine i32 @tgt() {\r\nentry:\r\n br label %for.cond\r\n\r\nfor.cond: ; preds = %if.end, %entry\r\n %storemerge = phi i32 [ 3, %entry ], [ %dec, %if.end ]\r\n %h = phi i32 [ 1, %entry ], [ %hres, %if.end ]\r\n %e = phi i32 [ 0, %entry ], [ -1, %if.end ]\r\n %tobool.not = icmp eq i32 %storemerge, 0\r\n br i1 %tobool.not, label %for.end9, label %for.body\r\n\r\nfor.body: ; preds = %for.cond\r\n %cmp = icmp eq i32 %h, 5\r\n %conv1 = zext i1 %cmp to i64\r\n %conv2 = sext i32 %e to i64\r\n %cond.i = call i64 @llvm.umax.i64(i64 %conv1, i64 %conv2)\r\n %0 = zext i32 %e to i64\r\n %tobool6.not = icmp eq i64 %cond.i, %0\r\n br i1 %tobool6.not, label %if.end, label %if.then\r\n\r\nif.then: ; preds = %for.body\r\n br label %if.end\r\n\r\nif.end: ; preds = %if.then, %for.body\r\n %hres = phi i32 [ 0, %if.then ], [ %h, %for.body ]\r\n %dec = add nsw i32 %storemerge, -1\r\n br label %for.cond\r\n\r\nfor.end9: ; preds = %for.cond\r\n ret i32 %h\r\n}\r\n```\r\n\r\nllvm version: de9b386f84b58ad0ffc12e221bc6d9161ca5b62d", "author": "dtcxzyw", "labels": ["miscompilation", "llvm:instcombine"], "comments": [{"author": "dtcxzyw", "body": "Reduced test case: https://alive2.llvm.org/ce/z/ndR8PQ\r\n```\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 i1 @src(i64 %x, i32 %y) {\r\n %conv1 = trunc nsw i64 %x to i16\r\n %conv2 = trunc nsw i32 %y to i16\r\n %cond = icmp eq i16 %conv1, %conv2\r\n ret i1 %cond\r\n}\r\n\r\ndefine i1 @tgt(i64 %x, i32 %y) {\r\n %1 = zext i32 %y to i64\r\n %cond = icmp eq i64 %1, %x\r\n ret i1 %cond\r\n}\r\n```\r\n\r\nIt should be caused by https://github.com/llvm/llvm-project/pull/90436.\r\n\r\nI will post a fix later. cc @nikic\r\n"}, {"author": "dtcxzyw", "body": "POC without DataLayout:\r\n```\r\ndefine i1 @test_eq(i32 %x, i16 %y) {\r\n %conv1 = trunc nsw i32 %x to i8\r\n %conv2 = trunc nsw i16 %y to i8\r\n %cond = icmp eq i8 %conv1, %conv2\r\n ret i1 %cond\r\n}\r\n\r\ndefine i1 @test_ult(i32 %x, i16 %y) {\r\n %conv1 = trunc nsw i32 %x to i8\r\n %conv2 = trunc nsw i16 %y to i8\r\n %cond = icmp ult i8 %conv1, %conv2\r\n ret i1 %cond\r\n}\r\n\r\ndefine i1 @test_slt(i32 %x, i16 %y) {\r\n %conv1 = trunc nsw i32 %x to i8\r\n %conv2 = trunc nsw i16 %y to i8\r\n %cond = icmp slt i8 %conv1, %conv2\r\n ret i1 %cond\r\n}\r\n```"}]}, "verified": true} @@ -180,7 +189,7 @@ {"bug_id": "98660", "issue_url": "https://github.com/llvm/llvm-project/issues/98660", "bug_type": "crash", "base_commit": "efde640cdfede834fa79e0eea69f82fb769d6beb", "knowledge_cutoff": "2024-07-12T16:45:01Z", "lit_test_dir": ["llvm/test/Transforms/LoopVectorize"], "hints": {"fix_commit": "fc9cd3272b50f4ee9f18c4ab82c278bbb014d99f", "components": ["LoopVectorize"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [[8693, 8698]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": ["addUsersInExitBlock"]}}, "patch": "commit fc9cd3272b50f4ee9f18c4ab82c278bbb014d99f\nAuthor: Florian Hahn \nDate: Sun Jul 14 20:49:03 2024 +0100\n\n [VPlan] Don't add live-outs for IV phis.\n \n Resume and exit values for inductions are currently still created\n outside of VPlan and independent of the induction recipes. Don't add\n live-outs for now, as the additional unneeded users can pessimize other\n anlysis.\n \n Fixes https://github.com/llvm/llvm-project/issues/98660.\n\ndiff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\nindex 7d37d67cde29..5520baef7152 100644\n--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n@@ -8693,6 +8693,14 @@ static void addUsersInExitBlock(VPBasicBlock *HeaderVPBB, Loop *OrigLoop,\n Value *IncomingValue =\n ExitPhi.getIncomingValueForBlock(ExitingBB);\n VPValue *V = Builder.getVPValueOrAddLiveIn(IncomingValue, Plan);\n+ // Exit values for inductions are computed and updated outside of VPlan and\n+ // independent of induction recipes.\n+ // TODO: Compute induction exit values in VPlan, use VPLiveOuts to update\n+ // live-outs.\n+ if ((isa(V) &&\n+ !cast(V)->getTruncInst()) ||\n+ isa(V))\n+ continue;\n Plan.addLiveOut(&ExitPhi, V);\n }\n }\n", "tests": [{"file": "llvm/test/Transforms/LoopVectorize/AArch64/sve-live-out-pointer-induction.ll", "commands": ["opt -passes=loop-vectorize -mtriple=aarch64-unknown -mattr=+sve -S %s"], "tests": [{"test_name": "test", "test_body": "define ptr @test(ptr %start.1, ptr %start.2, ptr %end) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv.1 = phi ptr [ %start.1, %entry ], [ %iv.1.next, %loop ]\n %iv.2 = phi ptr [ %start.2, %entry ], [ %iv.2.next, %loop ]\n store i64 0, ptr %iv.2, align 4\n %iv.2.next = getelementptr inbounds ptr, ptr %iv.2, i64 1\n %iv.1.next = getelementptr inbounds ptr, ptr %iv.1, i64 1\n %cmp.i.i.not.i = icmp eq ptr %iv.2.next, %end\n br i1 %cmp.i.i.not.i, label %exit, label %loop\n\nexit: ; preds = %loop\n %res.lcssa = phi ptr [ %iv.1, %loop ]\n ret ptr %res.lcssa\n}\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/X86/ephemeral-recipes.ll", "commands": ["opt -p loop-vectorize -S %s"], "tests": [{"test_name": "ephemeral_load_and_compare_iv_used_outside", "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\"\ntarget triple = \"x86_64-apple-macosx\"\n\ndefine i32 @ephemeral_load_and_compare_iv_used_outside(ptr %start, ptr %end) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi ptr [ %start, %entry ], [ %iv.next, %loop ]\n %iv.next = getelementptr nusw i8, ptr %iv, i64 -8\n %l1 = load i32, ptr %iv, align 4\n %cmp = icmp ne i32 %l1, 0\n call void @llvm.assume(i1 %cmp)\n %cmp.not = icmp eq ptr %iv, %end\n br i1 %cmp.not, label %exit, label %loop\n\nexit: ; preds = %loop\n %final.load = load i32, ptr %iv, align 4\n ret i32 %final.load\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #1\n\nattributes #0 = { \"target-cpu\"=\"skylake-avx512\" }\nattributes #1 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/X86/iv-live-outs.ll", "commands": ["opt -p loop-vectorize -mcpu=skylake-avx512 -S %s"], "tests": [{"test_name": "", "test_body": "\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i64 @test_pr98660(ptr %dst, i64 %N) {\n;\nentry:\n br label %loop.header\n\nloop.header:\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %or = or disjoint i64 %iv, 1\n %gep = getelementptr i32, ptr %dst, i64 %or\n %l = load i32, ptr %gep\n %c = icmp eq i32 %l, 0\n br i1 %c, label %then, label %loop.latch\n\nthen:\n store i32 0, ptr %gep, align 4\n br label %loop.latch\n\nloop.latch:\n %iv.next = add i64 %iv, 1\n %ec = icmp ult i64 %iv, %N\n br i1 %ec, label %loop.header, label %exit\n\nexit:\n %ret = phi i64 [ %iv, %loop.latch ]\n ret i64 %ret\n}\n;.\n;."}]}, {"file": "llvm/test/Transforms/LoopVectorize/iv_outside_user.ll", "commands": ["opt -S -passes=loop-vectorize -force-vector-interleave=1 -force-vector-width=2 < %s", "opt -S -passes=loop-vectorize -force-vector-interleave=2 -force-vector-width=1 < %s"], "tests": [{"test_name": "iv_2_dead_in_loop_only_used_outside", "test_body": "define i32 @iv_2_dead_in_loop_only_used_outside(ptr %ptr) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.2 = phi i32 [ 0, %entry ], [ %iv.2.next, %loop ]\n %iv.next = add nuw i64 %iv, 1\n %iv.2.next = add nuw i32 %iv.2, 2\n %gep.ptr = getelementptr inbounds i64, ptr %ptr, i64 %iv\n store i64 %iv, ptr %gep.ptr, align 4\n %exitcond = icmp ugt i64 %iv, 1000\n br i1 %exitcond, label %exit, label %loop\n\nexit: ; preds = %loop\n %iv.2.lcssa = phi i32 [ %iv.2, %loop ]\n ret i32 %iv.2.lcssa\n}\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/no-fold-tail-by-masking-iv-external-uses.ll", "commands": ["opt < %s -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S"], "tests": [{"test_name": "test", "test_body": "define i32 @test(ptr %arr, i64 %n) {\nentry:\n %cmp1 = icmp ugt i64 %n, 1\n br i1 %cmp1, label %preheader, label %done\n\npreheader: ; preds = %entry\n br label %loop\n\nloop: ; preds = %loop, %preheader\n %conv = phi i64 [ %conv2, %loop ], [ 1, %preheader ]\n %i = phi i8 [ %inc, %loop ], [ 1, %preheader ]\n %sub = add nsw i64 %conv, -1\n %ptr = getelementptr inbounds i32, ptr %arr, i64 %sub\n store i32 65, ptr %ptr, align 4\n %inc = add i8 %i, 1\n %conv2 = zext i8 %inc to i64\n %cmp2 = icmp ult i64 %conv2, %n\n br i1 %cmp2, label %loop, label %load_val, !llvm.loop !0\n\nload_val: ; preds = %loop\n %final = phi i64 [ %conv, %loop ]\n %ptr2 = getelementptr inbounds i32, ptr %arr, i64 %final\n %val = load i32, ptr %ptr2, align 4\n br label %done\n\ndone: ; preds = %load_val, %entry\n %value = phi i32 [ %val, %load_val ], [ 0, %entry ]\n ret i32 %value\n}\n\n!0 = distinct !{!0, !1, !2, !3}\n!1 = !{!\"llvm.loop.unroll.disable\"}\n!2 = !{!\"llvm.loop.vectorize.predicate.enable\", i1 true}\n!3 = !{!\"llvm.loop.vectorize.enable\", i1 true}\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/pr58811-scev-expansion.ll", "commands": ["opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S %s"], "tests": [{"test_name": "test1_pr58811", "test_body": "define void @test1_pr58811() {\nentry:\n br label %loop.1.preheader\n\nloop.1.preheader: ; preds = %unreachable.bb, %entry\n %iv.1.ph = phi i32 [ %sub93.2, %unreachable.bb ], [ 0, %entry ]\n br label %loop.1\n\nloop.1: ; preds = %loop.1, %loop.1.preheader\n %iv.1 = phi i32 [ %iv.1.next, %loop.1 ], [ %iv.1.ph, %loop.1.preheader ]\n %iv.2 = phi i32 [ %iv.2.next, %loop.1 ], [ 0, %loop.1.preheader ]\n %iv.2.next = add i32 %iv.2, 1\n %iv.1.next = add i32 %iv.2, %iv.1\n br i1 false, label %loop.1, label %loop.2.preheader\n\nloop.2.preheader: ; preds = %loop.1\n %iv.1.lcssa = phi i32 [ %iv.1, %loop.1 ]\n br label %loop.2\n\nloop.2: ; preds = %loop.2, %loop.2.preheader\n %iv.3 = phi i16 [ %iv.3.next, %loop.2 ], [ 0, %loop.2.preheader ]\n %iv.4 = phi i32 [ %iv.4.next, %loop.2 ], [ 0, %loop.2.preheader ]\n %iv.4.next = sub i32 %iv.4, %iv.1.lcssa\n %iv.3.next = add i16 %iv.3, 1\n %cmp88.1 = icmp ult i16 %iv.3, 198\n br i1 %cmp88.1, label %loop.2, label %loop.3.preheader\n\nloop.3.preheader: ; preds = %loop.2\n %iv.4.lcssa = phi i32 [ %iv.4, %loop.2 ]\n br label %loop.3\n\nloop.3: ; preds = %loop.3, %loop.3.preheader\n %iv.5 = phi i32 [ %sub93.2, %loop.3 ], [ 0, %loop.3.preheader ]\n %sub93.2 = sub i32 %iv.5, %iv.4.lcssa\n br label %loop.3\n\nunreachable.bb: ; No predecessors!\n br label %loop.1.preheader\n}\n"}, {"test_name": "test2_pr58811", "test_body": "define void @test2_pr58811() {\nentry:\n br label %loop.1.header\n\nloop.1.header: ; preds = %loop.4, %entry\n %p.1 = phi i32 [ 0, %entry ], [ %sub93.2, %loop.4 ]\n br label %loop.2\n\nloop.2: ; preds = %loop.2, %loop.1.header\n %iv.2 = phi i32 [ %p.1, %loop.1.header ], [ %add101, %loop.2 ]\n %iv.3 = phi i32 [ 0, %loop.1.header ], [ %sub93, %loop.2 ]\n %sub93 = add i32 %iv.3, 1\n %add101 = add i32 %iv.3, %iv.2\n br i1 false, label %loop.2, label %loop.3\n\nloop.3: ; preds = %loop.3, %loop.2\n %iv.4 = phi i16 [ 0, %loop.2 ], [ %inc.1, %loop.3 ]\n %iv.5 = phi i32 [ 0, %loop.2 ], [ %sub93.1, %loop.3 ]\n %sub93.1 = sub i32 %iv.5, %iv.2\n %inc.1 = add i16 %iv.4, 1\n %cmp88.1 = icmp ult i16 %iv.4, 198\n br i1 %cmp88.1, label %loop.3, label %loop.4\n\nloop.4: ; preds = %loop.4, %loop.3\n %iv.6 = phi i32 [ 0, %loop.3 ], [ %sub93.2, %loop.4 ]\n %sub93.2 = sub i32 %iv.6, %iv.5\n br i1 false, label %loop.4, label %loop.1.header\n}\n"}, {"test_name": "test3_pr58811", "test_body": "define void @test3_pr58811() {\nentry:\n br label %loop.1.header\n\nloop.1.header: ; preds = %loop.1.latch, %entry\n %p.1 = phi i32 [ 0, %entry ], [ %sub93.2, %loop.1.latch ]\n %rem85 = urem i32 1, %p.1\n br label %loop.2\n\nloop.2: ; preds = %loop.2, %loop.1.header\n %p.2 = phi i32 [ 1, %loop.1.header ], [ 0, %loop.2 ]\n %add101 = add i32 %rem85, %p.2\n br i1 false, label %loop.2, label %loop.3\n\nloop.3: ; preds = %loop.3, %loop.2\n %iv.3 = phi i16 [ 0, %loop.2 ], [ %inc.1, %loop.3 ]\n %iv.4 = phi i32 [ 0, %loop.2 ], [ %sub93.1, %loop.3 ]\n %sub93.1 = sub i32 %iv.4, %add101\n %inc.1 = add i16 %iv.3, 1\n %cmp88.1 = icmp ult i16 %iv.3, 198\n br i1 %cmp88.1, label %loop.3, label %loop.4\n\nloop.4: ; preds = %loop.4, %loop.3\n %iv.5 = phi i32 [ 0, %loop.3 ], [ %sub93.2, %loop.4 ]\n %sub93.2 = sub i32 %iv.5, %iv.4\n br label %loop.4\n\nloop.1.latch: ; No predecessors!\n br label %loop.1.header\n}\n"}]}], "issue": {"title": "Assertion `(VF.isScalar() || Def->isLiveIn() || hasVectorValue(Def, Part) || (hasScalarValue(Def, VPIteration(Part, 0)) && Data.PerPartScalars[Def][Part].size() == 1)) && \"Trying to access a single scalar per part but has multiple scalars \" \"per part.\"' failed.", "body": "To reproduce run opt opt with -passes loop-vectorize with 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(i64 %arg) #0 gc \"statepoint-example\" {\r\nbb:\r\n br label %bb1\r\n\r\nbb1: ; preds = %bb3, %bb\r\n %phi = phi i64 [ 0, %bb ], [ %add, %bb3 ]\r\n br i1 false, label %bb2, label %bb3\r\n\r\nbb2: ; preds = %bb1\r\n %or = or disjoint i64 %phi, 0\r\n %getelementptr = getelementptr i32, ptr addrspace(1) null, i64 %or\r\n store i32 0, ptr addrspace(1) %getelementptr, align 4\r\n br label %bb3\r\n\r\nbb3: ; preds = %bb2, %bb1\r\n %add = add i64 %phi, 1\r\n %icmp = icmp ult i64 %phi, %arg\r\n br i1 %icmp, label %bb1, label %bb4\r\n\r\nbb4: ; preds = %bb3\r\n %phi5 = phi i64 [ %phi, %bb3 ]\r\n ret void\r\n}\r\n\r\nattributes #0 = { \"target-features\"=\"+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,-ndd,+xsaveopt,+rdrnd,+avx512f,-amx-bf16,-avx512bf16,-avx512vnni,-push2pop2,+cx8,+avx512bw,+sse3,+pku,+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\nReproducer:\r\nhttps://godbolt.org/z/Ghz3147nj\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 \r\n1.\tRunning pass \"function(loop-vectorize)\" on module \"\"\r\n2.\tRunning pass \"loop-vectorize\" on function \"wombat\"\r\n #0 0x0000000004e9b948 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e9b948)\r\n #1 0x0000000004e990bc SignalHandler(int) Signals.cpp:0:0\r\n #2 0x000070edf8442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000070edf84969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x000070edf8442476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x000070edf84287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x000070edf842871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x000070edf8439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x00000000040395f7 llvm::VPTransformState::get(llvm::VPValue*, unsigned int, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40395f7)\r\n #9 0x0000000004056ece llvm::VPInstruction::generatePerPart(llvm::VPTransformState&, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4056ece)\r\n#10 0x00000000040595ee llvm::VPInstruction::execute(llvm::VPTransformState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40595ee)\r\n#11 0x0000000004030a1f llvm::VPBasicBlock::executeRecipes(llvm::VPTransformState*, llvm::BasicBlock*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4030a1f)\r\n#12 0x00000000040320e8 llvm::VPBasicBlock::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40320e8)\r\n#13 0x0000000004030612 llvm::VPRegionBlock::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4030612)\r\n#14 0x0000000004039946 llvm::VPlan::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4039946)\r\n#15 0x0000000003f1d475 llvm::LoopVectorizationPlanner::executePlan(llvm::ElementCount, unsigned int, llvm::VPlan&, llvm::InnerLoopVectorizer&, llvm::DominatorTree*, bool, llvm::DenseMap, llvm::detail::DenseMapPair> const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f1d475)\r\n#16 0x0000000003f332ea llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f332ea)\r\n#17 0x0000000003f35a29 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+0x3f35a29)\r\n#18 0x0000000003f3614b llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f3614b)\r\n#19 0x0000000002e212be llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2e212be)\r\n#20 0x0000000004c9f2d8 llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4c9f2d8)\r\n#21 0x0000000000dc9bee llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xdc9bee)\r\n#22 0x0000000004c9dd46 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4c9dd46)\r\n#23 0x0000000000dca1fe llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xdca1fe)\r\n#24 0x0000000004c9bf10 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4c9bf10)\r\n#25 0x00000000008db1d2 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::ArrayRef>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8db1d2)\r\n#26 0x00000000008ce0fc optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ce0fc)\r\n#27 0x000070edf8429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#28 0x000070edf8429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#29 0x00000000008c556e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8c556e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "TatyanaDoubts", "labels": ["vectorizers", "crash"], "comments": [{"author": "fhahn", "body": "Interesting, let me take a look"}]}, "verified": true} {"bug_id": "89516", "issue_url": "https://github.com/llvm/llvm-project/issues/89516", "bug_type": "miscompilation", "base_commit": "18bb175428f520aaa4a5e388bd3b680a1a7c60c0", "knowledge_cutoff": "2024-04-20T22:58:16Z", "lit_test_dir": ["llvm/test/Transforms/InstCombine"], "hints": {"fix_commit": "6309440c218778db027306826993e484eab2be17", "components": ["InstCombine"], "bug_location_lineno": {"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [[2720, 2726]]}, "bug_location_funcname": {"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": ["foldSelectWithSRem"]}}, "patch": "commit 6309440c218778db027306826993e484eab2be17\nAuthor: Yingwei Zheng \nDate: Sun Apr 21 22:41:32 2024 +0800\n\n [InstCombine] Fix unexpected overwriting in `foldSelectWithSRem` (#89539)\n \n Fixes #89516\n\ndiff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp\nindex 0262af28068b..73600206a55c 100644\n--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp\n+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp\n@@ -2720,7 +2720,7 @@ static Instruction *foldSelectWithSRem(SelectInst &SI, InstCombinerImpl &IC,\n // %cnd = icmp slt i32 %rem, 0\n // %add = add i32 %rem, %n\n // %sel = select i1 %cnd, i32 %add, i32 %rem\n- if (match(TrueVal, m_Add(m_Value(RemRes), m_Value(Remainder))) &&\n+ if (match(TrueVal, m_Add(m_Specific(RemRes), m_Value(Remainder))) &&\n match(RemRes, m_SRem(m_Value(Op), m_Specific(Remainder))) &&\n IC.isKnownToBeAPowerOfTwo(Remainder, /*OrZero*/ true) &&\n FalseVal == RemRes)\n", "tests": [{"file": "llvm/test/Transforms/InstCombine/select-divrem.ll", "commands": ["opt < %s -passes=instcombine -S"], "tests": [{"test_name": "rem_euclid_pow2_false_arm_folded", "test_body": "define i32 @rem_euclid_pow2_false_arm_folded(i32 %n) {\n %rem = srem i32 %n, 2\n %nonneg = icmp sge i32 %rem, 0\n %res = select i1 %nonneg, i32 %rem, i32 1\n ret i32 %res\n}\n"}, {"test_name": "pr89516", "test_body": "define i8 @pr89516(i8 %n, i8 %x) {\n %cond = icmp slt i8 %x, 0\n %pow2 = shl nuw i8 1, %n\n %srem = srem i8 1, %pow2\n %add = add nuw i8 %srem, %pow2\n %res = select i1 %cond, i8 %add, i8 %srem\n ret i8 %res\n}\n"}]}], "issue": {"title": "miscompile of vanilla integer code by InstCombine", "body": "https://alive2.llvm.org/ce/z/jRfVLr\r\n\r\nthis function:\r\n```llvm\r\ndefine i8 @f(i8 %0, i8 %1) {\r\n %3 = icmp slt i8 %1, 0\r\n %4 = shl i8 1, %0\r\n %5 = srem i8 1, %4\r\n %6 = add i8 %5, %4\r\n %7 = select i1 %3, i8 %6, i8 %5\r\n ret i8 %7\r\n}\r\n```\r\nis getting mis-optimized to:\r\n```llvm\r\ndefine i8 @f(i8 %0, i8 %1) {\r\n %3 = icmp ne i8 %0, 0\r\n %4 = zext i1 %3 to i8\r\n ret i8 %4\r\n}\r\n```\r\nhere I'll just give Alive's work:\r\n```\r\nExample:\r\ni8 %#0 = #x00 (0)\r\ni8 %#1 = #xff (255, -1)\r\n\r\nSource:\r\ni1 %#3 = #x1 (1)\r\ni8 %#4 = #x01 (1)\r\ni8 %#5 = #x00 (0)\r\ni8 %#6 = #x01 (1)\r\ni8 %#7 = #x01 (1)\r\n\r\nTarget:\r\ni1 %#3 = #x0 (0)\r\ni8 %#4 = #x00 (0)\r\nSource value: #x01 (1)\r\nTarget value: #x00 (0)\r\n```\r\n\r\ncc @nunoplopes @hatsunespica", "author": "regehr", "labels": ["miscompilation", "llvm:instcombine"], "comments": []}, "verified": true} {"bug_id": "98139", "issue_url": "https://github.com/llvm/llvm-project/issues/98139", "bug_type": "miscompilation", "base_commit": "6aefa918768c834ec21e0b599fa14d03b9ce3dc0", "knowledge_cutoff": "2024-07-09T09:49:19Z", "lit_test_dir": ["llvm/test/Transforms/InstCombine"], "hints": {"fix_commit": "722151664ecfd53295392ad875ff9bfdcd1deaaf", "components": ["InstCombine"], "bug_location_lineno": {"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": [[411, 417]]}, "bug_location_funcname": {"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": ["InstCombinerImpl::SimplifyDemandedUseBits"]}}, "patch": "commit 722151664ecfd53295392ad875ff9bfdcd1deaaf\nAuthor: Yingwei Zheng \nDate: Tue Jul 9 22:04:55 2024 +0800\n\n [InstCombine] Fix typo in `adjustKnownBitsForSelectArm` (#98155)\n \n Fixes https://github.com/llvm/llvm-project/issues/98139.\n\ndiff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp\nindex 98f085a2c756..081e783c964f 100644\n--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp\n+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp\n@@ -411,7 +411,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Instruction *I,\n // Only known if known in both the LHS and RHS.\n adjustKnownBitsForSelectArm(LHSKnown, I->getOperand(0), I->getOperand(1),\n /*Invert=*/false, Depth, Q);\n- adjustKnownBitsForSelectArm(LHSKnown, I->getOperand(0), I->getOperand(2),\n+ adjustKnownBitsForSelectArm(RHSKnown, I->getOperand(0), I->getOperand(2),\n /*Invert=*/true, Depth, Q);\n Known = LHSKnown.intersectWith(RHSKnown);\n break;\n", "tests": [{"file": "llvm/test/Transforms/InstCombine/pr98139.ll", "commands": ["opt -S -passes=instcombine < %s"], "tests": [{"test_name": "pr98139", "test_body": "define i8 @pr98139(i16 %a, i16 %b, i1 %cond) {\n %sel = select i1 %cond, i16 1, i16 254\n %cond1 = icmp ne i16 %b, 0\n %mask = and i16 %a, 255\n %cond2 = icmp ne i16 %mask, 255\n %cond3 = or i1 %cond1, %cond2\n %sel2 = select i1 %cond3, i16 %sel, i16 255\n %sub = sub i16 %sel2, %a\n %trunc = trunc i16 %sub to i8\n ret i8 %trunc\n}\n"}]}], "issue": {"title": "wrong code at -O{s,2,3} on x86_64-linux-gnu", "body": "It appears to be a recent regression as it doesn't reproduce with 18.1.0 and earlier.\r\n\r\nCompiler Explorer: https://godbolt.org/z/o595xsMdb\r\n\r\n```\r\n[512] % clangtk -v\r\nclang version 19.0.0git (https://github.com/llvm/llvm-project.git 765e2f9a8de27cc8fd8c75540844e9630d8229ad)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /local/suz-local/software/local/clang-trunk/bin\r\nBuild config: +assertions\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9\r\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\r\nCandidate multilib: .;@m64\r\nSelected multilib: .;@m64\r\n[513] % \r\n[513] % clangtk -O1 small.c; ./a.out\r\n1\r\n[514] % clangtk -O3 small.c; ./a.out\r\n-2\r\n1\r\n[515] % cat small.c\r\nint printf(const char *, ...);\r\nint a, b, c, e;\r\nchar d;\r\nint main() {\r\n int f = 1;\r\n unsigned g = 1;\r\n for (; c < 2; c++) {\r\n if (g)\r\n b = 1;\r\n char h = f;\r\n f = ~h;\r\n d = ~b - ~g * (a || f);\r\n g = ~g;\r\n if (g < 1)\r\n break;\r\n if (d)\r\n printf(\"%d\\n\", g);\r\n f = e;\r\n }\r\n return 0;\r\n}\r\n```", "author": "zhendongsu", "labels": ["miscompilation", "confirmed", "llvm:instcombine"], "comments": [{"author": "dtcxzyw", "body": "There is a bug in `SimplifyDemandedInstructionBits` :)\r\nI am working to provide a minimal reproducer.\r\n"}, {"author": "dtcxzyw", "body": "@nikic https://github.com/llvm/llvm-project/blob/a9183b8899f2c02ba3710b27c0cbdde6831a627b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp#L411-L416\r\n\r\nI will post a fix later.\r\n"}, {"author": "dtcxzyw", "body": "Reproducer: https://alive2.llvm.org/ce/z/GAUsBC\r\n```\r\ndefine i8 @src(i16 %a, i16 %b, i1 %cond) {\r\n %sel = select i1 %cond, i16 1, i16 254\r\n %cond1 = icmp ne i16 %b, 0\r\n %mask = and i16 %a, 255\r\n %cond2 = icmp ne i16 %mask, 255\r\n %cond3 = or i1 %cond1, %cond2\r\n %sel2 = select i1 %cond3, i16 %sel, i16 255\r\n %sub = sub i16 %sel2, %a\r\n %trunc = trunc i16 %sub to i8\r\n ret i8 %trunc\r\n}\r\n\r\ndefine i8 @tgt(i16 %a1, i16 %a2, i1 %cond) {\r\n %1 = trunc i16 %a1 to i8\r\n %conv6 = xor i8 %1, -1\r\n ret i8 %conv6\r\n}\r\n```"}]}, "verified": true} -{"bug_id": "128736", "issue_url": "https://github.com/llvm/llvm-project/issues/128736", "bug_type": "crash", "base_commit": "02128342d2818e5a65846fec4179ed5344045102", "knowledge_cutoff": "2025-02-25T16:27:23Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "39bab1de33333ee3c62b586c4e8d26f8c443bc60", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[1389, 1397], [2849, 2859], [2915, 2926], [16466, 16474], [17075, 17081], [20449, 20456], [20678, 20684]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["tryToReduce", "removeInstructionsAndOperands", "BoUpSLP::vectorizeTree"]}}, "patch": "commit 39bab1de33333ee3c62b586c4e8d26f8c443bc60\nAuthor: Alexey Bataev \nDate: Wed Feb 26 14:12:05 2025 -0800\n\n [SLP]Check if the operand for removal is the reduction operand, awaiting for the reduction\n \n If the operand of the instruction-to-be-removed is a reduction value,\n which is not reduced yet, and, thus, it has no users, it may be removed\n during operands analysis.\n \n Fixes #128736\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex b25b09306aca..e8c91ebd508c 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -1389,9 +1389,10 @@ public:\n /// Vectorize the tree but with the list of externally used values \\p\n /// ExternallyUsedValues. Values in this MapVector can be replaced but the\n /// generated extractvalue instructions.\n- Value *\n- vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues,\n- Instruction *ReductionRoot = nullptr);\n+ Value *vectorizeTree(\n+ const ExtraValueToDebugLocsMap &ExternallyUsedValues,\n+ Instruction *ReductionRoot = nullptr,\n+ ArrayRef> VectorValuesAndScales = {});\n \n /// \\returns the cost incurred by unwanted spills and fills, caused by\n /// holding live values over call sites.\n@@ -2849,11 +2850,13 @@ public:\n /// Remove instructions from the parent function and clear the operands of \\p\n /// DeadVals instructions, marking for deletion trivially dead operands.\n template \n- void removeInstructionsAndOperands(ArrayRef DeadVals) {\n+ void removeInstructionsAndOperands(\n+ ArrayRef DeadVals,\n+ ArrayRef> VectorValuesAndScales) {\n SmallVector DeadInsts;\n for (T *V : DeadVals) {\n auto *I = cast(V);\n- DeletedInstructions.insert(I);\n+ eraseInstruction(I);\n }\n DenseSet Processed;\n for (T *V : DeadVals) {\n@@ -2915,12 +2918,17 @@ public:\n // loop iteration.\n if (auto *OpI = dyn_cast(OpV))\n if (!DeletedInstructions.contains(OpI) &&\n+ (!OpI->getType()->isVectorTy() ||\n+ none_of(VectorValuesAndScales,\n+ [&](const std::tuple &V) {\n+ return std::get<0>(V) == OpI;\n+ })) &&\n isInstructionTriviallyDead(OpI, TLI))\n DeadInsts.push_back(OpI);\n }\n \n VI->removeFromParent();\n- DeletedInstructions.insert(VI);\n+ eraseInstruction(VI);\n SE->forgetValue(VI);\n }\n }\n@@ -16466,9 +16474,10 @@ Value *BoUpSLP::vectorizeTree() {\n return vectorizeTree(ExternallyUsedValues);\n }\n \n-Value *\n-BoUpSLP::vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues,\n- Instruction *ReductionRoot) {\n+Value *BoUpSLP::vectorizeTree(\n+ const ExtraValueToDebugLocsMap &ExternallyUsedValues,\n+ Instruction *ReductionRoot,\n+ ArrayRef> VectorValuesAndScales) {\n // All blocks must be scheduled before any instructions are inserted.\n for (auto &BSIter : BlocksSchedules) {\n scheduleBlock(BSIter.second.get());\n@@ -17075,7 +17084,7 @@ BoUpSLP::vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues,\n // cache correctness.\n // NOTE: removeInstructionAndOperands only marks the instruction for deletion\n // - instructions are not deleted until later.\n- removeInstructionsAndOperands(ArrayRef(RemovedInsts));\n+ removeInstructionsAndOperands(ArrayRef(RemovedInsts), VectorValuesAndScales);\n \n Builder.ClearInsertionPoint();\n InstrElementSize.clear();\n@@ -20449,8 +20458,8 @@ public:\n InsertPt = GetCmpForMinMaxReduction(RdxRootInst);\n \n // Vectorize a tree.\n- Value *VectorizedRoot =\n- V.vectorizeTree(LocalExternallyUsedValues, InsertPt);\n+ Value *VectorizedRoot = V.vectorizeTree(\n+ LocalExternallyUsedValues, InsertPt, VectorValuesAndScales);\n // Update TrackedToOrig mapping, since the tracked values might be\n // updated.\n for (Value *RdxVal : Candidates) {\n@@ -20678,7 +20687,7 @@ public:\n Ignore->replaceAllUsesWith(P);\n }\n }\n- V.removeInstructionsAndOperands(RdxOps);\n+ V.removeInstructionsAndOperands(RdxOps, VectorValuesAndScales);\n }\n } else if (!CheckForReusedReductionOps) {\n for (ReductionOpsType &RdxOps : ReductionOps)\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/X86/reduction-with-removed-extracts.ll", "commands": ["opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -mcpu=znver2 < %s"], "tests": [{"test_name": "", "test_body": "\ndefine i32 @test(i32 %arg) {\n;\nbb:\n br label %bb1\n\nbb1:\n %phi = phi i32 [ 0, %bb ], [ %mul37, %bb1 ]\n %mul = mul i64 0, 0\n %trunc = trunc i64 %mul to i32\n %or = or i32 0, %trunc\n %or2 = or i32 0, %or\n %or3 = or i32 %or2, 0\n %mul4 = mul i32 0, %or3\n %mul5 = mul i32 %or3, 0\n %mul6 = mul i32 %mul5, %mul4\n %mul7 = mul i32 %mul6, %mul4\n %mul8 = mul i32 %mul7, %or3\n %mul9 = mul i64 0, 0\n %trunc10 = trunc i64 %mul9 to i32\n %or11 = or i32 0, %trunc10\n %or12 = or i32 %arg, %or11\n %or13 = or i32 %or12, 0\n %mul14 = mul i32 %or13, %mul8\n %mul15 = mul i32 %mul14, 0\n %mul16 = mul i32 %mul15, 0\n %mul17 = mul i32 %mul16, %or13\n %shl = shl i64 0, 0\n %mul18 = mul i64 %shl, 0\n %trunc19 = trunc i64 %mul18 to i32\n %or20 = or i32 0, %trunc19\n %or21 = or i32 0, %or20\n %or22 = or i32 %or21, 0\n %mul23 = mul i32 %or22, %mul17\n %mul24 = mul i32 %mul23, 0\n %mul25 = mul i32 %mul24, 0\n %mul26 = mul i32 %mul25, %or22\n %shl27 = shl i64 0, 0\n %mul28 = mul i64 %shl27, 0\n %trunc29 = trunc i64 %mul28 to i32\n %or30 = or i32 0, %trunc29\n %or31 = or i32 0, %or30\n %or32 = or i32 %or31, 0\n %mul33 = mul i32 0, %or32\n %mul34 = mul i32 %or32, %mul26\n %mul35 = mul i32 %mul34, %mul33\n %mul36 = mul i32 %mul35, %mul33\n %mul37 = mul i32 %mul36, %or32\n br label %bb1\n}"}]}], "issue": {"title": "Assertion `I->use_empty() && \"trying to erase instruction with users.\"' failed.", "body": "To reproduce run opt with the test below using -passes=slp-vectorizer.\n```\n; ModuleID = './reduced.ll'\nsource_filename = \"./reduced.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-ni:1-p2:32:8:8:32-ni:2\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i32 @wombat(i32 %arg) #0 gc \"statepoint-example\" {\nbb:\n br label %bb1\n \nbb1: ; preds = %bb1, %bb\n %phi = phi i32 [ 0, %bb ], [ %mul37, %bb1 ]\n %mul = mul i64 0, 0\n %trunc = trunc i64 %mul to i32\n %or = or i32 0, %trunc\n %or2 = or i32 0, %or\n %or3 = or i32 %or2, 0\n %mul4 = mul i32 0, %or3\n %mul5 = mul i32 %or3, 0\n %mul6 = mul i32 %mul5, %mul4\n %mul7 = mul i32 %mul6, %mul4\n %mul8 = mul i32 %mul7, %or3\n %mul9 = mul i64 0, 0\n %trunc10 = trunc i64 %mul9 to i32\n %or11 = or i32 0, %trunc10\n %or12 = or i32 %arg, %or11\n %or13 = or i32 %or12, 0\n %mul14 = mul i32 %or13, %mul8\n %mul15 = mul i32 %mul14, 0\n %mul16 = mul i32 %mul15, 0\n %mul17 = mul i32 %mul16, %or13\n %shl = shl i64 0, 0\n %mul18 = mul i64 %shl, 0\n %trunc19 = trunc i64 %mul18 to i32\n %or20 = or i32 0, %trunc19\n %or21 = or i32 0, %or20\n %or22 = or i32 %or21, 0\n %mul23 = mul i32 %or22, %mul17\n %mul24 = mul i32 %mul23, 0\n %mul25 = mul i32 %mul24, 0\n %mul26 = mul i32 %mul25, %or22\n %shl27 = shl i64 0, 0\n %mul28 = mul i64 %shl27, 0\n %trunc29 = trunc i64 %mul28 to i32\n %or30 = or i32 0, %trunc29\n %or31 = or i32 0, %or30\n %or32 = or i32 %or31, 0\n %mul33 = mul i32 0, %or32\n %mul34 = mul i32 %or32, %mul26\n %mul35 = mul i32 %mul34, %mul33\n %mul36 = mul i32 %mul35, %mul33\n %mul37 = mul i32 %mul36, %or32\n br label %bb1\n}\n\nattributes #0 = { \"target-cpu\"=\"znver2\" }\n```\n\nReproducer: https://godbolt.org/z/4PPzsMbP3\n\nStack dump:\n```\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:4570: llvm::slpvectorizer::BoUpSLP::~BoUpSLP(): Assertion `I->use_empty() && \"trying to erase instruction with users.\"' 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 \n1.\tRunning pass \"function(slp-vectorizer)\" on module \"\"\n2.\tRunning pass \"slp-vectorizer\" on function \"wombat\"\n #0 0x00000000054546a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x54546a8)\n #1 0x0000000005452064 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x00007b5c5f242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x00007b5c5f2969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x00007b5c5f242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x00007b5c5f2287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x00007b5c5f22871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #7 0x00007b5c5f239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #8 0x000000000440d177 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x440d177)\n #9 0x00000000044d46ae 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#10 0x00000000044d50cb llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44d50cb)\n#11 0x000000000318a35e llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x318a35e)\n#12 0x000000000524e9e0 llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x524e9e0)\n#13 0x0000000000e6f88e llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe6f88e)\n#14 0x000000000524d2fb llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x524d2fb)\n#15 0x0000000000e6eb7e llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe6eb7e)\n#16 0x000000000524cd00 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x524cd00)\n#17 0x0000000000935e7a llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::ArrayRef>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x935e7a)\n#18 0x00000000009294ec optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9294ec)\n#19 0x00007b5c5f229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#20 0x00007b5c5f229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#21 0x0000000000920dc5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x920dc5)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```", "author": "TatyanaDoubts", "labels": ["llvm:SLPVectorizer", "crash"], "comments": []}, "verified": true} +{"bug_id": "128736", "issue_url": "https://github.com/llvm/llvm-project/issues/128736", "bug_type": "crash", "base_commit": "02128342d2818e5a65846fec4179ed5344045102", "knowledge_cutoff": "2025-02-25T16:27:23Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "39bab1de33333ee3c62b586c4e8d26f8c443bc60", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[1389, 1397], [2849, 2859], [2915, 2926], [16466, 16474], [17075, 17081], [20449, 20456], [20678, 20684]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["BoUpSLP::vectorizeTree", "removeInstructionsAndOperands", "tryToReduce"]}}, "patch": "commit 39bab1de33333ee3c62b586c4e8d26f8c443bc60\nAuthor: Alexey Bataev \nDate: Wed Feb 26 14:12:05 2025 -0800\n\n [SLP]Check if the operand for removal is the reduction operand, awaiting for the reduction\n \n If the operand of the instruction-to-be-removed is a reduction value,\n which is not reduced yet, and, thus, it has no users, it may be removed\n during operands analysis.\n \n Fixes #128736\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex b25b09306aca..e8c91ebd508c 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -1389,9 +1389,10 @@ public:\n /// Vectorize the tree but with the list of externally used values \\p\n /// ExternallyUsedValues. Values in this MapVector can be replaced but the\n /// generated extractvalue instructions.\n- Value *\n- vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues,\n- Instruction *ReductionRoot = nullptr);\n+ Value *vectorizeTree(\n+ const ExtraValueToDebugLocsMap &ExternallyUsedValues,\n+ Instruction *ReductionRoot = nullptr,\n+ ArrayRef> VectorValuesAndScales = {});\n \n /// \\returns the cost incurred by unwanted spills and fills, caused by\n /// holding live values over call sites.\n@@ -2849,11 +2850,13 @@ public:\n /// Remove instructions from the parent function and clear the operands of \\p\n /// DeadVals instructions, marking for deletion trivially dead operands.\n template \n- void removeInstructionsAndOperands(ArrayRef DeadVals) {\n+ void removeInstructionsAndOperands(\n+ ArrayRef DeadVals,\n+ ArrayRef> VectorValuesAndScales) {\n SmallVector DeadInsts;\n for (T *V : DeadVals) {\n auto *I = cast(V);\n- DeletedInstructions.insert(I);\n+ eraseInstruction(I);\n }\n DenseSet Processed;\n for (T *V : DeadVals) {\n@@ -2915,12 +2918,17 @@ public:\n // loop iteration.\n if (auto *OpI = dyn_cast(OpV))\n if (!DeletedInstructions.contains(OpI) &&\n+ (!OpI->getType()->isVectorTy() ||\n+ none_of(VectorValuesAndScales,\n+ [&](const std::tuple &V) {\n+ return std::get<0>(V) == OpI;\n+ })) &&\n isInstructionTriviallyDead(OpI, TLI))\n DeadInsts.push_back(OpI);\n }\n \n VI->removeFromParent();\n- DeletedInstructions.insert(VI);\n+ eraseInstruction(VI);\n SE->forgetValue(VI);\n }\n }\n@@ -16466,9 +16474,10 @@ Value *BoUpSLP::vectorizeTree() {\n return vectorizeTree(ExternallyUsedValues);\n }\n \n-Value *\n-BoUpSLP::vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues,\n- Instruction *ReductionRoot) {\n+Value *BoUpSLP::vectorizeTree(\n+ const ExtraValueToDebugLocsMap &ExternallyUsedValues,\n+ Instruction *ReductionRoot,\n+ ArrayRef> VectorValuesAndScales) {\n // All blocks must be scheduled before any instructions are inserted.\n for (auto &BSIter : BlocksSchedules) {\n scheduleBlock(BSIter.second.get());\n@@ -17075,7 +17084,7 @@ BoUpSLP::vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues,\n // cache correctness.\n // NOTE: removeInstructionAndOperands only marks the instruction for deletion\n // - instructions are not deleted until later.\n- removeInstructionsAndOperands(ArrayRef(RemovedInsts));\n+ removeInstructionsAndOperands(ArrayRef(RemovedInsts), VectorValuesAndScales);\n \n Builder.ClearInsertionPoint();\n InstrElementSize.clear();\n@@ -20449,8 +20458,8 @@ public:\n InsertPt = GetCmpForMinMaxReduction(RdxRootInst);\n \n // Vectorize a tree.\n- Value *VectorizedRoot =\n- V.vectorizeTree(LocalExternallyUsedValues, InsertPt);\n+ Value *VectorizedRoot = V.vectorizeTree(\n+ LocalExternallyUsedValues, InsertPt, VectorValuesAndScales);\n // Update TrackedToOrig mapping, since the tracked values might be\n // updated.\n for (Value *RdxVal : Candidates) {\n@@ -20678,7 +20687,7 @@ public:\n Ignore->replaceAllUsesWith(P);\n }\n }\n- V.removeInstructionsAndOperands(RdxOps);\n+ V.removeInstructionsAndOperands(RdxOps, VectorValuesAndScales);\n }\n } else if (!CheckForReusedReductionOps) {\n for (ReductionOpsType &RdxOps : ReductionOps)\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/X86/reduction-with-removed-extracts.ll", "commands": ["opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -mcpu=znver2 < %s"], "tests": [{"test_name": "", "test_body": "\ndefine i32 @test(i32 %arg) {\n;\nbb:\n br label %bb1\n\nbb1:\n %phi = phi i32 [ 0, %bb ], [ %mul37, %bb1 ]\n %mul = mul i64 0, 0\n %trunc = trunc i64 %mul to i32\n %or = or i32 0, %trunc\n %or2 = or i32 0, %or\n %or3 = or i32 %or2, 0\n %mul4 = mul i32 0, %or3\n %mul5 = mul i32 %or3, 0\n %mul6 = mul i32 %mul5, %mul4\n %mul7 = mul i32 %mul6, %mul4\n %mul8 = mul i32 %mul7, %or3\n %mul9 = mul i64 0, 0\n %trunc10 = trunc i64 %mul9 to i32\n %or11 = or i32 0, %trunc10\n %or12 = or i32 %arg, %or11\n %or13 = or i32 %or12, 0\n %mul14 = mul i32 %or13, %mul8\n %mul15 = mul i32 %mul14, 0\n %mul16 = mul i32 %mul15, 0\n %mul17 = mul i32 %mul16, %or13\n %shl = shl i64 0, 0\n %mul18 = mul i64 %shl, 0\n %trunc19 = trunc i64 %mul18 to i32\n %or20 = or i32 0, %trunc19\n %or21 = or i32 0, %or20\n %or22 = or i32 %or21, 0\n %mul23 = mul i32 %or22, %mul17\n %mul24 = mul i32 %mul23, 0\n %mul25 = mul i32 %mul24, 0\n %mul26 = mul i32 %mul25, %or22\n %shl27 = shl i64 0, 0\n %mul28 = mul i64 %shl27, 0\n %trunc29 = trunc i64 %mul28 to i32\n %or30 = or i32 0, %trunc29\n %or31 = or i32 0, %or30\n %or32 = or i32 %or31, 0\n %mul33 = mul i32 0, %or32\n %mul34 = mul i32 %or32, %mul26\n %mul35 = mul i32 %mul34, %mul33\n %mul36 = mul i32 %mul35, %mul33\n %mul37 = mul i32 %mul36, %or32\n br label %bb1\n}"}]}], "issue": {"title": "Assertion `I->use_empty() && \"trying to erase instruction with users.\"' failed.", "body": "To reproduce run opt with the test below using -passes=slp-vectorizer.\n```\n; ModuleID = './reduced.ll'\nsource_filename = \"./reduced.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-ni:1-p2:32:8:8:32-ni:2\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i32 @wombat(i32 %arg) #0 gc \"statepoint-example\" {\nbb:\n br label %bb1\n \nbb1: ; preds = %bb1, %bb\n %phi = phi i32 [ 0, %bb ], [ %mul37, %bb1 ]\n %mul = mul i64 0, 0\n %trunc = trunc i64 %mul to i32\n %or = or i32 0, %trunc\n %or2 = or i32 0, %or\n %or3 = or i32 %or2, 0\n %mul4 = mul i32 0, %or3\n %mul5 = mul i32 %or3, 0\n %mul6 = mul i32 %mul5, %mul4\n %mul7 = mul i32 %mul6, %mul4\n %mul8 = mul i32 %mul7, %or3\n %mul9 = mul i64 0, 0\n %trunc10 = trunc i64 %mul9 to i32\n %or11 = or i32 0, %trunc10\n %or12 = or i32 %arg, %or11\n %or13 = or i32 %or12, 0\n %mul14 = mul i32 %or13, %mul8\n %mul15 = mul i32 %mul14, 0\n %mul16 = mul i32 %mul15, 0\n %mul17 = mul i32 %mul16, %or13\n %shl = shl i64 0, 0\n %mul18 = mul i64 %shl, 0\n %trunc19 = trunc i64 %mul18 to i32\n %or20 = or i32 0, %trunc19\n %or21 = or i32 0, %or20\n %or22 = or i32 %or21, 0\n %mul23 = mul i32 %or22, %mul17\n %mul24 = mul i32 %mul23, 0\n %mul25 = mul i32 %mul24, 0\n %mul26 = mul i32 %mul25, %or22\n %shl27 = shl i64 0, 0\n %mul28 = mul i64 %shl27, 0\n %trunc29 = trunc i64 %mul28 to i32\n %or30 = or i32 0, %trunc29\n %or31 = or i32 0, %or30\n %or32 = or i32 %or31, 0\n %mul33 = mul i32 0, %or32\n %mul34 = mul i32 %or32, %mul26\n %mul35 = mul i32 %mul34, %mul33\n %mul36 = mul i32 %mul35, %mul33\n %mul37 = mul i32 %mul36, %or32\n br label %bb1\n}\n\nattributes #0 = { \"target-cpu\"=\"znver2\" }\n```\n\nReproducer: https://godbolt.org/z/4PPzsMbP3\n\nStack dump:\n```\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:4570: llvm::slpvectorizer::BoUpSLP::~BoUpSLP(): Assertion `I->use_empty() && \"trying to erase instruction with users.\"' 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 \n1.\tRunning pass \"function(slp-vectorizer)\" on module \"\"\n2.\tRunning pass \"slp-vectorizer\" on function \"wombat\"\n #0 0x00000000054546a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x54546a8)\n #1 0x0000000005452064 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x00007b5c5f242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x00007b5c5f2969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x00007b5c5f242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x00007b5c5f2287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x00007b5c5f22871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #7 0x00007b5c5f239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #8 0x000000000440d177 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x440d177)\n #9 0x00000000044d46ae 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#10 0x00000000044d50cb llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44d50cb)\n#11 0x000000000318a35e llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x318a35e)\n#12 0x000000000524e9e0 llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x524e9e0)\n#13 0x0000000000e6f88e llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe6f88e)\n#14 0x000000000524d2fb llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x524d2fb)\n#15 0x0000000000e6eb7e llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe6eb7e)\n#16 0x000000000524cd00 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x524cd00)\n#17 0x0000000000935e7a llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::ArrayRef>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x935e7a)\n#18 0x00000000009294ec optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9294ec)\n#19 0x00007b5c5f229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#20 0x00007b5c5f229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#21 0x0000000000920dc5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x920dc5)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```", "author": "TatyanaDoubts", "labels": ["llvm:SLPVectorizer", "crash"], "comments": []}, "verified": true} {"bug_id": "109376", "issue_url": "https://github.com/llvm/llvm-project/issues/109376", "bug_type": "crash", "base_commit": "1c47fa9b620d0abb280647b4f361ada43784d00e", "knowledge_cutoff": "2024-09-20T05:30:57Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "3db0f8c895d4e814a18b754f9afbb1e03bd839a5", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[18668, 18673]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["tryToReduce"]}}, "patch": "commit 3db0f8c895d4e814a18b754f9afbb1e03bd839a5\nAuthor: Alexey Bataev \nDate: Mon Sep 23 10:49:54 2024 -0700\n\n [SLP]Update TrackedToOrig mappings after reduction vectorization\n \n Need to update mappings in TrackedToOrig to correctly provide mapping\n between updated reduced value after vectorization and its original\n value, otherwise the compiler might miss this update and it may cause\n compiler crash later, when it tries to find the original instruction\n mapping for the updated value.\n \n Fixes https://github.com/llvm/llvm-project/issues/109376\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex a88702b81096..04b8fc09a724 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -18668,6 +18668,14 @@ public:\n // Vectorize a tree.\n Value *VectorizedRoot =\n V.vectorizeTree(LocalExternallyUsedValues, InsertPt);\n+ // Update TrackedToOrig mapping, since the tracked values might be\n+ // updated.\n+ for (Value *RdxVal : Candidates) {\n+ Value *OrigVal = TrackedToOrig.at(RdxVal);\n+ Value *TransformedRdxVal = TrackedVals.at(OrigVal);\n+ if (TransformedRdxVal != RdxVal)\n+ TrackedToOrig.try_emplace(TransformedRdxVal, OrigVal);\n+ }\n \n Builder.SetInsertPoint(InsertPt);\n \n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/X86/reduced-value-vectorized-later.ll", "commands": ["opt -S -passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s"], "tests": [{"test_name": "test", "test_body": "define i16 @test() {\nentry:\n %subi = add i16 0, 0\n %sub40.i = add i16 %subi, 0\n %sub41.i = add i16 %subi, 0\n %sub42.i = add i16 %subi, 0\n %sub43.i = add i16 %subi, 0\n %sub44.i = add i16 %subi, 0\n %sub45.i = add i16 %subi, 0\n %sub46.i = add i16 0, 0\n %sub47.i = add i16 0, 0\n %sub48.i = add i16 0, 0\n %sub49.i = add i16 0, 0\n %or40.i = or i16 %sub40.i, %sub41.i\n %or41.i = or i16 %or40.i, %sub42.i\n %or42.i = or i16 %or41.i, %sub43.i\n %or43.i = or i16 %or42.i, %sub44.i\n %or44.i = or i16 %or43.i, %sub45.i\n %or45.i = or i16 %or44.i, %sub46.i\n %or46.i = or i16 %or45.i, %sub47.i\n %or47.i = or i16 %or46.i, %sub48.i\n %or48.i = or i16 %or47.i, %sub49.i\n %or50.i = or i16 %or48.i, %subi\n %subii = add i16 0, 0\n %subi16.i = add i16 %subii, 0\n %subi17.i = add i16 %subii, 0\n %0 = or i16 %subi16.i, %subi17.i\n %1 = or i16 %0, %or50.i\n ret i16 %1\n}\n"}]}], "issue": {"title": "[SLPVectorizer] Assertion `Iter != this->end() && \"DenseMap::at failed due to a missing key\"' failed.", "body": "Reproducer: https://godbolt.org/z/v5bqhPWqb\r\n```\r\n; bin/opt -passes=slp-vectorizer reduced.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 i16 @test() {\r\nentry:\r\n %sub.i487.i.reass.i = add i16 0, 0\r\n %sub.i487.i.reass.40.i = add i16 %sub.i487.i.reass.i, 0\r\n %sub.i487.i.reass.41.i = add i16 %sub.i487.i.reass.i, 0\r\n %sub.i487.i.reass.42.i = add i16 %sub.i487.i.reass.i, 0\r\n %sub.i487.i.reass.43.i = add i16 %sub.i487.i.reass.i, 0\r\n %sub.i487.i.reass.44.i = add i16 %sub.i487.i.reass.i, 0\r\n %sub.i487.i.reass.45.i = add i16 %sub.i487.i.reass.i, 0\r\n %sub.i487.i.reass.46.i = add i16 0, 0\r\n %sub.i487.i.reass.47.i = add i16 0, 0\r\n %sub.i487.i.reass.48.i = add i16 0, 0\r\n %sub.i487.i.reass.49.i = add i16 0, 0\r\n %or374461.i.40.i = or i16 %sub.i487.i.reass.40.i, %sub.i487.i.reass.41.i\r\n %or374461.i.41.i = or i16 %or374461.i.40.i, %sub.i487.i.reass.42.i\r\n %or374461.i.42.i = or i16 %or374461.i.41.i, %sub.i487.i.reass.43.i\r\n %or374461.i.43.i = or i16 %or374461.i.42.i, %sub.i487.i.reass.44.i\r\n %or374461.i.44.i = or i16 %or374461.i.43.i, %sub.i487.i.reass.45.i\r\n %or374461.i.45.i = or i16 %or374461.i.44.i, %sub.i487.i.reass.46.i\r\n %or374461.i.46.i = or i16 %or374461.i.45.i, %sub.i487.i.reass.47.i\r\n %or374461.i.47.i = or i16 %or374461.i.46.i, %sub.i487.i.reass.48.i\r\n %or374461.i.48.i = or i16 %or374461.i.47.i, %sub.i487.i.reass.49.i\r\n %or374461.i.50.i = or i16 %or374461.i.48.i, %sub.i487.i.reass.i\r\n %sub.i487.i96.reass.i = add i16 0, 0\r\n %sub.i487.i96.reass.16.i = add i16 %sub.i487.i96.reass.i, 0\r\n %sub.i487.i96.reass.17.i = add i16 %sub.i487.i96.reass.i, 0\r\n %0 = or i16 %sub.i487.i96.reass.16.i, %sub.i487.i96.reass.17.i\r\n %1 = or i16 %0, %or374461.i.50.i\r\n ret i16 %1\r\n}\r\n```\r\n```\r\nopt: /root/llvm-project/llvm/include/llvm/ADT/DenseMap.h:204: const ValueT& llvm::DenseMapBase::at(llvm::DenseMapBase::const_arg_type_t) const [with DerivedT = llvm::DenseMap; KeyT = llvm::Value*; ValueT = llvm::Value*; KeyInfoT = llvm::DenseMapInfo; BucketT = llvm::detail::DenseMapPair; llvm::DenseMapBase::const_arg_type_t = const llvm::Value*]: Assertion `Iter != this->end() && \"DenseMap::at failed due to a missing key\"' 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 \r\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"\"\r\n2.\tRunning pass \"slp-vectorizer\" on function \"test\"\r\n #0 0x0000000005035d68 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5035d68)\r\n #1 0x00000000050334ac SignalHandler(int) Signals.cpp:0:0\r\n #2 0x0000707bdcc42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x0000707bdcc969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x0000707bdcc42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x0000707bdcc287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x0000707bdcc2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x0000707bdcc39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x000000000409326e llvm::DenseMapBase, llvm::detail::DenseMapPair>, llvm::Value*, llvm::Value*, llvm::DenseMapInfo, llvm::detail::DenseMapPair>::at(llvm::Value const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x409326e)\r\n #9 0x000000000413473f (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\r\n#10 0x00000000041370d1 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::SmallVectorImpl&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41370d1)\r\n#11 0x000000000413b996 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*) (.constprop.0) SLPVectorizer.cpp:0:0\r\n#12 0x000000000413ff36 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x413ff36)\r\n#13 0x0000000004146401 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#14 0x000000000414708b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x414708b)\r\n#15 0x0000000002f1a1ae llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2f1a1ae)\r\n#16 0x0000000004e38158 llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e38158)\r\n#17 0x0000000000e0b02e llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe0b02e)\r\n#18 0x0000000004e36b7e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e36b7e)\r\n#19 0x0000000000e0a83e llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe0a83e)\r\n#20 0x0000000004e365b0 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e365b0)\r\n#21 0x00000000008feef2 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::ArrayRef>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8feef2)\r\n#22 0x00000000008f1d7c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f1d7c)\r\n#23 0x0000707bdcc29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#24 0x0000707bdcc29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#25 0x00000000008e984e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8e984e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```\r\nllvm version: e8a739062490ce1bb30974f216ba187cd7b5a2a4", "author": "dtcxzyw", "labels": ["llvm:SLPVectorizer", "crash-on-valid"], "comments": []}, "verified": true} {"bug_id": "88297", "issue_url": "https://github.com/llvm/llvm-project/issues/88297", "bug_type": "crash", "base_commit": "9ec6c5d26321f5d32d97218f850ae7cafda32b2e", "knowledge_cutoff": "2024-04-10T16:52:41Z", "lit_test_dir": ["llvm/test/Transforms/LoopVectorize"], "hints": {"fix_commit": "34777c238b117b52dd41a9d12e8b54fb83677a12", "components": ["LoopVectorize"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/VPlanValue.h": [[361, 368], [376, 382]]}, "bug_location_funcname": {}}, "patch": "commit 34777c238b117b52dd41a9d12e8b54fb83677a12\nAuthor: Florian Hahn \nDate: Tue Apr 16 21:24:24 2024 +0100\n\n [VPlan] Don't mark VPBlendRecipe as phi-like.\n \n VPBlendRecipes don't get lowered to phis and usually do not appear at\n the beginning of blocks, due to their masks appearing before them.\n \n This effectively relaxes an over-eager verifier message.\n \n Fixes https://github.com/llvm/llvm-project/issues/88297.\n Fixes https://github.com/llvm/llvm-project/issues/88804.\n\ndiff --git a/llvm/lib/Transforms/Vectorize/VPlanValue.h b/llvm/lib/Transforms/Vectorize/VPlanValue.h\nindex da3a768552fc..3f8d4f4fe7d6 100644\n--- a/llvm/lib/Transforms/Vectorize/VPlanValue.h\n+++ b/llvm/lib/Transforms/Vectorize/VPlanValue.h\n@@ -361,8 +361,8 @@ public:\n VPWidenMemoryInstructionSC,\n VPWidenSC,\n VPWidenSelectSC,\n- // START: Phi-like recipes. Need to be kept together.\n VPBlendSC,\n+ // START: Phi-like recipes. Need to be kept together.\n VPWidenPHISC,\n VPPredInstPHISC,\n // START: SubclassID for recipes that inherit VPHeaderPHIRecipe.\n@@ -376,7 +376,7 @@ public:\n VPReductionPHISC,\n // END: SubclassID for recipes that inherit VPHeaderPHIRecipe\n // END: Phi-like recipes\n- VPFirstPHISC = VPBlendSC,\n+ VPFirstPHISC = VPWidenPHISC,\n VPFirstHeaderPHISC = VPCanonicalIVPHISC,\n VPLastHeaderPHISC = VPReductionPHISC,\n VPLastPHISC = VPReductionPHISC,\n", "tests": [{"file": "llvm/test/Transforms/LoopVectorize/blend-in-header.ll", "commands": ["opt -p loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S %s"], "tests": [{"test_name": "", "test_body": "\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\"\n\n; Test with blend recipe in header VPBB, from\n; https://github.com/llvm/llvm-project/issues/88297.\ndefine i64 @pr88297() {\n;\nentry:\n br label %loop.header\n\nloop.header:\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]\n br i1 false, label %loop.latch, label %then\n\nthen:\n br label %loop.latch\n\nloop.latch:\n %r = phi i64 [ 1, %then ], [ 0, %loop.header ]\n %iv.next = add i32 %iv, 1\n %icmp = icmp sgt i32 %iv, 1000\n br i1 %icmp, label %exit, label %loop.header\n\nexit:\n %r.lcssa = phi i64 [ %r, %loop.latch ]\n ret i64 %r.lcssa\n}\n\ndefine i64 @pr88297_incoming_ops_reordered() {\n;\nentry:\n br label %loop.header\n\nloop.header:\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]\n br i1 false, label %loop.latch, label %then\n\nthen:\n br label %loop.latch\n\nloop.latch:\n %r = phi i64 [ 0, %loop.header ], [ 1, %then ]\n %iv.next = add i32 %iv, 1\n %icmp = icmp sgt i32 %iv, 1000\n br i1 %icmp, label %exit, label %loop.header\n\nexit:\n %r.lcssa = phi i64 [ %r, %loop.latch ]\n ret i64 %r.lcssa\n}\n\ndefine i64 @invar_cond(i1 %c) {\n;\nentry:\n br label %loop.header\n\nloop.header:\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]\n br i1 %c, label %loop.latch, label %then\n\nthen:\n br label %loop.latch\n\nloop.latch:\n %r = phi i64 [ 1, %then ], [ 0, %loop.header ]\n %iv.next = add i32 %iv, 1\n %icmp = icmp sgt i32 %iv, 1000\n br i1 %icmp, label %exit, label %loop.header\n\nexit:\n %r.lcssa = phi i64 [ %r, %loop.latch ]\n ret i64 %r.lcssa\n}\n\ndefine i64 @invar_cond_incoming_ops_reordered(i1 %c) {\n;\nentry:\n br label %loop.header\n\nloop.header:\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]\n br i1 %c, label %loop.latch, label %then\n\nthen:\n br label %loop.latch\n\nloop.latch:\n %r = phi i64 [ 0, %loop.header ], [ 1, %then ]\n %iv.next = add i32 %iv, 1\n %icmp = icmp sgt i32 %iv, 1000\n br i1 %icmp, label %exit, label %loop.header\n\nexit:\n %r.lcssa = phi i64 [ %r, %loop.latch ]\n ret i64 %r.lcssa\n}\n;.\n;."}]}], "issue": {"title": "Assertion `verifyVPlanIsValid(*Plan) && \"VPlan is invalid\"' failed", "body": "The following test fails when run opt with -passes loop-vectorize\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() gc \"statepoint-example\" {\r\nbb:\r\n br label %bb1\r\n\r\nbb1: ; preds = %bb2, %bb\r\n %phi = phi i32 [ %add, %bb2 ], [ 0, %bb ]\r\n br i1 false, label %bb2, label %bb4\r\n\r\nbb2: ; preds = %bb4, %bb1\r\n %phi3 = phi i64 [ 1, %bb4 ], [ 0, %bb1 ]\r\n %add = add i32 %phi, 1\r\n %icmp = icmp sgt i32 %phi, 0\r\n br i1 %icmp, label %bb5, label %bb1\r\n\r\nbb4: ; preds = %bb1\r\n br label %bb2\r\n\r\nbb5: ; preds = %bb2\r\n %phi6 = phi i64 [ %phi3, %bb2 ]\r\n ret void\r\n}\r\n```\r\nReproducer https://godbolt.org/z/9YW1o7qo6\r\nStack dump:\r\n```\r\nFound non-header PHI recipe in header VPBB: BLEND ir<%phi3> = ir<1> ir<0>/ir\r\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:8555: void llvm::LoopVectorizationPlanner::buildVPlansWithVPRecipes(llvm::ElementCount, llvm::ElementCount): Assertion `verifyVPlanIsValid(*Plan) && \"VPlan is invalid\"' 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 loop-vectorize \r\n #0 0x0000000004d05ee8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d05ee8)\r\n #1 0x0000000004d0363c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007f7623242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007f76232969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007f7623242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007f76232287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00007f762322871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x00007f7623239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x0000000003de70b8 llvm::LoopVectorizationPlanner::buildVPlansWithVPRecipes(llvm::ElementCount, llvm::ElementCount) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3de70b8)\r\n #9 0x0000000003dee731 llvm::LoopVectorizationPlanner::plan(llvm::ElementCount, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3dee731)\r\n#10 0x0000000003df18fe llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3df18fe)\r\n#11 0x0000000003df4c6d 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+0x3df4c6d)\r\n#12 0x0000000003df5e7b llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3df5e7b)\r\n#13 0x0000000002d67f0e llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2d67f0e)\r\n#14 0x0000000000db3554 llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xdb3554)\r\n#15 0x0000000004b1663e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4b1663e)\r\n#16 0x0000000000d97cce llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xd97cce)\r\n#17 0x0000000004b1454c llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4b1454c)\r\n#18 0x00000000008c74f2 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::ArrayRef>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8c74f2)\r\n#19 0x00000000008bad45 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8bad45)\r\n#20 0x00007f7623229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#21 0x00007f7623229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#22 0x00000000008b1aee _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8b1aee)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "TatyanaDoubts", "labels": ["vectorizers", "crash"], "comments": []}, "verified": true} {"bug_id": "110295", "issue_url": "https://github.com/llvm/llvm-project/issues/110295", "bug_type": "crash", "base_commit": "51e0a997ca607f64beafb838ba1325f0465eecd4", "knowledge_cutoff": "2024-09-27T16:39:37Z", "lit_test_dir": ["llvm/test/Transforms/LoopVectorize"], "hints": {"fix_commit": "2c8836c899015cce49a399a6bc47b260a24a22e7", "components": ["LoopVectorize"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [[6539, 6546]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": ["LoopVectorizationCostModel::getInstructionCost"]}}, "patch": "commit 2c8836c899015cce49a399a6bc47b260a24a22e7\nAuthor: Florian Hahn \nDate: Sun Sep 29 20:31:23 2024 +0100\n\n [LV] Don't consider predicated insts as invariant unconditionally in CM.\n \n Predicated instructions cannot hoisted trivially, so don't treat them as\n uniform value in the cost model.\n \n This fixes a difference between legacy and VPlan-based cost model.\n \n Fixes https://github.com/llvm/llvm-project/issues/110295.\n\ndiff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\nindex cb346be8ffe5..792e0e17dd87 100644\n--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n@@ -6539,8 +6539,16 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I,\n Op2 = cast(PSE.getSCEV(Op2))->getValue();\n }\n auto Op2Info = TTI.getOperandInfo(Op2);\n- if (Op2Info.Kind == TargetTransformInfo::OK_AnyValue &&\n- Legal->isInvariant(Op2))\n+ auto IsInvariant = [this](Value *Op) {\n+ if (!Legal->isInvariant(Op))\n+ return false;\n+ // Consider Op2 invariant, if it is not a predicated instruction in the\n+ // loop. In that case, it is not trivially hoistable.\n+ return !isa(Op) ||\n+ !TheLoop->contains(cast(Op)) ||\n+ !isPredicatedInst(cast(Op));\n+ };\n+ if (Op2Info.Kind == TargetTransformInfo::OK_AnyValue && IsInvariant(Op2))\n Op2Info.Kind = TargetTransformInfo::OK_UniformValue;\n \n SmallVector Operands(I->operand_values());\n", "tests": [{"file": "llvm/test/Transforms/LoopVectorize/X86/predicated-instruction-cost.ll", "commands": ["opt -p loop-vectorize -S %s"], "tests": [{"test_name": "predicated_urem_shl_cost", "test_body": "target 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\ndefine void @predicated_urem_shl_cost(ptr %A, i32 %x, i1 %c) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ]\n %gep = getelementptr inbounds i32, ptr %A, i32 %iv\n %l = load i32, ptr %gep, align 4\n br i1 %c, label %then, label %loop.latch\n\nthen: ; preds = %loop.header\n %rem = urem i32 2, %x\n %shl = shl i32 %l, %rem\n br label %loop.latch\n\nloop.latch: ; preds = %then, %loop.header\n %p = phi i32 [ 0, %loop.header ], [ %shl, %then ]\n store i32 %p, ptr %gep, align 4\n %iv.next = add i32 %iv, 1\n %ec = icmp eq i32 %iv, 0\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret void\n}\n"}]}], "issue": {"title": "clang crashes at -O{2,3} on x86_64-linux-gnu: Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), CostCtx, OrigLoop)) && \" VPlan cost model and legacy cost model disagreed\"' failed ", "body": "Compiler Explorer: https://godbolt.org/z/YhKsza3dx\r\n\r\nRelated to https://github.com/llvm/llvm-project/issues/108697, but it doesn't seem to trigger anymore with the latest build.\r\n\r\n```\r\n[519] % clangtk -v\r\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git 631bcbe9de13e160d427ad7452a7ef2ca67911ab)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /local/suz-local/software/local/clang-trunk/bin\r\nBuild config: +assertions\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9\r\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\r\nCandidate multilib: .;@m64\r\nSelected multilib: .;@m64\r\n[520] % \r\n[520] % clangtk -O2 small.c\r\nclang-20: /local/suz-local/software/clangbuild/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7380: 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, preprocessed source, and associated run script.\r\nStack dump:\r\n0.\tProgram arguments: /local/suz-local/software/local/clang-trunk/bin/clang-20 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name small.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/local/suz-local/software/emitesting/bugs/20240927-clangtk-m64-O3-build-064435/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/20240927-clangtk-m64-O3-build-064435/delta -resource-dir /local/suz-local/software/local/clang-trunk/lib/clang/20 -I /usr/local/include -I /local/suz-local/software/local/include -internal-isystem /local/suz-local/software/local/clang-trunk/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/small-c6819e.o -x c small.c\r\n1.\t parser at end of file\r\n2.\tOptimizer\r\n3.\tRunning pass \"function(float2int,lower-constant-intrinsics,loop(loop-rotate,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize,infer-alignment,loop-load-elim,instcombine,simplifycfg,slp-vectorizer,vector-combine,instcombine,loop-unroll,transform-warning,sroa,infer-alignment,instcombine,loop-mssa(licm),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg)\" on module \"small.c\"\r\n4.\tRunning pass \"loop-vectorize\" on function \"main\"\r\n #0 0x0000560d31f97bef llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x43b3bef)\r\n #1 0x0000560d31f953c4 SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007f3f4386e420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\r\n #3 0x00007f3f432a500b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\r\n #4 0x00007f3f43284859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\r\n #5 0x00007f3f43284729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\r\n #6 0x00007f3f43284729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\r\n #7 0x00007f3f43295fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\r\n #8 0x0000560d3393ac39 llvm::LoopVectorizationPlanner::computeBestVF() (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5d56c39)\r\n #9 0x0000560d3395443b llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5d7043b)\r\n#10 0x0000560d33957301 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5d73301)\r\n#11 0x0000560d33957973 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5d73973)\r\n#12 0x0000560d334c3406 llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x58df406)\r\n#13 0x0000560d31924a81 llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x3d40a81)\r\n#14 0x0000560d2f43df76 llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x1859f76)\r\n#15 0x0000560d319233ed llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x3d3f3ed)\r\n#16 0x0000560d2f43cb56 llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x1858b56)\r\n#17 0x0000560d31922e21 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x3d3ee21)\r\n#18 0x0000560d322504b3 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr>&, std::unique_ptr>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\r\n#19 0x0000560d32253a88 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr, std::unique_ptr>, clang::BackendConsumer*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x466fa88)\r\n#20 0x0000560d3293154c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4d4d54c)\r\n#21 0x0000560d347d56cc clang::ParseAST(clang::Sema&, bool, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x6bf16cc)\r\n#22 0x0000560d32931968 clang::CodeGenAction::ExecuteAction() (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4d4d968)\r\n#23 0x0000560d32bf9249 clang::FrontendAction::Execute() (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5015249)\r\n#24 0x0000560d32b752fe clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4f912fe)\r\n#25 0x0000560d32ce5926 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5101926)\r\n#26 0x0000560d2f004695 cc1_main(llvm::ArrayRef, char const*, void*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x1420695)\r\n#27 0x0000560d2effc1aa ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&) driver.cpp:0:0\r\n#28 0x0000560d2f000bde clang_main(int, char**, llvm::ToolContext const&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x141cbde)\r\n#29 0x0000560d2eeed47b main (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x130947b)\r\n#30 0x00007f3f43286083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\r\n#31 0x0000560d2effbc3e _start (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x1417c3e)\r\nclangtk: error: unable to execute command: Aborted\r\nclangtk: error: clang frontend command failed due to signal (use -v to see invocation)\r\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git 631bcbe9de13e160d427ad7452a7ef2ca67911ab)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /local/suz-local/software/local/clang-trunk/bin\r\nBuild config: +assertions\r\nclangtk: note: diagnostic msg: \r\n********************\r\n\r\nPLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:\r\nPreprocessed source(s) and associated run script(s) are located at:\r\nclangtk: note: diagnostic msg: /tmp/small-49ab95.c\r\nclangtk: note: diagnostic msg: /tmp/small-49ab95.sh\r\nclangtk: note: diagnostic msg: \r\n\r\n********************\r\n[521] % \r\n[521] % cat small.c\r\nint a, b, c, e, f, i, g, h, k, l, m;\r\nunsigned d;\r\nvolatile int j;\r\nint n(short o) { return o ? a % o : 0; }\r\nint main() {\r\n short q;\r\n if (h)\r\n while (1)\r\n ;\r\nr:\r\n e && j;\r\n if (a && j)\r\n goto r;\r\ns:\r\n while (g)\r\n if (l)\r\n goto s;\r\n for (; i; i++) {\r\n f = !d ? : 2 % d;\r\n q = f > 1 ? 0 : c << f;\r\n m = q;\r\n b = n(k ^ q);\r\n }\r\n return 0;\r\n}\r\n```\r\n", "author": "zhendongsu", "labels": ["regression", "vectorizers", "confirmed", "crash"], "comments": [{"author": "shafik", "body": "This looks like a regression in trunk: https://godbolt.org/z/c5Wxf5Teh\r\n\r\nI know godbolt does not have clang assertions build beyond trunk but you can use clang++ and just use `-x c` to check out if the assert exists in previous versions.\r\n\r\nCC @fhahn "}, {"author": "zhendongsu", "body": "> I know godbolt does not have clang assertions build beyond trunk but you can use clang++ and just use `-x c` to check out if the assert exists in previous versions.\r\n\r\n@shafik: Thanks for the tip!\r\n\r\n"}]}, "verified": true} @@ -191,7 +200,7 @@ {"bug_id": "122558", "issue_url": "https://github.com/llvm/llvm-project/issues/122558", "bug_type": "crash", "base_commit": "25f28ddd69ed2453726c0934ba6feea8ae6f10f8", "knowledge_cutoff": "2025-01-11T00:36:48Z", "lit_test_dir": ["llvm/test/Transforms/LoopVectorize"], "hints": {"fix_commit": "1de3dc7d23dd6b856efad3a3a04f2396328726d7", "components": ["LoopVectorize"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [[4052, 4058], [4064, 4069]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": ["LoopVectorizationCostModel::computeMaxVF"]}}, "patch": "commit 1de3dc7d23dd6b856efad3a3a04f2396328726d7\nAuthor: Florian Hahn \nDate: Tue Jan 14 22:07:38 2025 +0000\n\n [LV] Bail out early if BTC+1 wraps.\n \n Currently we fail to detect the case where BTC + 1 wraps, i.e. the\n vector trip count is 0, In those cases, the minimum iteration count\n check will fail, and the vector code will never be executed.\n \n Explicitly check for this condition in computeMaxVF and avoid trying to\n vectorize alltogether.\n \n Note that a number of tests needed to be updated, because the vector\n loop would never be executed given the input IR.\n \n Fixes https://github.com/llvm/llvm-project/issues/122558.\n\ndiff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\nindex 744faef19243..fe2fb5e9faae 100644\n--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n@@ -4052,7 +4052,8 @@ LoopVectorizationCostModel::computeMaxVF(ElementCount UserVF, unsigned UserIC) {\n return FixedScalableVFPair::getNone();\n }\n \n- unsigned TC = PSE.getSE()->getSmallConstantTripCount(TheLoop);\n+ ScalarEvolution *SE = PSE.getSE();\n+ unsigned TC = SE->getSmallConstantTripCount(TheLoop);\n unsigned MaxTC = PSE.getSmallConstantMaxTripCount();\n LLVM_DEBUG(dbgs() << \"LV: Found trip count: \" << TC << '\\n');\n if (TC != MaxTC)\n@@ -4064,6 +4065,22 @@ LoopVectorizationCostModel::computeMaxVF(ElementCount UserVF, unsigned UserIC) {\n return FixedScalableVFPair::getNone();\n }\n \n+ // If BTC matches the widest induction type and is -1 then the trip count\n+ // computation will wrap to 0 and the vector trip count will be 0. Do not try\n+ // to vectorize.\n+ const SCEV *BTC = SE->getBackedgeTakenCount(TheLoop);\n+ if (!isa(BTC) &&\n+ BTC->getType()->getScalarSizeInBits() >=\n+ Legal->getWidestInductionType()->getScalarSizeInBits() &&\n+ SE->isKnownPredicate(CmpInst::ICMP_EQ, BTC,\n+ SE->getMinusOne(BTC->getType()))) {\n+ reportVectorizationFailure(\n+ \"Trip count computation wrapped\",\n+ \"backedge-taken count is -1, loop trip count wrapped to 0\",\n+ \"TripCountWrapped\", ORE, TheLoop);\n+ return FixedScalableVFPair::getNone();\n+ }\n+\n switch (ScalarEpilogueStatus) {\n case CM_ScalarEpilogueAllowed:\n return computeFeasibleMaxVF(MaxTC, UserVF, false);\n", "tests": [{"file": "llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-dot-product-epilogue.ll", "commands": ["opt -mattr=+dotprod -passes=loop-vectorize -force-vector-interleave=1 -S < %s"], "tests": [{"test_name": "dotp", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @dotp(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-dot-product-mixed.ll", "commands": ["opt -passes=loop-vectorize -enable-epilogue-vectorization=false -mattr=+i8mm,+dotprod -S < %s", "opt -passes=loop-vectorize -enable-epilogue-vectorization=false -mattr=+dotprod -S < %s"], "tests": [{"test_name": "dotp_z_s", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @dotp_z_s(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = sext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n"}, {"test_name": "dotp_s_z", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @dotp_s_z(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = sext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-dot-product-neon.ll", "commands": ["opt -passes=loop-vectorize -enable-epilogue-vectorization=false -mattr=+neon,+dotprod -force-vector-interleave=1 -S < %s", "opt -passes=loop-vectorize -enable-epilogue-vectorization=false -mattr=+neon,+dotprod -S < %s", "opt -passes=loop-vectorize -enable-epilogue-vectorization=false -mattr=+neon,+dotprod -force-vector-interleave=1 -vectorizer-maximize-bandwidth -S < %s"], "tests": [{"test_name": "dotp_unrolled", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @dotp_unrolled(i32 %num_out, i64 %num_in, ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum3 = phi i32 [ 0, %entry ], [ %add.a3, %for.body ]\n %accum2 = phi i32 [ 0, %entry ], [ %add.a2, %for.body ]\n %accum1 = phi i32 [ 0, %entry ], [ %add.a1, %for.body ]\n %accum0 = phi i32 [ 0, %entry ], [ %add.a0, %for.body ]\n %gep.a0 = getelementptr inbounds i8, ptr %a, i64 %iv\n %gep.b0 = getelementptr inbounds i8, ptr %b, i64 %iv\n %offset.1 = or disjoint i64 %iv, 1\n %gep.a1 = getelementptr inbounds i8, ptr %a, i64 %offset.1\n %gep.b1 = getelementptr inbounds i8, ptr %b, i64 %offset.1\n %offset.2 = or disjoint i64 %iv, 2\n %gep.a2 = getelementptr inbounds i8, ptr %a, i64 %offset.2\n %gep.b2 = getelementptr inbounds i8, ptr %b, i64 %offset.2\n %offset.3 = or disjoint i64 %iv, 3\n %gep.a3 = getelementptr inbounds i8, ptr %a, i64 %offset.3\n %gep.b3 = getelementptr inbounds i8, ptr %b, i64 %offset.3\n %load.a0 = load i8, ptr %gep.a0, align 1\n %ext.a0 = sext i8 %load.a0 to i32\n %load.b0 = load i8, ptr %gep.b0, align 1\n %ext.b0 = sext i8 %load.b0 to i32\n %mul.a0 = mul nsw i32 %ext.b0, %ext.a0\n %add.a0 = add nsw i32 %mul.a0, %accum0\n %load.a1 = load i8, ptr %gep.a1, align 1\n %ext.a1 = sext i8 %load.a1 to i32\n %load.b1 = load i8, ptr %gep.b1, align 1\n %ext.b1 = sext i8 %load.b1 to i32\n %mul.a1 = mul nsw i32 %ext.a1, %ext.b1\n %add.a1 = add nsw i32 %mul.a1, %accum1\n %load.a2 = load i8, ptr %gep.a2, align 1\n %ext.a2 = sext i8 %load.a2 to i32\n %load.b2 = load i8, ptr %gep.b2, align 1\n %ext.b2 = sext i8 %load.b2 to i32\n %mul.a2 = mul nsw i32 %ext.a2, %ext.b2\n %add.a2 = add nsw i32 %mul.a2, %accum2\n %load.a3 = load i8, ptr %gep.a3, align 1\n %ext.a3 = sext i8 %load.a3 to i32\n %load.b3 = load i8, ptr %gep.b3, align 1\n %ext.b3 = sext i8 %load.b3 to i32\n %mul.a3 = mul nsw i32 %ext.a3, %ext.b3\n %add.a3 = add nsw i32 %mul.a3, %accum3\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, %num_in\n br i1 %exitcond.not, label %exit, label %for.body\n\nexit: ; preds = %for.body\n %result0 = add nsw i32 %add.a0, %add.a1\n %result1 = add nsw i32 %add.a2, %add.a3\n %result = add nsw i32 %result0, %result1\n ret i32 %result\n}\n"}, {"test_name": "dotp", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @dotp(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n"}, {"test_name": "not_dotp_predicated_pragma", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp_predicated_pragma(i64 %N, ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr inbounds i8, ptr %b, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = sext i8 %load.a to i32\n %gep.a2 = getelementptr inbounds i8, ptr %a, i64 %iv\n %load.b = load i8, ptr %gep.a2, align 1\n %ext.b = sext i8 %load.b to i32\n %mul = mul nsw i32 %ext.b, %ext.a\n %add = add nsw i32 %mul, %accum\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, %N\n br i1 %exitcond.not, label %exit, label %for.body, !llvm.loop !0\n\nexit: ; preds = %for.body\n ret i32 %add\n}\n\n!0 = distinct !{!0, !1, !2, !3}\n!1 = !{!\"llvm.loop.mustprogress\"}\n!2 = !{!\"llvm.loop.vectorize.predicate.enable\", i1 true}\n!3 = !{!\"llvm.loop.vectorize.enable\", i1 true}\n"}, {"test_name": "not_dotp_not_loop_carried", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp_not_loop_carried(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %mul, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n"}, {"test_name": "not_dotp_different_types", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp_different_types(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i16, ptr %gep.b, align 2\n %ext.b = zext i16 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n"}, {"test_name": "not_dotp_not_phi", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp_not_phi(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %ext.b\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n"}, {"test_name": "not_dotp_extend_user", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp_extend_user(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n %result = add i32 %add, %ext.b\n ret i32 %result\n}\n"}, {"test_name": "not_dotp_predicated", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp_predicated(i64 %N, ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr inbounds i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = sext i8 %load.a to i32\n %gep.b = getelementptr inbounds i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = sext i8 %load.b to i32\n %mul = mul nsw i32 %ext.b, %ext.a\n %add = add nsw i32 %mul, %accum\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, %N\n br i1 %exitcond.not, label %exit, label %for.body\n\nexit: ; preds = %for.body\n ret i32 %add\n}\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-dot-product.ll", "commands": ["opt -passes=loop-vectorize -force-vector-interleave=1 -enable-epilogue-vectorization=false -S < %s", "opt -passes=loop-vectorize -enable-epilogue-vectorization=false -S < %s", "opt -passes=loop-vectorize -force-vector-interleave=1 -vectorizer-maximize-bandwidth -enable-epilogue-vectorization=false -S < %s"], "tests": [{"test_name": "not_dotp_not_phi2", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine void @not_dotp_not_phi2(ptr %matrix, i32 %n) #0 {\nentry:\n %cmp = icmp sgt i32 %n, 0\n br i1 %cmp, label %for.preheader, label %exit\n\nfor.preheader: ; preds = %entry\n %load.a = load i8, ptr null, align 1\n %load.a1 = load i8, ptr inttoptr (i64 1 to ptr), align 1\n %a.ext = sext i8 %load.a to i32\n %a.ext1 = sext i8 %load.a1 to i32\n br label %for.body\n\nfor.body: ; preds = %for.body, %for.preheader\n %iv = phi i32 [ %iv.next, %for.body ], [ 0, %for.preheader ]\n %ptr = phi ptr [ %scevgep, %for.body ], [ %matrix, %for.preheader ]\n %accum = phi i32 [ %add.1, %for.body ], [ 0, %for.preheader ]\n %gep.b = getelementptr i8, ptr %ptr, i64 1\n %gep.b1 = getelementptr i8, ptr %ptr, i64 2\n %load.b = load i8, ptr %gep.b, align 1\n %b.ext = sext i8 %load.b to i32\n %mul = mul nsw i32 %a.ext, %b.ext\n %add = add i32 %mul, %accum\n %load.b1 = load i8, ptr %gep.b1, align 1\n %b.ext1 = sext i8 %load.b1 to i32\n %mul.1 = mul nsw i32 %a.ext1, %b.ext1\n %add.1 = add i32 %mul.1, %add\n %scevgep = getelementptr i8, ptr %ptr, i64 16\n %iv.next = add nuw nsw i32 %iv, 1\n %exitcond.not = icmp eq i32 %iv.next, %n\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n %add.1.lcssa = phi i32 [ %add.1, %for.body ]\n %add.float = sitofp i32 %add.1.lcssa to float\n br label %exit\n\nexit: ; preds = %for.exit, %entry\n %result = phi float [ 0.000000e+00, %entry ], [ %add.float, %for.exit ]\n store float %result, ptr %matrix, align 4\n ret void\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n"}, {"test_name": "not_dotp_ext_outside_plan2", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i64 @not_dotp_ext_outside_plan2(ptr %a, i16 %b, i64 %n) #0 {\nentry:\n %cmp = icmp eq i64 %n, 0\n br i1 %cmp, label %exit, label %for.ph\n\nfor.ph: ; preds = %entry\n %ext.b = zext i16 %b to i64\n br label %for.body\n\nfor.body: ; preds = %for.body, %for.ph\n %iv = phi i64 [ 0, %for.ph ], [ %iv.next, %for.body ]\n %accum = phi i64 [ 0, %for.ph ], [ %add, %for.body ]\n %gep.a = getelementptr inbounds nuw i16, ptr %a, i64 %iv\n %load.a = load i16, ptr %gep.a, align 2\n %ext.a = zext i16 %load.a to i64\n %mul = mul nuw nsw i64 %ext.b, %ext.a\n %add = add i64 %mul, %accum\n %iv.next = add nuw nsw i64 %iv, 1\n %cmp.1 = icmp eq i64 %iv.next, %n\n br i1 %cmp.1, label %exit, label %for.body\n\nexit: ; preds = %for.body, %entry\n %result = phi i64 [ 0, %entry ], [ %add, %for.body ]\n ret i64 %result\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n"}, {"test_name": "dotp_unrolled", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @dotp_unrolled(i32 %num_out, i64 %num_in, ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum3 = phi i32 [ 0, %entry ], [ %add.a3, %for.body ]\n %accum2 = phi i32 [ 0, %entry ], [ %add.a2, %for.body ]\n %accum1 = phi i32 [ 0, %entry ], [ %add.a1, %for.body ]\n %accum0 = phi i32 [ 0, %entry ], [ %add.a0, %for.body ]\n %gep.a0 = getelementptr inbounds i8, ptr %a, i64 %iv\n %gep.b0 = getelementptr inbounds i8, ptr %b, i64 %iv\n %offset.1 = or disjoint i64 %iv, 1\n %gep.a1 = getelementptr inbounds i8, ptr %a, i64 %offset.1\n %gep.b1 = getelementptr inbounds i8, ptr %b, i64 %offset.1\n %offset.2 = or disjoint i64 %iv, 2\n %gep.a2 = getelementptr inbounds i8, ptr %a, i64 %offset.2\n %gep.b2 = getelementptr inbounds i8, ptr %b, i64 %offset.2\n %offset.3 = or disjoint i64 %iv, 3\n %gep.a3 = getelementptr inbounds i8, ptr %a, i64 %offset.3\n %gep.b3 = getelementptr inbounds i8, ptr %b, i64 %offset.3\n %load.a0 = load i8, ptr %gep.a0, align 1\n %ext.a0 = sext i8 %load.a0 to i32\n %load.b0 = load i8, ptr %gep.b0, align 1\n %ext.b0 = sext i8 %load.b0 to i32\n %mul.a0 = mul nsw i32 %ext.b0, %ext.a0\n %add.a0 = add nsw i32 %mul.a0, %accum0\n %load.a1 = load i8, ptr %gep.a1, align 1\n %ext.a1 = sext i8 %load.a1 to i32\n %load.b1 = load i8, ptr %gep.b1, align 1\n %ext.b1 = sext i8 %load.b1 to i32\n %mul.a1 = mul nsw i32 %ext.a1, %ext.b1\n %add.a1 = add nsw i32 %mul.a1, %accum1\n %load.a2 = load i8, ptr %gep.a2, align 1\n %ext.a2 = sext i8 %load.a2 to i32\n %load.b2 = load i8, ptr %gep.b2, align 1\n %ext.b2 = sext i8 %load.b2 to i32\n %mul.a2 = mul nsw i32 %ext.a2, %ext.b2\n %add.a2 = add nsw i32 %mul.a2, %accum2\n %load.a3 = load i8, ptr %gep.a3, align 1\n %ext.a3 = sext i8 %load.a3 to i32\n %load.b3 = load i8, ptr %gep.b3, align 1\n %ext.b3 = sext i8 %load.b3 to i32\n %mul.a3 = mul nsw i32 %ext.a3, %ext.b3\n %add.a3 = add nsw i32 %mul.a3, %accum3\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, %num_in\n br i1 %exitcond.not, label %exit, label %for.body\n\nexit: ; preds = %for.body\n %result0 = add nsw i32 %add.a0, %add.a1\n %result1 = add nsw i32 %add.a2, %add.a3\n %result = add nsw i32 %result0, %result1\n ret i32 %result\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n"}, {"test_name": "dotp", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @dotp(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n"}, {"test_name": "not_dotp_predicated_pragma", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @not_dotp_predicated_pragma(i64 %N, ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr inbounds i8, ptr %b, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = sext i8 %load.a to i32\n %gep.a2 = getelementptr inbounds i8, ptr %a, i64 %iv\n %load.b = load i8, ptr %gep.a2, align 1\n %ext.b = sext i8 %load.b to i32\n %mul = mul nsw i32 %ext.b, %ext.a\n %add = add nsw i32 %mul, %accum\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, %N\n br i1 %exitcond.not, label %exit, label %for.body, !llvm.loop !0\n\nexit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n\n!0 = distinct !{!0, !1, !2, !3}\n!1 = !{!\"llvm.loop.mustprogress\"}\n!2 = !{!\"llvm.loop.vectorize.predicate.enable\", i1 true}\n!3 = !{!\"llvm.loop.vectorize.enable\", i1 true}\n"}, {"test_name": "dotp_cost_disagreement", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i64 @dotp_cost_disagreement(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i.iv = phi i64 [ 0, %entry ], [ %i.iv.next, %for.body ]\n %sum = phi i64 [ 0, %entry ], [ %add, %for.body ]\n %arrayidx = getelementptr inbounds nuw i8, ptr %a, i64 %i.iv\n %0 = load i8, ptr %arrayidx, align 1\n %conv = zext i8 %0 to i64\n %i.iv.next = add nuw nsw i64 %i.iv, 1\n %arrayidx2 = getelementptr inbounds nuw i8, ptr %b, i64 %i.iv.next\n %1 = load i8, ptr %arrayidx2, align 1\n %conv3 = zext i8 %1 to i64\n %mul = mul nuw nsw i64 %conv3, %conv\n %add = add i64 %sum, %mul\n %exitcond.not = icmp eq i64 %i.iv.next, 16\n br i1 %exitcond.not, label %exit, label %for.body\n\nexit: ; preds = %for.body\n ret i64 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n"}, {"test_name": "not_dotp_not_loop_carried", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @not_dotp_not_loop_carried(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %mul, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n"}, {"test_name": "not_dotp_different_types", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @not_dotp_different_types(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i16, ptr %gep.b, align 2\n %ext.b = zext i16 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n"}, {"test_name": "not_dotp_not_phi", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @not_dotp_not_phi(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %ext.b\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n"}, {"test_name": "not_dotp_extend_user", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @not_dotp_extend_user(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n %result = add i32 %add, %ext.b\n ret i32 %result\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n"}, {"test_name": "not_dotp_ext_outside_plan", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i64 @not_dotp_ext_outside_plan(ptr %a, i16 %b, i64 %n) #0 {\nentry:\n %cmp = icmp eq i64 %n, 0\n br i1 %cmp, label %exit, label %for.ph\n\nfor.ph: ; preds = %entry\n %ext.b = zext i16 %b to i64\n br label %for.body\n\nfor.body: ; preds = %for.body, %for.ph\n %iv = phi i64 [ 0, %for.ph ], [ %iv.next, %for.body ]\n %accum = phi i64 [ 0, %for.ph ], [ %add, %for.body ]\n %gep.a = getelementptr inbounds nuw i16, ptr %a, i64 %iv\n %load.a = load i16, ptr %gep.a, align 2\n %ext.a = zext i16 %load.a to i64\n %mul = mul nuw nsw i64 %ext.a, %ext.b\n %add = add i64 %mul, %accum\n %iv.next = add nuw nsw i64 %iv, 1\n %cmp.1 = icmp eq i64 %iv.next, %n\n br i1 %cmp.1, label %exit, label %for.body\n\nexit: ; preds = %for.body, %entry\n %result = phi i64 [ 0, %entry ], [ %add, %for.body ]\n ret i64 %result\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n"}, {"test_name": "not_dotp_predicated", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @not_dotp_predicated(i64 %N, ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr inbounds i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = sext i8 %load.a to i32\n %gep.b = getelementptr inbounds i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = sext i8 %load.b to i32\n %mul = mul nsw i32 %ext.b, %ext.a\n %add = add nsw i32 %mul, %accum\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, %N\n br i1 %exitcond.not, label %exit, label %for.body\n\nexit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-no-dotprod.ll", "commands": ["opt -passes=loop-vectorize -enable-epilogue-vectorization=false -mattr=+neon -S < %s"], "tests": [{"test_name": "not_dotp", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1000\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/AArch64/store-costs-sve.ll", "commands": ["opt -p loop-vectorize -S %s", "opt -p loop-vectorize -prefer-predicate-over-epilogue=predicate-else-scalar-epilogue -S %s"], "tests": [{"test_name": "trunc_store", "test_body": "target datalayout = \"e-m:o-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"arm64-apple-macosx14.0.0\"\n\n; Function Attrs: vscale_range(1,16)\ndefine void @trunc_store(ptr %dst, ptr %src, i16 %x) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %x.ext = zext i16 %x to i64\n %l = load i64, ptr %src, align 8\n %and = and i64 %l, %x.ext\n %trunc = trunc i64 %and to i8\n %gep = getelementptr i8, ptr %dst, i64 %iv\n store i8 %trunc, ptr %gep, align 1\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 1000\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/AArch64/vplan-printing.ll", "commands": ["opt -mattr=+neon,+dotprod -passes=loop-vectorize -debug-only=loop-vectorize -force-vector-interleave=1 -disable-output %s 2>&1"], "tests": [{"test_name": "print_partial_reduction", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @print_partial_reduction(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %exit, label %for.body\n\nexit: ; preds = %for.body\n ret i32 %add\n}\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/Hexagon/maximum-vf-crash.ll", "commands": ["opt -mtriple=hexagon -hexagon-autohvx -passes=loop-vectorize -S < %s 2>&1"], "tests": [{"test_name": "f", "test_body": "target datalayout = \"e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048\"\n\n; Function Attrs: optsize\ndefine i32 @f(ptr %src) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %g.016 = phi i32 [ 0, %entry ], [ %g.1.lcssa, %loop ]\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %0 = load i8, ptr %src, align 1\n %g.1.lcssa = add i32 %g.016, 1\n %iv.next = add nsw i32 %iv, 1\n %exitcond = icmp eq i32 %iv.next, 1000\n br i1 %exitcond, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i32 %g.1.lcssa\n}\n\nattributes #0 = { optsize \"target-features\"=\"+hvx-length128b\" }\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/X86/cost-constant-known-via-scev.ll", "commands": ["opt -p loop-vectorize -S %s"], "tests": [{"test_name": "second_lshr_operand_zero_via_scev", "test_body": "target 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\ndefine i64 @second_lshr_operand_zero_via_scev() {\nentry:\n %ext.0 = sext i8 0 to i32\n br label %loops\n\nloops: ; preds = %loops, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loops ]\n %red = phi i64 [ 0, %entry ], [ %red.next, %loops ]\n %c = icmp eq i64 %iv, 0\n %and = and i64 %iv, 0\n %0 = trunc i64 %iv to i32\n %shr = lshr i32 %0, %ext.0\n %conv.1 = zext i32 %shr to i64\n %red.next.v = select i1 %c, i64 %and, i64 %conv.1\n %red.next = or i64 %red.next.v, %red\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 1000\n br i1 %ec, label %exit, label %loops\n\nexit: ; preds = %loops\n %res = phi i64 [ %red.next, %loops ]\n ret i64 %res\n}\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/X86/cost-model.ll", "commands": ["opt < %s -passes=loop-vectorize -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx -S"], "tests": [{"test_name": "narrowed_reduction", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.8.0\"\n\ndefine i32 @narrowed_reduction(ptr %a, i1 %cmp) #0 {\nentry:\n %conv = zext i1 %cmp to i32\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 1, %entry ], [ %inc, %loop ]\n %or13 = phi i32 [ 0, %entry ], [ %or, %loop ]\n %and = and i32 %or13, 1\n %or = or i32 %and, %conv\n %inc = add i32 %iv, 1\n %ec = icmp eq i32 %iv, 16\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i32 %or\n}\n\nattributes #0 = { \"target-cpu\"=\"penryn\" }\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/X86/drop-poison-generating-flags.ll", "commands": ["opt %s -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S"], "tests": [{"test_name": "drop_zext_nneg", "test_body": "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-pc-linux-gnu\"\n\n; Function Attrs: noinline nounwind uwtable\ndefine void @drop_zext_nneg(ptr noalias %p, ptr noalias %p1) #0 {\nentry:\n br label %body\n\nbody: ; preds = %else, %entry\n %iv = phi i64 [ %next, %else ], [ 0, %entry ]\n %0 = trunc i64 %iv to i32\n %c = icmp eq i32 %0, 0\n br i1 %c, label %then, label %else\n\nthen: ; preds = %body\n %zext = zext nneg i32 %0 to i64\n %idx1 = getelementptr double, ptr %p, i64 %zext\n %idx2 = getelementptr double, ptr %p, i64 %zext\n %1 = load double, ptr %idx2, align 8\n br label %else\n\nelse: ; preds = %then, %body\n %phi = phi double [ %1, %then ], [ 0.000000e+00, %body ]\n store double %phi, ptr %p1, align 8\n %next = add i64 %iv, 1\n %cmp = icmp eq i64 %next, 1024\n br i1 %cmp, label %exit, label %body\n\nexit: ; preds = %else\n ret void\n}\n\nattributes #0 = { noinline nounwind uwtable \"target-features\"=\"+avx512bw,+avx512cd,+avx512dq,+avx512f,+avx512vl\" }\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/X86/interleave-cost.ll", "commands": ["opt -p loop-vectorize -S %s"], "tests": [{"test_name": "test_free_instructions_feeding_geps_for_interleave_groups", "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\"\ntarget triple = \"x86_64-apple-macosx10.15.0\"\n\ndefine void @test_free_instructions_feeding_geps_for_interleave_groups(ptr noalias %p.invar, ptr noalias %dst.1, ptr noalias %dst.2) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %l.0 = load float, ptr %p.invar, align 4\n %iv.mul = shl i64 %iv, 2\n %gep.dst.19 = getelementptr float, ptr %dst.1, i64 %iv.mul\n store float %l.0, ptr %gep.dst.19, align 4\n %l.1 = load float, ptr %p.invar, align 4\n %add.1 = or disjoint i64 %iv.mul, 1\n %gep.dst.119 = getelementptr float, ptr %dst.1, i64 %add.1\n store float %l.1, ptr %gep.dst.119, align 4\n %add.2 = or disjoint i64 %iv.mul, 2\n %gep.dst.129 = getelementptr float, ptr %dst.1, i64 %add.2\n store float 0.000000e+00, ptr %gep.dst.129, align 4\n %add.3 = or disjoint i64 %iv.mul, 3\n %gep.dst.140 = getelementptr float, ptr %dst.1, i64 %add.3\n store float 0.000000e+00, ptr %gep.dst.140, align 4\n %l.2 = load float, ptr %p.invar, align 4\n %gep.dst.247 = getelementptr float, ptr %dst.2, i64 %iv.mul\n store float %l.2, ptr %gep.dst.247, align 4\n %gep.dst.255 = getelementptr float, ptr %dst.2, i64 %add.1\n store float 0.000000e+00, ptr %gep.dst.255, align 4\n %gep.dst.265 = getelementptr float, ptr %dst.2, i64 %add.2\n store float 0.000000e+00, ptr %gep.dst.265, align 4\n %gep.dst.276 = getelementptr float, ptr %dst.2, i64 %add.3\n store float 0.000000e+00, ptr %gep.dst.276, align 4\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 1024\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/X86/replicate-uniform-call.ll", "commands": ["opt -p loop-vectorize -S %s"], "tests": [{"test_name": "smax_call_uniform", "test_body": "target 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\ndefine void @smax_call_uniform(ptr %dst, i64 %x) {\nentry:\n %c = icmp ult i8 -68, -69\n %mul = mul nuw nsw i64 %x, 0\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n br i1 %c, label %loop.latch, label %else\n\nelse: ; preds = %loop.header\n %rem = urem i64 %mul, %x\n %smax = tail call i64 @llvm.smax.i64(i64 %rem, i64 0)\n br label %loop.latch\n\nloop.latch: ; preds = %else, %loop.header\n %p = phi i64 [ 1, %loop.header ], [ %smax, %else ]\n %add = add i64 %p, 1\n %gep = getelementptr i64, ptr %dst, i64 %add\n store i64 0, ptr %gep, align 8\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 1024\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret void\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i64 @llvm.smax.i64(i64, i64) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/epilog-vectorization-vector-trip-count-zero.ll", "commands": ["opt -p loop-vectorize -force-vector-width=2 -epilogue-vectorization-force-VF=2 -S %s"], "tests": [{"test_name": "vector_trip_count_0_as_btc_is_all_1", "test_body": "target datalayout = \"E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64\"\n\ndefine void @vector_trip_count_0_as_btc_is_all_1(ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.next = add i32 %iv, -1\n %gep = getelementptr inbounds i32, ptr %dst, i32 %iv\n store i32 %iv.next, ptr %gep, align 4\n %ec = icmp eq i32 %iv.next, 0\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/first-order-recurrence-chains.ll", "commands": ["opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S %s"], "tests": [{"test_name": "test_resinking_required", "test_body": "define double @test_resinking_required(ptr %p, ptr noalias %a, ptr noalias %b) {\nEntry:\n br label %Loop\n\nLoop: ; preds = %Loop, %Entry\n %for.1 = phi double [ %l1, %Loop ], [ 0.000000e+00, %Entry ]\n %for.2 = phi double [ %l2, %Loop ], [ 0.000000e+00, %Entry ]\n %for.3 = phi double [ %for.2, %Loop ], [ 0.000000e+00, %Entry ]\n %iv = phi i64 [ %iv.next, %Loop ], [ 0, %Entry ]\n %USE_2_FORS = fdiv double %for.3, %for.1\n %div = fdiv double 0.000000e+00, %for.1\n %l1 = load double, ptr %a, align 8\n %iv.next = add nuw nsw i64 %iv, 1\n %l2 = load double, ptr %b, align 8\n store double %div, ptr %p, align 8\n %cond = icmp eq i64 %iv.next, 1000\n br i1 %cond, label %End, label %Loop\n\nEnd: ; preds = %Loop\n %res.1 = fadd double %for.1, %for.2\n %res.2 = fadd double %res.1, %for.3\n ret double %res.2\n}\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/if-pred-stores.ll", "commands": ["opt -S -vectorize-num-stores-pred=1 -force-vector-width=1 -force-vector-interleave=2 -passes=loop-vectorize,simplifycfg -verify-loop-info -simplifycfg-require-and-preserve-domtree=1 < %s", "opt -S -vectorize-num-stores-pred=1 -force-vector-width=1 -force-vector-interleave=2 -passes=loop-vectorize -verify-loop-info < %s", "opt -S -vectorize-num-stores-pred=1 -force-vector-width=2 -force-vector-interleave=1 -passes=loop-vectorize,simplifycfg -verify-loop-info -simplifycfg-require-and-preserve-domtree=1 < %s"], "tests": [{"test_name": "minimal_bit_widths_with_aliasing_store", "test_body": "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine void @minimal_bit_widths_with_aliasing_store(i1 %c, ptr %ptr) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.inc, %entry\n %tmp0 = phi i64 [ %tmp6, %for.inc ], [ 0, %entry ]\n %tmp1 = phi i64 [ %tmp7, %for.inc ], [ 1000, %entry ]\n %tmp2 = getelementptr i8, ptr %ptr, i64 %tmp0\n %tmp3 = load i8, ptr %tmp2, align 1\n store i8 0, ptr %tmp2, align 1\n br i1 %c, label %if.then, label %for.inc\n\nif.then: ; preds = %for.body\n %tmp4 = zext i8 %tmp3 to i32\n %tmp5 = trunc i32 %tmp4 to i8\n store i8 %tmp5, ptr %tmp2, align 1\n br label %for.inc\n\nfor.inc: ; preds = %if.then, %for.body\n %tmp6 = add nuw nsw i64 %tmp0, 1\n %tmp7 = add i64 %tmp1, -1\n %tmp8 = icmp eq i64 %tmp7, 0\n br i1 %tmp8, label %for.end, label %for.body\n\nfor.end: ; preds = %for.inc\n ret void\n}\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/induction.ll", "commands": ["opt < %s -passes=loop-vectorize -force-vector-interleave=1 -force-vector-width=2 -force-widen-divrem-via-safe-divisor=0 -S", "opt < %s -passes=loop-vectorize,instcombine -force-vector-interleave=1 -force-vector-width=2 -force-widen-divrem-via-safe-divisor=0 -S", "opt < %s -passes=loop-vectorize,instcombine -force-vector-interleave=2 -force-vector-width=2 -force-widen-divrem-via-safe-divisor=0 -S", "opt < %s -passes=loop-vectorize -force-vector-interleave=2 -force-vector-width=2 -force-widen-divrem-via-safe-divisor=0 -S", "opt < %s -passes=loop-vectorize,instcombine -force-vector-interleave=2 -force-vector-width=4 -force-widen-divrem-via-safe-divisor=0 -enable-interleaved-mem-accesses -S"], "tests": [{"test_name": "max_i32_backedgetaken", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine i32 @max_i32_backedgetaken() {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %a.0 = phi i32 [ 1, %entry ], [ %a.0.and, %loop ]\n %b.0 = phi i32 [ 0, %entry ], [ %b.next, %loop ]\n %a.0.and = and i32 %a.0, 4\n %b.next = add i32 %b.0, -1\n %ec = icmp eq i32 %b.next, 0\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i32 %a.0.and\n}\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/interleave-and-scalarize-only.ll", "commands": ["opt -passes=loop-vectorize -force-vector-width=1 -force-vector-interleave=2 -debug -disable-output %s 2>&1", "opt -passes=loop-vectorize -force-vector-width=1 -force-vector-interleave=2 -S %s"], "tests": [{"test_name": "scalarize_ptrtoint", "test_body": "define void @scalarize_ptrtoint(ptr %src, ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep = getelementptr ptr, ptr %src, i64 %iv\n %l = load ptr, ptr %gep, align 8\n %cast = ptrtoint ptr %l to i64\n %add = add i64 %cast, 10\n %cast.2 = inttoptr i64 %add to ptr\n store ptr %cast.2, ptr %dst, align 8\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 1024\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/is_fpclass.ll", "commands": ["opt < %s -passes=loop-vectorize -force-vector-width=2 -S"], "tests": [{"test_name": "d", "test_body": "define void @d() {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %i = phi i64 [ 0, %entry ], [ %i7, %loop ]\n %i3 = load float, ptr null, align 4\n %i4 = getelementptr float, ptr @d, i64 %i\n %i5 = tail call i1 @llvm.is.fpclass.f32(float %i3, i32 0)\n %i6 = select i1 %i5, float 0.000000e+00, float 0.000000e+00\n store float %i6, ptr %i4, align 4\n %i7 = add i64 %i, 1\n %i8 = icmp eq i64 %i7, 128\n br i1 %i8, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i1 @llvm.is.fpclass.f32(float, i32 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/optimal-epilog-vectorization.ll", "commands": ["opt -passes='loop-vectorize' -force-vector-width=4 -enable-epilogue-vectorization -epilogue-vectorization-force-VF=4 -S %s", "opt -passes='loop-vectorize' -enable-epilogue-vectorization -epilogue-vectorization-force-VF=2 -S %s"], "tests": [{"test_name": "multiple_ivs_wide", "test_body": "target datalayout = \"e-m:e-i64:64-n32:64-v128:128:128\"\n\ndefine void @multiple_ivs_wide(ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.2 = phi i32 [ -64, %entry ], [ %iv.2.next, %loop ]\n %iv.next = add i32 %iv, 2\n %iv.2.next = add i32 %iv.2, 2\n %gep = getelementptr inbounds i32, ptr %dst, i32 %iv\n store i32 %iv.2.next, ptr %gep, align 4\n %ec = icmp eq i32 %iv.next, 128\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/runtime-checks-hoist.ll", "commands": ["opt < %s -passes='loop-vectorize' -force-vector-interleave=1 -S -force-vector-width=4 -debug-only=loop-accesses,loop-vectorize,loop-utils"], "tests": [{"test_name": "stride_check_known_via_loop_guard", "test_body": "target datalayout = \"e-m:e-i64:64-i128:128-n32:64-S128\"\n\ndefine void @stride_check_known_via_loop_guard(ptr %C, ptr %A, i32 %Acols) {\nentry:\n %pre.c = icmp ugt i32 %Acols, 0\n br i1 %pre.c, label %exit, label %outer.header\n\nouter.header: ; preds = %outer.latch, %entry\n %outer.iv = phi i32 [ 0, %entry ], [ %outer.iv.next, %outer.latch ]\n %mul.us = mul i32 %outer.iv, %Acols\n %arrayidx.us = getelementptr double, ptr %A, i32 %mul.us\n br label %inner\n\ninner: ; preds = %inner, %outer.header\n %inner.iv = phi i32 [ 0, %outer.header ], [ %inner.iv.next, %inner ]\n %gep.C = getelementptr inbounds double, ptr %C, i32 %inner.iv\n %l = load double, ptr %arrayidx.us, align 8\n store double %l, ptr %gep.C, align 8\n %inner.iv.next = add i32 %inner.iv, 1\n %inner.c = icmp eq i32 %inner.iv.next, 1000\n br i1 %inner.c, label %outer.latch, label %inner\n\nouter.latch: ; preds = %inner\n %outer.iv.next = add i32 %outer.iv, 1\n %outer.c = icmp ult i32 %outer.iv, 128\n br i1 %outer.c, label %exit, label %outer.header\n\nexit: ; preds = %outer.latch, %entry\n ret void\n}\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/scev-predicate-reasoning.ll", "commands": ["opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -lv-strided-pointer-ivs=true -S %s"], "tests": [{"test_name": "step_direction_unknown", "test_body": "define void @step_direction_unknown(i32 %arg, ptr %dst) {\nentry:\n %add = add i32 %arg, 1\n br label %loop\n\nloop: ; preds = %loop, %entry\n %phi = phi i64 [ 0, %entry ], [ %add2, %loop ]\n %trunc = trunc i64 %phi to i32\n %mul = mul i32 %add, %trunc\n %zext = zext i32 %mul to i64\n %getelementptr = getelementptr double, ptr %dst, i64 %zext\n store double 0.000000e+00, ptr %getelementptr, align 8\n %add2 = add i64 %phi, 1\n %icmp = icmp eq i64 %add2, 1024\n br i1 %icmp, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n"}, {"test_name": "integer_induction_wraps_scev_predicate_known", "test_body": "define void @integer_induction_wraps_scev_predicate_known(i32 %x, ptr %call, ptr %start) {\nentry:\n %mul = shl i32 %x, 1\n br label %for.cond\n\nfor.cond: ; preds = %for.cond, %entry\n %iv = phi i32 [ 30, %entry ], [ %inc, %for.cond ]\n %p.0 = phi ptr [ %start, %entry ], [ %add.ptr, %for.cond ]\n %add.ptr = getelementptr i8, ptr %p.0, i32 %mul\n %arrayidx = getelementptr ptr, ptr %call, i32 %iv\n store ptr %p.0, ptr %arrayidx, align 4\n %inc = add i32 %iv, 1\n %tobool.not = icmp eq i32 %iv, 1024\n br i1 %tobool.not, label %for.end, label %for.cond\n\nfor.end: ; preds = %for.cond\n ret void\n}\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/vplan-sink-scalars-and-merge-vf1.ll", "commands": ["opt -passes=loop-vectorize -force-vector-interleave=2 -force-vector-width=1 -debug -disable-output %s 2>&1"], "tests": [{"test_name": "sink_with_sideeffects", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @sink_with_sideeffects(i1 %c, ptr %ptr) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.inc, %entry\n %tmp0 = phi i64 [ %tmp6, %for.inc ], [ 0, %entry ]\n %tmp1 = phi i64 [ %tmp7, %for.inc ], [ 1024, %entry ]\n %tmp2 = getelementptr i8, ptr %ptr, i64 %tmp0\n %tmp3 = load i8, ptr %tmp2, align 1\n store i8 0, ptr %tmp2, align 1\n %tmp4 = zext i8 %tmp3 to i32\n %tmp5 = trunc i32 %tmp4 to i8\n br i1 %c, label %if.then, label %for.inc\n\nif.then: ; preds = %for.body\n store i8 %tmp5, ptr %tmp2, align 1\n br label %for.inc\n\nfor.inc: ; preds = %if.then, %for.body\n %tmp6 = add nuw nsw i64 %tmp0, 1\n %tmp7 = add i64 %tmp1, -1\n %tmp8 = icmp eq i64 %tmp7, 0\n br i1 %tmp8, label %for.end, label %for.body\n\nfor.end: ; preds = %for.inc\n ret void\n}\n"}]}], "issue": {"title": "[LoopVectorizer] Assertion `EPResumeVal && \"must have a resume value for the canonical IV\"' failed.", "body": "clang -Wno-incompatible-pointer-types -O3 -march=z13 -S -c crash19.i -o a.out -w -mllvm -disable-licm-promotion -mllvm -epilogue-vectorization-force-VF=2 \n\n[crash19.tar.gz](https://github.com/user-attachments/files/18383534/crash19.tar.gz)\n\n#9 0x000002aa3ff5e440 preparePlanForEpilogueVectorLoop\n#12 0x000002aa3ffa098a llvm::LoopVectorizePass::run\n\n@bmahjour \n@fhahn ", "author": "JonPsson1", "labels": ["vectorizers", "crash"], "comments": [{"author": "fhahn", "body": "@JonPsson1 Was the test case fuzzer generated? Just curious, because it had a loop with unsigned max as iteration count."}, {"author": "JonPsson1", "body": "> [@JonPsson1](https://github.com/JonPsson1) Was the test case fuzzer generated? Just curious, because it had a loop with unsigned max as iteration count.\n\nNo, it was a CSmith test case."}, {"author": "fhahn", "body": "@JonPsson1 Could you check if it fixes the full reproducer? If not, it would be great if you could share the full reproducer?"}]}, "verified": true} {"bug_id": "109333", "issue_url": "https://github.com/llvm/llvm-project/issues/109333", "bug_type": "crash", "base_commit": "c498af71d73e96e95730f3b3caaea08d3edbe62c", "knowledge_cutoff": "2024-09-19T20:50:34Z", "lit_test_dir": ["llvm/test/Transforms/LoopUnroll"], "hints": {"fix_commit": "5bcc82d43388bb0daa122d5fe7ecda5eca27fc16", "components": ["LoopPeel"], "bug_location_lineno": {"llvm/lib/Transforms/Utils/LoopPeel.cpp": [[859, 865]]}, "bug_location_funcname": {"llvm/lib/Transforms/Utils/LoopPeel.cpp": ["cloneLoopBlocks"]}}, "patch": "commit 5bcc82d43388bb0daa122d5fe7ecda5eca27fc16\nAuthor: Nikita Popov \nDate: Fri Sep 20 16:57:46 2024 +0200\n\n [LoopPeel] Fix LCSSA phi node invalidation\n \n In the test case, the BECount of the second loop uses %load,\n but we only have an LCSSA phi node for %add, so that is what\n gets invalidated. Use the forgetLcssaPhiWithNewPredecessor()\n API instead, which will invalidate the roots of the expression\n instead.\n \n Fixes https://github.com/llvm/llvm-project/issues/109333.\n\ndiff --git a/llvm/lib/Transforms/Utils/LoopPeel.cpp b/llvm/lib/Transforms/Utils/LoopPeel.cpp\nindex 5d7c0d947fac..760f1619e030 100644\n--- a/llvm/lib/Transforms/Utils/LoopPeel.cpp\n+++ b/llvm/lib/Transforms/Utils/LoopPeel.cpp\n@@ -859,7 +859,7 @@ static void cloneLoopBlocks(\n if (LatchInst && L->contains(LatchInst))\n LatchVal = VMap[LatchVal];\n PHI.addIncoming(LatchVal, cast(VMap[Edge.first]));\n- SE.forgetValue(&PHI);\n+ SE.forgetLcssaPhiWithNewPredecessor(L, &PHI);\n }\n \n // LastValueMap is updated with the values for the current loop\n", "tests": [{"file": "llvm/test/Transforms/LoopUnroll/pr109333.ll", "commands": ["opt -S -passes=\"print,loop-unroll\" -unroll-runtime < %s 2>&1"], "tests": [{"test_name": "test", "test_body": "define void @test(i1 %c, ptr %p) {\nentry:\n br label %loop.1\n\nloop.1: ; preds = %loop.1, %entry\n %phi = phi ptr [ null, %entry ], [ %p, %loop.1 ]\n %load = load i64, ptr %p, align 8\n %add = add i64 %load, 1\n br i1 %c, label %if, label %loop.1\n\nif: ; preds = %loop.1\n %add.lcssa = phi i64 [ %add, %loop.1 ]\n %gep = getelementptr i64, ptr %p, i64 %add.lcssa\n br label %loop.2\n\nloop.2: ; preds = %loop.2, %if\n %iv = phi ptr [ %p, %if ], [ %iv.next, %loop.2 ]\n %iv.next = getelementptr i8, ptr %iv, i64 8\n %icmp = icmp eq ptr %iv, %gep\n br i1 %icmp, label %exit, label %loop.2\n\nexit: ; preds = %loop.2\n ret void\n}\n"}]}], "issue": {"title": "LTO error: Instruction does not dominate all uses", "body": "clang crashes while linking\r\n```\r\nclang: error: unable to execute command: Aborted (core dumped)\r\nclang: error: linker command failed due to signal (use -v to see invocation)\r\n```\r\nI followed the instructions [here](https://llvm.org/docs/HowToSubmitABug.html) and narrowed it down to an LTO bug. File to reproduce is attached. [a.out.0.2.internalize-reduced.bc.tar.gz](https://github.com/user-attachments/files/17066318/a.out.0.2.internalize-reduced.bc.tar.gz)\r\n```\r\n$ opt \"-passes=lto\" a.out.0.2.internalize-reduced.bc\r\nWARNING: You're attempting to print out a bitcode file.\r\nThis is inadvisable as it may cause display problems. If\r\nyou REALLY want to taste LLVM bitcode first-hand, you\r\ncan force output with the `-f' option.\r\n\r\nInstruction does not dominate all uses!\r\n %.lcssa16 = phi i64 [ %12, %9 ]\r\n %27 = add i64 %.lcssa16, 2\r\nLLVM ERROR: Broken module found, compilation aborted!\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0. Program arguments: opt -passes=lto reduced-redacted.bc #0 0x00007e899efc4d90 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /usr/src/debug/llvm/llvm-18.1.8.src/lib/Support/Unix/Signals.inc:723:22\r\n #1 0x00007e899efc1d4d llvm::sys::RunSignalHandlers() /usr/src/debug/llvm/llvm-18.1.8.src/lib/Support/Signals.cpp:105:20\r\n #2 0x00007e899efc1d4d SignalHandler /usr/src/debug/llvm/llvm-18.1.8.src/lib/Support/Unix/Signals.inc:403:31\r\n #3 0x00007e899e24c1d0 (/usr/lib/libc.so.6+0x3d1d0)\r\n #4 0x00007e899e2a53f4 __pthread_kill_implementation /usr/src/debug/glibc/glibc/nptl/pthread_kill.c:44:76\r\n #5 0x00007e899e24c120 raise /usr/src/debug/glibc/glibc/signal/../sysdeps/posix/raise.c:27:6\r\n #6 0x00007e899e2334c3 abort /usr/src/debug/glibc/glibc/stdlib/abort.c:81:7\r\n #7 0x00007e899ecaba1b std::mutex::lock() /usr/include/c++/14.1.1/bits/std_mutex.h:117:22\r\n #8 0x00007e899ecaba1b std::lock_guard::lock_guard(std::mutex&) /usr/include/c++/14.1.1/bits/std_mutex.h:250:23\r\n #9 0x00007e899ecaba1b llvm::install_bad_alloc_error_handler(void (*)(void*, char const*, bool), void*) /usr/src/debug/llvm/llvm-18.1.8.src/lib/Support/ErrorHandling.cpp:131:61\r\n#10 0x00007e899eec070e (/usr/lib/libLLVM.so.18.1+0x6c070e)\r\n#11 0x00007e899f21aa1b (/usr/lib/libLLVM.so.18.1+0xa1aa1b)\r\n#12 0x000055a86e4acf57 llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) /usr/src/debug/llvm/llvm-18.1.8.src/include/llvm/IR/PassManagerInternal.h:90:3\r\n#13 0x00007e899f1d767e llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) /usr/src/debug/llvm/llvm-18.1.8.src/incl\r\nude/llvm/IR/PassManager.h:547:20\r\n#14 0x000055a86e4b7052 llvm::SmallPtrSetImplBase::isSmall() const /usr/src/debug/llvm/llvm-18.1.8.src/include/llvm/ADT/SmallPtrSet.h:195:33\r\n#15 0x000055a86e4b7052 llvm::SmallPtrSetImplBase::~SmallPtrSetImplBase() /usr/src/debug/llvm/llvm-18.1.8.src/include/llvm/ADT/SmallPtrSet.h:83:17\r\n#16 0x000055a86e4b7052 llvm::SmallPtrSetImpl::~SmallPtrSetImpl() /usr/src/debug/llvm/llvm-18.1.8.src/include/llvm/ADT/SmallPtrSet.h:345:7\r\n#17 0x000055a86e4b7052 llvm::SmallPtrSet::~SmallPtrSet() /usr/src/debug/llvm/llvm-18.1.8.src/include/llvm/ADT/SmallPtrSet.h:451:7\r\n#18 0x000055a86e4b7052 llvm::PreservedAnalyses::~PreservedAnalyses() /usr/src/debug/llvm/llvm-18.1.8.src/include/llvm/IR/PassManager.h:172:7\r\n#19 0x000055a86e4b7052 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutpu\r\ntFile*, llvm::StringRef, llvm::ArrayRef, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) /usr/src/debug/llvm/llvm-18.1.8\r\n.src/tools/opt/NewPMDriver.cpp:527:10\r\n#20 0x000055a86e4ab1ed std::__cxx11::basic_string, std::allocator>::~basic_string() /usr/include/c++/14.1.1/bits/basic_string.h:809:19\r\n#21 0x000055a86e4ab1ed main /usr/src/debug/llvm/llvm-18.1.8.src/tools/opt/opt.cpp:747:3\r\n#22 0x00007e899e234e08 __libc_start_call_main /usr/src/debug/glibc/glibc/csu/../sysdeps/nptl/libc_start_call_main.h:74:3\r\n#23 0x00007e899e234ecc call_init /usr/src/debug/glibc/glibc/csu/../csu/libc-start.c:128:20\r\n#24 0x00007e899e234ecc __libc_start_main /usr/src/debug/glibc/glibc/csu/../csu/libc-start.c:347:5\r\n#25 0x000055a86e4abfd5 _start (/usr/bin/opt+0x1cfd5)\r\nAborted (core dumped)\r\n```\r\nThis happened after adding `-fsplit-lto-unit` to some parts of my code base.\r\n", "author": "googlebleh", "labels": ["loopoptim", "release:backport", "llvm:crash"], "comments": [{"author": "googlebleh", "body": "While bisecting using this reduced test case, I was able to reproduce this crash on several versions of LLVM between 15 and 18.1.8. I was also able to reproduce on the tip of `main` (e439fdf4ea0dbc6f001428f4d4956700bf26bb97). However, this crash did not reproduce on 15.0.7. The commit on 15.0.7 that \"fixed\" the issue is\r\n```\r\ncommit f3c5289e78462fb96015f79c954d95a0d527ba55 \r\nAuthor: Martin Storsjö \r\nDate: Wed Oct 5 14:44:21 2022 +0300 \r\n \r\n Revert \"Recommit \"[SCEV] Look through single value PHIs.\" (take 3)\" \r\n \r\n This reverts commit 20d798bd47ec5191de1b2a8a031da06a04e612e1. \r\n \r\n This commit caused crashes in some cases, see github issue #58152. \r\n This is fixed on main, but backporting it requires multiple \r\n nontrivial cherrypicks. \r\n \r\n Updating llvm/test/Transforms/LoopVectorize/create-induction-resume.ll \r\n with update_test_checks.py, so this isn't an exact automatic revert, \r\n as that test case was added after the reverted commit. \r\n \r\n This fixes #58152 for the release branch. \r\n \r\n llvm/lib/Analysis/ScalarEvolution.cpp | 7 ++-\r\n llvm/test/Analysis/DependenceAnalysis/lcssa.ll | 2 +- \r\n llvm/test/Analysis/ScalarEvolution/cycled_phis.ll | 4 +- \r\n .../ScalarEvolution/incorrect-exit-count.ll | 2 +- \r\n .../Analysis/ScalarEvolution/solve-quadratic-i1.ll | 4 +- \r\n .../ScalarEvolution/solve-quadratic-overflow.ll | 6 +-- \r\n llvm/test/Analysis/ScalarEvolution/trivial-phis.ll | 2 +- \r\n llvm/test/Transforms/LoopStrengthReduce/funclet.ll | 40 +++++++++-------\r\n .../LoopVectorize/create-induction-resume.ll | 24 ++++------\r\n llvm/test/Transforms/LoopVectorize/pr45259.ll | 55 +++++++++++-----------\r\n 10 files changed, 75 insertions(+), 71 deletions(-)\r\n```\r\nspecifically, this (almost) 1-line diff\r\n```diff\r\ndiff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp\r\nindex 4b2db80bc1ec..3b73f9511eca 100644\r\n--- a/llvm/lib/Analysis/ScalarEvolution.cpp\r\n+++ b/llvm/lib/Analysis/ScalarEvolution.cpp\r\n@@ -6023,8 +6023,13 @@ const SCEV *ScalarEvolution::createNodeForPHI(PHINode *PN) {\r\n if (const SCEV *S = createAddRecFromPHI(PN))\r\n return S;\r\n \r\n+ // If the PHI has a single incoming value, follow that value, unless the\r\n+ // PHI's incoming blocks are in a different loop, in which case doing so\r\n+ // risks breaking LCSSA form. Instcombine would normally zap these, but\r\n+ // it doesn't have DominatorTree information, so it may miss cases.\r\n if (Value *V = simplifyInstruction(PN, {getDataLayout(), &TLI, &DT, &AC}))\r\n- return getSCEV(V);\r\n+ if (LI.replacementPreservesLCSSAForm(PN, V))\r\n+ return getSCEV(V);\r\n \r\n if (const SCEV *S = createNodeFromSelectLikePHI(PN))\r\n return S;\r\n```\r\n"}, {"author": "nikic", "body": "Reduced:\r\n```llvm\r\n; RUN: opt -passes=\"print,loop-unroll\" -unroll-runtime\r\ndefine void @test(i1 %c, ptr %p) {\r\nentry:\r\n br label %loop\r\n\r\nloop:\r\n %phi = phi ptr [ null, %entry ], [ %p, %loop ]\r\n %load = load i64, ptr %p, align 8\r\n %add = add i64 %load, 1\r\n br i1 %c, label %bb2, label %loop\r\n\r\nbb2:\r\n %add.lcssa = phi i64 [ %add, %loop ]\r\n %gep = getelementptr i64, ptr %p, i64 %add.lcssa\r\n br label %loop2\r\n\r\nloop2:\r\n %iv = phi ptr [ %p, %bb2 ], [ %iv.next, %loop2 ]\r\n %iv.next = getelementptr i8, ptr %iv, i64 8\r\n %icmp = icmp eq ptr %iv, %gep\r\n br i1 %icmp, label %exit, label %loop2\r\n\r\nexit:\r\n ret void\r\n}\r\n```"}, {"author": "nikic", "body": "From a cursory look, the problem here is that the BECount of `loop2` depends on `%load`, and after peeling it should instead depend on a phi node, but instead still depends on `%load`. As the BECount does not dominate the loop, SCEV is invalid.\r\n\r\nThis issue sounds very familiar, we've fixed variants of this in the past."}]}, "verified": true} {"bug_id": "102279", "issue_url": "https://github.com/llvm/llvm-project/issues/102279", "bug_type": "crash", "base_commit": "f7e1efe8bcea14686d1c303e058f687b6ca1c79f", "knowledge_cutoff": "2024-08-07T07:28:15Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "441f94f4bdf6e2b9747ec12194c595098d9c3a5b", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[17336, 17362]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["tryToReduce"]}}, "patch": "commit 441f94f4bdf6e2b9747ec12194c595098d9c3a5b\nAuthor: Alexey Bataev \nDate: Wed Aug 7 04:09:55 2024 -0700\n\n [SLP]Fix PR102279: check the tracked values for extractelements, not the original values\n \n If the reduced value was replaced by the extractelement instruction\n during vectorization and we attempt to check if this is so, need to\n check the tracked value, not the original (deleted) instruction.\n Otherwise, the compiler may crash\n \n Fixes https://github.com/llvm/llvm-project/issues/102279\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex c9335b7a89e1..1fee06d145b9 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -17336,27 +17336,23 @@ public:\n // Try to handle shuffled extractelements.\n if (S.getOpcode() == Instruction::ExtractElement && !S.isAltShuffle() &&\n I + 1 < E) {\n- InstructionsState NextS = getSameOpcode(ReducedVals[I + 1], TLI);\n- if (NextS.getOpcode() == Instruction::ExtractElement &&\n- !NextS.isAltShuffle()) {\n- SmallVector CommonCandidates(Candidates);\n- for (Value *RV : ReducedVals[I + 1]) {\n- Value *RdxVal = TrackedVals.find(RV)->second;\n- // Check if the reduction value was not overriden by the\n- // extractelement instruction because of the vectorization and\n- // exclude it, if it is not compatible with other values.\n- if (auto *Inst = dyn_cast(RdxVal))\n- if (!NextS.getOpcode() || !NextS.isOpcodeOrAlt(Inst))\n- continue;\n- CommonCandidates.push_back(RdxVal);\n- TrackedToOrig.try_emplace(RdxVal, RV);\n- }\n- SmallVector Mask;\n- if (isFixedVectorShuffle(CommonCandidates, Mask)) {\n- ++I;\n- Candidates.swap(CommonCandidates);\n- ShuffledExtracts = true;\n- }\n+ SmallVector CommonCandidates(Candidates);\n+ for (Value *RV : ReducedVals[I + 1]) {\n+ Value *RdxVal = TrackedVals.find(RV)->second;\n+ // Check if the reduction value was not overriden by the\n+ // extractelement instruction because of the vectorization and\n+ // exclude it, if it is not compatible with other values.\n+ auto *Inst = dyn_cast(RdxVal);\n+ if (!Inst)\n+ continue;\n+ CommonCandidates.push_back(RdxVal);\n+ TrackedToOrig.try_emplace(RdxVal, RV);\n+ }\n+ SmallVector Mask;\n+ if (isFixedVectorShuffle(CommonCandidates, Mask)) {\n+ ++I;\n+ Candidates.swap(CommonCandidates);\n+ ShuffledExtracts = true;\n }\n }\n \n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/X86/reduced-value-replace-extractelement.ll", "commands": ["opt -S --passes=slp-vectorizer -slp-threshold=-99999 < %s -mtriple=x86_64-unknown-linux-gnu"], "tests": [{"test_name": "test", "test_body": "define void @test() {\nbb:\n br label %bb1\n\nbb1: ; preds = %bb1, %bb\n %phi = phi i32 [ 0, %bb ], [ %mul9, %bb1 ]\n %phi2 = phi i32 [ 0, %bb ], [ 0, %bb1 ]\n %trunc = trunc i64 0 to i32\n %mul = mul i32 0, %trunc\n %mul3 = mul i32 %trunc, %phi\n %mul4 = mul i32 %mul3, %mul\n %mul5 = mul i32 %mul4, %mul\n %trunc6 = trunc i64 0 to i32\n %mul7 = mul i32 0, %trunc6\n %mul8 = mul i32 %mul5, %mul7\n %mul9 = mul i32 %mul8, %mul7\n br label %bb1\n}\n"}]}, {"file": "llvm/test/Transforms/SLPVectorizer/X86/reduction-gather-non-scheduled-extracts.ll", "commands": ["opt -S --passes=slp-vectorizer -mtriple=x86_64-sie-ps5 < %s"], "tests": [{"test_name": "tes", "test_body": "define void @tes() {\nentry:\n %0 = extractelement <2 x i1> zeroinitializer, i64 0\n %1 = extractelement <2 x i1> zeroinitializer, i64 0\n %2 = fcmp ole <2 x double> zeroinitializer, zeroinitializer\n %3 = extractelement <2 x i1> %2, i64 0\n %4 = extractelement <2 x i1> zeroinitializer, i64 0\n br label %5\n\n5: ; preds = %entry\n %6 = select i1 false, i1 false, i1 false\n %7 = select i1 %6, i1 %0, i1 false\n %8 = select i1 %7, i1 %1, i1 false\n %9 = select i1 %8, i1 false, i1 false\n %10 = select i1 %9, i1 %3, i1 false\n %11 = select i1 %10, i1 %4, i1 false\n br i1 %11, label %12, label %13\n\n12: ; preds = %5\n ret void\n\n13: ; preds = %5\n ret void\n}\n"}]}], "issue": {"title": "Crash in getSameOpcode(llvm::ArrayRef, llvm::TargetLibraryInfo const&, unsigned int)", "body": " To reproduce run the test below with `-passes slp-vectorizer -slp-threshold=-99999`\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() #0 gc \"statepoint-example\" {\r\nbb:\r\n br label %bb1\r\n\r\nbb1: ; preds = %bb1, %bb\r\n %phi = phi i32 [ 0, %bb ], [ %mul9, %bb1 ]\r\n %phi2 = phi i32 [ 0, %bb ], [ 0, %bb1 ]\r\n %trunc = trunc i64 0 to i32\r\n %mul = mul i32 0, %trunc\r\n %mul3 = mul i32 %trunc, %phi\r\n %mul4 = mul i32 %mul3, %mul\r\n %mul5 = mul i32 %mul4, %mul\r\n %trunc6 = trunc i64 0 to i32\r\n %mul7 = mul i32 0, %trunc6\r\n %mul8 = mul i32 %mul5, %mul7\r\n %mul9 = mul i32 %mul8, %mul7\r\n br label %bb1\r\n}\r\n\r\n```\r\nReproducer: https://godbolt.org/z/sqEov8n9h\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 slp-vectorizer -slp-threshold=-99999 \r\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"\"\r\n2.\tRunning pass \"slp-vectorizer\" on function \"wombat\"\r\n #0 0x0000000004f2ff18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f2ff18)\r\n #1 0x0000000004f2d68c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007a3cdfe42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000000000403fb8a getSameOpcode(llvm::ArrayRef, llvm::TargetLibraryInfo const&, unsigned int) (.constprop.1) SLPVectorizer.cpp:0:0\r\n #4 0x000000000406b0a4 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\r\n #5 0x000000000406dab4 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::SmallVectorImpl&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x406dab4)\r\n #6 0x00000000040720f8 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40720f8)\r\n #7 0x00000000040763be llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40763be)\r\n #8 0x000000000407c648 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 #9 0x000000000407d11b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x407d11b)\r\n#10 0x0000000002e7f61e llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2e7f61e)\r\n#11 0x0000000004d2d348 llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d2d348)\r\n#12 0x0000000000de6cce llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xde6cce)\r\n#13 0x0000000004d2bd3e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d2bd3e)\r\n#14 0x0000000000de731e llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xde731e)\r\n#15 0x0000000004d29ea0 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d29ea0)\r\n#16 0x00000000008e4312 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::ArrayRef>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8e4312)\r\n#17 0x00000000008d723c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d723c)\r\n#18 0x00007a3cdfe29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#19 0x00007a3cdfe29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#20 0x00000000008ce6ae _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ce6ae)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "TatyanaDoubts", "labels": ["llvm:SLPVectorizer", "crash"], "comments": [{"author": "RKSimon", "body": "CC @alexey-bataev "}]}, "verified": true} -{"bug_id": "128401", "issue_url": "https://github.com/llvm/llvm-project/issues/128401", "bug_type": "crash", "base_commit": "22a5bb32b787443b70476cc1359709b6c888b591", "knowledge_cutoff": "2025-02-23T05:19:16Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "eb14d2a1d48fe76c5faed71a08547135a35ee742", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[13320, 13328], [13874, 13888]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["BoUpSLP::isGatherShuffledSingleRegisterEntry", "BoUpSLP::isGatherShuffledEntry"]}}, "patch": "commit eb14d2a1d48fe76c5faed71a08547135a35ee742\nAuthor: Alexey Bataev \nDate: Mon Feb 24 06:02:56 2025 -0800\n\n [SLP]Fix check for matched gather node, if it is a subvector node\n \n If the gather node is a subvector node, it may match the existing\n vector/gather node in the graph, but still may require reordering. in\n this case need to fully check its dependencies to prevent a compiler\n crash.\n \n Fixes #128401\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex bf256d82ae17..5fc5fb10fad5 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -13320,9 +13320,16 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry(\n Entries.clear();\n // TODO: currently checking only for Scalars in the tree entry, need to count\n // reused elements too for better cost estimation.\n- const EdgeInfo &TEUseEI = TE == VectorizableTree.front().get()\n- ? EdgeInfo(const_cast(TE), 0)\n- : TE->UserTreeIndex;\n+ auto GetUserEntry = [&](const TreeEntry *TE) {\n+ while (TE->UserTreeIndex && TE->UserTreeIndex.EdgeIdx == UINT_MAX)\n+ TE = TE->UserTreeIndex.UserTE;\n+ if (TE == VectorizableTree.front().get())\n+ return EdgeInfo(const_cast(TE), 0);\n+ return TE->UserTreeIndex;\n+ };\n+ const EdgeInfo TEUseEI = GetUserEntry(TE);\n+ if (!TEUseEI)\n+ return std::nullopt;\n const Instruction *TEInsertPt = &getLastInstructionInBundle(TEUseEI.UserTE);\n const BasicBlock *TEInsertBlock = nullptr;\n // Main node of PHI entries keeps the correct order of operands/incoming\n@@ -13874,15 +13881,13 @@ BoUpSLP::isGatherShuffledEntry(\n assert(VL.size() % NumParts == 0 &&\n \"Number of scalars must be divisible by NumParts.\");\n if (TE->UserTreeIndex && TE->UserTreeIndex.UserTE->isGather() &&\n- TE->UserTreeIndex.EdgeIdx == UINT_MAX) {\n- assert(\n- (TE->Idx == 0 ||\n- (TE->hasState() && TE->getOpcode() == Instruction::ExtractElement) ||\n- isSplat(TE->Scalars) ||\n- getSameValuesTreeEntry(TE->getMainOp(), TE->Scalars)) &&\n- \"Expected splat or extractelements only node.\");\n+ TE->UserTreeIndex.EdgeIdx == UINT_MAX &&\n+ (TE->Idx == 0 ||\n+ (TE->hasState() && TE->getOpcode() == Instruction::ExtractElement) ||\n+ isSplat(TE->Scalars) ||\n+ (TE->hasState() &&\n+ getSameValuesTreeEntry(TE->getMainOp(), TE->Scalars))))\n return {};\n- }\n unsigned SliceSize = getPartNumElems(VL.size(), NumParts);\n SmallVector> Res;\n for (unsigned Part : seq(NumParts)) {\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/X86/bv-matched-node-reorder.ll", "commands": ["opt -passes=slp-vectorizer -S -mtriple=x86_64-unknown-linux-gnu < %s"], "tests": [{"test_name": "", "test_body": "\n@g = global [8 x i8] zeroinitializer\n\ndefine i32 @main() {\n;\nentry:\n %l2.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 5), align 1\n %li.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 4), align 1\n %l1.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 7), align 1\n %l6.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 6), align 1\n br i1 false, label %if.end151.1.i.i.1.i.i.i, label %end\n\npre:\n br label %end\n\nend:\n %0 = phi i8 [ 0, %pre ], [ %li.i.i.i, %entry ]\n %1 = phi i8 [ 0, %pre ], [ %l2.i.i.i.i, %entry ]\n %2 = phi i8 [ 0, %pre ], [ %l6.i.i.i.i, %entry ]\n %3 = phi i8 [ 0, %pre ], [ %l1.i.i.i.i, %entry ]\n %4 = phi i8 [ 0, %pre ], [ %l1.i.i.i.i, %entry ]\n %5 = phi i8 [ 0, %pre ], [ %l6.i.i.i.i, %entry ]\n %6 = phi i8 [ 0, %pre ], [ %l2.i.i.i.i, %entry ]\n %7 = phi i8 [ 0, %pre ], [ %li.i.i.i, %entry ]\n br label %if.end151.1.i.i.1.i.i.i\n\nif.end151.1.i.i.1.i.i.i:\n %8 = phi i8 [ %li.i.i.i, %entry ], [ %7, %end ]\n %9 = phi i8 [ %l2.i.i.i.i, %entry ], [ %6, %end ]\n %10 = phi i8 [ %l6.i.i.i.i, %entry ], [ %5, %end ]\n %11 = phi i8 [ %l1.i.i.i.i, %entry ], [ %4, %end ]\n %12 = phi i8 [ %l1.i.i.i.i, %entry ], [ %3, %end ]\n %13 = phi i8 [ 0, %entry ], [ %2, %end ]\n %14 = phi i8 [ %l2.i.i.i.i, %entry ], [ %1, %end ]\n %15 = phi i8 [ %li.i.i.i, %entry ], [ %0, %end ]\n %16 = phi i8 [ 0, %entry ], [ %6, %end ]\n %17 = phi i8 [ %l1.i.i.i.i, %entry ], [ %4, %end ]\n %18 = phi i8 [ %l6.i.i.i.i, %entry ], [ %5, %end ]\n %19 = phi i8 [ %l1.i.i.i.i, %entry ], [ %4, %end ]\n %20 = phi i8 [ %l6.i.i.i.i, %entry ], [ %5, %end ]\n %21 = phi i8 [ %l2.i.i.i.i, %entry ], [ %6, %end ]\n %22 = phi i8 [ %li.i.i.i, %entry ], [ %7, %end ]\n %tobool.not.i.1121.i.1.i.i.i = icmp ne i8 %18, 0\n %c1.1.1117.i.1.i9.i.i = icmp eq i8 %17, 0\n %c1.i.1.i.i.i = icmp eq i8 %16, 0\n %c1.1.i.i.i.i = icmp eq i8 %12, 0\n %cmp258.i.1.i.i.i.i = icmp eq i8 %13, 0\n %c1.i.i.i.i = icmp eq i8 %14, 0\n %cmp258.i.i.i.i.i = icmp eq i8 %15, 0\n %c1.1.1.i.i.i.i = icmp eq i8 %11, 0\n %cmp258.i.1.1.i.i.i.i = icmp eq i8 %10, 0\n %c1.187.i.i.i.i = icmp eq i8 %9, 0\n %cmp258.i.185.i.i.i.i = icmp eq i8 %8, 0\n %c1.1.1117.i.i.i.i = icmp eq i8 %19, 0\n %cmp258.i.1.1115.i.i.i.i = icmp eq i8 %20, 0\n %c1.1113.i.i.i.i = icmp eq i8 %21, 0\n %cmp258.i.1111.i.i.i.i = icmp eq i8 %22, 0\n %c1.187.1.i.i.i.i = icmp eq i8 %16, 0\n ret i32 0\n}"}]}], "issue": {"title": "[SLPVectorizer] Assertion `\"Expected splat or extractelements only node.\"' failed.", "body": "Reproducer: https://godbolt.org/z/9jx1xejoe\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 [8 x i8] zeroinitializer\n\ndefine i32 @main() {\nentry:\n %.promoted42.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 5), align 1\n %.promoted.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 4), align 1\n %.promoted51.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 7), align 1\n %.promoted56.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 6), align 1\n br i1 false, label %if.end151.1.i.i.1.i.i.i, label %if.end151.1.i.1.i.i.i.i\n\nfor.cond79.preheader.us.preheader.1.i.1.i.i.i.i:\n br label %if.end151.1.i.1.i.i.i.i\n\nif.end151.1.i.1.i.i.i.i:\n %0 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted.i.i.i.i, %entry ]\n %1 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted42.i.i.i.i, %entry ]\n %2 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted56.i.i.i.i, %entry ]\n %3 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted51.i.i.i.i, %entry ]\n %4 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted51.i.i.i.i, %entry ]\n %5 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted56.i.i.i.i, %entry ]\n %6 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted42.i.i.i.i, %entry ]\n %7 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted.i.i.i.i, %entry ]\n br label %if.end151.1.i.i.1.i.i.i\n\nif.end151.1.i.i.1.i.i.i:\n %8 = phi i8 [ %.promoted.i.i.i.i, %entry ], [ %7, %if.end151.1.i.1.i.i.i.i ]\n %9 = phi i8 [ %.promoted42.i.i.i.i, %entry ], [ %6, %if.end151.1.i.1.i.i.i.i ]\n %10 = phi i8 [ %.promoted56.i.i.i.i, %entry ], [ %5, %if.end151.1.i.1.i.i.i.i ]\n %11 = phi i8 [ %.promoted51.i.i.i.i, %entry ], [ %4, %if.end151.1.i.1.i.i.i.i ]\n %12 = phi i8 [ %.promoted51.i.i.i.i, %entry ], [ %3, %if.end151.1.i.1.i.i.i.i ]\n %13 = phi i8 [ 0, %entry ], [ %2, %if.end151.1.i.1.i.i.i.i ]\n %14 = phi i8 [ %.promoted42.i.i.i.i, %entry ], [ %1, %if.end151.1.i.1.i.i.i.i ]\n %15 = phi i8 [ %.promoted.i.i.i.i, %entry ], [ %0, %if.end151.1.i.1.i.i.i.i ]\n %16 = phi i8 [ 0, %entry ], [ %6, %if.end151.1.i.1.i.i.i.i ]\n %17 = phi i8 [ %.promoted51.i.i.i.i, %entry ], [ %4, %if.end151.1.i.1.i.i.i.i ]\n %18 = phi i8 [ %.promoted56.i.i.i.i, %entry ], [ %5, %if.end151.1.i.1.i.i.i.i ]\n %19 = phi i8 [ %.promoted51.i.i.i.i, %entry ], [ %4, %if.end151.1.i.1.i.i.i.i ]\n %20 = phi i8 [ %.promoted56.i.i.i.i, %entry ], [ %5, %if.end151.1.i.1.i.i.i.i ]\n %21 = phi i8 [ %.promoted42.i.i.i.i, %entry ], [ %6, %if.end151.1.i.1.i.i.i.i ]\n %22 = phi i8 [ %.promoted.i.i.i.i, %entry ], [ %7, %if.end151.1.i.1.i.i.i.i ]\n %tobool.not.i.1121.i.1.i.i.i = icmp ne i8 %18, 0\n %cmp258.1.i.1.1117.i.1.i9.i.i = icmp eq i8 %17, 0\n %cmp258.1.i.i.1.i.i.i = icmp eq i8 %16, 0\n %cmp258.1.i.1.i.i.i.i = icmp eq i8 %12, 0\n %cmp258.i.1.i.i.i.i = icmp eq i8 %13, 0\n %cmp258.1.i.i.i.i.i = icmp eq i8 %14, 0\n %cmp258.i.i.i.i.i = icmp eq i8 %15, 0\n %cmp258.1.i.1.1.i.i.i.i = icmp eq i8 %11, 0\n %cmp258.i.1.1.i.i.i.i = icmp eq i8 %10, 0\n %cmp258.1.i.187.i.i.i.i = icmp eq i8 %9, 0\n %cmp258.i.185.i.i.i.i = icmp eq i8 %8, 0\n %cmp258.1.i.1.1117.i.i.i.i = icmp eq i8 %19, 0\n %cmp258.i.1.1115.i.i.i.i = icmp eq i8 %20, 0\n %cmp258.1.i.1113.i.i.i.i = icmp eq i8 %21, 0\n %cmp258.i.1111.i.i.i.i = icmp eq i8 %22, 0\n %cmp258.1.i.187.1.i.i.i.i = icmp eq i8 %16, 0\n ret i32 0\n}\n```\n```\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:13878: llvm::SmallVector > llvm::slpvectorizer::BoUpSLP::isGatherShuffledEntry(const llvm::slpvectorizer::BoUpSLP::TreeEntry*, llvm::ArrayRef, llvm::SmallVectorImpl&, llvm::SmallVectorImpl >&, unsigned int, bool): Assertion `(TE->Idx == 0 || (TE->hasState() && TE->getOpcode() == Instruction::ExtractElement) || isSplat(TE->Scalars) || getSameValuesTreeEntry(TE->getMainOp(), TE->Scalars)) && \"Expected splat or extractelements only node.\"' 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 \n1.\tRunning pass \"function(slp-vectorizer)\" on module \"\"\n2.\tRunning pass \"slp-vectorizer\" on function \"main\"\n #0 0x0000000005447b18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5447b18)\n #1 0x00000000054454d4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x000072c4b8a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x000072c4b8a969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x000072c4b8a42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x000072c4b8a287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x000072c4b8a2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #7 0x000072c4b8a39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #8 0x000000000447b405 llvm::slpvectorizer::BoUpSLP::isGatherShuffledEntry(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef, llvm::SmallVectorImpl&, llvm::SmallVectorImpl>&, unsigned int, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x447b405)\n #9 0x000000000447c786 llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::processBuildVector, llvm::slpvectorizer::BoUpSLP, llvm::SmallPtrSetImpl>(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::Type*, llvm::TargetTransformInfo&, llvm::ArrayRef&, llvm::slpvectorizer::BoUpSLP&, llvm::SmallPtrSetImpl&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x447c786)\n#10 0x000000000447ec37 llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef, llvm::SmallPtrSetImpl&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x447ec37)\n#11 0x00000000044b3879 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44b3879)\n#12 0x00000000044bd45d llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef, llvm::slpvectorizer::BoUpSLP&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44bd45d)\n#13 0x00000000044c1701 bool llvm::SLPVectorizerPass::vectorizeCmpInsts>(llvm::iterator_range>, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44c1701)\n#14 0x00000000044c1fab llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&)::'lambda3'(bool)::operator()(bool) const SLPVectorizer.cpp:0:0\n#15 0x00000000044c575f llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44c575f)\n#16 0x00000000044cbef6 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#17 0x00000000044cca4b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44cca4b)\n#18 0x0000000003182e1e llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3182e1e)\n#19 0x00000000052431d0 llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x52431d0)\n#20 0x0000000000e6e03e llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe6e03e)\n#21 0x0000000005241aeb llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5241aeb)\n#22 0x0000000000e6d34e llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe6d34e)\n#23 0x00000000052414f0 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x52414f0)\n#24 0x0000000000935a5a llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::ArrayRef>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x935a5a)\n#25 0x00000000009290cc optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9290cc)\n#26 0x000072c4b8a29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#27 0x000072c4b8a29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#28 0x00000000009209a5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9209a5)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```\nllvm version: dbd219aef4be56754c793589c60bd787b7de60c2\n", "author": "dtcxzyw", "labels": ["llvm:SLPVectorizer", "crash-on-valid", "generated by fuzzer"], "comments": []}, "verified": true} +{"bug_id": "128401", "issue_url": "https://github.com/llvm/llvm-project/issues/128401", "bug_type": "crash", "base_commit": "22a5bb32b787443b70476cc1359709b6c888b591", "knowledge_cutoff": "2025-02-23T05:19:16Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "eb14d2a1d48fe76c5faed71a08547135a35ee742", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[13320, 13328], [13874, 13888]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["BoUpSLP::isGatherShuffledEntry", "BoUpSLP::isGatherShuffledSingleRegisterEntry"]}}, "patch": "commit eb14d2a1d48fe76c5faed71a08547135a35ee742\nAuthor: Alexey Bataev \nDate: Mon Feb 24 06:02:56 2025 -0800\n\n [SLP]Fix check for matched gather node, if it is a subvector node\n \n If the gather node is a subvector node, it may match the existing\n vector/gather node in the graph, but still may require reordering. in\n this case need to fully check its dependencies to prevent a compiler\n crash.\n \n Fixes #128401\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex bf256d82ae17..5fc5fb10fad5 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -13320,9 +13320,16 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry(\n Entries.clear();\n // TODO: currently checking only for Scalars in the tree entry, need to count\n // reused elements too for better cost estimation.\n- const EdgeInfo &TEUseEI = TE == VectorizableTree.front().get()\n- ? EdgeInfo(const_cast(TE), 0)\n- : TE->UserTreeIndex;\n+ auto GetUserEntry = [&](const TreeEntry *TE) {\n+ while (TE->UserTreeIndex && TE->UserTreeIndex.EdgeIdx == UINT_MAX)\n+ TE = TE->UserTreeIndex.UserTE;\n+ if (TE == VectorizableTree.front().get())\n+ return EdgeInfo(const_cast(TE), 0);\n+ return TE->UserTreeIndex;\n+ };\n+ const EdgeInfo TEUseEI = GetUserEntry(TE);\n+ if (!TEUseEI)\n+ return std::nullopt;\n const Instruction *TEInsertPt = &getLastInstructionInBundle(TEUseEI.UserTE);\n const BasicBlock *TEInsertBlock = nullptr;\n // Main node of PHI entries keeps the correct order of operands/incoming\n@@ -13874,15 +13881,13 @@ BoUpSLP::isGatherShuffledEntry(\n assert(VL.size() % NumParts == 0 &&\n \"Number of scalars must be divisible by NumParts.\");\n if (TE->UserTreeIndex && TE->UserTreeIndex.UserTE->isGather() &&\n- TE->UserTreeIndex.EdgeIdx == UINT_MAX) {\n- assert(\n- (TE->Idx == 0 ||\n- (TE->hasState() && TE->getOpcode() == Instruction::ExtractElement) ||\n- isSplat(TE->Scalars) ||\n- getSameValuesTreeEntry(TE->getMainOp(), TE->Scalars)) &&\n- \"Expected splat or extractelements only node.\");\n+ TE->UserTreeIndex.EdgeIdx == UINT_MAX &&\n+ (TE->Idx == 0 ||\n+ (TE->hasState() && TE->getOpcode() == Instruction::ExtractElement) ||\n+ isSplat(TE->Scalars) ||\n+ (TE->hasState() &&\n+ getSameValuesTreeEntry(TE->getMainOp(), TE->Scalars))))\n return {};\n- }\n unsigned SliceSize = getPartNumElems(VL.size(), NumParts);\n SmallVector> Res;\n for (unsigned Part : seq(NumParts)) {\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/X86/bv-matched-node-reorder.ll", "commands": ["opt -passes=slp-vectorizer -S -mtriple=x86_64-unknown-linux-gnu < %s"], "tests": [{"test_name": "", "test_body": "\n@g = global [8 x i8] zeroinitializer\n\ndefine i32 @main() {\n;\nentry:\n %l2.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 5), align 1\n %li.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 4), align 1\n %l1.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 7), align 1\n %l6.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 6), align 1\n br i1 false, label %if.end151.1.i.i.1.i.i.i, label %end\n\npre:\n br label %end\n\nend:\n %0 = phi i8 [ 0, %pre ], [ %li.i.i.i, %entry ]\n %1 = phi i8 [ 0, %pre ], [ %l2.i.i.i.i, %entry ]\n %2 = phi i8 [ 0, %pre ], [ %l6.i.i.i.i, %entry ]\n %3 = phi i8 [ 0, %pre ], [ %l1.i.i.i.i, %entry ]\n %4 = phi i8 [ 0, %pre ], [ %l1.i.i.i.i, %entry ]\n %5 = phi i8 [ 0, %pre ], [ %l6.i.i.i.i, %entry ]\n %6 = phi i8 [ 0, %pre ], [ %l2.i.i.i.i, %entry ]\n %7 = phi i8 [ 0, %pre ], [ %li.i.i.i, %entry ]\n br label %if.end151.1.i.i.1.i.i.i\n\nif.end151.1.i.i.1.i.i.i:\n %8 = phi i8 [ %li.i.i.i, %entry ], [ %7, %end ]\n %9 = phi i8 [ %l2.i.i.i.i, %entry ], [ %6, %end ]\n %10 = phi i8 [ %l6.i.i.i.i, %entry ], [ %5, %end ]\n %11 = phi i8 [ %l1.i.i.i.i, %entry ], [ %4, %end ]\n %12 = phi i8 [ %l1.i.i.i.i, %entry ], [ %3, %end ]\n %13 = phi i8 [ 0, %entry ], [ %2, %end ]\n %14 = phi i8 [ %l2.i.i.i.i, %entry ], [ %1, %end ]\n %15 = phi i8 [ %li.i.i.i, %entry ], [ %0, %end ]\n %16 = phi i8 [ 0, %entry ], [ %6, %end ]\n %17 = phi i8 [ %l1.i.i.i.i, %entry ], [ %4, %end ]\n %18 = phi i8 [ %l6.i.i.i.i, %entry ], [ %5, %end ]\n %19 = phi i8 [ %l1.i.i.i.i, %entry ], [ %4, %end ]\n %20 = phi i8 [ %l6.i.i.i.i, %entry ], [ %5, %end ]\n %21 = phi i8 [ %l2.i.i.i.i, %entry ], [ %6, %end ]\n %22 = phi i8 [ %li.i.i.i, %entry ], [ %7, %end ]\n %tobool.not.i.1121.i.1.i.i.i = icmp ne i8 %18, 0\n %c1.1.1117.i.1.i9.i.i = icmp eq i8 %17, 0\n %c1.i.1.i.i.i = icmp eq i8 %16, 0\n %c1.1.i.i.i.i = icmp eq i8 %12, 0\n %cmp258.i.1.i.i.i.i = icmp eq i8 %13, 0\n %c1.i.i.i.i = icmp eq i8 %14, 0\n %cmp258.i.i.i.i.i = icmp eq i8 %15, 0\n %c1.1.1.i.i.i.i = icmp eq i8 %11, 0\n %cmp258.i.1.1.i.i.i.i = icmp eq i8 %10, 0\n %c1.187.i.i.i.i = icmp eq i8 %9, 0\n %cmp258.i.185.i.i.i.i = icmp eq i8 %8, 0\n %c1.1.1117.i.i.i.i = icmp eq i8 %19, 0\n %cmp258.i.1.1115.i.i.i.i = icmp eq i8 %20, 0\n %c1.1113.i.i.i.i = icmp eq i8 %21, 0\n %cmp258.i.1111.i.i.i.i = icmp eq i8 %22, 0\n %c1.187.1.i.i.i.i = icmp eq i8 %16, 0\n ret i32 0\n}"}]}], "issue": {"title": "[SLPVectorizer] Assertion `\"Expected splat or extractelements only node.\"' failed.", "body": "Reproducer: https://godbolt.org/z/9jx1xejoe\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 [8 x i8] zeroinitializer\n\ndefine i32 @main() {\nentry:\n %.promoted42.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 5), align 1\n %.promoted.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 4), align 1\n %.promoted51.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 7), align 1\n %.promoted56.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 6), align 1\n br i1 false, label %if.end151.1.i.i.1.i.i.i, label %if.end151.1.i.1.i.i.i.i\n\nfor.cond79.preheader.us.preheader.1.i.1.i.i.i.i:\n br label %if.end151.1.i.1.i.i.i.i\n\nif.end151.1.i.1.i.i.i.i:\n %0 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted.i.i.i.i, %entry ]\n %1 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted42.i.i.i.i, %entry ]\n %2 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted56.i.i.i.i, %entry ]\n %3 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted51.i.i.i.i, %entry ]\n %4 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted51.i.i.i.i, %entry ]\n %5 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted56.i.i.i.i, %entry ]\n %6 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted42.i.i.i.i, %entry ]\n %7 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted.i.i.i.i, %entry ]\n br label %if.end151.1.i.i.1.i.i.i\n\nif.end151.1.i.i.1.i.i.i:\n %8 = phi i8 [ %.promoted.i.i.i.i, %entry ], [ %7, %if.end151.1.i.1.i.i.i.i ]\n %9 = phi i8 [ %.promoted42.i.i.i.i, %entry ], [ %6, %if.end151.1.i.1.i.i.i.i ]\n %10 = phi i8 [ %.promoted56.i.i.i.i, %entry ], [ %5, %if.end151.1.i.1.i.i.i.i ]\n %11 = phi i8 [ %.promoted51.i.i.i.i, %entry ], [ %4, %if.end151.1.i.1.i.i.i.i ]\n %12 = phi i8 [ %.promoted51.i.i.i.i, %entry ], [ %3, %if.end151.1.i.1.i.i.i.i ]\n %13 = phi i8 [ 0, %entry ], [ %2, %if.end151.1.i.1.i.i.i.i ]\n %14 = phi i8 [ %.promoted42.i.i.i.i, %entry ], [ %1, %if.end151.1.i.1.i.i.i.i ]\n %15 = phi i8 [ %.promoted.i.i.i.i, %entry ], [ %0, %if.end151.1.i.1.i.i.i.i ]\n %16 = phi i8 [ 0, %entry ], [ %6, %if.end151.1.i.1.i.i.i.i ]\n %17 = phi i8 [ %.promoted51.i.i.i.i, %entry ], [ %4, %if.end151.1.i.1.i.i.i.i ]\n %18 = phi i8 [ %.promoted56.i.i.i.i, %entry ], [ %5, %if.end151.1.i.1.i.i.i.i ]\n %19 = phi i8 [ %.promoted51.i.i.i.i, %entry ], [ %4, %if.end151.1.i.1.i.i.i.i ]\n %20 = phi i8 [ %.promoted56.i.i.i.i, %entry ], [ %5, %if.end151.1.i.1.i.i.i.i ]\n %21 = phi i8 [ %.promoted42.i.i.i.i, %entry ], [ %6, %if.end151.1.i.1.i.i.i.i ]\n %22 = phi i8 [ %.promoted.i.i.i.i, %entry ], [ %7, %if.end151.1.i.1.i.i.i.i ]\n %tobool.not.i.1121.i.1.i.i.i = icmp ne i8 %18, 0\n %cmp258.1.i.1.1117.i.1.i9.i.i = icmp eq i8 %17, 0\n %cmp258.1.i.i.1.i.i.i = icmp eq i8 %16, 0\n %cmp258.1.i.1.i.i.i.i = icmp eq i8 %12, 0\n %cmp258.i.1.i.i.i.i = icmp eq i8 %13, 0\n %cmp258.1.i.i.i.i.i = icmp eq i8 %14, 0\n %cmp258.i.i.i.i.i = icmp eq i8 %15, 0\n %cmp258.1.i.1.1.i.i.i.i = icmp eq i8 %11, 0\n %cmp258.i.1.1.i.i.i.i = icmp eq i8 %10, 0\n %cmp258.1.i.187.i.i.i.i = icmp eq i8 %9, 0\n %cmp258.i.185.i.i.i.i = icmp eq i8 %8, 0\n %cmp258.1.i.1.1117.i.i.i.i = icmp eq i8 %19, 0\n %cmp258.i.1.1115.i.i.i.i = icmp eq i8 %20, 0\n %cmp258.1.i.1113.i.i.i.i = icmp eq i8 %21, 0\n %cmp258.i.1111.i.i.i.i = icmp eq i8 %22, 0\n %cmp258.1.i.187.1.i.i.i.i = icmp eq i8 %16, 0\n ret i32 0\n}\n```\n```\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:13878: llvm::SmallVector > llvm::slpvectorizer::BoUpSLP::isGatherShuffledEntry(const llvm::slpvectorizer::BoUpSLP::TreeEntry*, llvm::ArrayRef, llvm::SmallVectorImpl&, llvm::SmallVectorImpl >&, unsigned int, bool): Assertion `(TE->Idx == 0 || (TE->hasState() && TE->getOpcode() == Instruction::ExtractElement) || isSplat(TE->Scalars) || getSameValuesTreeEntry(TE->getMainOp(), TE->Scalars)) && \"Expected splat or extractelements only node.\"' 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 \n1.\tRunning pass \"function(slp-vectorizer)\" on module \"\"\n2.\tRunning pass \"slp-vectorizer\" on function \"main\"\n #0 0x0000000005447b18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5447b18)\n #1 0x00000000054454d4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x000072c4b8a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x000072c4b8a969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x000072c4b8a42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x000072c4b8a287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x000072c4b8a2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #7 0x000072c4b8a39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #8 0x000000000447b405 llvm::slpvectorizer::BoUpSLP::isGatherShuffledEntry(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef, llvm::SmallVectorImpl&, llvm::SmallVectorImpl>&, unsigned int, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x447b405)\n #9 0x000000000447c786 llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::processBuildVector, llvm::slpvectorizer::BoUpSLP, llvm::SmallPtrSetImpl>(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::Type*, llvm::TargetTransformInfo&, llvm::ArrayRef&, llvm::slpvectorizer::BoUpSLP&, llvm::SmallPtrSetImpl&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x447c786)\n#10 0x000000000447ec37 llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef, llvm::SmallPtrSetImpl&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x447ec37)\n#11 0x00000000044b3879 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44b3879)\n#12 0x00000000044bd45d llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef, llvm::slpvectorizer::BoUpSLP&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44bd45d)\n#13 0x00000000044c1701 bool llvm::SLPVectorizerPass::vectorizeCmpInsts>(llvm::iterator_range>, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44c1701)\n#14 0x00000000044c1fab llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&)::'lambda3'(bool)::operator()(bool) const SLPVectorizer.cpp:0:0\n#15 0x00000000044c575f llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44c575f)\n#16 0x00000000044cbef6 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#17 0x00000000044cca4b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44cca4b)\n#18 0x0000000003182e1e llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3182e1e)\n#19 0x00000000052431d0 llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x52431d0)\n#20 0x0000000000e6e03e llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe6e03e)\n#21 0x0000000005241aeb llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5241aeb)\n#22 0x0000000000e6d34e llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe6d34e)\n#23 0x00000000052414f0 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x52414f0)\n#24 0x0000000000935a5a llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::ArrayRef>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x935a5a)\n#25 0x00000000009290cc optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9290cc)\n#26 0x000072c4b8a29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#27 0x000072c4b8a29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#28 0x00000000009209a5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9209a5)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```\nllvm version: dbd219aef4be56754c793589c60bd787b7de60c2\n", "author": "dtcxzyw", "labels": ["llvm:SLPVectorizer", "crash-on-valid", "generated by fuzzer"], "comments": []}, "verified": true} {"bug_id": "106248", "issue_url": "https://github.com/llvm/llvm-project/issues/106248", "bug_type": "crash", "base_commit": "616f7d3d4f6d9bea6f776e357c938847e522a681", "knowledge_cutoff": "2024-08-27T17:02:16Z", "lit_test_dir": ["llvm/test/Transforms/LoopVectorize"], "hints": {"fix_commit": "0a272d3a1703415abca42dc2e2cc2b57cb30734e", "components": ["LoopVectorize"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [[6529, 6534]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": ["LoopVectorizationCostModel::getInstructionCost"]}}, "patch": "commit 0a272d3a1703415abca42dc2e2cc2b57cb30734e\nAuthor: Florian Hahn \nDate: Thu Aug 29 12:08:27 2024 +0100\n\n [LV] Use SCEV to analyze second operand for cost query.\n \n Improve operand analysis using SCEV for cost purposes. This fixes a\n divergence between legacy and VPlan-based cost-modeling after\n 533e6bbd0d34.\n \n Fixes https://github.com/llvm/llvm-project/issues/106248.\n\ndiff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\nindex 56f51e14a6eb..4cc75e2e7546 100644\n--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n@@ -6529,6 +6529,10 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I,\n // Certain instructions can be cheaper to vectorize if they have a constant\n // second vector operand. One example of this are shifts on x86.\n Value *Op2 = I->getOperand(1);\n+ if (!isa(Op2) && PSE.getSE()->isSCEVable(Op2->getType()) &&\n+ isa(PSE.getSCEV(Op2))) {\n+ Op2 = cast(PSE.getSCEV(Op2))->getValue();\n+ }\n auto Op2Info = TTI.getOperandInfo(Op2);\n if (Op2Info.Kind == TargetTransformInfo::OK_AnyValue &&\n Legal->isInvariant(Op2))\n", "tests": [{"file": "llvm/test/Transforms/LoopVectorize/X86/cost-constant-known-via-scev.ll", "commands": ["opt -p loop-vectorize -S %s"], "tests": [{"test_name": "test_foldable_live_in_via_scev", "test_body": "target 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\ndefine i64 @test_foldable_live_in_via_scev() {\nentry:\n %conv = zext i16 -6 to i64\n %add = add nsw i64 %conv, -65528\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop ]\n %red = phi i64 [ 1, %entry ], [ %mul, %loop ]\n %mul = mul nsw i64 %red, %add\n %iv.next = add nsw i32 %iv, 1\n %ec = icmp eq i32 %iv.next, 100\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n %ret = phi i64 [ %mul, %loop ]\n ret i64 %ret\n}\n"}]}], "issue": {"title": "[clang] Assertion failed in Vectorize", "body": "In #105722 , we resolved the assertion failure in vectorization. However, I met this crash again with the following case:\r\n\r\n```c\r\n#include \r\nint a;\r\nlong b;\r\nstruct e {\r\n uint16_t f;\r\n uint64_t g;\r\n int32_t h\r\n} static i = {65530};\r\nvoid c(int d) {\r\n for (; a; a++)\r\n b *= d;\r\n}\r\nuint32_t j(struct e, uint16_t);\r\nuint64_t k() { j(i, 0); }\r\nuint32_t j(struct e, uint16_t) { c(i.f - 65528); }\r\n```\r\nI compiled it with -O2 flag and it crashed. But when I compiled with -O1/-O0, it worked.\r\n\r\nThe crash is: clang++: /root/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7359: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), BestFactor.Width, CostCtx, OrigLoop, CM)) && \" VPlan cost model and legacy cost model disagreed\"' failed.\r\n\r\nThe details can be found here: https://godbolt.org/z/8x48xsKs6", "author": "cardigan1008", "labels": ["vectorizers", "crash"], "comments": [{"author": "fhahn", "body": "Thanks for the report @cardigan1008, should be fixed now"}]}, "verified": true} {"bug_id": "104761", "issue_url": "https://github.com/llvm/llvm-project/issues/104761", "bug_type": "crash", "base_commit": "5cfa8baef33636827e5aa8dd76888c724433b53e", "knowledge_cutoff": "2024-08-19T11:00:31Z", "lit_test_dir": ["llvm/test/Analysis/LoopCacheAnalysis"], "hints": {"fix_commit": "2e6deb1dd3a4422807633ba08773e8d786e43d4c", "components": ["LoopCacheAnalysis"], "bug_location_lineno": {"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": [[16, 21], [31, 37], [192, 199]], "llvm/lib/Analysis/LoopCacheAnalysis.cpp": [[328, 333], [338, 351], [696, 702]]}, "bug_location_funcname": {"llvm/lib/Analysis/LoopCacheAnalysis.cpp": ["CacheCost::computeLoopCacheCost", "IndexedReference::computeRefCost", "IndexedReference::tryDelinearizeFixedSize"]}}, "patch": "commit 2e6deb1dd3a4422807633ba08773e8d786e43d4c\nAuthor: Sjoerd Meijer \nDate: Thu Nov 14 08:40:45 2024 +0000\n\n [LoopInterchange] Fix overflow in cost calculation (#111807)\n \n If the iteration count is really large, e.g. UINT_MAX, then the cost\n calculation can overflows and trigger an assert. So saturate the cost to\n INT_MAX if this is the case by using InstructionCost as a type which\n already supports this kind of overflow handling.\n \n This fixes #104761\n\ndiff --git a/llvm/include/llvm/Analysis/LoopCacheAnalysis.h b/llvm/include/llvm/Analysis/LoopCacheAnalysis.h\nindex 4fd2485e39d6..3e22487e5e34 100644\n--- a/llvm/include/llvm/Analysis/LoopCacheAnalysis.h\n+++ b/llvm/include/llvm/Analysis/LoopCacheAnalysis.h\n@@ -16,6 +16,7 @@\n \n #include \"llvm/Analysis/LoopAnalysisManager.h\"\n #include \"llvm/IR/PassManager.h\"\n+#include \"llvm/Support/InstructionCost.h\"\n #include \n \n namespace llvm {\n@@ -31,7 +32,7 @@ class ScalarEvolution;\n class SCEV;\n class TargetTransformInfo;\n \n-using CacheCostTy = int64_t;\n+using CacheCostTy = InstructionCost;\n using LoopVectorTy = SmallVector;\n \n /// Represents a memory reference as a base pointer and a set of indexing\n@@ -192,8 +193,6 @@ class CacheCost {\n using LoopCacheCostTy = std::pair;\n \n public:\n- static CacheCostTy constexpr InvalidCost = -1;\n-\n /// Construct a CacheCost object for the loop nest described by \\p Loops.\n /// The optional parameter \\p TRT can be used to specify the max. distance\n /// between array elements accessed in a loop so that the elements are\ndiff --git a/llvm/lib/Analysis/LoopCacheAnalysis.cpp b/llvm/lib/Analysis/LoopCacheAnalysis.cpp\nindex 7ca9f15ad5fc..2897b922f61e 100644\n--- a/llvm/lib/Analysis/LoopCacheAnalysis.cpp\n+++ b/llvm/lib/Analysis/LoopCacheAnalysis.cpp\n@@ -328,6 +328,8 @@ CacheCostTy IndexedReference::computeRefCost(const Loop &L,\n const SCEV *TripCount =\n computeTripCount(*AR->getLoop(), *Sizes.back(), SE);\n Type *WiderType = SE.getWiderType(RefCost->getType(), TripCount->getType());\n+ // For the multiplication result to fit, request a type twice as wide.\n+ WiderType = WiderType->getExtendedType();\n RefCost = SE.getMulExpr(SE.getNoopOrZeroExtend(RefCost, WiderType),\n SE.getNoopOrZeroExtend(TripCount, WiderType));\n }\n@@ -338,14 +340,18 @@ CacheCostTy IndexedReference::computeRefCost(const Loop &L,\n assert(RefCost && \"Expecting a valid RefCost\");\n \n // Attempt to fold RefCost into a constant.\n+ // CacheCostTy is a signed integer, but the tripcount value can be large\n+ // and may not fit, so saturate/limit the value to the maximum signed\n+ // integer value.\n if (auto ConstantCost = dyn_cast(RefCost))\n- return ConstantCost->getValue()->getZExtValue();\n+ return ConstantCost->getValue()->getLimitedValue(\n+ std::numeric_limits::max());\n \n LLVM_DEBUG(dbgs().indent(4)\n << \"RefCost is not a constant! Setting to RefCost=InvalidCost \"\n \"(invalid value).\\n\");\n \n- return CacheCost::InvalidCost;\n+ return CacheCostTy::getInvalid();\n }\n \n bool IndexedReference::tryDelinearizeFixedSize(\n@@ -696,7 +702,7 @@ CacheCostTy\n CacheCost::computeLoopCacheCost(const Loop &L,\n const ReferenceGroupsTy &RefGroups) const {\n if (!L.isLoopSimplifyForm())\n- return InvalidCost;\n+ return CacheCostTy::getInvalid();\n \n LLVM_DEBUG(dbgs() << \"Considering loop '\" << L.getName()\n << \"' as innermost loop.\\n\");\n", "tests": [{"file": "llvm/test/Analysis/LoopCacheAnalysis/interchange-refcost-overflow.ll", "commands": ["opt < %s -passes='print' -disable-output 2>&1"], "tests": [{"test_name": "foo", "test_body": "@A = external local_unnamed_addr global [11 x [11 x [11 x i32]]], align 16\n\ndefine void @foo(i32 noundef %b) {\nentry:\n %0 = sext i32 %b to i64\n br label %outer.loop\n\nouter.loop: ; preds = %outer.loop.cleanup, %entry\n %indvars.iv = phi i64 [ %indvars.iv.next, %outer.loop.cleanup ], [ 0, %entry ]\n br label %inner.loop\n\nouter.loop.cleanup: ; preds = %inner.loop\n %indvars.iv.next = add nsw i64 %indvars.iv, %0\n br label %outer.loop\n\ninner.loop: ; preds = %inner.loop, %outer.loop\n %inner.iv = phi i64 [ 0, %outer.loop ], [ %add, %inner.loop ]\n %arrayidx3 = getelementptr inbounds [11 x [11 x [11 x i32]]], ptr @A, i64 0, i64 %indvars.iv, i64 %inner.iv, i64 %inner.iv\n store i32 0, ptr %arrayidx3, align 4\n %add = add nuw i64 %inner.iv, 2\n %cmp = icmp ult i64 %inner.iv, -5\n br i1 %cmp, label %inner.loop, label %outer.loop.cleanup\n}\n"}]}], "issue": {"title": "[LoopInterchange] Assertion `getActiveBits() <= 64 && \"Too many bits for uint64_t\"", "body": "With options \"-O3 --target=aarch64 func.cpp -mllvm -enable-loopinterchange\" and this input:\r\n```\r\nunsigned int A[11][11][11] __attribute__((aligned(16)));\r\nvoid a(int b) {\r\n for (int c;; c += b)\r\n for (long d = 0; d < -3ULL; d += 2ULL)\r\n A[c][d][d] = 0;\r\n}\r\n```\r\n\r\nLoop-interchange runs in an assert:\r\n\r\n```\r\nllvm-project/llvm/include/llvm/ADT/APInt.h:1501: uint64_t llvm::APInt::getZExtValue() const: Assertion `getActiveBits() <= 64 && \"Too many bits for uint64_t\"' failed.\r\n```\r\n\r\nIR reproducer, compile this with \"opt -passes=loop-interchange -S\":\r\n\r\n```\r\ntarget datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32\"\r\ntarget triple = \"aarch64-unknown-linux-gnu\"\r\n\r\n@A = local_unnamed_addr global [11 x [11 x [11 x i32]]] zeroinitializer, align 16\r\n\r\ndefine void @_Z1ai(i32 noundef %b) local_unnamed_addr #0 {\r\nentry:\r\n %0 = sext i32 %b to i64\r\n br label %for.cond\r\n\r\n; Loop:\r\nfor.cond: ; preds = %for.cond.cleanup, %entry\r\n %indvars.iv = phi i64 [ %indvars.iv.next, %for.cond.cleanup ], [ 0, %entry ]\r\n br label %for.body\r\n\r\nfor.cond.cleanup: ; preds = %for.body\r\n %indvars.iv.next = add nsw i64 %indvars.iv, %0\r\n br label %for.cond\r\n\r\nfor.body: ; preds = %for.cond, %for.body\r\n %d.010 = phi i64 [ 0, %for.cond ], [ %add, %for.body ]\r\n %arrayidx3 = getelementptr inbounds [11 x [11 x [11 x i32]]], ptr @A, i64 0, i64 %indvars.iv, i64 %d.010, i64 %d.010\r\n store i32 0, ptr %arrayidx3, align 4\r\n %add = add nuw i64 %d.010, 2\r\n %cmp = icmp ult i64 %d.010, -5\r\n br i1 %cmp, label %for.body, label %for.cond.cleanup\r\n}\r\n```", "author": "sjoerdmeijer", "labels": ["crash-on-valid", "llvm:analysis"], "comments": [{"author": "RKSimon", "body": "```\r\nopt: /root/llvm-project/llvm/include/llvm/ADT/APInt.h:1501: uint64_t llvm::APInt::getZExtValue() const: Assertion `getActiveBits() <= 64 && \"Too many bits for uint64_t\"' 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=loop-interchange -debug \r\n1.\tRunning pass \"function(loop(loop-interchange))\" on module \"\"\r\n2.\tRunning pass \"loop(loop-interchange)\" on function \"_Z1ai\"\r\n #0 0x0000000004f7f528 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f7f528)\r\n #1 0x0000000004f7cc9c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007f497b842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007f497b8969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007f497b842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007f497b8287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00007f497b82871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x00007f497b839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x00000000045677cc llvm::IndexedReference::computeRefCost(llvm::Loop const&, unsigned int) const (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x45677cc)\r\n #9 0x000000000456995f llvm::CacheCost::computeLoopCacheCost(llvm::Loop const&, llvm::SmallVector>, 8u>, 8u> const&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x456995f)\r\n#10 0x000000000456c137 llvm::CacheCost::calculateCacheFootprint() (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x456c137)\r\n#11 0x0000000004573d5c llvm::CacheCost::getCacheCost(llvm::Loop&, llvm::LoopStandardAnalysisResults&, llvm::DependenceInfo&, std::optional) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4573d5c)\r\n#12 0x0000000003c71d66 llvm::LoopInterchangePass::run(llvm::LoopNest&, llvm::AnalysisManager&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3c71d66)\r\n#13 0x0000000002eb0a6e llvm::detail::PassModel, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::LoopNest&, llvm::AnalysisManager&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2eb0a6e)\r\n#14 0x0000000003c85255 llvm::PassManager, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::runWithLoopNestPasses(llvm::Loop&, llvm::AnalysisManager&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3c85255)\r\n#15 0x0000000003c85ce3 llvm::PassManager, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3c85ce3)\r\n#16 0x0000000003c868b8 llvm::FunctionToLoopPassAdaptor::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3c868b8)\r\n#17 0x0000000000df128e llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xdf128e)\r\n#18 0x0000000004d7c368 llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d7c368)\r\n#19 0x0000000000df14be llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xdf14be)\r\n#20 0x0000000004d7ad5e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d7ad5e)\r\n#21 0x0000000000df0f8e llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xdf0f8e)\r\n#22 0x0000000004d78ec0 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d78ec0)\r\n#23 0x00000000008e7582 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::ArrayRef>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8e7582)\r\n#24 0x00000000008da45c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8da45c)\r\n#25 0x00007f497b829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#26 0x00007f497b829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#27 0x00000000008d1eee _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d1eee)\r\n```\r\nWhich seems to be due to the getZExtValue() call inside IndexedReference::computeRefCost\r\nhttps://github.com/llvm/llvm-project/blob/b05c55472bf7cadcd0e4cb1a669b3474695b0524/llvm/lib/Analysis/LoopCacheAnalysis.cpp#L340:L343"}, {"author": "svs-quic", "body": "cc: @caojoshua "}, {"author": "sjoerdmeijer", "body": "I have a fix, will put it up for review tomorrow. "}]}, "verified": true} {"bug_id": "114738", "issue_url": "https://github.com/llvm/llvm-project/issues/114738", "bug_type": "miscompilation", "base_commit": "2588b8be5624f721c56f44fd2a69f7327de8c0c1", "knowledge_cutoff": "2024-11-04T05:50:07Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "899336735aeb2b41a48b6ac2c895da5e0f22dbf0", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[19490, 19498]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["tryToReduce"]}}, "patch": "commit 899336735aeb2b41a48b6ac2c895da5e0f22dbf0\nAuthor: Alexey Bataev \nDate: Mon Nov 4 06:02:06 2024 -0800\n\n [SLP]Be more pessimistic about poisonous reductions\n \n Consider all possible reductions ops as being non-poisoning boolean\n logical operations, which require freeze to be fully correct.\n \n https://alive2.llvm.org/ce/z/TKWDMP\n \n Fixes #114738\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex 427b8bd0e75a..3c6daf7b9fbb 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -19490,9 +19490,7 @@ public:\n // To prevent poison from leaking across what used to be sequential,\n // safe, scalar boolean logic operations, the reduction operand must be\n // frozen.\n- if ((isBoolLogicOp(RdxRootInst) ||\n- (AnyBoolLogicOp && VL.size() != TrackedVals.size())) &&\n- !isGuaranteedNotToBePoison(VectorizedRoot))\n+ if (AnyBoolLogicOp && !isGuaranteedNotToBePoison(VectorizedRoot))\n VectorizedRoot = Builder.CreateFreeze(VectorizedRoot);\n \n // Emit code to correctly handle reused reduced values, if required.\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/reudction-or-non-poisoned.ll", "commands": ["opt -S --passes=slp-vectorizer < %s"], "tests": [{"test_name": "test", "test_body": "define i1 @test(i32 %x, i32 %a, i32 %b, i32 %c, i32 %d) {\n %cmp = icmp sgt i32 %x, 1\n %cmp2 = icmp sgt i32 %b, 1\n %cmp3 = icmp sgt i32 %c, 1\n %cmp4 = icmp sgt i32 %d, 1\n %sel2 = select i1 %cmp4, i1 true, i1 %cmp2\n %sel3 = select i1 %sel2, i1 true, i1 %cmp3\n %sel4 = select i1 %cmp, i1 true, i1 %cmp4\n %ret = or i1 %sel3, %sel4\n ret i1 %ret\n}\n"}]}], "issue": {"title": "[SLPVectorizer] wrong vectorization to `reduce_or` due to poisonous value", "body": "Alive2 report: https://alive2.llvm.org/ce/z/f8PDZj\r\n\r\n```llvm\r\n----------------------------------------\r\ndefine i1 @test1.2(i32 %x, i32 %a, i32 %b, i32 %c, i32 %d) {\r\n#0:\r\n %cmp = icmp sgt i32 %x, 1\r\n %cmp2 = icmp sgt i32 %b, 1\r\n %cmp3 = icmp sgt i32 %c, 1\r\n %cmp4 = icmp sgt i32 %d, 1\r\n %sel2 = select i1 %cmp4, i1 1, i1 %cmp2\r\n %sel3 = select i1 %sel2, i1 1, i1 %cmp3\r\n %sel4 = select i1 %cmp, i1 1, i1 %cmp4\r\n %ret = or i1 %sel3, %sel4\r\n ret i1 %ret\r\n}\r\n=>\r\ndefine i1 @test1.2(i32 %x, i32 %a, i32 %b, i32 %c, i32 %d) {\r\n#0:\r\n %#1 = insertelement <4 x i32> poison, i32 %d, i32 0\r\n %#2 = insertelement <4 x i32> %#1, i32 %b, i32 1\r\n %#3 = insertelement <4 x i32> %#2, i32 %c, i32 2\r\n %#4 = insertelement <4 x i32> %#3, i32 %x, i32 3\r\n %#5 = icmp sgt <4 x i32> %#4, { 1, 1, 1, 1 }\r\n %#6 = reduce_or <4 x i1> %#5\r\n ret i1 %#6\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Target is more poisonous than source\r\n\r\nExample:\r\ni32 %x = #x00000000 (0)\r\ni32 %a = poison\r\ni32 %b = #x00000002 (2)\r\ni32 %c = poison\r\ni32 %d = #x00000000 (0)\r\n\r\nSource:\r\ni1 %cmp = #x0 (0)\r\ni1 %cmp2 = #x1 (1)\r\ni1 %cmp3 = poison\r\ni1 %cmp4 = #x0 (0)\r\ni1 %sel2 = #x1 (1)\r\ni1 %sel3 = #x1 (1)\r\ni1 %sel4 = #x0 (0)\r\ni1 %ret = #x1 (1)\r\n\r\nTarget:\r\n<4 x i32> %#1 = < #x00000000 (0), poison, poison, poison >\r\n<4 x i32> %#2 = < #x00000000 (0), #x00000002 (2), poison, poison >\r\n<4 x i32> %#3 = < #x00000000 (0), #x00000002 (2), poison, poison >\r\n<4 x i32> %#4 = < #x00000000 (0), #x00000002 (2), poison, #x00000000 (0) >\r\n<4 x i1> %#5 = < #x0 (0), #x1 (1), poison, #x0 (0) >\r\ni1 %#6 = poison\r\nSource value: #x1 (1)\r\nTarget value: poison\r\n\r\nSummary:\r\n 0 correct transformations\r\n 1 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\n```", "author": "bongjunj", "labels": ["miscompilation", "llvm:SLPVectorizer"], "comments": []}, "verified": true} @@ -206,6 +215,7 @@ {"bug_id": "88849", "issue_url": "https://github.com/llvm/llvm-project/issues/88849", "bug_type": "crash", "base_commit": "6b98ab95f0d36705b5a1fc1e755c992ba2329c89", "knowledge_cutoff": "2024-04-16T07:36:13Z", "lit_test_dir": ["llvm/test/Transforms/LoopVectorize"], "hints": {"fix_commit": "b8741cc185e89a95c9161218084f7c8b5578cf96", "components": ["LoopVectorize"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/VPlan.cpp": [[254, 259]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/VPlan.cpp": ["VPTransformState::get"]}}, "patch": "commit b8741cc185e89a95c9161218084f7c8b5578cf96\nAuthor: Florian Hahn \nDate: Fri Jul 19 10:33:07 2024 +0100\n\n [VPlan] Relax assertion retrieving a scalar from VPTransformState::get.\n \n The current assertion VPTransformState::get when retrieving a single\n scalar only does not account for cases where a def has multiple users,\n some demanding all scalar lanes, some demanding only a single scalar.\n \n For an example, see the modified test case. Relax the assertion by also\n allowing requesting scalar lanes only when the Def doesn't have only its\n first lane used.\n \n Fixes https://github.com/llvm/llvm-project/issues/88849.\n\ndiff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp\nindex 83a035fb4df8..58de6256900f 100644\n--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp\n+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp\n@@ -254,6 +254,7 @@ Value *VPTransformState::get(VPValue *Def, const VPIteration &Instance) {\n Value *VPTransformState::get(VPValue *Def, unsigned Part, bool NeedsScalar) {\n if (NeedsScalar) {\n assert((VF.isScalar() || Def->isLiveIn() || hasVectorValue(Def, Part) ||\n+ !vputils::onlyFirstLaneUsed(Def) ||\n (hasScalarValue(Def, VPIteration(Part, 0)) &&\n Data.PerPartScalars[Def][Part].size() == 1)) &&\n \"Trying to access a single scalar per part but has multiple scalars \"\n", "tests": [{"file": "llvm/test/Transforms/LoopVectorize/SystemZ/scalar-steps-with-users-demanding-all-lanes-and-first-lane-only.ll", "commands": ["opt -p loop-vectorize -mtriple=s390x-unknown-linux -mcpu=z16 -S %s"], "tests": [{"test_name": "test_scalar_iv_steps_used_by_replicate_and_first_lane_only_vpinst", "test_body": "target datalayout = \"E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64\"\n\n@src = external global [8 x i32], align 4\n\ndefine void @test_scalar_iv_steps_used_by_replicate_and_first_lane_only_vpinst(ptr noalias %dst, ptr noalias %src.1) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %mul.iv = mul nsw i64 %iv, 4\n %gep.src.1 = getelementptr inbounds i8, ptr %src.1, i64 %mul.iv\n %l.1 = load i8, ptr %gep.src.1, align 1\n %c = icmp eq i8 %l.1, 0\n br i1 %c, label %then, label %loop.latch\n\nthen: ; preds = %loop.header\n %iv.or = or disjoint i64 %iv, 4\n %gep.src = getelementptr inbounds [8 x i32], ptr @src, i64 0, i64 %iv.or\n %l.2 = load i32, ptr %gep.src, align 4\n store i32 %l.2, ptr %dst, align 4\n br label %loop.latch\n\nloop.latch: ; preds = %then, %loop.header\n %iv.next = add nuw nsw i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 4\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret void\n}\n"}]}], "issue": {"title": "LoopVectorizer asserts: Assertion `(VF.isScalar() || Def->isLiveIn() || (hasScalarValue(Def, VPIteration(Part, 0)) && Data.PerPartScalars[Def][Part].size() == 1)) && \"Trying to access a single scalar per part but has multiple scalars \" \"per part.", "body": "[tc_crash35_aftercreduce.ll.tar.gz](https://github.com/llvm/llvm-project/files/14988465/tc_crash35_aftercreduce.ll.tar.gz)\r\n\r\nopt -mtriple=s390x-unknown-linux -mcpu=z16 -O3 tc_crash35_aftercreduce.ll -o /dev/null\r\n\r\nVPlan.cpp:253: llvm::Value* llvm::VPTransformState::get(llvm::VPValue*, unsigned int, bool): Assertion `(VF.isScalar() || Def->isLiveIn() || (hasScalarValue(Def, VPIteration(Part, 0)) && Data.PerPartScalars[Def][Part].size() == 1)) && \"Trying to access a single scalar per part but has multiple scalars \" \"per part.\"' failed.\r\n\r\n@fhahn ", "author": "JonPsson1", "labels": ["vectorizers", "crash"], "comments": [{"author": "fhahn", "body": "Should be fixed now, sorry for the delay @JonPsson1 !"}]}, "verified": true} {"bug_id": "89672", "issue_url": "https://github.com/llvm/llvm-project/issues/89672", "bug_type": "miscompilation", "base_commit": "b64e483785bfef5ec4977988543ed5cfaf62f306", "knowledge_cutoff": "2024-04-22T21:35:16Z", "lit_test_dir": ["llvm/test/Transforms/SimplifyCFG"], "hints": {"fix_commit": "883887493c882d656d5da100ee637a348e81357c", "components": ["SimplifyCFG"], "bug_location_lineno": {"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": [[2888, 2894], [2896, 2902]]}, "bug_location_funcname": {"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": ["isSafeToSpeculateStore"]}}, "patch": "commit 883887493c882d656d5da100ee637a348e81357c\nAuthor: Nikita Popov \nDate: Tue Apr 23 12:36:35 2024 +0900\n\n [SimplifyCFG] Check alignment when speculating stores\n \n When speculating a store based on a preceding load/store, we need\n to ensure that the speculated store does not have a higher\n alignment (which might only be guaranteed by the branch condition).\n \n There are various ways in which this could be strengthened (we\n could get or enforce the alignment), but for now just do the\n simple check against the preceding load/store.\n \n Fixes https://github.com/llvm/llvm-project/issues/89672.\n\ndiff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp\nindex da3eb229c041..0826d748ba0d 100644\n--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp\n+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp\n@@ -2888,7 +2888,8 @@ static Value *isSafeToSpeculateStore(Instruction *I, BasicBlock *BrBB,\n // simple, to avoid introducing a spurious non-atomic write after an\n // atomic write.\n if (SI->getPointerOperand() == StorePtr &&\n- SI->getValueOperand()->getType() == StoreTy && SI->isSimple())\n+ SI->getValueOperand()->getType() == StoreTy && SI->isSimple() &&\n+ SI->getAlign() >= StoreToHoist->getAlign())\n // Found the previous store, return its value operand.\n return SI->getValueOperand();\n return nullptr; // Unknown store.\n@@ -2896,7 +2897,7 @@ static Value *isSafeToSpeculateStore(Instruction *I, BasicBlock *BrBB,\n \n if (auto *LI = dyn_cast(&CurI)) {\n if (LI->getPointerOperand() == StorePtr && LI->getType() == StoreTy &&\n- LI->isSimple()) {\n+ LI->isSimple() && LI->getAlign() >= StoreToHoist->getAlign()) {\n // Local objects (created by an `alloca` instruction) are always\n // writable, so once we are past a read from a location it is valid to\n // also write to that same location.\n", "tests": [{"file": "llvm/test/Transforms/SimplifyCFG/speculate-store.ll", "commands": ["opt -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S < %s"], "tests": [{"test_name": "wrong_align_store", "test_body": "define void @wrong_align_store(ptr %A, i32 %B, i32 %C, i32 %D) {\nentry:\n store i32 %B, ptr %A, align 4\n %cmp = icmp sgt i32 %D, 42\n br i1 %cmp, label %if.then, label %ret.end\n\nif.then: ; preds = %entry\n store i32 %C, ptr %A, align 8\n br label %ret.end\n\nret.end: ; preds = %if.then, %entry\n ret void\n}\n"}, {"test_name": "wrong_align_load", "test_body": "define void @wrong_align_load(i32 %C, i32 %D) {\nentry:\n %A = alloca i32, align 4\n %0 = load i32, ptr %A, align 4\n %cmp = icmp sgt i32 %D, 42\n br i1 %cmp, label %if.then, label %ret.end\n\nif.then: ; preds = %entry\n store i32 %C, ptr %A, align 8\n br label %ret.end\n\nret.end: ; preds = %if.then, %entry\n ret void\n}\n"}]}], "issue": {"title": "coalescing of redundant vector stores isn't preserving alignment correctly", "body": "https://alive2.llvm.org/ce/z/-qQphe\r\n\r\noptimizing this code:\r\n```llvm\r\ndefine i32 @f(ptr %0, i1 %1) {\r\n store <2 x i64> zeroinitializer, ptr %0, align 8\r\n br i1 %1, label %4, label %3\r\n\r\n3: ; preds = %2\r\n store <2 x i64> zeroinitializer, ptr %0, align 16\r\n br label %4\r\n\r\n4: ; preds = %3, %2\r\n ret i32 0\r\n}\r\n```\r\n\r\nis mostly doing what we expect, but the coalesced store should retain the smaller alignnment value of the two, not the larger:\r\n```lllvm\r\ndefine noundef i32 @f(ptr nocapture writeonly %0, i1 %1) local_unnamed_addr #0 {\r\n store <2 x i64> zeroinitializer, ptr %0, align 16\r\n ret i32 0\r\n}\r\n\r\nattributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) }\r\n```\r\n\r\ncc @nunoplopes @hatsunespica", "author": "regehr", "labels": ["miscompilation", "llvm:transforms"], "comments": [{"author": "nikic", "body": "The issue is introduced by SimplifyCFG: https://alive2.llvm.org/ce/z/zf-j74"}, {"author": "nikic", "body": "Specifically this is isSafeToSpeculateStore(), which looks for a preceding store to check whether it is safe to speculate, but fails to check alignment."}]}, "verified": true} {"bug_id": "112577", "issue_url": "https://github.com/llvm/llvm-project/issues/112577", "bug_type": "miscompilation", "base_commit": "76196998e25b98d81abc437708622261810782ca", "knowledge_cutoff": "2024-10-16T16:30:23Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "709abacdc350d63c61888607edb28ce272daa0a0", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[17224, 17232]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["BoUpSLP::collectValuesToDemote"]}}, "patch": "commit 709abacdc350d63c61888607edb28ce272daa0a0\nAuthor: Alexey Bataev \nDate: Fri Oct 18 13:54:30 2024 -0700\n\n [SLP]Check that operand of abs does not overflow before making it part of minbitwidth transformation\n \n Need to check that the operand of the abs intrinsic can be safely\n truncated before making it part of the minbitwidth transformation.\n \n Fixes #112577\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex e7b52fbdcc3b..e1aa6127ac03 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -17224,9 +17224,25 @@ bool BoUpSLP::collectValuesToDemote(\n MaskedValueIsZero(I->getOperand(1), Mask, SimplifyQuery(*DL)));\n });\n };\n+ auto AbsChecker = [&](unsigned BitWidth, unsigned OrigBitWidth) {\n+ assert(BitWidth <= OrigBitWidth && \"Unexpected bitwidths!\");\n+ return all_of(E.Scalars, [&](Value *V) {\n+ auto *I = cast(V);\n+ unsigned SignBits = OrigBitWidth - BitWidth;\n+ APInt Mask = APInt::getBitsSetFrom(OrigBitWidth, BitWidth - 1);\n+ unsigned Op0SignBits =\n+ ComputeNumSignBits(I->getOperand(0), *DL, 0, AC, nullptr, DT);\n+ return SignBits <= Op0SignBits &&\n+ ((SignBits != Op0SignBits &&\n+ !isKnownNonNegative(I->getOperand(0), SimplifyQuery(*DL))) ||\n+ MaskedValueIsZero(I->getOperand(0), Mask, SimplifyQuery(*DL)));\n+ });\n+ };\n if (ID != Intrinsic::abs) {\n Operands.push_back(getOperandEntry(&E, 1));\n CallChecker = CompChecker;\n+ } else {\n+ CallChecker = AbsChecker;\n }\n InstructionCost BestCost =\n std::numeric_limits::max();\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/abs-overflow-incorrect-minbws.ll", "commands": ["opt -S --passes=slp-vectorizer < %s"], "tests": [{"test_name": "test", "test_body": "define i32 @test(i32 %n) {\nentry:\n %n1 = add i32 %n, 1\n %zn1 = zext nneg i32 %n1 to i64\n %m1 = mul nuw nsw i64 %zn1, 273837369\n %a1 = call i64 @llvm.abs.i64(i64 %m1, i1 true)\n %t1 = trunc i64 %a1 to i32\n %n2 = add i32 %n, 2\n %zn2 = zext nneg i32 %n2 to i64\n %m2 = mul nuw nsw i64 %zn2, 273837369\n %a2 = call i64 @llvm.abs.i64(i64 %m2, i1 true)\n %t2 = trunc i64 %a2 to i32\n %res1 = add i32 %t1, %t2\n ret i32 %res1\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i64 @llvm.abs.i64(i64, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n"}]}], "issue": {"title": "[SLP] SLP Vectorizer miscompile from reducing abs bitwidth", "body": "Bisected miscompile to this change https://github.com/llvm/llvm-project/commit/4a1c53f9fabbc18d436dcd4d5b572b82656fbbf9\r\n\r\nReduced internal test to this example:\r\nhttps://godbolt.org/z/njWYP9exd\r\n```llvm\r\ndefine dso_local noundef i32 @test(i32 %n) local_unnamed_addr #0 {\r\nentry:\r\n %n1 = add i32 %n, 1\r\n %zn1 = zext nneg i32 %n1 to i64\r\n %m1 = mul nuw nsw i64 %zn1, 273837369\r\n %a1 = call noundef i64 @llvm.abs.i64(i64 %m1, i1 true)\r\n %t1 = trunc i64 %a1 to i32\r\n %n2 = add i32 %n, 2\r\n %zn2 = zext nneg i32 %n2 to i64\r\n %m2 = mul nuw nsw i64 %zn2, 273837369\r\n %a2 = call noundef i64 @llvm.abs.i64(i64 %m2, i1 true)\r\n %t2 = trunc i64 %a2 to i32\r\n\r\n %res1 = add i32 %t1, %t2\r\n ret i32 %res1\r\n}\r\n```\r\nRunning slp vectorizer on it gives\r\n```llvm\r\ndefine dso_local noundef i32 @test(i32 %n) local_unnamed_addr {\r\n %0 = insertelement <2 x i32> poison, i32 %n, i32 0\r\n %1 = shufflevector <2 x i32> %0, <2 x i32> poison, <2 x i32> zeroinitializer\r\n %2 = add <2 x i32> %1, \r\n %3 = mul <2 x i32> %2, \r\n %4 = call <2 x i32> @llvm.abs.v2i32(<2 x i32> %3, i1 false)\r\n %5 = extractelement <2 x i32> %4, i32 0\r\n %6 = extractelement <2 x i32> %4, i32 1\r\n %res1 = add i32 %5, %6\r\n ret i32 %res1\r\n}\r\n```\r\nwhich is incorrect. Counterexample by alive2:\r\nhttps://alive2.llvm.org/ce/z/cEcY-u", "author": "danilaml", "labels": ["miscompilation", "release:backport", "llvm:SLPVectorizer"], "comments": [{"author": "AZero13", "body": "Do we plan on backporting this to 19.x @alexey-bataev "}]}, "verified": true} +{"bug_id": "115744", "issue_url": "https://github.com/llvm/llvm-project/issues/115744", "bug_type": "crash", "base_commit": "28002dd50fb7ec97da1770a11f9c6a99dd9aecb9", "knowledge_cutoff": "2024-11-11T17:12:17Z", "lit_test_dir": ["llvm/test/Transforms/LoopVectorize"], "hints": {"fix_commit": "8009c1fd81ad0b6ac65724d2b134a92db48f8fbf", "components": ["LoopVectorize"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [[7291, 7297], [7311, 7317]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": ["LoopVectorizationPlanner::precomputeCosts"]}}, "patch": "commit 8009c1fd81ad0b6ac65724d2b134a92db48f8fbf\nAuthor: Elvis Wang \nDate: Tue Feb 25 11:09:09 2025 +0800\n\n [LV][VPlan] Prevent calculate cost for skiped instructions in precomputeCosts(). (#127966)\n \n Skip calculating instruction costs for exit conditions in\n precomputeCosts() when it should be skipped.\n \n Reported from:\n https://github.com/llvm/llvm-project/issues/115744#issuecomment-2670479463\n Godbolt for reduced test cases: https://godbolt.org/z/fr4YMeqcv\n\ndiff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\nindex 4d2df9179aa3..0bf2d71a63ef 100644\n--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n@@ -7291,7 +7291,7 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF,\n // Collect all exit conditions.\n for (BasicBlock *EB : Exiting) {\n auto *Term = dyn_cast(EB->getTerminator());\n- if (!Term)\n+ if (!Term || CostCtx.skipCostComputation(Term, VF.isVector()))\n continue;\n if (auto *CondI = dyn_cast(Term->getOperand(0))) {\n ExitInstrs.insert(CondI);\n@@ -7311,7 +7311,8 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF,\n Cost += CondICost;\n for (Value *Op : CondI->operands()) {\n auto *OpI = dyn_cast(Op);\n- if (!OpI || any_of(OpI->users(), [&ExitInstrs, this](User *U) {\n+ if (!OpI || CostCtx.skipCostComputation(OpI, VF.isVector()) ||\n+ any_of(OpI->users(), [&ExitInstrs, this](User *U) {\n return OrigLoop->contains(cast(U)->getParent()) &&\n !ExitInstrs.contains(cast(U));\n }))\n", "tests": [{"file": "llvm/test/Transforms/LoopVectorize/X86/cost-model.ll", "commands": ["opt < %s -passes=loop-vectorize -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx -S"], "tests": [{"test_name": "g", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.8.0\"\n\ndefine i32 @g(i64 %n) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %select = phi i32 [ 0, %entry ], [ %select.next, %loop ]\n %iv.widen = zext i32 %iv to i64\n %exitcond = icmp eq i64 %n, %iv.widen\n %select.i = select i1 %exitcond, i32 0, i32 2\n %select.next = or i32 %select.i, %select\n %iv.next = add i32 %iv, 1\n br i1 %exitcond, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i32 %select.next\n}\n"}]}], "issue": {"title": "[VPlan] Assertion \"VPlan cost model and legacy cost model disagreed\"' failed.", "body": "C program:\r\n```c\r\nsigned char a;\r\nshort b;\r\nint c, g;\r\nlong d, e, f;\r\nvoid h(long i[][2], long j[][2][2], short k[][2]) {\r\n for (unsigned l = g; l; l += 4) {\r\n a *= (signed char)((f ? 0 : k[l][l]) ?: (_Bool)(d << j[8][l][e]) ? i[l][l] : c);\r\n b = ~i[e][l];\r\n }\r\n}\r\n```\r\n`/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/clang -march=rv64gcv -O3 red.c -o rv64gcv.bc -w -emit-llvm -c`\r\n\r\nLLVM IR:\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\ndefine void @h(ptr %i, ptr %k, i64 %idxprom.us) #0 {\r\nentry:\r\n br label %for.body.us\r\n\r\nfor.body.us: ; preds = %cond.end23.us, %entry\r\n %l.046.us = phi i32 [ %add.us, %cond.end23.us ], [ 0, %entry ]\r\n %conv284345.us = phi i8 [ %conv28.us, %cond.end23.us ], [ 0, %entry ]\r\n %idxprom.us1 = zext i32 %l.046.us to i64\r\n %arrayidx3.us = getelementptr [2 x i16], ptr %k, i64 %idxprom.us1, i64 %idxprom.us\r\n %0 = load i16, ptr %arrayidx3.us, align 2\r\n %tobool4.not.us = icmp eq i16 %0, 0\r\n br i1 %tobool4.not.us, label %cond.false7.us, label %cond.end23.us\r\n\r\ncond.false7.us: ; preds = %for.body.us\r\n %1 = load i64, ptr %i, align 8\r\n %shl.us = shl i64 0, %1\r\n %tobool12.not.us = icmp eq i64 %shl.us, 0\r\n br i1 %tobool12.not.us, label %cond.end23.us, label %cond.true14.us\r\n\r\ncond.true14.us: ; preds = %cond.false7.us\r\n %2 = load i64, ptr %i, align 8\r\n %3 = trunc i64 %2 to i32\r\n br label %cond.end23.us\r\n\r\ncond.end23.us: ; preds = %cond.true14.us, %cond.false7.us, %for.body.us\r\n %cond24.us = phi i32 [ %3, %cond.true14.us ], [ 0, %for.body.us ], [ 0, %cond.false7.us ]\r\n %4 = trunc i32 %cond24.us to i8\r\n %conv28.us = mul i8 0, %4\r\n %arrayidx31.us = getelementptr [2 x i64], ptr %i, i64 0, i64 %idxprom.us1\r\n %5 = load i64, ptr %arrayidx31.us, align 8\r\n %6 = trunc i64 %5 to i16\r\n %conv32.us = xor i16 %6, 0\r\n store i16 %conv32.us, ptr null, align 2\r\n %add.us = add i32 %l.046.us, 4\r\n %tobool.not.us = icmp eq i32 %add.us, 0\r\n br i1 %tobool.not.us, label %for.cond.for.cond.cleanup_crit_edge, label %for.body.us\r\n\r\nfor.cond.for.cond.cleanup_crit_edge: ; preds = %cond.end23.us\r\n store i8 %4, ptr null, align 1\r\n ret void\r\n}\r\n\r\nattributes #0 = { \"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-ssctr,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-experimental-zvbc32e,-experimental-zvkgs,-h,-sha,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smdbltrp,-smepmp,-smmpm,-smnpm,-smrnmi,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssdbltrp,-ssnpm,-sspm,-ssqosid,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-supm,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-svvptc,-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,-zacas,-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 -f\r\nopt: /scratch/tc-testing/tc-compiler-fuzz-trunk/llvm/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7522: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), CostCtx, OrigLoop) || planContainsAdditionalSimplifications(getPlanFor(LegacyVF.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 -f\r\n1. Running pass \"function(loop-vectorize)\" on module \"reduced.ll\"\r\n2. Running pass \"loop-vectorize\" on function \"h\"\r\n #0 0x000062cc6ec1de70 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x319de70)\r\n #1 0x000062cc6ec1b27f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x319b27f)\r\n #2 0x000062cc6ec1b3d5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x000074efe9a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x000074efe9a969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x000074efe9a969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x000074efe9a969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x000074efe9a42476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x000074efe9a287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x000074efe9a2871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x000074efe9a39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x000062cc6db65039 llvm::LoopVectorizationPlanner::computeBestVF() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20e5039)\r\n#12 0x000062cc6db7c50c llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20fc50c)\r\n#13 0x000062cc6db7f1e1 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20ff1e1)\r\n#14 0x000062cc6db7f857 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20ff857)\r\n#15 0x000062cc6c963a06 llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xee3a06)\r\n#16 0x000062cc6ea24b0f llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2fa4b0f)\r\n#17 0x000062cc6c966b96 llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xee6b96)\r\n#18 0x000062cc6ea22e9b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2fa2e9b)\r\n#19 0x000062cc6c962ac6 llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xee2ac6)\r\n#20 0x000062cc6ea239fd llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2fa39fd)\r\n#21 0x000062cc6c15c33d llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::ArrayRef>, 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+0x6dc33d)\r\n#22 0x000062cc6c14e1c1 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x6ce1c1)\r\n#23 0x000074efe9a29d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#24 0x000074efe9a29e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#25 0x000074efe9a29e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#26 0x000062cc6c144725 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x6c4725)\r\nzsh: IOT instruction (core dumped) /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt\r\n```\r\n\r\nGodbolt: https://godbolt.org/z/v5K5Wbxcn\r\n\r\nFound via fuzzer\r\n\r\ncc @fhahn ", "author": "patrick-rivos", "labels": ["release:backport", "vectorizers", "crash"], "comments": [{"author": "patrick-rivos", "body": "Bisected to b3edc764f70f4e56807af60abdcfbef4dbdc5d95\r\ncc @ElvisWang123 "}, {"author": "ElvisWang123", "body": "> Bisected to [b3edc76](https://github.com/llvm/llvm-project/commit/b3edc764f70f4e56807af60abdcfbef4dbdc5d95) cc @ElvisWang123\r\n\r\nI will take a look."}, {"author": "ElvisWang123", "body": "The main difference of this case is that \r\n`LV: Found an estimated cost of 3 for VF vscale x 2 For instruction: %3 = trunc i64 %2 to i32` from legacy cost model and `Cost of 1 for VF vscale x 2: WIDEN-CAST ir<%3> = trunc ir<%2> to i32` from VPlan-based cost model.\r\n\r\nLegacy cost model will consider the new type after MinBW by `canTruncateToMinimalBitwidth()`. And finds that `i32` can further truncate to `i8`. So the legacy cost model will calculate the cost from `i64` to `i8`.\r\n But in the VPTransforms, the result type of this recipe cannot be shrunk from `i32` to `i8`. So the final recipes will only calculate the cost from `i64` to `i32`.\r\n\r\nI think this might be the MinBW transformation issue which cannot further truncate the type.\r\n\r\nBTW, the cost from the VPlan-based cost model is closer to the generated vector loop.\r\n\r\nSome cost model information:\r\nLegacy cost\r\n```\r\nLV: Found an estimated cost of 0 for VF vscale x 2 For instruction: %l.046.us = phi i32 [ %add.us, %cond.end23.us ], [ 0, %entry ]\r\nLV: Found an estimated cost of 2 for VF vscale x 2 For instruction: %conv284345.us = phi i8 [ %conv28.us, %cond.end23.us ], [ 0, %entr\r\ny ]\r\nLV: Found an estimated cost of 2 for VF vscale x 2 For instruction: %idxprom.us1 = zext i32 %l.046.us to i64\r\nLV: Found an estimated cost of 0 for VF vscale x 2 For instruction: %arrayidx3.us = getelementptr [2 x i16], ptr %k, i64 %idxprom.us1,\r\n i64 %idxprom.us\r\nLV: Found an estimated cost of 4 for VF vscale x 2 For instruction: %0 = load i16, ptr %arrayidx3.us, align 2\r\nLV: Found an estimated cost of 1 for VF vscale x 2 For instruction: %tobool4.not.us = icmp eq i16 %0, 0\r\nLV: Found an estimated cost of 0 for VF vscale x 2 For instruction: br i1 %tobool4.not.us, label %cond.false7.us, label %cond.end23.us\r\nLV: Found an estimated cost of 4 for VF vscale x 2 For instruction: %1 = load i64, ptr %i, align 8\r\nLV: Found an estimated cost of 2 for VF vscale x 2 For instruction: %shl.us = shl i64 0, %1\r\nLV: Found an estimated cost of 2 for VF vscale x 2 For instruction: %tobool12.not.us = icmp eq i64 %shl.us, 0\r\nLV: Found an estimated cost of 0 for VF vscale x 2 For instruction: br i1 %tobool12.not.us, label %cond.end23.us, label %cond.true14.u\r\ns\r\nLV: Found an estimated cost of 4 for VF vscale x 2 For instruction: %2 = load i64, ptr %i, align 8\r\n====> LV: Found an estimated cost of 3 for VF vscale x 2 For instruction: %3 = trunc i64 %2 to i32 <=====\r\nLV: Found an estimated cost of 0 for VF vscale x 2 For instruction: br label %cond.end23.us\r\nLV: Found an estimated cost of 2 for VF vscale x 2 For instruction: %cond24.us = phi i32 [ %3, %cond.true14.us ], [ 0, %for.body.us ],\r\n [ 0, %cond.false7.us ]\r\nLV: Found an estimated cost of 2 for VF vscale x 2 For instruction: %4 = trunc i32 %cond24.us to i8\r\nLV: Found an estimated cost of 1 for VF vscale x 2 For instruction: %conv28.us = mul i8 0, %4\r\nLV: Found an estimated cost of 0 for VF vscale x 2 For instruction: %arrayidx31.us = getelementptr [2 x i64], ptr %i, i64 0, i64 %idxp\r\nrom.us1\r\nLV: Found an estimated cost of 4 for VF vscale x 2 For instruction: %5 = load i64, ptr %arrayidx31.us, align 8\r\nLV: Found an estimated cost of 2 for VF vscale x 2 For instruction: %6 = trunc i64 %5 to i16\r\nLV: Found an estimated cost of 1 for VF vscale x 2 For instruction: %conv32.us = xor i16 %6, 0\r\nLV: Found an estimated cost of 3 for VF vscale x 2 For instruction: store i16 %conv32.us, ptr null, align 2\r\nLV: Found an estimated cost of 1 for VF vscale x 2 For instruction: %add.us = add i32 %l.046.us, 4\r\nLV: Found an estimated cost of 1 for VF vscale x 2 For instruction: %tobool.not.us = icmp eq i32 %add.us, 0\r\nLV: Found an estimated cost of 0 for VF vscale x 2 For instruction: br i1 %tobool.not.us, label %for.cond.for.cond.cleanup_crit_edge, \r\nlabel %for.body.us\r\nLV: Vector loop of width vscale x 2 costs: 10 (assuming a minimum vscale of 2).\r\n```\r\n\r\nVPlan-based\r\n```\r\nCost of 1 for VF vscale x 2: induction instruction %add.us = add i32 %l.046.us, 4\r\nCost of 0 for VF vscale x 2: induction instruction %l.046.us = phi i32 [ %add.us, %cond.end23.us ], [ 0, %entry ]\r\nCost of 1 for VF vscale x 2: exit condition instruction %tobool.not.us = icmp eq i32 %add.us, 0\r\nCost of 0 for VF vscale x 2: EMIT vp<%3> = CANONICAL-INDUCTION ir<0>, vp<%index.next>\r\nCost of 0 for VF vscale x 2: WIDEN-INDUCTION %l.046.us = phi %add.us, 0, ir<4>, vp<%0>\r\nCost of 2 for VF vscale x 2: FIRST-ORDER-RECURRENCE-PHI ir<%conv284345.us> = phi ir<0>, ir<%conv28.us>\r\nCost of 2 for VF vscale x 2: WIDEN-CAST ir<%idxprom.us1> = zext ir<%l.046.us> to i64\r\nCost of 0 for VF vscale x 2: WIDEN-GEP Inv[Var][Inv] ir<%arrayidx3.us> = getelementptr ir<%k>, ir<%idxprom.us1>, ir<%idxprom.us>\r\nCost of 4 for VF vscale x 2: WIDEN ir<%0> = load ir<%arrayidx3.us>\r\nCost of 1 for VF vscale x 2: WIDEN ir<%tobool4.not.us> = icmp eq ir<%0>, ir<0>\r\nCost of 4 for VF vscale x 2: WIDEN ir<%1> = load ir<%i>, ir<%tobool4.not.us>\r\nCost of 2 for VF vscale x 2: WIDEN ir<%shl.us> = shl ir<0>, ir<%1>\r\nCost of 2 for VF vscale x 2: WIDEN ir<%tobool12.not.us> = icmp eq ir<%shl.us>, ir<0>\r\nCost of 0 for VF vscale x 2: EMIT vp<%4> = not ir<%tobool12.not.us>\r\nCost of 0 for VF vscale x 2: EMIT vp<%5> = logical-and ir<%tobool4.not.us>, vp<%4>\r\nCost of 4 for VF vscale x 2: WIDEN ir<%2> = load ir<%i>, vp<%5>\r\n====> Cost of 1 for VF vscale x 2: WIDEN-CAST ir<%3> = trunc ir<%2> to i32 <=======\r\nCost of 0 for VF vscale x 2: EMIT vp<%6> = not ir<%tobool4.not.us>\r\nCost of 2 for VF vscale x 2: BLEND ir<%cond24.us> = ir<0> ir<%3>/vp<%5> ir<0>/vp<%6>\r\nCost of 2 for VF vscale x 2: WIDEN-CAST ir<%4> = trunc ir<%cond24.us> to i8\r\nCost of 1 for VF vscale x 2: WIDEN ir<%conv28.us> = mul ir<0>, ir<%4>\r\nCost of 0 for VF vscale x 2: WIDEN-GEP Inv[Inv][Var] ir<%arrayidx31.us> = getelementptr ir<%i>, ir<0>, ir<%idxprom.us1>\r\nCost of 4 for VF vscale x 2: WIDEN ir<%5> = load ir<%arrayidx31.us>\r\nCost of 2 for VF vscale x 2: WIDEN-CAST ir<%6> = trunc ir<%5> to i16\r\nCost of 1 for VF vscale x 2: WIDEN ir<%conv32.us> = xor ir<%6>, ir<0>\r\nCost of 3 for VF vscale x 2: REPLICATE store ir<%conv32.us>, ir\r\nCost of 0 for VF vscale x 2: EMIT vp<%index.next> = add nuw vp<%3>, vp<%1>\r\nCost of 0 for VF vscale x 2: EMIT branch-on-count vp<%index.next>, vp<%2>\r\nCost of 0 for VF vscale x 2: vector loop backedge\r\nCost for VF vscale x 2: 39\r\n```\r\nGenerated vector.body\r\n``` \r\nvector.body: ; preds = %vector.body, %vector.ph\r\n %index = phi i32 [ 0, %vector.ph ]\r\n %vec.ind = phi [ %induction, %vector.ph ], [ %vec.ind.next, %vector.ph ]\r\n %vector.recur = phi [ %vector.recur.init, %vector.ph ]\r\n %vec.ind.next = add %vec.ind, %.splat\r\n %15 = zext %vec.ind to \r\n %16 = getelementptr [2 x i16], ptr %k, %15, i64 %idxprom.us\r\n %wide.masked.gather = call @llvm.masked.gather.nxv2i16.nxv2p0( %16, i32 2, shufflevector ( insertelement ( poison, i1 true, i64 0), poison, zeroinitializer), poison)\r\n %17 = icmp eq %wide.masked.gather, zeroinitializer\r\n %wide.masked.gather1 = call @llvm.masked.gather.nxv2i64.nxv2p0( %broadcast.splat, i32 8, %17, poison)\r\n %18 = shl zeroinitializer, %wide.masked.gather1\r\n %19 = icmp eq %18, zeroinitializer\r\n %20 = xor %19, shufflevector ( insertelement ( poison, i1 true, i64 0), poison, zeroinitializer)\r\n %21 = select %17, %20, zeroinitializer\r\n %wide.masked.gather2 = call @llvm.masked.gather.nxv2i64.nxv2p0( %broadcast.splat, i32 8, %21, poison)\r\n %22 = trunc %wide.masked.gather2 to <================\r\n %23 = xor %17, shufflevector ( insertelement ( poison, i1 true, i64 0), poison, zeroinitializer)\r\n %predphi = select %21, %22, zeroinitializer\r\n %predphi3 = select %23, zeroinitializer, %predphi\r\n %24 = trunc %predphi3 to \r\n %25 = mul zeroinitializer, %24\r\n %26 = getelementptr [2 x i64], ptr %i, i64 0, %15\r\n %wide.masked.gather4 = call @llvm.masked.gather.nxv2i64.nxv2p0( %26, i32 8, shufflevector ( insertelement ( poison, i1 true, i64 0), poison, zeroinitializer), poison)\r\n %27 = trunc %wide.masked.gather4 to \r\n %28 = xor %27, zeroinitializer\r\n %29 = call i32 @llvm.vscale.i32()\r\n%30 = mul i32 %29, 2\r\n %31 = sub i32 %30, 1\r\n %32 = extractelement %28, i32 %31\r\n store i16 %32, ptr null, align 2\r\n %index.next = add nuw i32 %index, %7\r\n %33 = icmp eq i32 %index.next, %n.vec\r\n br i1 %33, , label %vector.body\r\n..."}, {"author": "ElvisWang123", "body": "In this case, we can find that all the following recipes can be shrinkage to `i8`.\n```\n====> Cost of 1 for VF vscale x 2: WIDEN-CAST ir<%3> = trunc ir<%2> to i32 <=======\nCost of 0 for VF vscale x 2: EMIT vp<%6> = not ir<%tobool4.not.us>\nCost of 2 for VF vscale x 2: BLEND ir<%cond24.us> = ir<0> ir<%3>/vp<%5> ir<0>/vp<%6>\nCost of 2 for VF vscale x 2: WIDEN-CAST ir<%4> = trunc ir<%cond24.us> to i8\nCost of 1 for VF vscale x 2: WIDEN ir<%conv28.us> = mul ir<0>, ir<%4>\n```\nBut in current minimal-bit-width analysis, there are some checks prevent this type shrinkage.\n1. If any of instructions in the EC (equivalent class) is PHI node, minimal-bit-width wont narrow the type.\n\nTo support type shrinkage for this case. We need to change the MinBW which is the analysis based on the scalar instructions.\n\nModify current minimal-bit-width architecture (Analysis scalar instructions). This implementation may not be accurate since the VPlan may contains some of the recipe without underlying instructions.\n1. Support Phi node in the EC. Although induction phi should not be modified and the recurrence descriptor will handle the type shrinkage. We still need the information from MinBW to shrinkage the non-header phis.\n2. Add the support of `VPBlendRecipe` in `truncateToMinimalBitWidth()` in VPTransform.\n\nOr rewrite a new minimal-bit-width analysis based on Vplan. This implementation will be more accurate than the current analysis but will be more works.\n\n1. To support Vplan-based MinBW, we may need to rewrite a new VPlan-based DemandedBits analysis.\n\n\n@fhahn What do you think about the these two implementations, modify current MinBW or rewrite a new vplan-based MinBW. Or do you have a better implementation to make MinBW more accurate on Vplan?\n\n@patrick-rivos BTW, the C program in this issue is a little bit weird. Without initializing `a`, loop vectorizer cannot recognize the reduction pattern of the `a *= (signed char)((f ? 0 : k[l][l]) ?: (_Bool)(d << j[8][l][e]) ? i[l][l] : c);`. However, we still have some issue on the minimal-bit-width analysis."}, {"author": "cardigan1008", "body": "Hi, there's another case that triggers this crash:\n\n```c\nint a;\nint b(int c) {\n int d = 0;\n for (; d < c; d++) {\n a++;\n if (d != c - 1)\n a++;\n }\n}\nint *e;\nint f;\nvoid g() {\n for (; e[f]; f++)\n e[b(f + 9)];\n}\n```\n\nCompiler Explorer: https://godbolt.org/z/16Tr15KGx\n\nHope this helps :)"}, {"author": "ElvisWang123", "body": "@cardigan1008 Thanks for your test case. I will take a look."}]}, "verified": true} {"bug_id": "124275", "issue_url": "https://github.com/llvm/llvm-project/issues/124275", "bug_type": "miscompilation", "base_commit": "35df525fd00c2037ef144189ee818b7d612241ff", "knowledge_cutoff": "2025-01-24T14:33:26Z", "lit_test_dir": ["llvm/test/Analysis/ValueTracking"], "hints": {"fix_commit": "c2fba023475fddb893eac29dc9f34dfbdb221cd5", "components": ["ValueTracking"], "bug_location_lineno": {"llvm/lib/Analysis/ValueTracking.cpp": [[593, 603], [610, 620], [1673, 1680], [1705, 1713]]}, "bug_location_funcname": {"llvm/lib/Analysis/ValueTracking.cpp": ["breakSelfRecursivePHI", "computeKnownBitsFromOperator"]}}, "patch": "commit c2fba023475fddb893eac29dc9f34dfbdb221cd5\nAuthor: goldsteinn <35538541+goldsteinn@users.noreply.github.com>\nDate: Tue Jan 28 15:54:00 2025 -0600\n\n [ValueTracking] Fix bug of using wrong condition for deducing KnownBits (#124481)\n \n - **[ValueTracking] Add test for issue 124275**\n - **[ValueTracking] Fix bug of using wrong condition for deducing\n KnownBits**\n \n Fixes https://github.com/llvm/llvm-project/issues/124275\n \n Bug was introduced by https://github.com/llvm/llvm-project/pull/114689\n \n Now that computeKnownBits supports breaking out of recursive Phi\n nodes, `IncValue` can be an operand of a different Phi than `P`. This\n breaks the previous assumptions we had when using the possibly\n condition at `CxtI` to constrain `IncValue`.\n\ndiff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp\nindex eba728c7c8c3..b63a0a07f7de 100644\n--- a/llvm/lib/Analysis/ValueTracking.cpp\n+++ b/llvm/lib/Analysis/ValueTracking.cpp\n@@ -593,11 +593,14 @@ static bool cmpExcludesZero(CmpInst::Predicate Pred, const Value *RHS) {\n }\n \n static void breakSelfRecursivePHI(const Use *U, const PHINode *PHI,\n- Value *&ValOut, Instruction *&CtxIOut) {\n+ Value *&ValOut, Instruction *&CtxIOut,\n+ const PHINode **PhiOut = nullptr) {\n ValOut = U->get();\n if (ValOut == PHI)\n return;\n CtxIOut = PHI->getIncomingBlock(*U)->getTerminator();\n+ if (PhiOut)\n+ *PhiOut = PHI;\n Value *V;\n // If the Use is a select of this phi, compute analysis on other arm to break\n // recursion.\n@@ -610,11 +613,13 @@ static void breakSelfRecursivePHI(const Use *U, const PHINode *PHI,\n // incoming value to break recursion.\n // TODO: We could handle any number of incoming edges as long as we only have\n // two unique values.\n- else if (auto *IncPhi = dyn_cast(ValOut);\n- IncPhi && IncPhi->getNumIncomingValues() == 2) {\n+ if (auto *IncPhi = dyn_cast(ValOut);\n+ IncPhi && IncPhi->getNumIncomingValues() == 2) {\n for (int Idx = 0; Idx < 2; ++Idx) {\n if (IncPhi->getIncomingValue(Idx) == PHI) {\n ValOut = IncPhi->getIncomingValue(1 - Idx);\n+ if (PhiOut)\n+ *PhiOut = IncPhi;\n CtxIOut = IncPhi->getIncomingBlock(1 - Idx)->getTerminator();\n break;\n }\n@@ -1673,8 +1678,9 @@ static void computeKnownBitsFromOperator(const Operator *I,\n Known.One.setAllBits();\n for (const Use &U : P->operands()) {\n Value *IncValue;\n+ const PHINode *CxtPhi;\n Instruction *CxtI;\n- breakSelfRecursivePHI(&U, P, IncValue, CxtI);\n+ breakSelfRecursivePHI(&U, P, IncValue, CxtI, &CxtPhi);\n // Skip direct self references.\n if (IncValue == P)\n continue;\n@@ -1705,9 +1711,10 @@ static void computeKnownBitsFromOperator(const Operator *I,\n m_Br(m_c_ICmp(Pred, m_Specific(IncValue), m_APInt(RHSC)),\n m_BasicBlock(TrueSucc), m_BasicBlock(FalseSucc)))) {\n // Check for cases of duplicate successors.\n- if ((TrueSucc == P->getParent()) != (FalseSucc == P->getParent())) {\n+ if ((TrueSucc == CxtPhi->getParent()) !=\n+ (FalseSucc == CxtPhi->getParent())) {\n // If we're using the false successor, invert the predicate.\n- if (FalseSucc == P->getParent())\n+ if (FalseSucc == CxtPhi->getParent())\n Pred = CmpInst::getInversePredicate(Pred);\n // Get the knownbits implied by the incoming phi condition.\n auto CR = ConstantRange::makeExactICmpRegion(Pred, *RHSC);\n", "tests": [{"file": "llvm/test/Analysis/ValueTracking/phi-known-bits.ll", "commands": ["opt -O1 < %s -S"], "tests": [{"test_name": "issue_124275_wrong_br_direction", "test_body": "target 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@c = dso_local global i32 1, align 4\n@a = dso_local global i32 0, align 4\n@b = dso_local global i32 0, align 4\n\ndefine dso_local i32 @main() #0 {\nentry:\n %retval = alloca i32, align 4\n %d = alloca i32, align 4\n store i32 0, ptr %retval, align 4\n store i32 -1, ptr @a, align 4\n %0 = load i32, ptr @a, align 4\n %cmp = icmp ult i32 %0, 1\n br i1 %cmp, label %if.then, label %if.end\n\nif.then:\n br label %e\n\nif.end:\n %1 = load i32, ptr @c, align 4\n store i32 %1, ptr %d, align 4\n %2 = load i32, ptr %d, align 4\n %tobool = icmp ne i32 %2, 0\n br i1 %tobool, label %if.then1, label %if.end2\n\nif.then1:\n br label %e\n\ne:\n br label %if.end2\n\nif.end2:\n %3 = load i32, ptr %d, align 4\n %tobool3 = icmp ne i32 %3, 0\n br i1 %tobool3, label %if.end5, label %if.then4\n\nif.then4:\n unreachable\n\nif.end5:\n %4 = load i32, ptr @b, align 4\n %tobool6 = icmp ne i32 %4, 0\n br i1 %tobool6, label %if.then7, label %if.end8\n\nif.then7:\n br label %e\n\nif.end8:\n ret i32 0\n}\n\nattributes #0 = { noinline nounwind uwtable \"frame-pointer\"=\"all\" \"min-legal-vector-width\"=\"0\" \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"x86-64\" \"target-features\"=\"+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87\" \"tune-cpu\"=\"generic\" }\n\n!llvm.module.flags = !{!0, !1, !2, !3, !4, !5}\n!llvm.ident = !{!6}\n\n!0 = !{i32 7, !\"Dwarf Version\", i32 4}\n!1 = !{i32 1, !\"wchar_size\", i32 4}\n!2 = !{i32 8, !\"PIC Level\", i32 2}\n!3 = !{i32 7, !\"PIE Level\", i32 2}\n!4 = !{i32 7, !\"uwtable\", i32 2}\n!5 = !{i32 7, !\"frame-pointer\", i32 2}\n!6 = !{!\"clang version 21.0.0git (https://github.com/llvm/llvm-project.git 5c3c0a8cec9205efba78583bd0b8a646270968a1)\"}\n", "additional_args": "-src-unroll=4 -tgt-unroll=4"}]}], "issue": {"title": "wrong code at -O1 and above on x86_64-linux-gnu", "body": "It appears to be a recent regression from 19.1.0. \n\nCompiler Explorer: https://godbolt.org/z/haMfGoo6h\n\n```\n[548] % clangtk -v\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git ddd2f57b29661f21308eec0400fa92a6d075b0c6)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/home/suz/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12\nCandidate multilib: .;@m64\nSelected multilib: .;@m64\nFound CUDA installation: /usr/local/cuda, version 12.1\n[549] % \n[549] % clangtk -O1 small.c\n[550] % ./a.out\nAborted\n[551] % \n[551] % cat small.c\nint printf(const char *, ...);\nunsigned a;\nint b, c = 1;\nint main() {\n int d;\n a = -1;\n if (a < 1)\n goto e;\n d = c;\n if (d) {\n e:;\n }\n if (!d)\n __builtin_abort();\n if (b)\n goto e;\n return 0;\n}\n```", "author": "zhendongsu", "labels": ["miscompilation", "llvm:analysis"], "comments": [{"author": "zhendongsu", "body": "Another likely related test:\n```\n[552] % clangtk -v\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git ddd2f57b29661f21308eec0400fa92a6d075b0c6)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/home/suz/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12\nCandidate multilib: .;@m64\nSelected multilib: .;@m64\nFound CUDA installation: /usr/local/cuda, version 12.1\n[553] % \n[553] % clangtk -O0 small.c\n[554] % ./a.out\n[555] % \n[555] % clangtk -O1 small.c\n[556] % timeout -s 9 5 ./a.out\nKilled\n[557] % cat small.c\nint a, b;\nint main() {\n {\n int c;\n if (a && 0)\n goto d;\n }\n int e = -~b;\n if (e) {\n d:;\n }\n while (!e)\n goto d;\n return 0;\n}\n```"}, {"author": "antoniofrighetto", "body": "Reduced to:\n\n```llvm\n; opt -p instcombine small.ll\ndefine i32 @small(i32 noundef %0) {\n %2 = xor i32 %0, 1\n %3 = sub i32 0, %2\n %4 = icmp ne i32 %3, 0\n br i1 %4, label %5, label %6\n\n5: ; preds = %6, %1\n %.0 = phi i32 [ %.1, %6 ], [ %3, %1 ]\n br label %6\n\n6: ; preds = %5, %1\n %.1 = phi i32 [ %.0, %5 ], [ 0, %1 ]\n %7 = icmp ne i32 %.1, 0\n %8 = xor i1 %7, true\n br i1 %8, label %5, label %9\n\n9: ; preds = %6\n ret i32 0\n}\n```"}, {"author": "goldsteinn", "body": "Fix at: https://github.com/llvm/llvm-project/pull/124481"}]}, "verified": true} {"bug_id": "121745", "issue_url": "https://github.com/llvm/llvm-project/issues/121745", "bug_type": "miscompilation", "base_commit": "3874c64418d2a7e36eab9af9253d905b48b36078", "knowledge_cutoff": "2025-01-06T10:26:21Z", "lit_test_dir": ["llvm/test/Transforms/LoopVectorize"], "hints": {"fix_commit": "f9369cc602272796c15de1065a782f812e791df3", "components": ["LoopVectorize"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": [[562, 582], [1086, 1103]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": ["VPlanTransforms::adjustFixedOrderRecurrences", "VPlanTransforms::clearReductionWrapFlags", "collectUsersRecursively", "createScalarIVSteps", "legalizeAndOptimizeInductions"]}}, "patch": "commit f9369cc602272796c15de1065a782f812e791df3\nAuthor: Florian Hahn \nDate: Mon Jan 6 22:40:41 2025 +0000\n\n [VPlan] Make sure last IV increment value is available if needed.\n \n Legalize extract-from-ends using uniform VPReplicateRecipe of wide\n inductions to use regular VPReplicateRecipe, so the correct end value\n is available.\n \n Fixes https://github.com/llvm/llvm-project/issues/121745.\n\ndiff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp\nindex 395287bde76f..3e3f5adf73a0 100644\n--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp\n+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp\n@@ -562,21 +562,63 @@ createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind,\n return Builder.createScalarIVSteps(InductionOpcode, FPBinOp, BaseIV, Step);\n }\n \n+static SmallVector collectUsersRecursively(VPValue *V) {\n+ SetVector Users(V->user_begin(), V->user_end());\n+ for (unsigned I = 0; I != Users.size(); ++I) {\n+ VPRecipeBase *Cur = cast(Users[I]);\n+ if (isa(Cur))\n+ continue;\n+ for (VPValue *V : Cur->definedValues())\n+ Users.insert(V->user_begin(), V->user_end());\n+ }\n+ return Users.takeVector();\n+}\n+\n /// Legalize VPWidenPointerInductionRecipe, by replacing it with a PtrAdd\n /// (IndStart, ScalarIVSteps (0, Step)) if only its scalar values are used, as\n /// VPWidenPointerInductionRecipe will generate vectors only. If some users\n /// require vectors while other require scalars, the scalar uses need to extract\n /// the scalars from the generated vectors (Note that this is different to how\n-/// int/fp inductions are handled). Also optimize VPWidenIntOrFpInductionRecipe,\n-/// if any of its users needs scalar values, by providing them scalar steps\n-/// built on the canonical scalar IV and update the original IV's users. This is\n-/// an optional optimization to reduce the needs of vector extracts.\n+/// int/fp inductions are handled). Legalize extract-from-ends using uniform\n+/// VPReplicateRecipe of wide inductions to use regular VPReplicateRecipe, so\n+/// the correct end value is available. Also optimize\n+/// VPWidenIntOrFpInductionRecipe, if any of its users needs scalar values, by\n+/// providing them scalar steps built on the canonical scalar IV and update the\n+/// original IV's users. This is an optional optimization to reduce the needs of\n+/// vector extracts.\n static void legalizeAndOptimizeInductions(VPlan &Plan) {\n+ using namespace llvm::VPlanPatternMatch;\n SmallVector ToRemove;\n VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();\n bool HasOnlyVectorVFs = !Plan.hasVF(ElementCount::getFixed(1));\n VPBuilder Builder(HeaderVPBB, HeaderVPBB->getFirstNonPhi());\n for (VPRecipeBase &Phi : HeaderVPBB->phis()) {\n+ auto *PhiR = dyn_cast(&Phi);\n+ if (!PhiR)\n+ break;\n+\n+ // Check if any uniform VPReplicateRecipes using the phi recipe are used by\n+ // ExtractFromEnd. Those must be replaced by a regular VPReplicateRecipe to\n+ // ensure the final value is available.\n+ // TODO: Remove once uniformity analysis is done on VPlan.\n+ for (VPUser *U : collectUsersRecursively(PhiR)) {\n+ auto *ExitIRI = dyn_cast(U);\n+ VPValue *Op;\n+ if (!ExitIRI || !match(ExitIRI->getOperand(0),\n+ m_VPInstruction(\n+ m_VPValue(Op), m_VPValue())))\n+ continue;\n+ auto *RepR = dyn_cast(Op);\n+ if (!RepR || !RepR->isUniform())\n+ continue;\n+ assert(!RepR->isPredicated() && \"RepR must not be predicated\");\n+ Instruction *I = RepR->getUnderlyingInstr();\n+ auto *Clone =\n+ new VPReplicateRecipe(I, RepR->operands(), /*IsUniform*/ false);\n+ Clone->insertAfter(RepR);\n+ RepR->replaceAllUsesWith(Clone);\n+ }\n+\n // Replace wide pointer inductions which have only their scalars used by\n // PtrAdd(IndStart, ScalarIVSteps (0, Step)).\n if (auto *PtrIV = dyn_cast(&Phi)) {\n@@ -1086,18 +1128,6 @@ bool VPlanTransforms::adjustFixedOrderRecurrences(VPlan &Plan,\n return true;\n }\n \n-static SmallVector collectUsersRecursively(VPValue *V) {\n- SetVector Users(V->user_begin(), V->user_end());\n- for (unsigned I = 0; I != Users.size(); ++I) {\n- VPRecipeBase *Cur = cast(Users[I]);\n- if (isa(Cur))\n- continue;\n- for (VPValue *V : Cur->definedValues())\n- Users.insert(V->user_begin(), V->user_end());\n- }\n- return Users.takeVector();\n-}\n-\n void VPlanTransforms::clearReductionWrapFlags(VPlan &Plan) {\n for (VPRecipeBase &R :\n Plan.getVectorLoopRegion()->getEntryBasicBlock()->phis()) {\n", "tests": [{"file": "llvm/test/Transforms/LoopVectorize/iv_outside_user.ll", "commands": ["opt -S -passes=loop-vectorize -force-vector-interleave=1 -force-vector-width=2 < %s", "opt -S -passes=loop-vectorize -force-vector-interleave=2 -force-vector-width=1 < %s"], "tests": [{"test_name": "test_iv_uniform_with_outside_use_scev_simplification", "test_body": "define i32 @test_iv_uniform_with_outside_use_scev_simplification(ptr %dst) {\nentry:\n %step.1 = sext i8 0 to i32\n %step.2 = add nsw i32 %step.1, 1\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %gep.dst = getelementptr inbounds i16, ptr %dst, i32 %iv\n store i16 0, ptr %gep.dst, align 2\n %iv.next = add i32 %step.2, %iv\n %cmp.i = icmp slt i32 %iv.next, 8\n br i1 %cmp.i, label %loop, label %e.exit\n\ne.exit: ; preds = %loop\n %res = phi i32 [ %iv.next, %loop ]\n ret i32 %res\n}\n", "additional_args": "-src-unroll=8 -tgt-unroll=8"}]}], "issue": {"title": "[clang] Miscompilation at -O2/3", "body": "This code prints 8 at `-O0/1` and prints 1 at `-O2/3`:\n\n```c\nint printf(const char *, ...);\nstatic char a;\nstatic char *b = &a;\nstatic int c;\nshort d;\nvoid e() {\n short f[8];\n char **g[] = {&b, &b};\n c = 0;\n for (; c < 8; c = 81 + 462704684 + *b - 462704765 + c + 1)\n f[c] = 0;\n d = f[5];\n}\nint main() {\n e();\n printf(\"%d\\n\", c);\n}\n```\n\nCompiler Explorer: https://godbolt.org/z/MEKz8oncP\n\nBisected to https://github.com/llvm/llvm-project/commit/df4a615c988f3ae56f7e68a7df86acb60f16493a, which was committed by @fhahn ", "author": "cardigan1008", "labels": ["miscompilation", "vectorizers"], "comments": [{"author": "dtcxzyw", "body": "Reduced testcase: https://alive2.llvm.org/ce/z/6Bg63G\n```\n; bin/opt -passes=loop-vectorize 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\ndefine i32 @src() {\nentry:\n %f.i = alloca [8 x i16], align 16\n %conv.i = sext i8 0 to i32\n %invariant.op.i = add nsw i32 %conv.i, 1\n br label %for.body.i\n\nfor.body.i: ; preds = %for.body.i, %entry\n %0 = phi i32 [ 0, %entry ], [ %add2.reass.i, %for.body.i ]\n %idxprom.i = sext i32 %0 to i64\n %arrayidx.i = getelementptr [8 x i16], ptr %f.i, i64 0, i64 %idxprom.i\n store i16 0, ptr %arrayidx.i, align 2\n %add2.reass.i = add i32 %invariant.op.i, %0\n %cmp.i = icmp slt i32 %add2.reass.i, 8\n br i1 %cmp.i, label %for.body.i, label %e.exit\n\ne.exit: ; preds = %for.body.i\n %add2.reass.i.lcssa = phi i32 [ %add2.reass.i, %for.body.i ]\n ret i32 %add2.reass.i.lcssa\n}\n```"}, {"author": "fhahn", "body": "Looking into it now, thanks"}, {"author": "yaoxinliu", "body": "Thank God! clang19 works as expected."}]}, "verified": true} {"bug_id": "112467", "issue_url": "https://github.com/llvm/llvm-project/issues/112467", "bug_type": "miscompilation", "base_commit": "9df8d8d05c2650b51bd4233e1759206d163f3133", "knowledge_cutoff": "2024-10-16T03:31:20Z", "lit_test_dir": ["llvm/test/Transforms/InstCombine"], "hints": {"fix_commit": "3bf2295ee0ebd1eafe66ca15dff44bdb31e6198a", "components": ["InstCombine"], "bug_location_lineno": {"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": [[3369, 3376]]}, "bug_location_funcname": {"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": ["InstCombinerImpl::foldAndOrOfICmps"]}}, "patch": "commit 3bf2295ee0ebd1eafe66ca15dff44bdb31e6198a\nAuthor: Yingwei Zheng \nDate: Wed Oct 16 16:24:44 2024 +0800\n\n [InstCombine] Drop `samesign` flag in `foldAndOrOfICmpsWithConstEq` (#112489)\n \n In\n https://github.com/llvm/llvm-project/commit/5dbfca30c1a672cd0c5089df2b4fdd171436643a\n we assume that RHS is poison implies LHS is also poison. It doesn't hold\n after introducing samesign flag.\n \n This patch drops the `samesign` flag on RHS if the original expression\n is a logical and/or.\n \n Closes #112467.\n\ndiff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp\nindex 64bee4ab974e..c8407e8ba5ab 100644\n--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp\n+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp\n@@ -3369,8 +3369,14 @@ Value *InstCombinerImpl::foldAndOrOfICmps(ICmpInst *LHS, ICmpInst *RHS,\n // We can convert this case to bitwise and, because both operands are used\n // on the LHS, and as such poison from both will propagate.\n if (Value *V = foldAndOrOfICmpsWithConstEq(RHS, LHS, IsAnd,\n- /*IsLogical*/ false, Builder, Q))\n+ /*IsLogical=*/false, Builder, Q)) {\n+ // If RHS is still used, we should drop samesign flag.\n+ if (IsLogical && RHS->hasSameSign() && !RHS->use_empty()) {\n+ RHS->setSameSign(false);\n+ addToWorklist(RHS);\n+ }\n return V;\n+ }\n \n if (Value *V = foldIsPowerOf2OrZero(LHS, RHS, IsAnd, Builder, *this))\n return V;\n", "tests": [{"file": "llvm/test/Transforms/InstCombine/and-or-icmp-min-max.ll", "commands": ["opt < %s -passes=instcombine -S"], "tests": [{"test_name": "sge_and_max_commute", "test_body": "define i1 @sge_and_max_commute(i8 %x, i8 %y) {\n %cmp = icmp sge i8 %x, %y\n %cmpeq = icmp eq i8 %x, 127\n %r = and i1 %cmpeq, %cmp\n ret i1 %r\n}\n"}, {"test_name": "sge_and_max_logical", "test_body": "define i1 @sge_and_max_logical(i8 %x, i8 %y) {\n %cmp = icmp sge i8 %x, %y\n %cmpeq = icmp eq i8 %x, 127\n %r = select i1 %cmp, i1 %cmpeq, i1 false\n ret i1 %r\n}\n"}, {"test_name": "sge_and_max_logical_samesign", "test_body": "define i1 @sge_and_max_logical_samesign(i8 %x, i8 %y) {\n %cmp = icmp sge i8 %x, %y\n %cmpeq = icmp samesign eq i8 %x, 127\n %r = select i1 %cmp, i1 %cmpeq, i1 false\n ret i1 %r\n}\n"}]}, {"file": "llvm/test/Transforms/InstCombine/and-or-icmp-nullptr.ll", "commands": ["opt < %s -passes=instcombine -S"], "tests": [{"test_name": "sgt_and_min_logical_samesign", "test_body": "define i1 @sgt_and_min_logical_samesign(ptr %x, ptr %y) {\n %cmp = icmp sgt ptr %x, %y\n %cmpeq = icmp samesign eq ptr %x, null\n %r = select i1 %cmp, i1 %cmpeq, i1 false\n ret i1 %r\n}\n"}, {"test_name": "sgt_and_min_logical", "test_body": "define i1 @sgt_and_min_logical(ptr %x, ptr %y) {\n %cmp = icmp sgt ptr %x, %y\n %cmpeq = icmp eq ptr %x, null\n %r = select i1 %cmp, i1 %cmpeq, i1 false\n ret i1 %r\n}\n"}, {"test_name": "sle_or_not_min", "test_body": "define i1 @sle_or_not_min(ptr %x, ptr %y) {\n %cmp = icmp sle ptr %x, %y\n %cmpeq = icmp ne ptr %x, null\n %r = or i1 %cmp, %cmpeq\n ret i1 %r\n}\n"}]}], "issue": {"title": "[InstCombine] `samesign` flag should be dropped in `foldAndOrOfICmpsWithConstEq`", "body": "Reproducer:\r\n```\r\n; bin/opt -passes=instcombine test.ll -S\r\ndefine i1 @src(i8 %x, i8 %y) {\r\n %cmp = icmp sgt i8 %x, %y\r\n %cmpeq = icmp samesign ne i8 %x, 0\r\n %r = select i1 %cmp, i1 true, i1 %cmpeq\r\n ret i1 %r\r\n}\r\n```\r\n```\r\ndefine i1 @tgt(i8 %x, i8 %y) {\r\n %cmpeq = icmp samesign ne i8 %x, 0\r\n %1 = icmp slt i8 %y, 0\r\n %r = or i1 %cmpeq, %1\r\n ret i1 %r\r\n}\r\n```\r\n```\r\n----------------------------------------\r\ndefine i1 @src(i8 %x, i8 %y) {\r\n#0:\r\n %cmp = icmp sgt i8 %x, %y\r\n %cmpeq = icmp samesign ne i8 %x, 0\r\n %r = select i1 %cmp, i1 1, i1 %cmpeq\r\n ret i1 %r\r\n}\r\n=>\r\ndefine i1 @tgt(i8 %x, i8 %y) {\r\n#0:\r\n %cmpeq = icmp samesign ne i8 %x, 0\r\n %#1 = icmp slt i8 %y, 0\r\n %r = or i1 %cmpeq, %#1\r\n ret i1 %r\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Target is more poisonous than source\r\n\r\nExample:\r\ni8 %x = #x81 (129, -127)\r\ni8 %y = #x80 (128, -128)\r\n\r\nSource:\r\ni1 %cmp = #x1 (1)\r\ni1 %cmpeq = poison\r\ni1 %r = #x1 (1)\r\n\r\nTarget:\r\ni1 %cmpeq = poison\r\ni1 %#1 = #x1 (1)\r\ni1 %r = poison\r\nSource value: #x1 (1)\r\nTarget value: poison\r\n```\r\n", "author": "dtcxzyw", "labels": ["miscompilation", "llvm:instcombine"], "comments": []}, "verified": true} @@ -220,6 +230,7 @@ {"bug_id": "119893", "issue_url": "https://github.com/llvm/llvm-project/issues/119893", "bug_type": "crash", "base_commit": "cd093c2e1bac35dd2c6b914d0b64ce56683cb50a", "knowledge_cutoff": "2024-12-13T16:00:39Z", "lit_test_dir": ["llvm/test/Transforms/EarlyCSE"], "hints": {"fix_commit": "5528388e3664c6d7d292f20a739f1bf1c8ef768d", "components": ["EarlyCSE", "IR"], "bug_location_lineno": {"llvm/include/llvm/IR/CmpPredicate.h": [[71, 83]], "llvm/lib/IR/Instructions.cpp": [[3946, 3955]], "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": [[290, 296]]}, "bug_location_funcname": {"llvm/lib/IR/Instructions.cpp": ["CmpPredicate::getSwapped", "llvm::hash_value"], "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": ["getHashValueImpl"]}}, "patch": "commit 5528388e3664c6d7d292f20a739f1bf1c8ef768d\nAuthor: Ramkumar Ramachandra \nDate: Fri Dec 13 22:06:39 2024 +0000\n\n EarlyCSE: fix CmpPredicate duplicate-hashing (#119902)\n \n Strip hash_value() for CmpPredicate, as different callers have different\n hashing use-cases. In this case, there is just one caller, namely\n EarlyCSE, which calls hash_combine() on a CmpPredicate, which used to\n call hash_combine() on a CmpInst::Predicate prior to 4a0d53a\n (PatternMatch: migrate to CmpPredicate). This has uncovered a bug where\n two icmp instructions differing in just the fact that one of them has\n the samesign flag on it are hashed differently, leading to divergent\n hashing, and a crash. Fix this crash by dropping samesign information on\n icmp instructions before hashing them, preserving the former behavior.\n \n Fixes #119893.\n\ndiff --git a/llvm/include/llvm/IR/CmpPredicate.h b/llvm/include/llvm/IR/CmpPredicate.h\nindex ce78e4311f9f..9aa1449465f5 100644\n--- a/llvm/include/llvm/IR/CmpPredicate.h\n+++ b/llvm/include/llvm/IR/CmpPredicate.h\n@@ -71,13 +71,7 @@ public:\n \n /// Get the swapped predicate of a CmpInst.\n static CmpPredicate getSwapped(const CmpInst *Cmp);\n-\n- /// Provided to facilitate storing a CmpPredicate in data structures that\n- /// require hashing.\n- friend hash_code hash_value(const CmpPredicate &Arg); // NOLINT\n };\n-\n-[[nodiscard]] hash_code hash_value(const CmpPredicate &Arg);\n } // namespace llvm\n \n #endif\ndiff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp\nindex d1da02c744f1..2d6fe40f4c1d 100644\n--- a/llvm/lib/IR/Instructions.cpp\n+++ b/llvm/lib/IR/Instructions.cpp\n@@ -3946,10 +3946,6 @@ CmpPredicate CmpPredicate::getSwapped(const CmpInst *Cmp) {\n return getSwapped(get(Cmp));\n }\n \n-hash_code llvm::hash_value(const CmpPredicate &Arg) { // NOLINT\n- return hash_combine(Arg.Pred, Arg.HasSameSign);\n-}\n-\n //===----------------------------------------------------------------------===//\n // SwitchInst Implementation\n //===----------------------------------------------------------------------===//\ndiff --git a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp\nindex 682c5c3d8c63..3a0ae6b01a11 100644\n--- a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp\n+++ b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp\n@@ -290,7 +290,8 @@ static unsigned getHashValueImpl(SimpleValue Val) {\n Pred = CmpInst::getInversePredicate(Pred);\n std::swap(A, B);\n }\n- return hash_combine(Inst->getOpcode(), Pred, X, Y, A, B);\n+ return hash_combine(Inst->getOpcode(),\n+ static_cast(Pred), X, Y, A, B);\n }\n \n if (CastInst *CI = dyn_cast(Inst))\n", "tests": [{"file": "llvm/test/Transforms/EarlyCSE/pr119893.ll", "commands": ["opt -passes=early-cse -S %s"], "tests": [{"test_name": "samesign_hash_bug", "test_body": "define i32 @samesign_hash_bug(i16 %v) {\n %zext = zext i16 %v to i32\n %icmp.samesign = icmp samesign ugt i32 %zext, 31\n %select.icmp.samesign = select i1 %icmp.samesign, i32 0, i32 1\n %ashr = ashr i32 0, %select.icmp.samesign\n %icmp = icmp ugt i32 %zext, 31\n %select.icmp = select i1 %icmp, i32 1, i32 0\n %ret = add i32 %ashr, %select.icmp\n ret i32 %ret\n}\n"}]}], "issue": {"title": "[EarlyCSE] Assertion `!FoundVal && \"Key already in new map?\"' failed.", "body": "Reproducer:\n```\n; bin/opt -passes=early-cse reduced.ll -S\n\ndefine i32 @func_207(i16 %p_208.coerce, i32 %conv, i32 %0, i64 %1, ptr %p) {\nentry:\n %conv1 = zext i16 %p_208.coerce to i32\n %conv31 = sext i32 %conv to i64\n %cmp.i = icmp eq i64 %conv31, 0\n %xor = xor i32 %conv, 1\n store i32 %xor, ptr %p, align 4\n %cmp2.i = icmp samesign ugt i32 %conv1, 31\n %shr.i601 = select i1 %cmp2.i, i32 0, i32 %conv1\n %cond.i602 = ashr i32 1, %shr.i601\n %conv6.i603 = trunc i32 %cond.i602 to i16\n %conv245 = trunc i16 %p_208.coerce to i8\n %mul.i628 = mul i8 -107, %conv245\n %conv247 = sext i8 %mul.i628 to i64\n %cond.i629 = call i64 @llvm.smin.i64(i64 0, i64 %conv247)\n %cmp249 = icmp slt i64 %cond.i629, 0\n %conv251 = zext i1 %cmp249 to i64\n %cmp1.i630 = icmp ugt i32 %conv1, 31\n %narrow.i631 = select i1 %cmp1.i630, i32 0, i32 %conv1\n %shr.i632 = zext i32 %narrow.i631 to i64\n %cond.i633 = lshr i64 %conv251, %shr.i632\n %cmp258 = icmp slt i16 %p_208.coerce, 0\n %2 = zext i1 %cmp258 to i16\n %cmp261 = icmp ugt i16 1, %2\n %conv263 = zext i1 %cmp261 to i64\n %cmp344 = icmp eq i16 %p_208.coerce, 0\n %conv345 = zext i1 %cmp344 to i32\n store i32 %conv345, ptr %p, align 4\n %conv351 = sext i32 %0 to i64\n %sub.i641 = call i64 @llvm.ucmp.i64.i64(i64 0, i64 %conv351)\n %conv353 = trunc i64 %sub.i641 to i16\n %3 = mul i16 %conv353, -1\n %conv355 = zext i16 %3 to i64\n %cmp356 = icmp sle i64 1, %conv355\n %conv357 = zext i1 %cmp356 to i32\n %conv359 = trunc i32 %conv357 to i8\n %conv.i650 = sext i8 %conv359 to i32\n %4 = icmp ugt i32 %conv, 0\n %shr.i652 = lshr i32 1, %conv\n %cmp9.i = icmp slt i32 %shr.i652, 1\n %or.cond.i = select i1 %4, i1 false, i1 %cmp9.i\n %shl.i653 = shl i32 %conv.i650, 1\n %5 = trunc i32 %shl.i653 to i8\n %cond.i654 = select i1 %or.cond.i, i8 0, i8 %5\n %conv3612 = sext i8 %cond.i654 to i32\n %conv3623 = trunc i64 %1 to i32\n %6 = or i32 1, %conv3612\n %or.cond.i655 = icmp slt i32 %6, 0\n %cmp3.i = icmp sgt i32 %conv3623, 0\n %or.cond4.i = or i1 %cmp3.i, %or.cond.i655\n %shr.i656 = select i1 %or.cond4.i, i32 0, i32 1\n %cond.i657 = ashr i32 %conv, %shr.i656\n %cmp.i658 = icmp slt i32 %cond.i657, 0\n %shr.i660 = select i1 %cmp.i658, i32 0, i32 1\n %cond.i661 = ashr i32 1, %shr.i660\n %conv365 = trunc i32 %cond.i661 to i16\n %add.i662 = or i16 1, %conv365\n %conv368 = sext i16 %add.i662 to i32\n ret i32 %conv368\n}\n```\n```\nopt: /data/zyw/llvm-project/llvm/include/llvm/ADT/DenseMap.h:419: void llvm::DenseMapBase::moveFromOldBuckets(BucketT*, BucketT*) [with DerivedT = llvm::DenseMap<{anonymous}::SimpleValue, llvm::ScopedHashTableVal<{anonymous}::SimpleValue, llvm::Value*>*, llvm::DenseMapInfo<{anonymous}::SimpleValue>, llvm::detail::DenseMapPair<{anonymous}::SimpleValue, llvm::ScopedHashTableVal<{anonymous}::SimpleValue, llvm::Value*>*> >; KeyT = {anonymous}::SimpleValue; ValueT = llvm::ScopedHashTableVal<{anonymous}::SimpleValue, llvm::Value*>*; KeyInfoT = llvm::DenseMapInfo<{anonymous}::SimpleValue>; BucketT = llvm::detail::DenseMapPair<{anonymous}::SimpleValue, llvm::ScopedHashTableVal<{anonymous}::SimpleValue, llvm::Value*>*>]: Assertion `!FoundVal && \"Key already in new map?\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\nStack dump:\n0. Program arguments: /data/zyw/llvm-build/bin/opt -passes=early-cse reduced.ll\n1. Running pass \"function(early-cse<>)\" on module \"reduced.ll\"\n2. Running pass \"early-cse<>\" on function \"func_207\"\n #0 0x00007ffff7def832 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/zyw/llvm-build/bin/../lib/libLLVMSupport.so.20.0git+0x1ef832)\n #1 0x00007ffff7dec9ef llvm::sys::RunSignalHandlers() (/data/zyw/llvm-build/bin/../lib/libLLVMSupport.so.20.0git+0x1ec9ef)\n #2 0x00007ffff7decb35 SignalHandler(int) Signals.cpp:0:0\n #3 0x00007ffff7842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #4 0x00007ffff78969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #5 0x00007ffff7842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #6 0x00007ffff78287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #7 0x00007ffff782871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #8 0x00007ffff7839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #9 0x00007ffff4efa75e llvm::DenseMap<(anonymous namespace)::SimpleValue, llvm::ScopedHashTableVal<(anonymous namespace)::SimpleValue, llvm::Value*>*, llvm::DenseMapInfo<(anonymous namespace)::SimpleValue, void>, llvm::detail::DenseMapPair<(anonymous namespace)::SimpleValue, llvm::ScopedHashTableVal<(anonymous namespace)::SimpleValue, llvm::Value*>*>>::grow(unsigned int) EarlyCSE.cpp:0:0\n#10 0x00007ffff4efbd5a llvm::ScopedHashTable<(anonymous namespace)::SimpleValue, llvm::Value*, llvm::DenseMapInfo<(anonymous namespace)::SimpleValue, void>, llvm::RecyclingAllocator, llvm::ScopedHashTableVal<(anonymous namespace)::SimpleValue, llvm::Value*>, 32ul, 8ul>>::insertIntoScope(llvm::ScopedHashTableScope<(anonymous namespace)::SimpleValue, llvm::Value*, llvm::DenseMapInfo<(anonymous namespace)::SimpleValue, void>, llvm::RecyclingAllocator, llvm::ScopedHashTableVal<(anonymous namespace)::SimpleValue, llvm::Value*>, 32ul, 8ul>>*, (anonymous namespace)::SimpleValue const&, llvm::Value* const&) EarlyCSE.cpp:0:0\n#11 0x00007ffff4efdf19 (anonymous namespace)::EarlyCSE::processNode(llvm::DomTreeNodeBase*) (.isra.0) EarlyCSE.cpp:0:0\n#12 0x00007ffff4efeef5 (anonymous namespace)::EarlyCSE::run() EarlyCSE.cpp:0:0\n#13 0x00007ffff4f00796 llvm::EarlyCSEPass::run(llvm::Function&, llvm::AnalysisManager&) (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMScalarOpts.so.20.0git+0x100796)\n#14 0x00007ffff6684345 llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMPasses.so.20.0git+0x84345)\n#15 0x00007ffff38ee63d llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x2ee63d)\n#16 0x00007ffff70a9445 llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.20.0git+0xa9445)\n#17 0x00007ffff38ec628 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x2ec628)\n#18 0x00007ffff70a9e05 llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.20.0git+0xa9e05)\n#19 0x00007ffff38ed28d llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x2ed28d)\n#20 0x00007ffff7f9b1eb llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::ArrayRef>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/data/zyw/llvm-build/bin/../lib/libLLVMOptDriver.so.20.0git+0x241eb)\n#21 0x00007ffff7fa5619 optMain (/data/zyw/llvm-build/bin/../lib/libLLVMOptDriver.so.20.0git+0x2e619)\n#22 0x00007ffff7829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#23 0x00007ffff7829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#24 0x0000555555555095 _start (/data/zyw/llvm-build/bin/opt+0x1095)\nAborted (core dumped)\n```", "author": "dtcxzyw", "labels": ["crash-on-valid", "llvm:transforms"], "comments": [{"author": "dtcxzyw", "body": "Reverting 4a0d53a0b0a58a3c6980a7c551357ac71ba3db10 fixes this issue.\ncc @artagnon @nikic Can you double check the implementation of `hash_value(const CmpPredicate&)`?\n"}, {"author": "nikic", "body": "Yeah, the implementation is incorrect for EarlyCSE (which should not take into account poison generating flags). I think we should remove the hash_value implementation and make the caller handler it appropriately."}, {"author": "artagnon", "body": "Not sure I understand. The backtrace points to EarlyCSE.cpp:1558, and the Instruction it crashes on is an `or`. With surrounding context it is:\n\nhttps://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/Scalar/EarlyCSE.cpp#L1392-L1560"}, {"author": "artagnon", "body": "So I think this would fix the issue, although I'm not sure I understand the underlying issue:\n\n```diff\ndiff --git a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp\nindex 682c5c3d8c63..8e87f8b9a457 100644\n--- a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp\n+++ b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp\n@@ -290,7 +290,7 @@ static unsigned getHashValueImpl(SimpleValue Val) {\n Pred = CmpInst::getInversePredicate(Pred);\n std::swap(A, B);\n }\n- return hash_combine(Inst->getOpcode(), Pred, X, Y, A, B);\n+ return hash_combine(Inst->getOpcode(), static_cast(Pred), X, Y, A, B);\n }\n\n if (CastInst *CI = dyn_cast(Inst))\n```"}, {"author": "artagnon", "body": "We hash two equal predicates, one with with samesign information (leading to a divergent hash), leading to a divergent hash_combine call, and hence a duplicate insertion into DenseMap:\n\n```cpp\n SelectPatternFlavor SPF;\n Value *Cond, *A, *B;\n if (matchSelectWithOptionalNotCond(Inst, Cond, A, B, SPF)) {\n // Hash min/max (cmp + select) to allow for commuted operands.\n // Min/max may also have non-canonical compare predicate (eg, the compare for\n // smin may use 'sgt' rather than 'slt'), and non-canonical operands in the\n // compare.\n // TODO: We should also detect FP min/max.\n if (SPF == SPF_SMIN || SPF == SPF_SMAX ||\n SPF == SPF_UMIN || SPF == SPF_UMAX) {\n if (A > B)\n std::swap(A, B);\n return hash_combine(Inst->getOpcode(), SPF, A, B);\n }\n\n // Hash general selects to allow matching commuted true/false operands.\n\n // If we do not have a compare as the condition, just hash in the condition.\n CmpPredicate Pred;\n Value *X, *Y;\n if (!match(Cond, m_Cmp(Pred, m_Value(X), m_Value(Y))))\n return hash_combine(Inst->getOpcode(), Cond, A, B);\n\n // Similar to cmp normalization (above) - canonicalize the predicate value:\n // select (icmp Pred, X, Y), A, B --> select (icmp InvPred, X, Y), B, A\n if (CmpInst::getInversePredicate(Pred) < Pred) {\n Pred = CmpInst::getInversePredicate(Pred);\n std::swap(A, B);\n }\n return hash_combine(Inst->getOpcode(), static_cast(Pred), X, Y, A, B); /// fixed\n }\n```\n\nThese are the duplicates:\n\n```llvm\n %cmp2.i = icmp samesign ugt i32 %conv1, 31\n %cmp1.i630 = icmp ugt i32 %conv1, 31\n```"}]}, "verified": true} {"bug_id": "90900", "issue_url": "https://github.com/llvm/llvm-project/issues/90900", "bug_type": "crash", "base_commit": "311339e25cd4d431902f93b1cbc6b67ac3fd2abf", "knowledge_cutoff": "2024-05-02T19:52:37Z", "lit_test_dir": ["llvm/test/Transforms/Reg2Mem"], "hints": {"fix_commit": "fdaad738753cde2bba6480c2ee5d1e9fb45064b9", "components": ["DemoteRegToStack"], "bug_location_lineno": {"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": [[50, 55], [102, 110]]}, "bug_location_funcname": {"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": ["llvm::DemoteRegToStack"]}}, "patch": "commit fdaad738753cde2bba6480c2ee5d1e9fb45064b9\nAuthor: XChy \nDate: Thu May 16 20:13:39 2024 +0800\n\n [Reg2Mem] Handle CallBr instructions (#90953)\n \n Fixes #90900\n\ndiff --git a/llvm/lib/Transforms/Utils/DemoteRegToStack.cpp b/llvm/lib/Transforms/Utils/DemoteRegToStack.cpp\nindex b2a88eadd3de..f03de2f25a41 100644\n--- a/llvm/lib/Transforms/Utils/DemoteRegToStack.cpp\n+++ b/llvm/lib/Transforms/Utils/DemoteRegToStack.cpp\n@@ -50,6 +50,15 @@ AllocaInst *llvm::DemoteRegToStack(Instruction &I, bool VolatileLoads,\n assert(BB && \"Unable to split critical edge.\");\n (void)BB;\n }\n+ } else if (CallBrInst *CBI = dyn_cast(&I)) {\n+ for (int i = 0; i < CBI->getNumSuccessors(); i++) {\n+ auto *Succ = CBI->getSuccessor(i);\n+ if (!Succ->getSinglePredecessor()) {\n+ assert(isCriticalEdge(II, i) && \"Expected a critical edge!\");\n+ BasicBlock *BB = SplitCriticalEdge(II, i);\n+ assert(BB && \"Unable to split critical edge.\");\n+ }\n+ }\n }\n \n // Change all of the users of the instruction to read from the stack slot.\n@@ -102,9 +111,14 @@ AllocaInst *llvm::DemoteRegToStack(Instruction &I, bool VolatileLoads,\n new StoreInst(&I, Slot, Handler->getFirstInsertionPt());\n return Slot;\n }\n+ } else if (InvokeInst *II = dyn_cast(&I)) {\n+ InsertPt = II->getNormalDest()->getFirstInsertionPt();\n+ } else if (CallBrInst *CBI = dyn_cast(&I)) {\n+ for (BasicBlock *Succ : successors(CBI))\n+ new StoreInst(CBI, Slot, Succ->getFirstInsertionPt());\n+ return Slot;\n } else {\n- InvokeInst &II = cast(I);\n- InsertPt = II.getNormalDest()->getFirstInsertionPt();\n+ llvm_unreachable(\"Unsupported terminator for Reg2Mem\");\n }\n \n new StoreInst(&I, Slot, InsertPt);\n", "tests": [{"file": "llvm/test/Transforms/Reg2Mem/callbr-crash.ll", "commands": ["opt -passes=reg2mem -S < %s"], "tests": [{"test_name": "", "test_body": "\ndefine void @crash() {\n;\nentry:\n %a = callbr i64 asm \"\", \"=r,r,!i\"(i64 0)\n to label %then [label %else]\n\nthen:\n %b = inttoptr i64 %a to ptr\n br label %else\n\nelse:\n ret void\n}"}]}], "issue": {"title": "Reg2Mem pass triggered assertion `isa(V al) && \"cast() argument of incompatible type!\"", "body": "https://godbolt.org/z/oxW8zbKr6\r\n`opt --passes=reg2mem reduced.ll`\r\n```llvm\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\n%struct.__large_struct = type { [100 x i64] }\r\n\r\ndefine fastcc i64 @__se_sys_pselect6() {\r\n %1 = callbr i64 asm sideeffect \"\\0A1:\\09movq $1,$0\\0A .pushsection \\22__ex_table\\22,\\22a\\22\\0A .balign 4\\0A .long (1b) - .\\0A .long (${2:l}) - .\\0A .long 3 \\0A .popsection\\0A\", \"=r,*m,!i,~{dirflag},~{fpsr},~{flags}\"(ptr elementtype(%struct.__large_struct) null)\r\n to label %2 [label %common.ret]\r\n\r\n2: ; preds = %0\r\n %3 = inttoptr i64 %1 to ptr\r\n %4 = callbr i64 asm sideeffect \"\\0A1:\\09movq $1,$0\\0A .pushsection \\22__ex_table\\22,\\22a\\22\\0A .balign 4\\0A .long (1b) - .\\0A .long (${2:l}) - .\\0A .long 3 \\0A .popsection\\0A\", \"=r,*m,!i,~{dirflag},~{fpsr},~{flags}\"(ptr elementtype(%struct.__large_struct) null)\r\n to label %common.ret [label %common.ret]\r\n\r\ncommon.ret: ; preds = %2, %2, %0\r\n ret i64 0\r\n}\r\n```", "author": "XChy", "labels": ["crash", "llvm:transforms"], "comments": []}, "verified": true} {"bug_id": "114947", "issue_url": "https://github.com/llvm/llvm-project/issues/114947", "bug_type": "miscompilation", "base_commit": "1e5bfac933ea90ec4361446398551dd6b967c67f", "knowledge_cutoff": "2024-11-05T07:42:44Z", "lit_test_dir": ["llvm/test/Transforms/SCCP"], "hints": {"fix_commit": "cd88bfcb5906049e1387b856fc7256e5fae22e5f", "components": ["ConstantFold"], "bug_location_lineno": {"llvm/lib/Analysis/ConstantFolding.cpp": [[1266, 1279], [1298, 1344]]}, "bug_location_funcname": {"llvm/lib/Analysis/ConstantFolding.cpp": ["llvm::ConstantFoldBinaryOpOperands", "llvm::ConstantFoldCompareInstOperands", "llvm::ConstantFoldFPInstOperands", "llvm::FlushFPConstant"]}}, "patch": "commit cd88bfcb5906049e1387b856fc7256e5fae22e5f\nAuthor: Matt Arsenault \nDate: Wed Nov 13 07:43:50 2024 -0800\n\n ConstantFolding: Do not fold fcmp of denormal without known mode (#115407)\n \n Fixes #114947\n\ndiff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp\nindex 88db315ffd0b..1971c28fc4c4 100644\n--- a/llvm/lib/Analysis/ConstantFolding.cpp\n+++ b/llvm/lib/Analysis/ConstantFolding.cpp\n@@ -1266,14 +1266,16 @@ Constant *llvm::ConstantFoldCompareInstOperands(\n return ConstantFoldCompareInstOperands(Predicate, Ops1, Ops0, DL, TLI);\n }\n \n- // Flush any denormal constant float input according to denormal handling\n- // mode.\n- Ops0 = FlushFPConstant(Ops0, I, /* IsOutput */ false);\n- if (!Ops0)\n- return nullptr;\n- Ops1 = FlushFPConstant(Ops1, I, /* IsOutput */ false);\n- if (!Ops1)\n- return nullptr;\n+ if (CmpInst::isFPPredicate(Predicate)) {\n+ // Flush any denormal constant float input according to denormal handling\n+ // mode.\n+ Ops0 = FlushFPConstant(Ops0, I, /*IsOutput=*/false);\n+ if (!Ops0)\n+ return nullptr;\n+ Ops1 = FlushFPConstant(Ops1, I, /*IsOutput=*/false);\n+ if (!Ops1)\n+ return nullptr;\n+ }\n \n return ConstantFoldCompareInstruction(Predicate, Ops0, Ops1);\n }\n@@ -1298,47 +1300,110 @@ Constant *llvm::ConstantFoldBinaryOpOperands(unsigned Opcode, Constant *LHS,\n return ConstantFoldBinaryInstruction(Opcode, LHS, RHS);\n }\n \n-Constant *llvm::FlushFPConstant(Constant *Operand, const Instruction *I,\n- bool IsOutput) {\n- if (!I || !I->getParent() || !I->getFunction())\n- return Operand;\n+static ConstantFP *flushDenormalConstant(Type *Ty, const APFloat &APF,\n+ DenormalMode::DenormalModeKind Mode) {\n+ switch (Mode) {\n+ case DenormalMode::Dynamic:\n+ return nullptr;\n+ case DenormalMode::IEEE:\n+ return ConstantFP::get(Ty->getContext(), APF);\n+ case DenormalMode::PreserveSign:\n+ return ConstantFP::get(\n+ Ty->getContext(),\n+ APFloat::getZero(APF.getSemantics(), APF.isNegative()));\n+ case DenormalMode::PositiveZero:\n+ return ConstantFP::get(Ty->getContext(),\n+ APFloat::getZero(APF.getSemantics(), false));\n+ default:\n+ break;\n+ }\n \n- ConstantFP *CFP = dyn_cast(Operand);\n- if (!CFP)\n- return Operand;\n+ llvm_unreachable(\"unknown denormal mode\");\n+}\n+\n+/// Return the denormal mode that can be assumed when executing a floating point\n+/// operation at \\p CtxI.\n+static DenormalMode getInstrDenormalMode(const Instruction *CtxI, Type *Ty) {\n+ if (!CtxI || !CtxI->getParent() || !CtxI->getFunction())\n+ return DenormalMode::getDynamic();\n+ return CtxI->getFunction()->getDenormalMode(Ty->getFltSemantics());\n+}\n \n+static ConstantFP *flushDenormalConstantFP(ConstantFP *CFP,\n+ const Instruction *Inst,\n+ bool IsOutput) {\n const APFloat &APF = CFP->getValueAPF();\n- // TODO: Should this canonicalize nans?\n if (!APF.isDenormal())\n- return Operand;\n+ return CFP;\n \n- Type *Ty = CFP->getType();\n- DenormalMode DenormMode =\n- I->getFunction()->getDenormalMode(Ty->getFltSemantics());\n- DenormalMode::DenormalModeKind Mode =\n- IsOutput ? DenormMode.Output : DenormMode.Input;\n- switch (Mode) {\n- default:\n- llvm_unreachable(\"unknown denormal mode\");\n- case DenormalMode::Dynamic:\n- return nullptr;\n- case DenormalMode::IEEE:\n+ DenormalMode Mode = getInstrDenormalMode(Inst, CFP->getType());\n+ return flushDenormalConstant(CFP->getType(), APF,\n+ IsOutput ? Mode.Output : Mode.Input);\n+}\n+\n+Constant *llvm::FlushFPConstant(Constant *Operand, const Instruction *Inst,\n+ bool IsOutput) {\n+ if (ConstantFP *CFP = dyn_cast(Operand))\n+ return flushDenormalConstantFP(CFP, Inst, IsOutput);\n+\n+ if (isa(Operand))\n return Operand;\n- case DenormalMode::PreserveSign:\n- if (APF.isDenormal()) {\n- return ConstantFP::get(\n- Ty->getContext(),\n- APFloat::getZero(Ty->getFltSemantics(), APF.isNegative()));\n+\n+ Type *Ty = Operand->getType();\n+ VectorType *VecTy = dyn_cast(Ty);\n+ if (VecTy) {\n+ if (auto *Splat = dyn_cast_or_null(Operand->getSplatValue())) {\n+ ConstantFP *Folded = flushDenormalConstantFP(Splat, Inst, IsOutput);\n+ if (!Folded)\n+ return nullptr;\n+ return ConstantVector::getSplat(VecTy->getElementCount(), Folded);\n }\n- return Operand;\n- case DenormalMode::PositiveZero:\n- if (APF.isDenormal()) {\n- return ConstantFP::get(Ty->getContext(),\n- APFloat::getZero(Ty->getFltSemantics(), false));\n+\n+ Ty = VecTy->getElementType();\n+ }\n+\n+ if (const auto *CV = dyn_cast(Operand)) {\n+ SmallVector NewElts;\n+ for (unsigned i = 0, e = CV->getNumOperands(); i != e; ++i) {\n+ Constant *Element = CV->getAggregateElement(i);\n+ if (isa(Element)) {\n+ NewElts.push_back(Element);\n+ continue;\n+ }\n+\n+ ConstantFP *CFP = dyn_cast(Element);\n+ if (!CFP)\n+ return nullptr;\n+\n+ ConstantFP *Folded = flushDenormalConstantFP(CFP, Inst, IsOutput);\n+ if (!Folded)\n+ return nullptr;\n+ NewElts.push_back(Folded);\n }\n- return Operand;\n+\n+ return ConstantVector::get(NewElts);\n+ }\n+\n+ if (const auto *CDV = dyn_cast(Operand)) {\n+ SmallVector NewElts;\n+ for (unsigned I = 0, E = CDV->getNumElements(); I < E; ++I) {\n+ const APFloat &Elt = CDV->getElementAsAPFloat(I);\n+ if (!Elt.isDenormal()) {\n+ NewElts.push_back(ConstantFP::get(Ty, Elt));\n+ } else {\n+ DenormalMode Mode = getInstrDenormalMode(Inst, Ty);\n+ ConstantFP *Folded =\n+ flushDenormalConstant(Ty, Elt, IsOutput ? Mode.Output : Mode.Input);\n+ if (!Folded)\n+ return nullptr;\n+ NewElts.push_back(Folded);\n+ }\n+ }\n+\n+ return ConstantVector::get(NewElts);\n }\n- return Operand;\n+\n+ return nullptr;\n }\n \n Constant *llvm::ConstantFoldFPInstOperands(unsigned Opcode, Constant *LHS,\n", "tests": [{"file": "llvm/test/Transforms/SCCP/no-fold-fcmp-dynamic-denormal-mode-issue114947.ll", "commands": ["opt -S -passes=ipsccp < %s"], "tests": [{"test_name": "no_fold_fcmp_denormal_double_ieee_dynamic_vector_nonsplat", "test_body": "define <2 x i1> @no_fold_fcmp_denormal_double_ieee_dynamic_vector_nonsplat() #0 {\n %cmp = fcmp une <2 x double> , zeroinitializer\n ret <2 x i1> %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n"}, {"test_name": "fold_fcmp_nondenormal_double_ieee_dynamic_vector_nonsplat_undef", "test_body": "define <3 x i1> @fold_fcmp_nondenormal_double_ieee_dynamic_vector_nonsplat_undef() #0 {\n %cmp = fcmp une <3 x double> , \n ret <3 x i1> %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n"}, {"test_name": "no_fold_fcmp_denormal_double_ieee_dynamic_denormal_undef", "test_body": "define i1 @no_fold_fcmp_denormal_double_ieee_dynamic_denormal_undef() #0 {\n %cmp = fcmp une double 0x8000000000000, undef\n ret i1 %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n"}, {"test_name": "fold_fcmp_nondenormal_double_ieee_dynamic_vector_nonsplat", "test_body": "define <2 x i1> @fold_fcmp_nondenormal_double_ieee_dynamic_vector_nonsplat() #0 {\n %cmp = fcmp une <2 x double> , \n ret <2 x i1> %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n"}, {"test_name": "fold_fcmp_nondenormal_double_ieee_dynamic_vector_splat", "test_body": "define <2 x i1> @fold_fcmp_nondenormal_double_ieee_dynamic_vector_splat() #0 {\n %cmp = fcmp une <2 x double> splat (double 2.000000e+00), zeroinitializer\n ret <2 x i1> %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n"}, {"test_name": "fold_fcmp_nondenormal_double_ieee_dynamic", "test_body": "define i1 @fold_fcmp_nondenormal_double_ieee_dynamic() #0 {\n %cmp = fcmp une double 2.000000e+00, 0.000000e+00\n ret i1 %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n"}, {"test_name": "fold_fcmp_nondenormal_double_ieee_dynamic_zero", "test_body": "define <2 x i1> @fold_fcmp_nondenormal_double_ieee_dynamic_zero() #0 {\n %cmp = fcmp une <2 x double> zeroinitializer, zeroinitializer\n ret <2 x i1> %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n"}, {"test_name": "no_fold_fcmp_denormal_double_ieee_dynamic_denormal_poison", "test_body": "define i1 @no_fold_fcmp_denormal_double_ieee_dynamic_denormal_poison() #0 {\n %cmp = fcmp une double 0x8000000000000, poison\n ret i1 %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n"}, {"test_name": "no_fold_fcmp_denormal_double_ieee_dynamic_vector_splat", "test_body": "define <2 x i1> @no_fold_fcmp_denormal_double_ieee_dynamic_vector_splat() #0 {\n %cmp = fcmp une <2 x double> splat (double 0x8000000000000), zeroinitializer\n ret <2 x i1> %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n"}, {"test_name": "no_fold_fcmp_denormal_double_ieee_dynamic", "test_body": "define i1 @no_fold_fcmp_denormal_double_ieee_dynamic() #0 {\n %cmp = fcmp une double 0x8000000000000, 0.000000e+00\n ret i1 %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n"}]}], "issue": {"title": "`fcmp` miscompiled to a constant", "body": "Alive2 report: https://alive2.llvm.org/ce/z/324E7x\r\n\r\n```llvm\r\n----------------------------------------\r\ndefine i1 @fcmp_double_dynamic_dynamic.2() denormal-fp-math=dynamic,dynamic {\r\n#0:\r\n %cmp = fcmp une double 0x0008000000000000, -0.000000\r\n ret i1 %cmp\r\n}\r\n=>\r\ndefine i1 @fcmp_double_dynamic_dynamic.2() nofree noundef willreturn denormal-fp-math=dynamic,dynamic memory(none) {\r\n#0:\r\n ret i1 1\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Value mismatch\r\n\r\nExample:\r\n\r\nSource:\r\ni1 %cmp = #x0 (0)\r\n\r\nTarget:\r\nSource value: #x0 (0)\r\nTarget value: #x1 (1)\r\n\r\nSummary:\r\n 0 correct transformations\r\n 1 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\n```\r\n", "author": "bongjunj", "labels": ["miscompilation", "floating-point", "llvm:analysis"], "comments": [{"author": "arsenm", "body": "I don't see the issue? Those values are in fact not equal, so this is true. Alive bug? "}, {"author": "jcranmer-intel", "body": "it's comparing a denormal to 0, and the `denormal-fp-mode` is set to `dynamic`, so `fcmp` may or may not be flushing denormals to 0."}, {"author": "arsenm", "body": "InstCombine doesn't fold this, IPSCCP does "}, {"author": "nikic", "body": "I expect this is because we got through ValueLattice comparison, which does not have access to the denormal mode: https://github.com/llvm/llvm-project/blob/9501af5f92bb31fa9527d12a4b17b88d9fd651c4/llvm/lib/Analysis/ValueLattice.cpp#L28-L29\r\n\r\nReally, the constant folding implementation should be defaulting to the conservatively correct behavior if the denormal mode is unknown."}]}, "verified": true} +{"bug_id": "128838", "issue_url": "https://github.com/llvm/llvm-project/issues/128838", "bug_type": "crash", "base_commit": "9c65e6ac115a7d8566c874537791125c3ace7c1a", "knowledge_cutoff": "2025-02-26T07:25:33Z", "lit_test_dir": ["llvm/test/Transforms/LoopVectorize"], "hints": {"fix_commit": "62994c3291239f3d11f958d002319b2bd6eddbc9", "components": ["LoopVectorize"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [[7691, 7701]], "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": [[2180, 2186], [2189, 2206], [2210, 2219]], "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": [[189, 196]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": ["LoopVectorizationPlanner::executePlan"], "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": ["VPlanTransforms::handleUncountableEarlyExit", "VPlanTransforms::materializeLiveInBroadcasts"]}}, "patch": "commit 62994c3291239f3d11f958d002319b2bd6eddbc9\nAuthor: Florian Hahn \nDate: Wed Mar 12 22:03:18 2025 +0000\n\n [VPlan] Also introduce explicit broadcasts for values from entry VPBB.\n \n Update and generalize materializeBroadcasts to also introduce explicit\n broadcasts for VPValues defined in the Plans Entry block.\n \n This fixes a crash when trying to insert the broadcasts generated by\n VPTransformState::get after the generating instruction, which isn't\n possible after invoke instructions.\n \n Fixes https://github.com/llvm/llvm-project/issues/128838.\n\ndiff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\nindex bab2c6efd403..02bacde3f60a 100644\n--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n@@ -7691,11 +7691,11 @@ DenseMap LoopVectorizationPlanner::executePlan(\n ((VectorizingEpilogue && ExpandedSCEVs) ||\n (!VectorizingEpilogue && !ExpandedSCEVs)) &&\n \"expanded SCEVs to reuse can only be used during epilogue vectorization\");\n- VPlanTransforms::materializeLiveInBroadcasts(BestVPlan);\n // TODO: Move to VPlan transform stage once the transition to the VPlan-based\n // cost model is complete for better cost estimates.\n VPlanTransforms::runPass(VPlanTransforms::unrollByUF, BestVPlan, BestUF,\n OrigLoop->getHeader()->getContext());\n+ VPlanTransforms::materializeBroadcasts(BestVPlan);\n VPlanTransforms::optimizeForVFAndUF(BestVPlan, BestVF, BestUF, PSE);\n VPlanTransforms::simplifyRecipes(BestVPlan, *Legal->getWidestInductionType());\n VPlanTransforms::removeDeadRecipes(BestVPlan);\ndiff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp\nindex ecf52673480e..f23795f87d46 100644\n--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp\n+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp\n@@ -2180,7 +2180,7 @@ void VPlanTransforms::handleUncountableEarlyExit(\n LatchExitingBranch->eraseFromParent();\n }\n \n-void VPlanTransforms::materializeLiveInBroadcasts(VPlan &Plan) {\n+void VPlanTransforms::materializeBroadcasts(VPlan &Plan) {\n if (Plan.hasScalarVFOnly())\n return;\n \n@@ -2189,18 +2189,25 @@ void VPlanTransforms::materializeLiveInBroadcasts(VPlan &Plan) {\n VPDT.recalculate(Plan);\n #endif\n \n+ SmallVector VPValues;\n+ append_range(VPValues, Plan.getLiveIns());\n+ for (VPRecipeBase &R : *Plan.getEntry())\n+ append_range(VPValues, R.definedValues());\n+\n auto *VectorPreheader = Plan.getVectorPreheader();\n- for (VPValue *LiveIn : Plan.getLiveIns()) {\n- if (all_of(LiveIn->users(),\n- [LiveIn](VPUser *U) { return U->usesScalars(LiveIn); }) ||\n- !LiveIn->getLiveInIRValue() ||\n- isa(LiveIn->getLiveInIRValue()))\n+ for (VPValue *VPV : VPValues) {\n+ if (all_of(VPV->users(),\n+ [VPV](VPUser *U) { return U->usesScalars(VPV); }) ||\n+ (VPV->isLiveIn() &&\n+ (!VPV->getLiveInIRValue() || isa(VPV->getLiveInIRValue()))))\n continue;\n \n // Add explicit broadcast at the insert point that dominates all users.\n VPBasicBlock *HoistBlock = VectorPreheader;\n VPBasicBlock::iterator HoistPoint = VectorPreheader->end();\n- for (VPUser *User : LiveIn->users()) {\n+ for (VPUser *User : VPV->users()) {\n+ if (User->usesScalars(VPV))\n+ continue;\n if (cast(User)->getParent() == VectorPreheader)\n HoistPoint = HoistBlock->begin();\n else\n@@ -2210,10 +2217,10 @@ void VPlanTransforms::materializeLiveInBroadcasts(VPlan &Plan) {\n }\n \n VPBuilder Builder(cast(HoistBlock), HoistPoint);\n- auto *Broadcast = Builder.createNaryOp(VPInstruction::Broadcast, {LiveIn});\n- LiveIn->replaceUsesWithIf(\n- Broadcast, [LiveIn, Broadcast](VPUser &U, unsigned Idx) {\n- return Broadcast != &U && !U.usesScalars(LiveIn);\n- });\n+ auto *Broadcast = Builder.createNaryOp(VPInstruction::Broadcast, {VPV});\n+ VPV->replaceUsesWithIf(Broadcast,\n+ [VPV, Broadcast](VPUser &U, unsigned Idx) {\n+ return Broadcast != &U && !U.usesScalars(VPV);\n+ });\n }\n }\ndiff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h\nindex 8a9a81e00fe2..2ec07eea1ecc 100644\n--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h\n+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h\n@@ -189,8 +189,8 @@ struct VPlanTransforms {\n optimizeInductionExitUsers(VPlan &Plan,\n DenseMap &EndValues);\n \n- /// Add explicit broadcasts for live-ins used as vectors.\n- static void materializeLiveInBroadcasts(VPlan &Plan);\n+ /// Add explicit broadcasts for live-ins and VPValues defined in \\p Plan's entry block if they are used as vectors.\n+ static void materializeBroadcasts(VPlan &Plan);\n };\n \n } // namespace llvm\n", "tests": [{"file": "llvm/test/Transforms/LoopVectorize/RISCV/illegal-type.ll", "commands": ["opt < %s -passes=loop-vectorize -mattr=+v -force-vector-width=4 -scalable-vectorization=on -S 2>&1"], "tests": [{"test_name": "uniform_store_i1", "test_body": "target triple = \"riscv64-linux-gnu\"\n\ndefine void @uniform_store_i1(ptr noalias %dst, ptr noalias %start, i64 %N) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %first.sroa = phi ptr [ %incdec.ptr, %for.body ], [ %start, %entry ]\n %iv = phi i64 [ %iv.next, %for.body ], [ 0, %entry ]\n %iv.next = add i64 %iv, 1\n %incdec.ptr = getelementptr inbounds i64, ptr %first.sroa, i64 1\n %cmp.not = icmp eq ptr %incdec.ptr, %start\n store i1 %cmp.not, ptr %dst, align 1\n %cmp = icmp ult i64 %iv, %N\n br i1 %cmp, label %for.body, label %end, !llvm.loop !0\n\nend: ; preds = %for.body\n ret void\n}\n\n!0 = distinct !{!0, !1}\n!1 = !{!\"llvm.loop.vectorize.scalable.enable\", i1 true}\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/X86/epilog-vectorization-inductions.ll", "commands": ["opt -passes=loop-vectorize -mcpu=znver2 -S %s"], "tests": [{"test_name": "test_induction_step_needs_expansion", "test_body": "target triple = \"x86_64-unknown-linux-gnu\"\n\ndefine void @test_induction_step_needs_expansion(ptr noalias %j, ptr %k, i64 %l, i16 %off) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %p.09 = phi i16 [ 0, %entry ], [ %add, %loop ]\n %add = sub i16 %p.09, %off\n %arrayidx3 = getelementptr inbounds i16, ptr %k, i64 %iv\n store i16 %add, ptr %arrayidx3, align 2\n %iv.next = add nuw nsw i64 %iv, 1\n %ec = icmp eq i64 %iv.next, %l\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/X86/induction-step.ll", "commands": ["opt -passes=loop-vectorize -force-vector-width=4 -S %s"], "tests": [{"test_name": "wide_add_induction_step_live_in", "test_body": "target triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i16 @wide_add_induction_step_live_in(ptr %dst, i64 %N, i16 %off) {\nentry:\n %o.1 = add i16 %off, 2\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.2 = phi i16 [ 0, %entry ], [ %add, %loop ]\n %add = add i16 %iv.2, %o.1\n %gep.dst = getelementptr inbounds i16, ptr %dst, i64 %iv\n store i16 %add, ptr %gep.dst, align 2\n %iv.next = add nuw nsw i64 %iv, 1\n %ec = icmp eq i64 %iv.next, %N\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i16 %add\n}\n"}, {"test_name": "wide_sub_induction_step_live_in", "test_body": "target triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i16 @wide_sub_induction_step_live_in(ptr %dst, i64 %N, i16 %off) {\nentry:\n %o.1 = add i16 %off, 2\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.2 = phi i16 [ 0, %entry ], [ %sub, %loop ]\n %sub = sub i16 %iv.2, %o.1\n %gep.dst = getelementptr inbounds i16, ptr %dst, i64 %iv\n store i16 %sub, ptr %gep.dst, align 2\n %iv.next = add nuw nsw i64 %iv, 1\n %ec = icmp eq i64 %iv.next, %N\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i16 %sub\n}\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/expand-scev-after-invoke.ll", "commands": ["opt -p loop-vectorize -force-vector-width=4 -force-vector-interleave=2 -S %s"], "tests": [{"test_name": "", "test_body": "\ndeclare i32 @foo()\n\n; Test case for https://github.com/llvm/llvm-project/issues/128838. Make sure\n; we do not crash when expanding %step.\ndefine void @test(ptr %dst) personality ptr null {\n;\nentry:\n %step = invoke i32 @foo()\n to label %loop unwind label %lpad\n\nloop:\n %iv.1 = phi i64 [ 0, %entry ], [ %add, %loop ]\n %iv.2 = phi i32 [ 0, %entry ], [ %iv.2.next, %loop ]\n %add = add i64 %iv.1, 1\n %gep = getelementptr inbounds i32, ptr %dst, i64 %iv.1\n store i32 %iv.2, ptr %gep, align 8\n %iv.2.next = add i32 %iv.2, %step\n %ec = icmp ult i64 %iv.1, 161\n br i1 %ec, label %loop, label %exit\n\nexit:\n ret void\n\nlpad:\n %landingpad = landingpad { ptr, i32 }\n cleanup\n ret void\n}"}]}, {"file": "llvm/test/Transforms/LoopVectorize/float-induction.ll", "commands": ["opt < %s -passes=loop-vectorize,dce,instcombine -force-vector-interleave=1 -force-vector-width=4 -S", "opt < %s -passes=loop-vectorize,dce,instcombine -force-vector-interleave=2 -force-vector-width=4 -S", "opt < %s -passes=loop-vectorize,dce,instcombine -force-vector-interleave=2 -force-vector-width=1 -S", "opt < %s -passes=loop-vectorize,dce,simplifycfg,instcombine,simplifycfg -force-vector-interleave=1 -force-vector-width=2 -simplifycfg-require-and-preserve-domtree=1 -keep-loops=false -S"], "tests": [{"test_name": "fp_iv_loop1_fast_FMF", "test_body": "@fp_inc = external global float, align 4\n\ndefine void @fp_iv_loop1_fast_FMF(float %init, ptr noalias captures(none) %A, i32 %N) {\nentry:\n %cmp4 = icmp sgt i32 %N, 0\n br i1 %cmp4, label %for.body.lr.ph, label %for.end\n\nfor.body.lr.ph: ; preds = %entry\n %fpinc = load float, ptr @fp_inc, align 4\n br label %for.body\n\nfor.body: ; preds = %for.body, %for.body.lr.ph\n %indvars.iv = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next, %for.body ]\n %x.05 = phi float [ %init, %for.body.lr.ph ], [ %add, %for.body ]\n %arrayidx = getelementptr inbounds float, ptr %A, i64 %indvars.iv\n store float %x.05, ptr %arrayidx, align 4\n %add = fsub fast float %x.05, %fpinc\n %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1\n %lftr.wideiv = trunc i64 %indvars.iv.next to i32\n %exitcond = icmp eq i32 %lftr.wideiv, %N\n br i1 %exitcond, label %for.end.loopexit, label %for.body\n\nfor.end.loopexit: ; preds = %for.body\n br label %for.end\n\nfor.end: ; preds = %for.end.loopexit, %entry\n ret void\n}\n\n!llvm.module.flags = !{!0}\n\n!0 = !{i32 2, !\"Debug Info Version\", i32 3}\n"}, {"test_name": "fp_iv_loop3", "test_body": "@fp_inc = external global float, align 4\n\ndefine void @fp_iv_loop3(float %init, ptr noalias captures(none) %A, ptr noalias captures(none) %B, ptr noalias captures(none) %C, i32 %N) {\nentry:\n %cmp9 = icmp sgt i32 %N, 0\n br i1 %cmp9, label %for.body.lr.ph, label %for.end\n\nfor.body.lr.ph: ; preds = %entry\n %0 = load float, ptr @fp_inc, align 4\n br label %for.body\n\nfor.body: ; preds = %for.body, %for.body.lr.ph\n %indvars.iv = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next, %for.body ]\n %y.012 = phi float [ 0x3FB99999A0000000, %for.body.lr.ph ], [ %conv1, %for.body ]\n %x.011 = phi float [ %init, %for.body.lr.ph ], [ %add, %for.body ]\n %arrayidx = getelementptr inbounds float, ptr %A, i64 %indvars.iv\n store float %x.011, ptr %arrayidx, align 4\n %add = fadd fast float %x.011, %0\n %conv1 = fadd fast float %y.012, -5.000000e-01\n %add2 = fadd fast float %conv1, %add\n %arrayidx4 = getelementptr inbounds float, ptr %B, i64 %indvars.iv\n store float %add2, ptr %arrayidx4, align 4\n %arrayidx6 = getelementptr inbounds float, ptr %C, i64 %indvars.iv\n store float %conv1, ptr %arrayidx6, align 4\n %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1\n %lftr.wideiv = trunc i64 %indvars.iv.next to i32\n %exitcond = icmp eq i32 %lftr.wideiv, %N\n br i1 %exitcond, label %for.end.loopexit, label %for.body\n\nfor.end.loopexit: ; preds = %for.body\n br label %for.end\n\nfor.end: ; preds = %for.end.loopexit, %entry\n ret void\n}\n\n!llvm.module.flags = !{!0}\n\n!0 = !{i32 2, !\"Debug Info Version\", i32 3}\n"}, {"test_name": "fp_iv_loop1_reassoc_FMF", "test_body": "@fp_inc = external global float, align 4\n\ndefine void @fp_iv_loop1_reassoc_FMF(float %init, ptr noalias captures(none) %A, i32 %N) {\nentry:\n %cmp4 = icmp sgt i32 %N, 0\n br i1 %cmp4, label %for.body.lr.ph, label %for.end\n\nfor.body.lr.ph: ; preds = %entry\n %fpinc = load float, ptr @fp_inc, align 4\n br label %for.body\n\nfor.body: ; preds = %for.body, %for.body.lr.ph\n %indvars.iv = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next, %for.body ]\n %x.05 = phi float [ %init, %for.body.lr.ph ], [ %add, %for.body ]\n %arrayidx = getelementptr inbounds float, ptr %A, i64 %indvars.iv\n store float %x.05, ptr %arrayidx, align 4\n %add = fsub reassoc float %x.05, %fpinc\n %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1\n %lftr.wideiv = trunc i64 %indvars.iv.next to i32\n %exitcond = icmp eq i32 %lftr.wideiv, %N\n br i1 %exitcond, label %for.end.loopexit, label %for.body\n\nfor.end.loopexit: ; preds = %for.body\n br label %for.end\n\nfor.end: ; preds = %for.end.loopexit, %entry\n ret void\n}\n\n!llvm.module.flags = !{!0}\n\n!0 = !{i32 2, !\"Debug Info Version\", i32 3}\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/induction-step.ll", "commands": ["opt < %s -passes=loop-vectorize -force-vector-interleave=1 -force-vector-width=8 -S"], "tests": [{"test_name": "wide_add_induction_step_live_in", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine void @wide_add_induction_step_live_in(ptr %dst, i64 %N, i16 %off) {\nentry:\n %o.1 = add i16 %off, 2\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.2 = phi i16 [ 0, %entry ], [ %add, %loop ]\n %add = add i16 %iv.2, %o.1\n %gep.dst = getelementptr inbounds i16, ptr %dst, i64 %iv\n store i16 %add, ptr %gep.dst, align 2\n %iv.next = add nuw nsw i64 %iv, 1\n %ec = icmp eq i64 %iv.next, %N\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n"}]}, {"file": "llvm/test/Transforms/LoopVectorize/induction.ll", "commands": ["opt < %s -passes=loop-vectorize -force-vector-interleave=1 -force-vector-width=2 -force-widen-divrem-via-safe-divisor=0 -S", "opt < %s -passes=loop-vectorize,instcombine -force-vector-interleave=1 -force-vector-width=2 -force-widen-divrem-via-safe-divisor=0 -S", "opt < %s -passes=loop-vectorize,instcombine -force-vector-interleave=2 -force-vector-width=2 -force-widen-divrem-via-safe-divisor=0 -S", "opt < %s -passes=loop-vectorize -force-vector-interleave=2 -force-vector-width=2 -force-widen-divrem-via-safe-divisor=0 -S", "opt < %s -passes=loop-vectorize,instcombine -force-vector-interleave=2 -force-vector-width=4 -force-widen-divrem-via-safe-divisor=0 -enable-interleaved-mem-accesses -S"], "tests": [{"test_name": "test_optimized_cast_induction_feeding_first_order_recurrence", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @test_optimized_cast_induction_feeding_first_order_recurrence(i64 %n, i32 %step, ptr %ptr) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %for = phi i32 [ 0, %entry ], [ %iv.2.conv, %loop ]\n %iv.1 = phi i64 [ 0, %entry ], [ %iv.1.next, %loop ]\n %iv.2 = phi i32 [ 0, %entry ], [ %iv.2.next, %loop ]\n %iv.2.ext = shl i32 %iv.2, 24\n %iv.2.conv = ashr exact i32 %iv.2.ext, 24\n %gep = getelementptr inbounds i32, ptr %ptr, i64 %iv.1\n store i32 %for, ptr %gep, align 4\n %iv.2.next = add nsw i32 %iv.2.conv, %step\n %iv.1.next = add nuw nsw i64 %iv.1, 1\n %exitcond = icmp eq i64 %iv.1.next, %n\n br i1 %exitcond, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n"}]}], "issue": {"title": "Assertion `!NodePtr->isKnownSentinel()' failed.", "body": "To reproduce run opt with the test below, -passes=loop-vectorize\n```\n; ModuleID = './reduced.ll'\nsource_filename = \"./reduced.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-ni:1-p2:32:8:8:32-ni:2\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine void @wombat() gc \"statepoint-example\" personality ptr null {\nbb:\n %invoke = invoke i32 null(ptr addrspace(1) null, i32 0, i32 0, i32 0)\n to label %bb1 unwind label %bb5\n\nbb1: ; preds = %bb1, %bb\n %phi = phi i64 [ %add, %bb1 ], [ 0, %bb ]\n %phi2 = phi i32 [ %add3, %bb1 ], [ 0, %bb ]\n %add = add i64 %phi, 1\n %sitofp = sitofp i32 %phi2 to double\n store double %sitofp, ptr addrspace(1) null, align 8\n %add3 = add i32 %phi2, %invoke\n %icmp = icmp ult i64 %phi, 161\n br i1 %icmp, label %bb1, label %bb4\n\nbb4: ; preds = %bb1\n ret void\n\nbb5: ; preds = %bb\n %landingpad = landingpad { ptr, i32 }\n cleanup\n ret void\n}\n```\nReproducer: https://godbolt.org/z/3do96adnn\n\nStack dump:\n```\nopt: /root/llvm-project/llvm/include/llvm/ADT/ilist_iterator.h:322: llvm::ilist_iterator_w_bits::reference llvm::ilist_iterator_w_bits::operator*() const [with OptionsT = llvm::ilist_detail::node_options; bool IsReverse = false; bool IsConst = false; llvm::ilist_iterator_w_bits::reference = llvm::Instruction&]: Assertion `!NodePtr->isKnownSentinel()' 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=loop-vectorize \n1.\tRunning pass \"function(loop-vectorize)\" on module \"\"\n2.\tRunning pass \"loop-vectorize\" on function \"wombat\"\n #0 0x0000000005452b98 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5452b98)\n #1 0x0000000005450554 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x00007b16e6242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x00007b16e62969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x00007b16e6242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x00007b16e62287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x00007b16e622871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #7 0x00007b16e6239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #8 0x00000000044f6c23 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44f6c23)\n #9 0x000000000450ebb3 llvm::VPTransformState::get(llvm::VPValue*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x450ebb3)\n#10 0x0000000004543138 llvm::VPInstruction::generate(llvm::VPTransformState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4543138)\n#11 0x0000000004544ba4 llvm::VPInstruction::execute(llvm::VPTransformState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4544ba4)\n#12 0x00000000044f82e7 llvm::VPBasicBlock::executeRecipes(llvm::VPTransformState*, llvm::BasicBlock*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44f82e7)\n#13 0x00000000045038f9 llvm::VPIRBasicBlock::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x45038f9)\n#14 0x0000000004510249 llvm::VPlan::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4510249)\n#15 0x00000000043cccce llvm::LoopVectorizationPlanner::executePlan(llvm::ElementCount, unsigned int, llvm::VPlan&, llvm::InnerLoopVectorizer&, llvm::DominatorTree*, bool, llvm::DenseMap, llvm::detail::DenseMapPair> const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43cccce)\n#16 0x00000000043e15d8 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43e15d8)\n#17 0x00000000043e2f49 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43e2f49)\n#18 0x00000000043e35c3 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43e35c3)\n#19 0x000000000318aaae llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x318aaae)\n#20 0x000000000524cd90 llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x524cd90)\n#21 0x0000000000e6f54e llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe6f54e)\n#22 0x000000000524b6ab llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x524b6ab)\n#23 0x0000000000e6e83e llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe6e83e)\n#24 0x000000000524b0b0 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x524b0b0)\n#25 0x0000000000935a3a llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::ArrayRef>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x935a3a)\n#26 0x00000000009290ac optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9290ac)\n#27 0x00007b16e6229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#28 0x00007b16e6229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#29 0x0000000000920985 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x920985)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```", "author": "TatyanaDoubts", "labels": ["vectorizers", "crash-on-valid"], "comments": [{"author": "fhahn", "body": "looking "}]}, "verified": true} {"bug_id": "95016", "issue_url": "https://github.com/llvm/llvm-project/issues/95016", "bug_type": "crash", "base_commit": "1846523bb77275de954ac573110171bd39bfa930", "knowledge_cutoff": "2024-06-10T18:08:58Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "380beaec8633bad0148aec02f03a85d9a59b2a2d", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[835, 845]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["getSameOpcode"]}}, "patch": "commit 380beaec8633bad0148aec02f03a85d9a59b2a2d\nAuthor: Gabriel Baraldi \nDate: Tue Jul 2 09:15:51 2024 -0300\n\n Fix potential crash in SLPVectorizer caused by missing check (#95937)\n \n I'm not super familiar with this code, but it seems that we were just\n missing a check.\n \n The original code that triggered this did not have uselistorders but\n llvm-reduce created them and it reproduces the same issue in a way more\n compact way.\n \n Fixes https://github.com/llvm/llvm-project/issues/95016\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex c4876bb92a1c..868e9e2687f5 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -835,11 +835,11 @@ static InstructionsState getSameOpcode(ArrayRef VL,\n auto *CallBase = cast(IBase);\n if (Call->getCalledFunction() != CallBase->getCalledFunction())\n return InstructionsState(VL[BaseIndex], nullptr, nullptr);\n- if (Call->hasOperandBundles() &&\n+ if (Call->hasOperandBundles() && (!CallBase->hasOperandBundles() ||\n !std::equal(Call->op_begin() + Call->getBundleOperandsStartIndex(),\n Call->op_begin() + Call->getBundleOperandsEndIndex(),\n CallBase->op_begin() +\n- CallBase->getBundleOperandsStartIndex()))\n+ CallBase->getBundleOperandsStartIndex())))\n return InstructionsState(VL[BaseIndex], nullptr, nullptr);\n Intrinsic::ID ID = getVectorIntrinsicIDForCall(Call, &TLI);\n if (ID != BaseID)\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/AArch64/uselistorder.ll", "commands": ["opt < %s -passes=slp-vectorizer -S -pass-remarks-missed=slp-vectorizer 2>&1"], "tests": [{"test_name": "", "test_body": "\ntarget datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-unknown-linux-gnu\"\n\n; This test has UB but the crash in #95016 only happens with it\ndefine void @uselistorder_test() {\n;\n %max1 = call double @llvm.maximum.f64(double 0.000000e+00, double 0.000000e+00) [ \"a_list\"(ptr null) ]\n %add1 = fadd double %max1, 0.000000e+00\n %mul1 = fmul double 0.000000e+00, %add1\n %mul2 = fmul double %mul1, 0.000000e+00\n %sel1 = select i1 false, double 0.000000e+00, double %mul2\n %max2 = call double @llvm.maximum.f64(double 0.000000e+00, double 0.000000e+00)\n %add2 = fadd double %max2, 0.000000e+00\n %mul3 = fmul double 0.000000e+00, %add2\n %mul4 = fmul double %mul3, 0.000000e+00\n %sel2 = select i1 false, double 0.000000e+00, double %mul4\n %mul5 = fmul double %sel2, 0.000000e+00\n %add3 = fadd double 0.000000e+00, %mul5\n %gep1 = getelementptr { double, [1 x [2 x double]] }, ptr null, i64 0, i32 1\n store double %add3, ptr %gep1, align 8\n %mul6 = fmul double %sel1, 0.000000e+00\n %add4 = fadd double %mul6, 0.000000e+00\n store double %add4, ptr null, align 8\n ret void\n}\n\ndeclare double @llvm.maximum.f64(double, double) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }"}]}], "issue": {"title": "SLPVectorizer (hasOperandBundles() && \"Don't call otherwise!\") assertion trigger with verified module", "body": "SLPVectorize asserts while optimizing the following module\r\n```llvm-ir\r\ntarget datalayout = \"e-m:o-i64:64-i128:128-n32:64-S128-ni:10:11:12:13\"\r\ntarget triple = \"arm64-apple-darwin23.5.0\"\r\n\r\ndefine swiftcc void @julia_multiparameter_a_res_17823() {\r\ntop:\r\n %0 = call double @llvm.maximum.f64(double 0.000000e+00, double 0.000000e+00) [ \"jl_roots\"(ptr null) ]\r\n %1 = fadd double %0, 0.000000e+00\r\n %2 = fmul double 0.000000e+00, %1\r\n %3 = fmul double %2, 0.000000e+00\r\n %4 = select i1 false, double 0.000000e+00, double %3\r\n %5 = call double @llvm.maximum.f64(double 0.000000e+00, double 0.000000e+00)\r\n %6 = fadd double %5, 0.000000e+00\r\n %7 = fmul double 0.000000e+00, %6\r\n %8 = fmul double %7, 0.000000e+00\r\n %9 = select i1 false, double 0.000000e+00, double %8\r\n %10 = fmul double %9, 0.000000e+00\r\n %11 = fadd double 0.000000e+00, %10\r\n %12 = getelementptr { double, [1 x [2 x double]] }, ptr null, i64 0, i32 1\r\n store double %11, ptr %12, align 8\r\n %13 = fmul double %4, 0.000000e+00\r\n %14 = fadd double %13, 0.000000e+00\r\n store double %14, ptr null, align 8\r\n ret void\r\n}\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare double @llvm.maximum.f64(double, double) #0\r\n\r\n; uselistorder directives\r\nuselistorder ptr @llvm.maximum.f64, { 1, 0 }\r\n\r\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\n```\r\n\r\nThis also seems to trigger on godbolt on whatever version of trunk they have there\r\nhttps://godbolt.org/z/favErWG5K\r\n\r\n\r\nstacktrace:\r\n> #0 0x0000000004e258c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e258c8)\r\n #1 0x0000000004e2301c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007c7148042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007c71480969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007c7148042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007c71480287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00007c714802871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x00007c7148039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x0000000003ee5e8f (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3ee5e8f)\r\n #9 0x0000000003f5e546 getSameOpcode(llvm::ArrayRef, llvm::TargetLibraryInfo const&, unsigned int) (.constprop.1) SLPVectorizer.cpp:0:0\r\n#10 0x0000000003f67928 llvm::slpvectorizer::BoUpSLP::LookAheadHeuristics::getShallowScore(llvm::Value*, llvm::Value*, llvm::Instruction*, llvm::Instruction*, llvm::ArrayRef) const (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f67928)\r\n#11 0x0000000003f67de0 llvm::slpvectorizer::BoUpSLP::LookAheadHeuristics::getScoreAtLevelRec(llvm::Value*, llvm::Value*, llvm::Instruction*, llvm::Instruction*, int, llvm::ArrayRef) const (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f67de0)\r\n#12 0x0000000003f6aaf5 llvm::slpvectorizer::BoUpSLP::VLOperands::getBestOperand(unsigned int, int, int, llvm::ArrayRef, llvm::ArrayRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f6aaf5)\r\n#13 0x0000000003f6bfcb llvm::slpvectorizer::BoUpSLP::VLOperands::reorder() (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f6bfcb)\r\n#14 0x0000000003f6c4f6 llvm::slpvectorizer::BoUpSLP::reorderInputsAccordingToOpcode(llvm::ArrayRef, llvm::SmallVectorImpl&, llvm::SmallVectorImpl&, llvm::slpvectorizer::BoUpSLP const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f6c4f6)\r\n#15 0x0000000003f702f4 llvm::slpvectorizer::BoUpSLP::buildTree_rec(llvm::ArrayRef, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f702f4)\r\n#16 0x0000000003f70392 llvm::slpvectorizer::BoUpSLP::buildTree_rec(llvm::ArrayRef, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f70392)\r\n#17 0x0000000003f70362 llvm::slpvectorizer::BoUpSLP::buildTree_rec(llvm::ArrayRef, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f70362)\r\n#18 0x0000000003f7022b llvm::slpvectorizer::BoUpSLP::buildTree_rec(llvm::ArrayRef, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f7022b)\r\n#19 0x0000000003f70362 llvm::slpvectorizer::BoUpSLP::buildTree_rec(llvm::ArrayRef, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f70362)\r\n#20 0x0000000003f70362 llvm::slpvectorizer::BoUpSLP::buildTree_rec(llvm::ArrayRef, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f70362)\r\n#21 0x0000000003f6fe47 llvm::slpvectorizer::BoUpSLP::buildTree_rec(llvm::ArrayRef, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f6fe47)\r\n#22 0x0000000003f71b59 llvm::slpvectorizer::BoUpSLP::buildTree(llvm::ArrayRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f71b59)\r\n#23 0x0000000003f94622 llvm::SLPVectorizerPass::vectorizeStoreChain(llvm::ArrayRef, llvm::slpvectorizer::BoUpSLP&, unsigned int, unsigned int, unsigned int&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f94622)\r\n#24 0x0000000003f95fb0 llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet, llvm::DenseMapInfo, void>>&)::'lambda'(std::set, llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet, llvm::DenseMapInfo, void>>&)::StoreDistCompare, std::allocator>> const&)::operator()(std::set, llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet, llvm::DenseMapInfo, void>>&)::StoreDistCompare, std::allocator>> const&) const SLPVectorizer.cpp:0:0\r\n#25 0x0000000003f97e88 llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet, llvm::DenseMapInfo, void>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f97e88)\r\n#26 0x0000000003f985b3 llvm::SLPVectorizerPass::vectorizeStoreChains(llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f985b3)\r\n#27 0x0000000003f9970f 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#28 0x0000000003f9a163 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f9a163)\r\n#29 0x0000000002e1013e llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2e1013e)\r\n#30 0x0000000004c2e64c llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4c2e64c)\r\n#31 0x0000000000db3bce llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xdb3bce)\r\n#32 0x0000000004c2cf8e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4c2cf8e)\r\n#33 0x0000000000db563e llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xdb563e)\r\n#34 0x0000000004c2ae9c llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4c2ae9c)\r\n#35 0x00000000008d7b32 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::ArrayRef>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d7b32)\r\n#36 0x00000000008cacdc optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8cacdc)\r\n#37 0x00007c7148029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#38 0x00007c7148029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#39 0x00000000008c212e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8c212e)", "author": "gbaraldi", "labels": ["llvm:SLPVectorizer", "crash"], "comments": []}, "verified": true} {"bug_id": "113794", "issue_url": "https://github.com/llvm/llvm-project/issues/113794", "bug_type": "crash", "base_commit": "21895a84cf466f0a0632cfca0175f7e617a6dd5a", "knowledge_cutoff": "2024-10-27T05:55:32Z", "lit_test_dir": ["llvm/test/Transforms/LoopVectorize"], "hints": {"fix_commit": "17bad1a9da228ade0c0b9b020ee99769b188d9b3", "components": ["LoopVectorize"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [[6389, 6397]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": ["LoopVectorizationCostModel::getInstructionCost", "LoopVectorizationCostModel::shouldConsiderInvariant"]}}, "patch": "commit 17bad1a9da228ade0c0b9b020ee99769b188d9b3\nAuthor: Florian Hahn \nDate: Fri Nov 1 20:51:25 2024 +0000\n\n [LV] Bail out on header phis in shouldConsiderInvariant.\n \n This fixes an infinite recursion in rare cases.\n \n Fixes https://github.com/llvm/llvm-project/issues/113794.\n\ndiff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\nindex 659b4c30a58a..1c64bd2982d7 100644\n--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n@@ -6389,9 +6389,11 @@ bool LoopVectorizationCostModel::shouldConsiderInvariant(Value *Op) {\n return false;\n // Consider Op invariant, if it or its operands aren't predicated\n // instruction in the loop. In that case, it is not trivially hoistable.\n- return !isa(Op) || !TheLoop->contains(cast(Op)) ||\n- (!isPredicatedInst(cast(Op)) &&\n- all_of(cast(Op)->operands(),\n+ auto *OpI = dyn_cast(Op);\n+ return !OpI || !TheLoop->contains(OpI) ||\n+ (!isPredicatedInst(OpI) &&\n+ (!isa(OpI) || OpI->getParent() != TheLoop->getHeader()) &&\n+ all_of(OpI->operands(),\n [this](Value *Op) { return shouldConsiderInvariant(Op); }));\n }\n \n", "tests": [{"file": "llvm/test/Transforms/LoopVectorize/phi-cost.ll", "commands": ["opt < %s -passes='function(loop-vectorize,instcombine)' -force-vector-width=2 -force-vector-interleave=1 -debug-only=loop-vectorize -disable-output -print-after=instcombine 2>&1"], "tests": [{"test_name": "red_phi_0", "test_body": "target datalayout = \"e-m:e-i64:64-i128:128-n32:64-S128\"\n\ndefine i32 @red_phi_0(i32 %start, ptr %src) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %red = phi i32 [ %start, %entry ], [ %red.next, %loop ]\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %red.next = add i32 0, %red\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 100\n br i1 %exitcond.not, label %exit, label %loop\n\nexit: ; preds = %loop\n %res = phi i32 [ %red.next, %loop ]\n ret i32 %res\n}\n"}, {"test_name": "phi_three_incoming_values", "test_body": "target datalayout = \"e-m:e-i64:64-i128:128-n32:64-S128\"\n\ndefine void @phi_three_incoming_values(ptr noalias %a, ptr noalias %b, i64 %n) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %if.end, %entry\n %i = phi i64 [ %i.next, %if.end ], [ 0, %entry ]\n %tmp0 = getelementptr inbounds i32, ptr %a, i64 %i\n %tmp1 = load i32, ptr %tmp0, align 4\n %tmp2 = getelementptr inbounds i32, ptr %b, i64 %i\n %tmp3 = load i32, ptr %tmp2, align 4\n %tmp4 = icmp sgt i32 %tmp1, %tmp3\n br i1 %tmp4, label %if.then, label %if.end\n\nif.then: ; preds = %for.body\n %tmp5 = icmp sgt i32 %tmp1, 19\n br i1 %tmp5, label %if.end, label %if.else\n\nif.else: ; preds = %if.then\n %tmp6 = icmp slt i32 %tmp3, 4\n %tmp7 = select i1 %tmp6, i32 4, i32 5\n br label %if.end\n\nif.end: ; preds = %if.else, %if.then, %for.body\n %tmp8 = phi i32 [ 9, %for.body ], [ 3, %if.then ], [ %tmp7, %if.else ]\n store i32 %tmp8, ptr %tmp0, align 4\n %i.next = add i64 %i, 1\n %cond = icmp eq i64 %i, %n\n br i1 %cond, label %for.end, label %for.body\n\nfor.end: ; preds = %if.end\n ret void\n}\n"}, {"test_name": "phi_two_incoming_values", "test_body": "target datalayout = \"e-m:e-i64:64-i128:128-n32:64-S128\"\n\ndefine void @phi_two_incoming_values(ptr noalias %a, ptr noalias %b, i64 %n) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %if.end, %entry\n %i = phi i64 [ %i.next, %if.end ], [ 0, %entry ]\n %tmp0 = getelementptr inbounds i32, ptr %a, i64 %i\n %tmp1 = load i32, ptr %tmp0, align 4\n %tmp2 = getelementptr inbounds i32, ptr %b, i64 %i\n %tmp3 = icmp sgt i32 %tmp1, 0\n br i1 %tmp3, label %if.then, label %if.end\n\nif.then: ; preds = %for.body\n %tmp4 = add i32 %tmp1, 1\n br label %if.end\n\nif.end: ; preds = %if.then, %for.body\n %tmp5 = phi i32 [ %tmp1, %for.body ], [ %tmp4, %if.then ]\n store i32 %tmp5, ptr %tmp2, align 4\n %i.next = add i64 %i, 1\n %cond = icmp eq i64 %i, %n\n br i1 %cond, label %for.end, label %for.body\n\nfor.end: ; preds = %if.end\n ret void\n}\n"}]}], "issue": {"title": "[clang] Segmentation fault in loop vectorization cost model during optimization pass", "body": "When I compiled this code with -O2 flag, it crashed:\r\n\r\n```c\r\n#include \r\n#define UNDEFINED(x) ((x), 0)\r\nlong b;\r\nstatic int64_t j = 1;\r\nstatic int64_t *k = &j;\r\nstatic int64_t **l = &k;\r\nint64_t m;\r\nstatic uint64_t n;\r\nint16_t ***o;\r\nstatic int64_t ***p = &l;\r\nuint64_t **q;\r\n\r\nuint16_t\r\nsafe_mod_func_uint16_t_u_u(uint16_t ui1, uint16_t ui2)\r\n{\r\n return \r\n#ifndef UNSAFE\r\n (ui2 == 0) ? \r\n (UNDEFINED(ui1)) : \r\n#endif\r\n (ui1 % ui2);\r\n}\r\n\r\nint64_t\r\nsafe_mod_func_int64_t_s_s(int64_t si1, int64_t si2)\r\n{\r\n return \r\n#ifndef UNSAFE\r\n ((si2 == 0) || ((si1 == INT64_MIN) && (si2 == (-1)))) ? \r\n (UNDEFINED(si1)) : \r\n#endif\r\n (si1 % si2);\r\n}\r\n\r\nint a(int, int, int, int, int) {}\r\nlong c(int d, int *e) {\r\n switch (d) {\r\n case 9:\r\n return b;\r\n case 8:\r\n return *e;\r\n }\r\n}\r\nlong f(int g, long, int h) {\r\n long i = c(g, &h);\r\n return i;\r\n}\r\nint32_t r() { int32_t *s[] = {&k, &m}; }\r\nint32_t t(int32_t *aa) {\r\n uint64_t ab = 2599693332;\r\n uint8_t ac = 142;\r\n for (; n <= 4; n++)\r\n *aa = (safe_mod_func_uint16_t_u_u(\r\n safe_mod_func_int64_t_s_s(a(0, 0, 0, 0, **l + 20) + **l, **q),\r\n ***o |= f(**l, 0, ***p)),\r\n **l + ac + ab - -1695273821 + *aa);\r\n}\r\n```\r\n\r\nThe crash is: clang: error: unable to execute command: Segmentation fault (core dumped)\r\nclang: error: clang frontend command failed due to signal (use -v to see invocation)\r\nCompiler returned: 254\r\n\r\nDetails can be found here: https://godbolt.org/z/3h9j7W6dG", "author": "cardigan1008", "labels": ["regression", "vectorizers", "crash"], "comments": [{"author": "shafik", "body": "This looks like a clang trunk regression: https://godbolt.org/z/MoKeds3ev"}]}, "verified": true} {"bug_id": "106667", "issue_url": "https://github.com/llvm/llvm-project/issues/106667", "bug_type": "crash", "base_commit": "5500e21942f7047344b6fee62d3e08c0ba2f9182", "knowledge_cutoff": "2024-08-30T05:59:16Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "a4aa6bc8fc2130761b8db5db4748059127662785", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[2864, 2869], [6964, 6969], [7095, 7149], [9362, 9383], [12521, 12530], [12532, 12640]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["BoUpSLP::buildTree_rec", "BoUpSLP::getOperandEntry", "BoUpSLP::vectorizeOperand"]}}, "patch": "commit a4aa6bc8fc2130761b8db5db4748059127662785\nAuthor: Alexey Bataev \nDate: Fri Aug 30 10:17:31 2024 -0700\n\n [SLP]Fix PR106667: carefully look for operand nodes.\n \n If the operand node has the same scalars as one of the vectorized nodes,\n the compiler could miss this and incorrectly request minbitwidth data\n for the wrong node. It may lead to a compiler crash, because the\n vectorized node might have different minbw result.\n \n Fixes https://github.com/llvm/llvm-project/issues/106667\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex 4c0a1c4c094b..e9785ef9ded2 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -2864,6 +2864,12 @@ private:\n /// avoid issues with def-use order.\n Value *vectorizeTree(TreeEntry *E, bool PostponedPHIs);\n \n+ TreeEntry *getMatchedVectorizedOperand(const TreeEntry *E, unsigned NodeIdx);\n+ const TreeEntry *getMatchedVectorizedOperand(const TreeEntry *E,\n+ unsigned NodeIdx) const {\n+ return const_cast(this)->getMatchedVectorizedOperand(E, NodeIdx);\n+ }\n+\n /// Vectorize a single entry in the tree, the \\p Idx-th operand of the entry\n /// \\p E.\n /// \\param PostponedPHIs true, if need to postpone emission of phi nodes to\n@@ -6964,6 +6970,55 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth,\n }\n }\n \n+ // Check if this is a duplicate of another entry.\n+ if (TreeEntry *E = getTreeEntry(S.OpValue)) {\n+ LLVM_DEBUG(dbgs() << \"SLP: \\tChecking bundle: \" << *S.OpValue << \".\\n\");\n+ if (!E->isSame(VL)) {\n+ auto It = MultiNodeScalars.find(S.OpValue);\n+ if (It != MultiNodeScalars.end()) {\n+ auto *TEIt = find_if(It->getSecond(),\n+ [&](TreeEntry *ME) { return ME->isSame(VL); });\n+ if (TEIt != It->getSecond().end())\n+ E = *TEIt;\n+ else\n+ E = nullptr;\n+ } else {\n+ E = nullptr;\n+ }\n+ }\n+ if (!E) {\n+ if (!doesNotNeedToBeScheduled(S.OpValue)) {\n+ LLVM_DEBUG(dbgs() << \"SLP: Gathering due to partial overlap.\\n\");\n+ if (TryToFindDuplicates(S))\n+ newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx,\n+ ReuseShuffleIndices);\n+ return;\n+ }\n+ SmallPtrSet Nodes;\n+ Nodes.insert(getTreeEntry(S.OpValue));\n+ for (const TreeEntry *E : MultiNodeScalars.lookup(S.OpValue))\n+ Nodes.insert(E);\n+ SmallPtrSet Values(VL.begin(), VL.end());\n+ if (any_of(Nodes, [&](const TreeEntry *E) {\n+ return all_of(E->Scalars,\n+ [&](Value *V) { return Values.contains(V); });\n+ })) {\n+ LLVM_DEBUG(dbgs() << \"SLP: Gathering due to full overlap.\\n\");\n+ if (TryToFindDuplicates(S))\n+ newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx,\n+ ReuseShuffleIndices);\n+ return;\n+ }\n+ } else {\n+ // Record the reuse of the tree node. FIXME, currently this is only used\n+ // to properly draw the graph rather than for the actual vectorization.\n+ E->UserTreeIndices.push_back(UserTreeIdx);\n+ LLVM_DEBUG(dbgs() << \"SLP: Perfect diamond merge at \" << *S.OpValue\n+ << \".\\n\");\n+ return;\n+ }\n+ }\n+\n // Gather if we hit the RecursionMaxDepth, unless this is a load (or z/sext of\n // a load), in which case peek through to include it in the tree, without\n // ballooning over-budget.\n@@ -7095,55 +7150,6 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth,\n // We now know that this is a vector of instructions of the same type from\n // the same block.\n \n- // Check if this is a duplicate of another entry.\n- if (TreeEntry *E = getTreeEntry(S.OpValue)) {\n- LLVM_DEBUG(dbgs() << \"SLP: \\tChecking bundle: \" << *S.OpValue << \".\\n\");\n- if (!E->isSame(VL)) {\n- auto It = MultiNodeScalars.find(S.OpValue);\n- if (It != MultiNodeScalars.end()) {\n- auto *TEIt = find_if(It->getSecond(),\n- [&](TreeEntry *ME) { return ME->isSame(VL); });\n- if (TEIt != It->getSecond().end())\n- E = *TEIt;\n- else\n- E = nullptr;\n- } else {\n- E = nullptr;\n- }\n- }\n- if (!E) {\n- if (!doesNotNeedToBeScheduled(S.OpValue)) {\n- LLVM_DEBUG(dbgs() << \"SLP: Gathering due to partial overlap.\\n\");\n- if (TryToFindDuplicates(S))\n- newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx,\n- ReuseShuffleIndices);\n- return;\n- }\n- SmallPtrSet Nodes;\n- Nodes.insert(getTreeEntry(S.OpValue));\n- for (const TreeEntry *E : MultiNodeScalars.lookup(S.OpValue))\n- Nodes.insert(E);\n- SmallPtrSet Values(VL.begin(), VL.end());\n- if (any_of(Nodes, [&](const TreeEntry *E) {\n- return all_of(E->Scalars,\n- [&](Value *V) { return Values.contains(V); });\n- })) {\n- LLVM_DEBUG(dbgs() << \"SLP: Gathering due to full overlap.\\n\");\n- if (TryToFindDuplicates(S))\n- newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx,\n- ReuseShuffleIndices);\n- return;\n- }\n- } else {\n- // Record the reuse of the tree node. FIXME, currently this is only used\n- // to properly draw the graph rather than for the actual vectorization.\n- E->UserTreeIndices.push_back(UserTreeIdx);\n- LLVM_DEBUG(dbgs() << \"SLP: Perfect diamond merge at \" << *S.OpValue\n- << \".\\n\");\n- return;\n- }\n- }\n-\n // Check that none of the instructions in the bundle are already in the tree.\n for (Value *V : VL) {\n if ((!IsScatterVectorizeUserTE && !isa(V)) ||\n@@ -9362,22 +9368,8 @@ public:\n \n const BoUpSLP::TreeEntry *BoUpSLP::getOperandEntry(const TreeEntry *E,\n unsigned Idx) const {\n- Value *Op = E->getOperand(Idx).front();\n- if (const TreeEntry *TE = getTreeEntry(Op)) {\n- if (find_if(TE->UserTreeIndices, [&](const EdgeInfo &EI) {\n- return EI.EdgeIdx == Idx && EI.UserTE == E;\n- }) != TE->UserTreeIndices.end())\n- return TE;\n- auto MIt = MultiNodeScalars.find(Op);\n- if (MIt != MultiNodeScalars.end()) {\n- for (const TreeEntry *TE : MIt->second) {\n- if (find_if(TE->UserTreeIndices, [&](const EdgeInfo &EI) {\n- return EI.EdgeIdx == Idx && EI.UserTE == E;\n- }) != TE->UserTreeIndices.end())\n- return TE;\n- }\n- }\n- }\n+ if (const TreeEntry *VE = getMatchedVectorizedOperand(E, Idx))\n+ return VE;\n const auto *It =\n find_if(VectorizableTree, [&](const std::unique_ptr &TE) {\n return TE->isGather() &&\n@@ -12521,10 +12513,9 @@ public:\n }\n };\n \n-Value *BoUpSLP::vectorizeOperand(TreeEntry *E, unsigned NodeIdx,\n- bool PostponedPHIs) {\n- ValueList &VL = E->getOperand(NodeIdx);\n- const unsigned VF = VL.size();\n+BoUpSLP::TreeEntry *BoUpSLP::getMatchedVectorizedOperand(const TreeEntry *E,\n+ unsigned NodeIdx) {\n+ ArrayRef VL = E->getOperand(NodeIdx);\n InstructionsState S = getSameOpcode(VL, *TLI);\n // Special processing for GEPs bundle, which may include non-gep values.\n if (!S.getOpcode() && VL.front()->getType()->isPointerTy()) {\n@@ -12532,109 +12523,113 @@ Value *BoUpSLP::vectorizeOperand(TreeEntry *E, unsigned NodeIdx,\n if (It != VL.end())\n S = getSameOpcode(*It, *TLI);\n }\n- if (S.getOpcode()) {\n- auto CheckSameVE = [&](const TreeEntry *VE) {\n- return VE->isSame(VL) &&\n- (any_of(VE->UserTreeIndices,\n- [E, NodeIdx](const EdgeInfo &EI) {\n- return EI.UserTE == E && EI.EdgeIdx == NodeIdx;\n- }) ||\n- any_of(VectorizableTree,\n- [E, NodeIdx, VE](const std::unique_ptr &TE) {\n- return TE->isOperandGatherNode({E, NodeIdx}) &&\n- VE->isSame(TE->Scalars);\n- }));\n+ if (!S.getOpcode())\n+ return nullptr;\n+ auto CheckSameVE = [&](const TreeEntry *VE) {\n+ return VE->isSame(VL) &&\n+ (any_of(VE->UserTreeIndices,\n+ [E, NodeIdx](const EdgeInfo &EI) {\n+ return EI.UserTE == E && EI.EdgeIdx == NodeIdx;\n+ }) ||\n+ any_of(VectorizableTree,\n+ [E, NodeIdx, VE](const std::unique_ptr &TE) {\n+ return TE->isOperandGatherNode(\n+ {const_cast(E), NodeIdx}) &&\n+ VE->isSame(TE->Scalars);\n+ }));\n+ };\n+ TreeEntry *VE = getTreeEntry(S.OpValue);\n+ if (VE && CheckSameVE(VE))\n+ return VE;\n+ auto It = MultiNodeScalars.find(S.OpValue);\n+ if (It != MultiNodeScalars.end()) {\n+ auto *I = find_if(It->getSecond(), [&](const TreeEntry *TE) {\n+ return TE != VE && CheckSameVE(TE);\n+ });\n+ if (I != It->getSecond().end())\n+ return *I;\n+ }\n+ return nullptr;\n+}\n+\n+Value *BoUpSLP::vectorizeOperand(TreeEntry *E, unsigned NodeIdx,\n+ bool PostponedPHIs) {\n+ ValueList &VL = E->getOperand(NodeIdx);\n+ const unsigned VF = VL.size();\n+ if (TreeEntry *VE = getMatchedVectorizedOperand(E, NodeIdx)) {\n+ auto FinalShuffle = [&](Value *V, ArrayRef Mask) {\n+ // V may be affected by MinBWs.\n+ // We want ShuffleInstructionBuilder to correctly support REVEC. The key\n+ // factor is the number of elements, not their type.\n+ Type *ScalarTy = cast(V->getType())->getElementType();\n+ unsigned NumElements = getNumElements(VL.front()->getType());\n+ ShuffleInstructionBuilder ShuffleBuilder(\n+ NumElements != 1 ? FixedVectorType::get(ScalarTy, NumElements)\n+ : ScalarTy,\n+ Builder, *this);\n+ ShuffleBuilder.add(V, Mask);\n+ SmallVector> SubVectors(\n+ E->CombinedEntriesWithIndices.size());\n+ transform(E->CombinedEntriesWithIndices, SubVectors.begin(),\n+ [&](const auto &P) {\n+ return std::make_pair(VectorizableTree[P.first].get(),\n+ P.second);\n+ });\n+ return ShuffleBuilder.finalize(std::nullopt, SubVectors);\n };\n- TreeEntry *VE = getTreeEntry(S.OpValue);\n- bool IsSameVE = VE && CheckSameVE(VE);\n- if (!IsSameVE) {\n- auto It = MultiNodeScalars.find(S.OpValue);\n- if (It != MultiNodeScalars.end()) {\n- auto *I = find_if(It->getSecond(), [&](const TreeEntry *TE) {\n- return TE != VE && CheckSameVE(TE);\n- });\n- if (I != It->getSecond().end()) {\n- VE = *I;\n- IsSameVE = true;\n- }\n- }\n- }\n- if (IsSameVE) {\n- auto FinalShuffle = [&](Value *V, ArrayRef Mask) {\n- // V may be affected by MinBWs.\n- // We want ShuffleInstructionBuilder to correctly support REVEC. The key\n- // factor is the number of elements, not their type.\n- Type *ScalarTy = cast(V->getType())->getElementType();\n- unsigned NumElements = getNumElements(VL.front()->getType());\n- ShuffleInstructionBuilder ShuffleBuilder(\n- NumElements != 1 ? FixedVectorType::get(ScalarTy, NumElements)\n- : ScalarTy,\n- Builder, *this);\n- ShuffleBuilder.add(V, Mask);\n- SmallVector> SubVectors(\n- E->CombinedEntriesWithIndices.size());\n- transform(E->CombinedEntriesWithIndices, SubVectors.begin(),\n- [&](const auto &P) {\n- return std::make_pair(VectorizableTree[P.first].get(),\n- P.second);\n- });\n- return ShuffleBuilder.finalize(std::nullopt, SubVectors);\n- };\n- Value *V = vectorizeTree(VE, PostponedPHIs);\n- if (VF * getNumElements(VL[0]->getType()) !=\n- cast(V->getType())->getNumElements()) {\n- if (!VE->ReuseShuffleIndices.empty()) {\n- // Reshuffle to get only unique values.\n- // If some of the scalars are duplicated in the vectorization\n- // tree entry, we do not vectorize them but instead generate a\n- // mask for the reuses. But if there are several users of the\n- // same entry, they may have different vectorization factors.\n- // This is especially important for PHI nodes. In this case, we\n- // need to adapt the resulting instruction for the user\n- // vectorization factor and have to reshuffle it again to take\n- // only unique elements of the vector. Without this code the\n- // function incorrectly returns reduced vector instruction with\n- // the same elements, not with the unique ones.\n-\n- // block:\n- // %phi = phi <2 x > { .., %entry} {%shuffle, %block}\n- // %2 = shuffle <2 x > %phi, poison, <4 x > <1, 1, 0, 0>\n- // ... (use %2)\n- // %shuffle = shuffle <2 x> %2, poison, <2 x> {2, 0}\n- // br %block\n- SmallVector Mask(VF, PoisonMaskElem);\n- for (auto [I, V] : enumerate(VL)) {\n- if (isa(V))\n- continue;\n- Mask[I] = VE->findLaneForValue(V);\n- }\n- V = FinalShuffle(V, Mask);\n- } else {\n- assert(VF < cast(V->getType())->getNumElements() &&\n- \"Expected vectorization factor less \"\n- \"than original vector size.\");\n- SmallVector UniformMask(VF, 0);\n- std::iota(UniformMask.begin(), UniformMask.end(), 0);\n- V = FinalShuffle(V, UniformMask);\n+ Value *V = vectorizeTree(VE, PostponedPHIs);\n+ if (VF * getNumElements(VL[0]->getType()) !=\n+ cast(V->getType())->getNumElements()) {\n+ if (!VE->ReuseShuffleIndices.empty()) {\n+ // Reshuffle to get only unique values.\n+ // If some of the scalars are duplicated in the vectorization\n+ // tree entry, we do not vectorize them but instead generate a\n+ // mask for the reuses. But if there are several users of the\n+ // same entry, they may have different vectorization factors.\n+ // This is especially important for PHI nodes. In this case, we\n+ // need to adapt the resulting instruction for the user\n+ // vectorization factor and have to reshuffle it again to take\n+ // only unique elements of the vector. Without this code the\n+ // function incorrectly returns reduced vector instruction with\n+ // the same elements, not with the unique ones.\n+\n+ // block:\n+ // %phi = phi <2 x > { .., %entry} {%shuffle, %block}\n+ // %2 = shuffle <2 x > %phi, poison, <4 x > <1, 1, 0, 0>\n+ // ... (use %2)\n+ // %shuffle = shuffle <2 x> %2, poison, <2 x> {2, 0}\n+ // br %block\n+ SmallVector Mask(VF, PoisonMaskElem);\n+ for (auto [I, V] : enumerate(VL)) {\n+ if (isa(V))\n+ continue;\n+ Mask[I] = VE->findLaneForValue(V);\n }\n- }\n- // Need to update the operand gather node, if actually the operand is not a\n- // vectorized node, but the buildvector/gather node, which matches one of\n- // the vectorized nodes.\n- if (find_if(VE->UserTreeIndices, [&](const EdgeInfo &EI) {\n- return EI.UserTE == E && EI.EdgeIdx == NodeIdx;\n- }) == VE->UserTreeIndices.end()) {\n- auto *It = find_if(\n- VectorizableTree, [&](const std::unique_ptr &TE) {\n- return TE->isGather() &&\n- TE->UserTreeIndices.front().UserTE == E &&\n- TE->UserTreeIndices.front().EdgeIdx == NodeIdx;\n- });\n- assert(It != VectorizableTree.end() && \"Expected gather node operand.\");\n- (*It)->VectorizedValue = V;\n- }\n- return V;\n+ V = FinalShuffle(V, Mask);\n+ } else {\n+ assert(VF < cast(V->getType())->getNumElements() &&\n+ \"Expected vectorization factor less \"\n+ \"than original vector size.\");\n+ SmallVector UniformMask(VF, 0);\n+ std::iota(UniformMask.begin(), UniformMask.end(), 0);\n+ V = FinalShuffle(V, UniformMask);\n+ }\n+ }\n+ // Need to update the operand gather node, if actually the operand is not a\n+ // vectorized node, but the buildvector/gather node, which matches one of\n+ // the vectorized nodes.\n+ if (find_if(VE->UserTreeIndices, [&](const EdgeInfo &EI) {\n+ return EI.UserTE == E && EI.EdgeIdx == NodeIdx;\n+ }) == VE->UserTreeIndices.end()) {\n+ auto *It =\n+ find_if(VectorizableTree, [&](const std::unique_ptr &TE) {\n+ return TE->isGather() && TE->UserTreeIndices.front().UserTE == E &&\n+ TE->UserTreeIndices.front().EdgeIdx == NodeIdx;\n+ });\n+ assert(It != VectorizableTree.end() && \"Expected gather node operand.\");\n+ (*It)->VectorizedValue = V;\n }\n+ return V;\n }\n \n // Find the corresponding gather entry and vectorize it.\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/X86/multi-nodes-bv-vectorized.ll", "commands": ["opt -passes=slp-vectorizer -S -mtriple=x86_64-unknown-linux-gnu < %s"], "tests": [{"test_name": "test", "test_body": "define void @test(ptr %p) {\nentry:\n %conv548.2.i.13 = zext i32 0 to i64\n %and551.2.i.13 = and i64 0, %conv548.2.i.13\n %conv548.3.i.13 = zext i32 0 to i64\n %and551.3.i.13 = and i64 0, %conv548.3.i.13\n %0 = trunc i64 %and551.2.i.13 to i32\n %conv54.2.i.14 = and i32 %0, 0\n %conv548.2.i.14 = zext i32 %conv54.2.i.14 to i64\n %and551.2.i.14 = and i64 %and551.2.i.13, %conv548.2.i.14\n %1 = trunc i64 %and551.3.i.13 to i32\n %conv54.3.i.14 = and i32 %1, 0\n %conv548.3.i.14 = zext i32 %conv54.3.i.14 to i64\n %and551.3.i.14 = and i64 %and551.3.i.13, %conv548.3.i.14\n %and551.2.i.15 = and i64 %and551.2.i.14, 0\n %and551.3.i.15 = and i64 %and551.3.i.14, 0\n %and551.2.i.16 = and i64 %and551.2.i.15, 0\n %and551.3.i.16 = and i64 %and551.3.i.15, 0\n %and551.2.i.17 = and i64 %and551.2.i.16, 0\n %and551.3.i.17 = and i64 %and551.3.i.16, 0\n %and551.2.i.18 = and i64 %and551.2.i.17, 0\n %and551.3.i.18 = and i64 %and551.3.i.17, 0\n %and551.2.i.19 = and i64 %and551.2.i.18, 0\n %and551.3.i.19 = and i64 %and551.3.i.18, 0\n %and551.2.i.20 = and i64 %and551.2.i.19, 0\n %and551.3.i.20 = and i64 %and551.3.i.19, 0\n %and551.2.i.21 = and i64 %and551.2.i.20, 0\n %and551.3.i.21 = and i64 %and551.3.i.20, 0\n %gep1 = getelementptr inbounds i8, ptr %p, i64 16\n %gep2 = getelementptr inbounds i8, ptr %p, i64 24\n store i64 %and551.2.i.21, ptr %gep1, align 16\n store i64 %and551.3.i.21, ptr %gep2, align 8\n ret void\n}\n"}]}], "issue": {"title": "[SLPVectorizer] Assertion `CastInst::castIsValid(opc, C, Ty) && \"Invalid constantexpr cast!\"' failed.", "body": "Reproducer: https://godbolt.org/z/PeoMv3Tsn\r\n```\r\n; bin/opt -passes=slp-vectorizer reduced.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 @main(ptr %p) {\r\nentry:\r\n %conv548.2.i.13 = zext i32 0 to i64\r\n %and551.2.i.13 = and i64 0, %conv548.2.i.13\r\n %conv548.3.i.13 = zext i32 0 to i64\r\n %and551.3.i.13 = and i64 0, %conv548.3.i.13\r\n %0 = trunc i64 %and551.2.i.13 to i32\r\n %conv54.2.i.14 = and i32 %0, 0\r\n %conv548.2.i.14 = zext i32 %conv54.2.i.14 to i64\r\n %and551.2.i.14 = and i64 %and551.2.i.13, %conv548.2.i.14\r\n %1 = trunc i64 %and551.3.i.13 to i32\r\n %conv54.3.i.14 = and i32 %1, 0\r\n %conv548.3.i.14 = zext i32 %conv54.3.i.14 to i64\r\n %and551.3.i.14 = and i64 %and551.3.i.13, %conv548.3.i.14\r\n %and551.2.i.15 = and i64 %and551.2.i.14, 0\r\n %and551.3.i.15 = and i64 %and551.3.i.14, 0\r\n %and551.2.i.16 = and i64 %and551.2.i.15, 0\r\n %and551.3.i.16 = and i64 %and551.3.i.15, 0\r\n %and551.2.i.17 = and i64 %and551.2.i.16, 0\r\n %and551.3.i.17 = and i64 %and551.3.i.16, 0\r\n %and551.2.i.18 = and i64 %and551.2.i.17, 0\r\n %and551.3.i.18 = and i64 %and551.3.i.17, 0\r\n %and551.2.i.19 = and i64 %and551.2.i.18, 0\r\n %and551.3.i.19 = and i64 %and551.3.i.18, 0\r\n %and551.2.i.20 = and i64 %and551.2.i.19, 0\r\n %and551.3.i.20 = and i64 %and551.3.i.19, 0\r\n %and551.2.i.21 = and i64 %and551.2.i.20, 0\r\n %and551.3.i.21 = and i64 %and551.3.i.20, 0\r\n %gep1 = getelementptr inbounds i8, ptr %p, i64 16\r\n %gep2 = getelementptr inbounds i8, ptr %p, i64 24\r\n store i64 %and551.2.i.21, ptr %gep1, align 16\r\n store i64 %and551.3.i.21, ptr %gep2, align 8\r\n ret void\r\n}\r\n```\r\n```\r\nopt: /home/dtcxzyw/WorkSpace/Projects/compilers/llvm-project/llvm/lib/IR/Constants.cpp:2202: static llvm::Constant* llvm::ConstantExpr::getCast(unsigned int, llvm::Constant*, llvm::Type*, bool): Assertion `CastInst::castIsValid(opc, C, Ty) && \"Invalid constantexpr cast!\"' 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: bin/opt -passes=slp-vectorizer reduced.ll -S\r\n1. Running pass \"function(slp-vectorizer)\" on module \"reduced.ll\"\r\n2. Running pass \"slp-vectorizer\" on function \"main\"\r\n #0 0x00007c5d3e8138d2 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.20.0git+0x2138d2)\r\n #1 0x00007c5d3e81079f llvm::sys::RunSignalHandlers() (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.20.0git+0x21079f)\r\n #2 0x00007c5d3e8108e5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007c5d3e242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007c5d3e2969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x00007c5d3e2969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x00007c5d3e2969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x00007c5d3e242476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x00007c5d3e2287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x00007c5d3e22871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x00007c5d3e239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x00007c5d36fb0c4d llvm::ConstantExpr::getCast(unsigned int, llvm::Constant*, llvm::Type*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x1b0c4d)\r\n#12 0x00007c5d394573b5 llvm::IRBuilderBase::CreateCast(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, llvm::Twine const&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x573b5)\r\n#13 0x00007c5d395ab173 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1ab173)\r\n#14 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#15 0x00007c5d395a7a13 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7a13)\r\n#16 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#17 0x00007c5d395a7cbb llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7cbb)\r\n#18 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#19 0x00007c5d395a7a41 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7a41)\r\n#20 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#21 0x00007c5d395a7a13 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7a13)\r\n#22 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#23 0x00007c5d395a7a13 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7a13)\r\n#24 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#25 0x00007c5d395a7a13 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7a13)\r\n#26 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#27 0x00007c5d395a7a13 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7a13)\r\n#28 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#29 0x00007c5d395a7a13 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7a13)\r\n#30 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#31 0x00007c5d395a7a13 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7a13)\r\n#32 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#33 0x00007c5d395a7a13 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7a13)\r\n#34 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#35 0x00007c5d395a8f65 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a8f65)\r\n#36 0x00007c5d395ae278 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::MapVector, llvm::DenseMap, llvm::detail::DenseMapPair>, llvm::SmallVector>, 0u>> const&, llvm::SmallVectorImpl>&, llvm::Instruction*) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1ae278)\r\n#37 0x00007c5d395b207c llvm::slpvectorizer::BoUpSLP::vectorizeTree() (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1b207c)\r\n#38 0x00007c5d395c7cac llvm::SLPVectorizerPass::vectorizeStoreChain(llvm::ArrayRef, llvm::slpvectorizer::BoUpSLP&, unsigned int, unsigned int, unsigned int&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1c7cac)\r\n#39 0x00007c5d395c9637 llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet, llvm::DenseMapInfo, void>>&)::'lambda'(std::set, llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet, llvm::DenseMapInfo, void>>&)::StoreDistCompare, std::allocator>> const&)::operator()(std::set, llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet, llvm::DenseMapInfo, void>>&)::StoreDistCompare, std::allocator>> const&) const SLPVectorizer.cpp:0:0\r\n#40 0x00007c5d395cb92c llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet, llvm::DenseMapInfo, void>>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1cb92c)\r\n#41 0x00007c5d395cc20f llvm::SLPVectorizerPass::vectorizeStoreChains(llvm::slpvectorizer::BoUpSLP&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1cc20f)\r\n#42 0x00007c5d395cd30f llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1cd30f)\r\n#43 0x00007c5d395cdf86 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1cdf86)\r\n#44 0x00007c5d39ed4015 llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMPasses.so.20.0git+0xd4015)\r\n#45 0x00007c5d371546ed llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x3546ed)\r\n#46 0x00007c5d3d4d7f35 llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.20.0git+0xd7f35)\r\n#47 0x00007c5d37153256 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x353256)\r\n#48 0x00007c5d3d4d88f5 llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.20.0git+0xd88f5)\r\n#49 0x00007c5d3715121a llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x35121a)\r\n#50 0x00007c5d3eb12fc7 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::ArrayRef>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.20.0git+0x2cfc7)\r\n#51 0x00007c5d3eb1e962 optMain (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.20.0git+0x38962)\r\n#52 0x00007c5d3e229d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#53 0x00007c5d3e229e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#54 0x00007c5d3e229e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#55 0x00005949b291d095 _start (bin/opt+0x1095)\r\nAborted (core dumped)\r\n```\r\n\r\ncc @alexey-bataev ", "author": "dtcxzyw", "labels": ["llvm:SLPVectorizer", "crash-on-valid"], "comments": [{"author": "dtcxzyw", "body": "Related PR: https://github.com/llvm/llvm-project/pull/103216\r\n"}]}, "verified": true}