Sync
Browse files- dataset.jsonl +1 -1
- dataset/109528.json +1 -1
dataset.jsonl
CHANGED
@@ -246,7 +246,7 @@
|
|
246 |
{"bug_id": "87378", "issue_url": "https://github.com/llvm/llvm-project/issues/87378", "bug_type": "crash", "base_commit": "d8db13edd60b195e6692deb04d63e633319e486a", "knowledge_cutoff": "2024-04-02T17:38:53Z", "lit_test_dir": ["llvm/test/Transforms/LoopVectorize"], "hints": {"fix_commit": "6261c53c6f9c82bfca5df2ed5917876d748ed079", "components": ["LoopVectorize"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": [[175, 181]], "llvm/lib/Transforms/Vectorize/VPlan.h": [[913, 918], [920, 928], [1016, 1021], [1221, 1226]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": ["createOr", "createSelect"], "llvm/lib/Transforms/Vectorize/VPlan.h": ["GEPFlagsTy", "VPInstruction", "VPRecipeWithIRFlags"]}}, "patch": "commit 6261c53c6f9c82bfca5df2ed5917876d748ed079\nAuthor: Florian Hahn <[email protected]>\nDate: Tue Apr 2 21:48:35 2024 +0100\n\n [VPlan] Make sure OR VPInstructions are treated as disjoint ops.\n \n Make sure that VPInstructions with OR opcodes are properly registered as\n disjoint ops.\n \n Fixes https://github.com/llvm/llvm-project/issues/87378.\n\ndiff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h\nindex 5d03b66b0ce3..ebca2d855a46 100644\n--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h\n+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h\n@@ -175,7 +175,10 @@ public:\n \n VPValue *createOr(VPValue *LHS, VPValue *RHS, DebugLoc DL = {},\n const Twine &Name = \"\") {\n- return createInstruction(Instruction::BinaryOps::Or, {LHS, RHS}, DL, Name);\n+\n+ return tryInsertInstruction(new VPInstruction(\n+ Instruction::BinaryOps::Or, {LHS, RHS},\n+ VPRecipeWithIRFlags::DisjointFlagsTy(false), DL, Name));\n }\n \n VPValue *createSelect(VPValue *Cond, VPValue *TrueVal, VPValue *FalseVal,\ndiff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h\nindex 3baca43f7276..707a826ecdc2 100644\n--- a/llvm/lib/Transforms/Vectorize/VPlan.h\n+++ b/llvm/lib/Transforms/Vectorize/VPlan.h\n@@ -913,6 +913,11 @@ public:\n WrapFlagsTy(bool HasNUW, bool HasNSW) : HasNUW(HasNUW), HasNSW(HasNSW) {}\n };\n \n+ struct DisjointFlagsTy {\n+ char IsDisjoint : 1;\n+ DisjointFlagsTy(bool IsDisjoint) : IsDisjoint(IsDisjoint) {}\n+ };\n+\n protected:\n struct GEPFlagsTy {\n char IsInBounds : 1;\n@@ -920,9 +925,6 @@ protected:\n };\n \n private:\n- struct DisjointFlagsTy {\n- char IsDisjoint : 1;\n- };\n struct ExactFlagsTy {\n char IsExact : 1;\n };\n@@ -1016,6 +1018,12 @@ public:\n : VPSingleDefRecipe(SC, Operands, DL), OpType(OperationType::FPMathOp),\n FMFs(FMFs) {}\n \n+ template <typename IterT>\n+ VPRecipeWithIRFlags(const unsigned char SC, IterT Operands,\n+ DisjointFlagsTy DisjointFlags, DebugLoc DL = {})\n+ : VPSingleDefRecipe(SC, Operands, DL), OpType(OperationType::DisjointOp),\n+ DisjointFlags(DisjointFlags) {}\n+\n protected:\n template <typename IterT>\n VPRecipeWithIRFlags(const unsigned char SC, IterT Operands,\n@@ -1221,6 +1229,14 @@ public:\n : VPRecipeWithIRFlags(VPDef::VPInstructionSC, Operands, WrapFlags, DL),\n Opcode(Opcode), Name(Name.str()) {}\n \n+ VPInstruction(unsigned Opcode, std::initializer_list<VPValue *> Operands,\n+ DisjointFlagsTy DisjointFlag, DebugLoc DL = {},\n+ const Twine &Name = \"\")\n+ : VPRecipeWithIRFlags(VPDef::VPInstructionSC, Operands, DisjointFlag, DL),\n+ Opcode(Opcode), Name(Name.str()) {\n+ assert(Opcode == Instruction::Or && \"only OR opcodes can be disjoint\");\n+ }\n+\n VPInstruction(unsigned Opcode, std::initializer_list<VPValue *> Operands,\n FastMathFlags FMFs, DebugLoc DL = {}, const Twine &Name = \"\");\n \n", "tests": [{"file": "llvm/test/Transforms/LoopVectorize/pr87378-vpinstruction-or-drop-poison-generating-flags.ll", "commands": ["opt -p loop-vectorize -mattr=\"+v\" -S %s"], "tests": [{"test_name": "<module>", "test_body": "\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\n; Test case for https://github.com/llvm/llvm-project/issues/87378.\ndefine void @pr87378_vpinstruction_or_drop_poison_generating_flags(ptr %arg, i64 %a, i64 %b, i64 %c) {\n;\nentry:\n br label %loop.header\n\nloop.header:\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %c.1 = icmp ule i64 %iv, %a\n br i1 %c.1, label %then.1, label %else.1\n\nthen.1:\n %c.2 = icmp ule i64 %iv, %b\n br i1 %c.2, label %else.1, label %merge\n\nelse.1:\n %c.3 = icmp ule i64 %iv, %c\n br i1 %c.3, label %then.2, label %loop.latch\n\nthen.2:\n br label %merge\n\nmerge:\n %idx = phi i64 [ poison, %then.1 ], [ %iv, %then.2 ]\n %getelementptr = getelementptr i16, ptr %arg, i64 %idx\n store i16 0, ptr %getelementptr, align 2\n br label %loop.latch\n\nloop.latch:\n %iv.next = add i64 %iv, 1\n %icmp = icmp eq i64 %iv, 1000\n br i1 %icmp, label %exit, label %loop.header\n\nexit:\n ret void\n}\n;.\n;."}]}], "issue": {"title": "[LoopVectorize] Assertion `OpType == OperationType::DisjointOp && \"recipe cannot have a disjoing flag\"' failed.", "body": "Reduced LLVM IR:\r\n``` llvm ir\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 i32 @main() #0 {\r\nentry:\r\n br label %for.body300.us.us.i\r\n\r\nfor.body300.us.us.i: ; preds = %if.end559.us.us.i, %entry\r\n br label %for.body326.us.us.i\r\n\r\nfor.body326.us.us.i: ; preds = %if.end559.us.us.i, %for.body300.us.us.i\r\n %indvars.iv18 = phi i64 [ 0, %for.body300.us.us.i ], [ %indvars.iv.next19, %if.end559.us.us.i ]\r\n br i1 false, label %cond.end339.us.us.i, label %cond.end354.us.us.i\r\n\r\ncond.end339.us.us.i: ; preds = %for.body326.us.us.i\r\n br i1 false, label %cond.end339.us.us.i.if.then357.us.us.i_crit_edge, label %cond.end339.us.us.i.cond.end354.us.us.i_crit_edge\r\n\r\ncond.end339.us.us.i.cond.end354.us.us.i_crit_edge: ; preds = %cond.end339.us.us.i\r\n br label %cond.end354.us.us.i\r\n\r\ncond.end339.us.us.i.if.then357.us.us.i_crit_edge: ; preds = %cond.end339.us.us.i\r\n br label %if.then357.us.us.i\r\n\r\ncond.end354.us.us.i: ; preds = %cond.end339.us.us.i.cond.end354.us.us.i_crit_edge, %for.body326.us.us.i\r\n br i1 false, label %cond.end354.us.us.i.if.then357.us.us.i_crit_edge, label %if.end559.us.us.i\r\n\r\ncond.end354.us.us.i.if.then357.us.us.i_crit_edge: ; preds = %cond.end354.us.us.i\r\n br label %if.then357.us.us.i\r\n\r\nif.then357.us.us.i: ; preds = %cond.end354.us.us.i.if.then357.us.us.i_crit_edge, %cond.end339.us.us.i.if.then357.us.us.i_crit_edge\r\n %.pre1143.i7 = phi i64 [ poison, %cond.end339.us.us.i.if.then357.us.us.i_crit_edge ], [ %indvars.iv18, %cond.end354.us.us.i.if.then357.us.us.i_crit_edge ]\r\n %arrayidx429.us.us.i = getelementptr [14 x i16], ptr null, i64 0, i64 %.pre1143.i7\r\n store i16 0, ptr %arrayidx429.us.us.i, align 2\r\n br label %if.end559.us.us.i\r\n\r\nif.end559.us.us.i: ; preds = %if.then357.us.us.i, %cond.end354.us.us.i\r\n %indvars.iv.next19 = add i64 %indvars.iv18, 1\r\n %0 = trunc i64 %indvars.iv18 to i32\r\n %cmp323.us.us.i = icmp slt i32 %0, 1\r\n br i1 %cmp323.us.us.i, label %for.body326.us.us.i, label %for.body300.us.us.i\r\n}\r\n\r\nattributes #0 = { \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl256b,+zvl32b,+zvl64b,-e,-experimental-smmpm,-experimental-smnpm,-experimental-ssnpm,-experimental-sspm,-experimental-ssqosid,-experimental-supm,-experimental-zaamo,-experimental-zabha,-experimental-zalasr,-experimental-zalrsc,-experimental-zcmop,-experimental-zfbfmin,-experimental-zicfilp,-experimental-zicfiss,-experimental-zimop,-experimental-ztso,-experimental-zvfbfmin,-experimental-zvfbfwma,-h,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smepmp,-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,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmp,-zcmt,-zdinx,-zfa,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zihintntl,-zihintpause,-zihpm,-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,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b\" }\r\n```\r\n\r\nBacktrace:\r\n```\r\nopt: /scratch/tc-testing/tc-apr-2/llvm/llvm/lib/Transforms/Vectorize/VPlan.h:1131: bool llvm::VPRecipeWithIRFlags::isDisjoint() const: Assertion `OpType == OperationType::DisjointOp && \"recipe cannot have a disjoing flag\"' 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-apr-2/build-rv64gcv/build-llvm-linux/bin/opt reduced.ll --passes=loop-vectorize\r\n #0 0x00005bd204995b60 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2d84b60)\r\n #1 0x00005bd204992f6f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2d81f6f)\r\n #2 0x00005bd2049930c5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x000076eef1a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x000076eef1a969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x000076eef1a969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x000076eef1a969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x000076eef1a42476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x000076eef1a287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x000076eef1a2871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x000076eef1a39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x00005bd203b25ea2 llvm::VPlanTransforms::dropPoisonGeneratingRecipes(llvm::VPlan&, llvm::function_ref<bool (llvm::BasicBlock*)>)::'lambda'(llvm::VPRecipeBase*)::operator()(llvm::VPRecipeBase*) const VPlanTransforms.cpp:0:0\r\n#12 0x00005bd203b2c77d llvm::VPlanTransforms::dropPoisonGeneratingRecipes(llvm::VPlan&, llvm::function_ref<bool (llvm::BasicBlock*)>) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1f1b77d)\r\n#13 0x00005bd203a05435 llvm::LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(llvm::VFRange&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1df4435)\r\n#14 0x00005bd203a05c9e llvm::LoopVectorizationPlanner::buildVPlansWithVPRecipes(llvm::ElementCount, llvm::ElementCount) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1df4c9e)\r\n#15 0x00005bd203a0c319 llvm::LoopVectorizationPlanner::plan(llvm::ElementCount, unsigned int) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1dfb319)\r\n#16 0x00005bd203a0f8a9 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1dfe8a9)\r\n#17 0x00005bd203a1273e 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*) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1e0173e)\r\n#18 0x00005bd203a1388d llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1e0288d)\r\n#19 0x00005bd20291a276 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0xd09276)\r\n#20 0x00005bd2047bc141 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2bab141)\r\n#21 0x00005bd202911bd6 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0xd00bd6)\r\n#22 0x00005bd2047bae3b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2ba9e3b)\r\n#23 0x00005bd202919dc6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0xd08dc6)\r\n#24 0x00005bd2047b8cb1 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2ba7cb1)\r\n#25 0x00005bd202193ce5 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x582ce5)\r\n#26 0x00005bd202186316 optMain (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x575316)\r\n#27 0x000076eef1a29d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#28 0x000076eef1a29e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#29 0x000076eef1a29e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#30 0x00005bd20217bf95 _start (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x56af95)\r\nzsh: IOT instruction (core dumped) /scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt reduced.l\r\n```\r\n\r\nGodbolt: https://godbolt.org/z/jj39h3z7M\r\n\r\nMinor spelling nit: `disjoing -> disjoint`\r\n\r\nFound via fuzzer.\r\n\r\nLikely caused/exposed by https://github.com/llvm/llvm-project/commit/6ef829941b38f7e8a28c4cba1ff25cd0ae9f7d3d https://github.com/llvm/llvm-project/pull/83821 @fhahn ", "author": "patrick-rivos", "labels": ["vectorizers", "crash"], "comments": []}, "verified": true}
|
247 |
{"bug_id": "121581", "issue_url": "https://github.com/llvm/llvm-project/issues/121581", "bug_type": "miscompilation", "base_commit": "95c5c5d4badf7c2128d098be325356e15c2197be", "knowledge_cutoff": "2025-01-03T16:31:11Z", "lit_test_dir": ["llvm/test/Transforms/InstCombine"], "hints": {"fix_commit": "fac46469977da9c4e9c6eeaac21103c971190577", "components": ["InstCombine"], "bug_location_lineno": {"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": [[747, 752], [764, 770], [804, 810]]}, "bug_location_funcname": {"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": ["InstCombinerImpl::foldGEPICmp"]}}, "patch": "commit fac46469977da9c4e9c6eeaac21103c971190577\nAuthor: Yingwei Zheng <[email protected]>\nDate: Sat Jan 4 17:23:57 2025 +0800\n\n [InstCombine] Check no wrap flags before folding icmp of GEPs with same indices (#121628)\n \n Alive2: https://alive2.llvm.org/ce/z/Dr3Sbe\n Closes https://github.com/llvm/llvm-project/issues/121581.\n\ndiff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp\nindex d6fdade25559..8b23583c5106 100644\n--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp\n+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp\n@@ -747,6 +747,8 @@ Instruction *InstCombinerImpl::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,\n ConstantExpr::getPointerBitCastOrAddrSpaceCast(\n cast<Constant>(RHS), Base->getType()));\n } else if (GEPOperator *GEPRHS = dyn_cast<GEPOperator>(RHS)) {\n+ GEPNoWrapFlags NW = GEPLHS->getNoWrapFlags() & GEPRHS->getNoWrapFlags();\n+\n // If the base pointers are different, but the indices are the same, just\n // compare the base pointer.\n if (PtrBase != GEPRHS->getOperand(0)) {\n@@ -764,7 +766,8 @@ Instruction *InstCombinerImpl::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,\n \n // If all indices are the same, just compare the base pointers.\n Type *BaseType = GEPLHS->getOperand(0)->getType();\n- if (IndicesTheSame && CmpInst::makeCmpResultType(BaseType) == I.getType())\n+ if (IndicesTheSame &&\n+ CmpInst::makeCmpResultType(BaseType) == I.getType() && CanFold(NW))\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n \n // If we're comparing GEPs with two base pointers that only differ in type\n@@ -804,7 +807,6 @@ Instruction *InstCombinerImpl::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,\n return transformToIndexedCompare(GEPLHS, RHS, Cond, DL, *this);\n }\n \n- GEPNoWrapFlags NW = GEPLHS->getNoWrapFlags() & GEPRHS->getNoWrapFlags();\n if (GEPLHS->getNumOperands() == GEPRHS->getNumOperands() &&\n GEPLHS->getSourceElementType() == GEPRHS->getSourceElementType()) {\n // If the GEPs only differ by one index, compare it.\n", "tests": [{"file": "llvm/test/Transforms/InstCombine/icmp-gep.ll", "commands": ["opt -passes=instcombine -S < %s"], "tests": [{"test_name": "pointer_icmp_aligned_with_offset_negative", "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 @pointer_icmp_aligned_with_offset_negative(ptr align 8 %a, ptr align 8 %a2) {\n %gep = getelementptr i8, ptr %a, i64 8\n %cmp = icmp eq ptr %gep, %a2\n ret i1 %cmp\n}\n"}, {"test_name": "gep_diff_base_same_indices_nuw_nusw", "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 @gep_diff_base_same_indices_nuw_nusw(ptr %x, ptr %y, i64 %z) {\n %gep1 = getelementptr nuw i8, ptr %x, i64 %z\n %gep2 = getelementptr nusw i8, ptr %y, i64 %z\n %cmp = icmp ult ptr %gep1, %gep2\n ret i1 %cmp\n}\n"}, {"test_name": "gep_diff_base_same_indices", "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 @gep_diff_base_same_indices(ptr %x, ptr %y, i64 %z) {\n %gep1 = getelementptr i8, ptr %x, i64 %z\n %gep2 = getelementptr i8, ptr %y, i64 %z\n %cmp = icmp ult ptr %gep1, %gep2\n ret i1 %cmp\n}\n"}, {"test_name": "gep_diff_base_same_indices_nusw", "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 @gep_diff_base_same_indices_nusw(ptr %x, ptr %y, i64 %z) {\n %gep1 = getelementptr nusw i8, ptr %x, i64 %z\n %gep2 = getelementptr nusw i8, ptr %y, i64 %z\n %cmp = icmp ult ptr %gep1, %gep2\n ret i1 %cmp\n}\n"}, {"test_name": "gep_diff_base_same_indices_nuw", "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 @gep_diff_base_same_indices_nuw(ptr %x, ptr %y, i64 %z) {\n %gep1 = getelementptr nuw i8, ptr %x, i64 %z\n %gep2 = getelementptr nuw i8, ptr %y, i64 %z\n %cmp = icmp ult ptr %gep1, %gep2\n ret i1 %cmp\n}\n"}]}], "issue": {"title": "[InstCombine] Incorrect fold of the comparison of GEPs", "body": "Alive2: https://alive2.llvm.org/ce/z/HRsqeW\n```\ndefine i1 @test(ptr %x, ptr %y) {\n %gep1 = getelementptr i8, ptr %x, i32 1\n %gep2 = getelementptr i8, ptr %y, i32 1\n %cmp = icmp ult ptr %gep1, %gep2\n ret i1 %cmp\n}\n```\n```\n\n----------------------------------------\ndefine i1 @test(ptr %x, ptr %y) {\n#0:\n %gep1 = gep ptr %x, 1 x i32 1\n %gep2 = gep ptr %y, 1 x i32 1\n %cmp = icmp ult ptr %gep1, %gep2\n ret i1 %cmp\n}\n=>\ndefine i1 @test(ptr %x, ptr %y) {\n#0:\n %cmp = icmp ult ptr %x, %y\n ret i1 %cmp\n}\nTransformation doesn't verify!\n\nERROR: Value mismatch\n\nExample:\nptr %x = pointer(non-local, block_id=0, offset=-1) / Address=#xf\nptr %y = null\n\nSource:\nptr %gep1 = null\nptr %gep2 = pointer(non-local, block_id=0, offset=1) / Address=#x1\ni1 %cmp = #x1 (1)\n\nSOURCE MEMORY STATE\n===================\nNON-LOCAL BLOCKS:\nBlock 0 >\tsize: 0\talign: 1\talloc type: 0\talive: false\taddress: 0\nBlock 1 >\tsize: 1\talign: 2\talloc type: 0\talive: true\taddress: 2\nBlock 2 >\tsize: 0\talign: 1\talloc type: 0\talive: true\taddress: 3\n\nTarget:\ni1 %cmp = #x0 (0)\nSource value: #x1 (1)\nTarget value: #x0 (0)\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}
|
248 |
{"bug_id": "117517", "issue_url": "https://github.com/llvm/llvm-project/issues/117517", "bug_type": "crash", "base_commit": "7e3187e12a2cef8b2552e08ce9423aca9c09d813", "knowledge_cutoff": "2024-11-25T05:18:47Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "57bbdbd7ae3698a274edd4dd6ef1b53d9129e552", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[1143, 1151]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["addMask"]}}, "patch": "commit 57bbdbd7ae3698a274edd4dd6ef1b53d9129e552\nAuthor: Alexey Bataev <[email protected]>\nDate: Mon Nov 25 07:56:45 2024 -0800\n\n [SLP]Relax assertion in mask combine for non-power-of-2 number of elements\n \n The nodes may contain non-power-of-2 number of elements. Need to relax\n the assertion to avoid possible compiler crash\n \n Fixes #117517\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex d033b7c2ef4a..73218f377a06 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -1143,9 +1143,7 @@ static void addMask(SmallVectorImpl<int> &Mask, ArrayRef<int> SubMask,\n assert(\n (!ExtendingManyInputs || SubMask.size() > Mask.size() ||\n // Check if input scalars were extended to match the size of other node.\n- (SubMask.size() == Mask.size() &&\n- std::all_of(std::next(Mask.begin(), Mask.size() / 2), Mask.end(),\n- [](int Idx) { return Idx == PoisonMaskElem; }))) &&\n+ (SubMask.size() == Mask.size() && Mask.back() == PoisonMaskElem)) &&\n \"SubMask with many inputs support must be larger than the mask.\");\n if (Mask.empty()) {\n Mask.append(SubMask.begin(), SubMask.end());\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/X86/non-power-2-num-elems-reused.ll", "commands": ["opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -slp-threshold=-10 < %s"], "tests": [{"test_name": "<module>", "test_body": "\ndefine i64 @test() {\n;\nentry:\n %xor148.2.i = xor i32 0, 0\n %conv193.i = zext i32 %xor148.2.i to i64\n %conv193.1.i = zext i32 %xor148.2.i to i64\n %or194.1.i = or i64 %conv193.i, %conv193.1.i\n %xor148.2.i.1 = xor i32 0, 0\n %conv193.i.1 = zext i32 %xor148.2.i.1 to i64\n %or194.i.1 = or i64 %or194.1.i, %conv193.i.1\n %conv193.1.i.1 = zext i32 %xor148.2.i.1 to i64\n %or194.1.i.1 = or i64 %or194.i.1, %conv193.1.i.1\n %xor148.2.i.2 = xor i32 0, 0\n %conv193.i.2 = zext i32 %xor148.2.i.2 to i64\n %or194.i.2 = or i64 %or194.1.i.1, %conv193.i.2\n %conv193.1.i.2 = zext i32 %xor148.2.i.2 to i64\n %or194.1.i.2 = or i64 %or194.i.2, %conv193.1.i.2\n %xor148.2.i.3 = xor i32 0, 0\n %conv193.i.3 = zext i32 %xor148.2.i.3 to i64\n %or194.i.3 = or i64 %or194.1.i.2, %conv193.i.3\n %conv193.1.i.3 = zext i32 %xor148.2.i.3 to i64\n %or194.1.i.3 = or i64 %or194.i.3, %conv193.1.i.3\n %xor148.2.i.4 = xor i32 0, 0\n %conv193.i.4 = zext i32 %xor148.2.i.4 to i64\n %or194.i.4 = or i64 %or194.1.i.3, %conv193.i.4\n %conv193.1.i.4 = zext i32 %xor148.2.i.4 to i64\n %or194.1.i.4 = or i64 %or194.i.4, %conv193.1.i.4\n %xor148.2.i.5 = xor i32 0, 0\n %conv193.i.5 = zext i32 %xor148.2.i.5 to i64\n %or194.i.5 = or i64 %or194.1.i.4, %conv193.i.5\n %conv193.1.i.5 = zext i32 %xor148.2.i.5 to i64\n %or194.1.i.5 = or i64 %or194.i.5, %conv193.1.i.5\n %xor148.2.i.6 = xor i32 0, 0\n %conv193.i.6 = zext i32 %xor148.2.i.6 to i64\n %or194.i.6 = or i64 %or194.1.i.5, %conv193.i.6\n %or54.i.i.6 = or i32 %xor148.2.i.6, 0\n %conv193.1.i.6 = zext i32 %or54.i.i.6 to i64\n %xor148.2.i.7 = xor i32 0, 0\n %conv193.i.7 = zext i32 %xor148.2.i.7 to i64\n %0 = or i64 %or194.i.6, %conv193.i.7\n %conv193.1.i.7 = zext i32 %xor148.2.i.7 to i64\n %1 = or i64 %0, %conv193.1.i.7\n %or194.1.i.7 = or i64 %1, %conv193.1.i.6\n ret i64 %or194.1.i.7\n}"}]}], "issue": {"title": "[SLPVectorizer] Assertion \"SubMask with many inputs support must be larger than the mask.\" failed.", "body": "Reproducer: https://godbolt.org/z/Mzbe1G875\r\n```\r\n; bin/opt -passes=slp-vectorizer test.ll -S\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine i64 @test() {\r\nentry:\r\n %xor148.2.i = xor i32 0, 0\r\n %conv193.i = zext i32 %xor148.2.i to i64\r\n %conv193.1.i = zext i32 %xor148.2.i to i64\r\n %or194.1.i = or i64 %conv193.i, %conv193.1.i\r\n %xor148.2.i.1 = xor i32 0, 0\r\n %conv193.i.1 = zext i32 %xor148.2.i.1 to i64\r\n %or194.i.1 = or i64 %or194.1.i, %conv193.i.1\r\n %conv193.1.i.1 = zext i32 %xor148.2.i.1 to i64\r\n %or194.1.i.1 = or i64 %or194.i.1, %conv193.1.i.1\r\n %xor148.2.i.2 = xor i32 0, 0\r\n %conv193.i.2 = zext i32 %xor148.2.i.2 to i64\r\n %or194.i.2 = or i64 %or194.1.i.1, %conv193.i.2\r\n %conv193.1.i.2 = zext i32 %xor148.2.i.2 to i64\r\n %or194.1.i.2 = or i64 %or194.i.2, %conv193.1.i.2\r\n %xor148.2.i.3 = xor i32 0, 0\r\n %conv193.i.3 = zext i32 %xor148.2.i.3 to i64\r\n %or194.i.3 = or i64 %or194.1.i.2, %conv193.i.3\r\n %conv193.1.i.3 = zext i32 %xor148.2.i.3 to i64\r\n %or194.1.i.3 = or i64 %or194.i.3, %conv193.1.i.3\r\n %xor148.2.i.4 = xor i32 0, 0\r\n %conv193.i.4 = zext i32 %xor148.2.i.4 to i64\r\n %or194.i.4 = or i64 %or194.1.i.3, %conv193.i.4\r\n %conv193.1.i.4 = zext i32 %xor148.2.i.4 to i64\r\n %or194.1.i.4 = or i64 %or194.i.4, %conv193.1.i.4\r\n %xor148.2.i.5 = xor i32 0, 0\r\n %conv193.i.5 = zext i32 %xor148.2.i.5 to i64\r\n %or194.i.5 = or i64 %or194.1.i.4, %conv193.i.5\r\n %conv193.1.i.5 = zext i32 %xor148.2.i.5 to i64\r\n %or194.1.i.5 = or i64 %or194.i.5, %conv193.1.i.5\r\n %xor148.2.i.6 = xor i32 0, 0\r\n %conv193.i.6 = zext i32 %xor148.2.i.6 to i64\r\n %or194.i.6 = or i64 %or194.1.i.5, %conv193.i.6\r\n %or54.i.i.6 = or i32 %xor148.2.i.6, 0\r\n %conv193.1.i.6 = zext i32 %or54.i.i.6 to i64\r\n %xor148.2.i.7 = xor i32 0, 0\r\n %conv193.i.7 = zext i32 %xor148.2.i.7 to i64\r\n %0 = or i64 %or194.i.6, %conv193.i.7\r\n %conv193.1.i.7 = zext i32 %xor148.2.i.7 to i64\r\n %1 = or i64 %0, %conv193.1.i.7\r\n %or194.1.i.7 = or i64 %1, %conv193.1.i.6\r\n ret i64 %or194.1.i.7\r\n}\r\n```\r\n```\r\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:1143: void addMask(llvm::SmallVectorImpl<int>&, llvm::ArrayRef<int>, bool): Assertion `(!ExtendingManyInputs || SubMask.size() > Mask.size() || (SubMask.size() == Mask.size() && std::all_of(std::next(Mask.begin(), Mask.size() / 2), Mask.end(), [](int Idx) { return Idx == PoisonMaskElem; }))) && \"SubMask with many inputs support must be larger than the mask.\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=slp-vectorizer <source>\r\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\r\n2.\tRunning pass \"slp-vectorizer\" on function \"test\"\r\n #0 0x00000000051b7378 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x51b7378)\r\n #1 0x00000000051b4d6c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x0000751221842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007512218969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x0000751221842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007512218287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x000075122182871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x0000751221839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x00000000041e91f7 llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator::finalize(llvm::ArrayRef<int>, llvm::ArrayRef<std::pair<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, unsigned int>>, llvm::ArrayRef<int>, unsigned int, llvm::function_ref<void (llvm::Value*&, llvm::SmallVectorImpl<int>&)>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41e91f7)\r\n #9 0x00000000042256f9 llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::processBuildVector<llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator, llvm::InstructionCost, llvm::TargetTransformInfo, llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP, llvm::SmallPtrSetImpl<llvm::Value*>>(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::Type*, llvm::TargetTransformInfo&, llvm::ArrayRef<llvm::Value*>&, llvm::slpvectorizer::BoUpSLP&, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x42256f9)\r\n#10 0x000000000422f707 llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x422f707)\r\n#11 0x00000000042636a1 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x42636a1)\r\n#12 0x00000000042691b0 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\r\n#13 0x000000000426c681 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x426c681)\r\n#14 0x0000000004270deb llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0\r\n#15 0x00000000042758a6 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x42758a6)\r\n#16 0x000000000427bf86 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0\r\n#17 0x000000000427ca9b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x427ca9b)\r\n#18 0x0000000002fcc5ce llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2fcc5ce)\r\n#19 0x0000000004fb6a68 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fb6a68)\r\n#20 0x0000000000e3dd4e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe3dd4e)\r\n#21 0x0000000004fb548e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fb548e)\r\n#22 0x0000000000e3d3fe llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe3d3fe)\r\n#23 0x0000000004fb4ec0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fb4ec0)\r\n#24 0x000000000090ce7a llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x90ce7a)\r\n#25 0x00000000008ff519 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ff519)\r\n#26 0x0000751221829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#27 0x0000751221829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#28 0x00000000008f6d6e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f6d6e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "dtcxzyw", "labels": ["llvm:SLPVectorizer", "crash-on-valid"], "comments": []}, "verified": true}
|
249 |
-
{"bug_id": "109528", "issue_url": "https://github.com/llvm/llvm-project/issues/109528", "bug_type": "crash", "base_commit": "586736226e3a25b1fd647d3257270c1388f907bf", "knowledge_cutoff": "2024-09-21T14:20:16Z", "lit_test_dir": ["llvm/test/Transforms/LoopVectorize"], "hints": {"fix_commit": "6d6eea92e36c301e34a7ec11b2a40e3080f79f53", "components": ["LoopVectorize"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [[8420, 8440]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": ["VPRecipeBuilder::
|
250 |
{"bug_id": "114191", "issue_url": "https://github.com/llvm/llvm-project/issues/114191", "bug_type": "miscompilation", "base_commit": "e577f14b670ee2ae6bb717133310b215be4331b3", "knowledge_cutoff": "2024-10-30T07:41:28Z", "lit_test_dir": ["llvm/test/Transforms/InstCombine", "llvm/test/Transforms/InstSimplify"], "hints": {"fix_commit": "a77dedcacb4c5eb221395b69877981dd6ad98989", "components": ["IR", "InstCombine", "InstructionSimplify"], "bug_location_lineno": {"llvm/lib/Analysis/InstructionSimplify.cpp": [[1095, 1113]], "llvm/lib/IR/ConstantFold.cpp": [[902, 912]], "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": [[102, 107]], "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": [[1158, 1186], [1189, 1194], [2138, 2166]]}, "bug_location_funcname": {"llvm/lib/Analysis/InstructionSimplify.cpp": ["simplifyDivRem"], "llvm/lib/IR/ConstantFold.cpp": ["llvm::ConstantFoldBinaryInstruction"], "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": ["InstCombinerImpl::commonIDivTransforms", "InstCombinerImpl::commonIRemTransforms", "foldIDivShl"]}}, "patch": "commit a77dedcacb4c5eb221395b69877981dd6ad98989\nAuthor: Yingwei Zheng <[email protected]>\nDate: Fri Nov 1 22:56:22 2024 +0800\n\n [InstSimplify][InstCombine][ConstantFold] Move vector div/rem by zero fold to InstCombine (#114280)\n \n Previously we fold `div/rem X, C` into `poison` if any element of the\n constant divisor `C` is zero or undef. However, it is incorrect when\n threading udiv over an vector select:\n https://alive2.llvm.org/ce/z/3Ninx5\n ```\n define <2 x i32> @vec_select_udiv_poison(<2 x i1> %x) {\n %sel = select <2 x i1> %x, <2 x i32> <i32 -1, i32 -1>, <2 x i32> <i32 0, i32 1>\n %div = udiv <2 x i32> <i32 42, i32 -7>, %sel\n ret <2 x i32> %div\n }\n ```\n In this case, `threadBinOpOverSelect` folds `udiv <i32 42, i32 -7>, <i32\n -1, i32 -1>` and `udiv <i32 42, i32 -7>, <i32 0, i32 1>` into\n `zeroinitializer` and `poison`, respectively. One solution is to\n introduce a new flag indicating that we are threading over a vector\n select. But it requires to modify both `InstSimplify` and\n `ConstantFold`.\n \n However, this optimization doesn't provide benefits to real-world\n programs:\n \n https://dtcxzyw.github.io/llvm-opt-benchmark/coverage/data/zyw/opt-ci/actions-runner/_work/llvm-opt-benchmark/llvm-opt-benchmark/llvm/llvm-project/llvm/lib/IR/ConstantFold.cpp.html#L908\n \n https://dtcxzyw.github.io/llvm-opt-benchmark/coverage/data/zyw/opt-ci/actions-runner/_work/llvm-opt-benchmark/llvm-opt-benchmark/llvm/llvm-project/llvm/lib/Analysis/InstructionSimplify.cpp.html#L1107\n \n This patch moves the fold into InstCombine to avoid breaking numerous\n existing tests.\n \n Fixes #114191 and #113866 (only poison-safety issue).\n\ndiff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp\nindex d08be1e55c85..2cb2612bf611 100644\n--- a/llvm/lib/Analysis/InstructionSimplify.cpp\n+++ b/llvm/lib/Analysis/InstructionSimplify.cpp\n@@ -1095,19 +1095,6 @@ static Value *simplifyDivRem(Instruction::BinaryOps Opcode, Value *Op0,\n if (match(Op1, m_Zero()))\n return PoisonValue::get(Ty);\n \n- // If any element of a constant divisor fixed width vector is zero or undef\n- // the behavior is undefined and we can fold the whole op to poison.\n- auto *Op1C = dyn_cast<Constant>(Op1);\n- auto *VTy = dyn_cast<FixedVectorType>(Ty);\n- if (Op1C && VTy) {\n- unsigned NumElts = VTy->getNumElements();\n- for (unsigned i = 0; i != NumElts; ++i) {\n- Constant *Elt = Op1C->getAggregateElement(i);\n- if (Elt && (Elt->isNullValue() || Q.isUndefValue(Elt)))\n- return PoisonValue::get(Ty);\n- }\n- }\n-\n // poison / X -> poison\n // poison % X -> poison\n if (isa<PoisonValue>(Op0))\ndiff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp\nindex 07dfbc41e79b..c2780faee403 100644\n--- a/llvm/lib/IR/ConstantFold.cpp\n+++ b/llvm/lib/IR/ConstantFold.cpp\n@@ -902,11 +902,6 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1,\n Constant *ExtractIdx = ConstantInt::get(Ty, i);\n Constant *LHS = ConstantExpr::getExtractElement(C1, ExtractIdx);\n Constant *RHS = ConstantExpr::getExtractElement(C2, ExtractIdx);\n-\n- // If any element of a divisor vector is zero, the whole op is poison.\n- if (Instruction::isIntDivRem(Opcode) && RHS->isNullValue())\n- return PoisonValue::get(VTy);\n-\n Constant *Res = ConstantExpr::isDesirableBinOp(Opcode)\n ? ConstantExpr::get(Opcode, LHS, RHS)\n : ConstantFoldBinaryInstruction(Opcode, LHS, RHS);\ndiff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h\nindex 7a060cdab2d3..adbd9186c59c 100644\n--- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h\n+++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h\n@@ -102,6 +102,7 @@ public:\n Instruction *visitSRem(BinaryOperator &I);\n Instruction *visitFRem(BinaryOperator &I);\n bool simplifyDivRemOfSelectWithZeroOp(BinaryOperator &I);\n+ Instruction *commonIDivRemTransforms(BinaryOperator &I);\n Instruction *commonIRemTransforms(BinaryOperator &I);\n Instruction *commonIDivTransforms(BinaryOperator &I);\n Instruction *visitUDiv(BinaryOperator &I);\ndiff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp\nindex b9c165da906d..f85a3c936513 100644\n--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp\n+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp\n@@ -1158,29 +1158,39 @@ static Value *foldIDivShl(BinaryOperator &I, InstCombiner::BuilderTy &Builder) {\n return nullptr;\n }\n \n-/// This function implements the transforms common to both integer division\n-/// instructions (udiv and sdiv). It is called by the visitors to those integer\n-/// division instructions.\n-/// Common integer divide transforms\n-Instruction *InstCombinerImpl::commonIDivTransforms(BinaryOperator &I) {\n- if (Instruction *Phi = foldBinopWithPhiOperands(I))\n- return Phi;\n-\n+/// Common integer divide/remainder transforms\n+Instruction *InstCombinerImpl::commonIDivRemTransforms(BinaryOperator &I) {\n+ assert(I.isIntDivRem() && \"Unexpected instruction\");\n Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);\n- bool IsSigned = I.getOpcode() == Instruction::SDiv;\n+\n+ // If any element of a constant divisor fixed width vector is zero or undef\n+ // the behavior is undefined and we can fold the whole op to poison.\n+ auto *Op1C = dyn_cast<Constant>(Op1);\n Type *Ty = I.getType();\n+ auto *VTy = dyn_cast<FixedVectorType>(Ty);\n+ if (Op1C && VTy) {\n+ unsigned NumElts = VTy->getNumElements();\n+ for (unsigned i = 0; i != NumElts; ++i) {\n+ Constant *Elt = Op1C->getAggregateElement(i);\n+ if (Elt && (Elt->isNullValue() || isa<UndefValue>(Elt)))\n+ return replaceInstUsesWith(I, PoisonValue::get(Ty));\n+ }\n+ }\n+\n+ if (Instruction *Phi = foldBinopWithPhiOperands(I))\n+ return Phi;\n \n // The RHS is known non-zero.\n if (Value *V = simplifyValueKnownNonZero(I.getOperand(1), *this, I))\n return replaceOperand(I, 1, V);\n \n- // Handle cases involving: [su]div X, (select Cond, Y, Z)\n- // This does not apply for fdiv.\n+ // Handle cases involving: div/rem X, (select Cond, Y, Z)\n if (simplifyDivRemOfSelectWithZeroOp(I))\n return &I;\n \n // If the divisor is a select-of-constants, try to constant fold all div ops:\n- // C / (select Cond, TrueC, FalseC) --> select Cond, (C / TrueC), (C / FalseC)\n+ // C div/rem (select Cond, TrueC, FalseC) --> select Cond, (C div/rem TrueC),\n+ // (C div/rem FalseC)\n // TODO: Adapt simplifyDivRemOfSelectWithZeroOp to allow this and other folds.\n if (match(Op0, m_ImmConstant()) &&\n match(Op1, m_Select(m_Value(), m_ImmConstant(), m_ImmConstant()))) {\n@@ -1189,6 +1199,21 @@ Instruction *InstCombinerImpl::commonIDivTransforms(BinaryOperator &I) {\n return R;\n }\n \n+ return nullptr;\n+}\n+\n+/// This function implements the transforms common to both integer division\n+/// instructions (udiv and sdiv). It is called by the visitors to those integer\n+/// division instructions.\n+/// Common integer divide transforms\n+Instruction *InstCombinerImpl::commonIDivTransforms(BinaryOperator &I) {\n+ if (Instruction *Res = commonIDivRemTransforms(I))\n+ return Res;\n+\n+ Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);\n+ bool IsSigned = I.getOpcode() == Instruction::SDiv;\n+ Type *Ty = I.getType();\n+\n const APInt *C2;\n if (match(Op1, m_APInt(C2))) {\n Value *X;\n@@ -2138,29 +2163,11 @@ static Instruction *simplifyIRemMulShl(BinaryOperator &I,\n /// remainder instructions.\n /// Common integer remainder transforms\n Instruction *InstCombinerImpl::commonIRemTransforms(BinaryOperator &I) {\n- if (Instruction *Phi = foldBinopWithPhiOperands(I))\n- return Phi;\n+ if (Instruction *Res = commonIDivRemTransforms(I))\n+ return Res;\n \n Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);\n \n- // The RHS is known non-zero.\n- if (Value *V = simplifyValueKnownNonZero(I.getOperand(1), *this, I))\n- return replaceOperand(I, 1, V);\n-\n- // Handle cases involving: rem X, (select Cond, Y, Z)\n- if (simplifyDivRemOfSelectWithZeroOp(I))\n- return &I;\n-\n- // If the divisor is a select-of-constants, try to constant fold all rem ops:\n- // C % (select Cond, TrueC, FalseC) --> select Cond, (C % TrueC), (C % FalseC)\n- // TODO: Adapt simplifyDivRemOfSelectWithZeroOp to allow this and other folds.\n- if (match(Op0, m_ImmConstant()) &&\n- match(Op1, m_Select(m_Value(), m_ImmConstant(), m_ImmConstant()))) {\n- if (Instruction *R = FoldOpIntoSelect(I, cast<SelectInst>(Op1),\n- /*FoldWithMultiUse*/ true))\n- return R;\n- }\n-\n if (isa<Constant>(Op1)) {\n if (Instruction *Op0I = dyn_cast<Instruction>(Op0)) {\n if (SelectInst *SI = dyn_cast<SelectInst>(Op0I)) {\n", "tests": [{"file": "llvm/test/Transforms/InstCombine/div.ll", "commands": ["opt < %s -passes=instcombine -S"], "tests": [{"test_name": "sdiv_constant_dividend_select_of_constants_divisor_vec", "test_body": "define <2 x i8> @sdiv_constant_dividend_select_of_constants_divisor_vec(i1 %b) {\n %s = select i1 %b, <2 x i8> <i8 12, i8 -5>, <2 x i8> <i8 -4, i8 4>\n %r = sdiv <2 x i8> <i8 42, i8 -42>, %s\n ret <2 x i8> %r\n}\n"}, {"test_name": "udiv_constant_dividend_select_of_constants_divisor_vec", "test_body": "define <2 x i8> @udiv_constant_dividend_select_of_constants_divisor_vec(i1 %b) {\n %s = select i1 %b, <2 x i8> <i8 12, i8 -5>, <2 x i8> <i8 -4, i8 4>\n %r = udiv <2 x i8> <i8 42, i8 -42>, %s\n ret <2 x i8> %r\n}\n"}, {"test_name": "sdiv_constant_dividend_select_of_constants_divisor_vec_ub1", "test_body": "define <2 x i8> @sdiv_constant_dividend_select_of_constants_divisor_vec_ub1(i1 %b) {\n %s = select i1 %b, <2 x i8> <i8 0, i8 -5>, <2 x i8> <i8 -4, i8 4>\n %r = sdiv <2 x i8> <i8 42, i8 -42>, %s\n ret <2 x i8> %r\n}\n"}, {"test_name": "udiv_constant_dividend_select_of_constants_divisor_vec_ub1", "test_body": "define <2 x i8> @udiv_constant_dividend_select_of_constants_divisor_vec_ub1(i1 %b) {\n %s = select i1 %b, <2 x i8> <i8 0, i8 -5>, <2 x i8> <i8 -4, i8 4>\n %r = udiv <2 x i8> <i8 42, i8 -42>, %s\n ret <2 x i8> %r\n}\n"}]}, {"file": "llvm/test/Transforms/InstCombine/rem.ll", "commands": ["opt < %s -passes=instcombine -S"], "tests": [{"test_name": "urem_constant_dividend_select_of_constants_divisor_vec_ub1", "test_body": "define <2 x i8> @urem_constant_dividend_select_of_constants_divisor_vec_ub1(i1 %b) {\n %s = select i1 %b, <2 x i8> <i8 0, i8 -5>, <2 x i8> <i8 -4, i8 4>\n %r = urem <2 x i8> <i8 42, i8 -42>, %s\n ret <2 x i8> %r\n}\n"}, {"test_name": "urem_constant_dividend_select_of_constants_divisor_vec", "test_body": "define <2 x i8> @urem_constant_dividend_select_of_constants_divisor_vec(i1 %b) {\n %s = select i1 %b, <2 x i8> <i8 12, i8 -5>, <2 x i8> <i8 -4, i8 4>\n %r = urem <2 x i8> <i8 42, i8 -42>, %s\n ret <2 x i8> %r\n}\n"}]}, {"file": "llvm/test/Transforms/InstCombine/vector-udiv.ll", "commands": ["opt < %s -passes=instcombine -S"], "tests": [{"test_name": "vec_select_udiv_poison", "test_body": "define <2 x i32> @vec_select_udiv_poison(<2 x i1> %x) {\n %sel = select <2 x i1> %x, <2 x i32> splat (i32 -1), <2 x i32> <i32 0, i32 1>\n %div = udiv <2 x i32> <i32 42, i32 -7>, %sel\n ret <2 x i32> %div\n}\n"}, {"test_name": "test_v4i32_zext_shl_const_pow2", "test_body": "define <4 x i32> @test_v4i32_zext_shl_const_pow2(<4 x i32> %a0, <4 x i16> %a1) {\n %1 = shl <4 x i16> <i16 4, i16 8, i16 16, i16 32>, %a1\n %2 = zext <4 x i16> %1 to <4 x i32>\n %3 = udiv <4 x i32> %a0, %2\n ret <4 x i32> %3\n}\n"}]}, {"file": "llvm/test/Transforms/InstSimplify/div.ll", "commands": ["opt < %s -passes=instsimplify -S"], "tests": [{"test_name": "udiv_zero_elt_vec", "test_body": "define <2 x i8> @udiv_zero_elt_vec(<2 x i8> %x) {\n %div = udiv <2 x i8> %x, <i8 0, i8 42>\n ret <2 x i8> %div\n}\n"}, {"test_name": "sdiv_zero_elt_vec", "test_body": "define <2 x i8> @sdiv_zero_elt_vec(<2 x i8> %x) {\n %div = sdiv <2 x i8> %x, <i8 -42, i8 0>\n ret <2 x i8> %div\n}\n"}, {"test_name": "udiv_poison_elt_vec", "test_body": "define <2 x i8> @udiv_poison_elt_vec(<2 x i8> %x) {\n %div = udiv <2 x i8> %x, <i8 poison, i8 42>\n ret <2 x i8> %div\n}\n"}, {"test_name": "sdiv_zero_elt_vec_constfold", "test_body": "define <2 x i8> @sdiv_zero_elt_vec_constfold(<2 x i8> %x) {\n %div = sdiv <2 x i8> <i8 1, i8 2>, <i8 0, i8 -42>\n ret <2 x i8> %div\n}\n"}, {"test_name": "sdiv_poison_elt_vec", "test_body": "define <2 x i8> @sdiv_poison_elt_vec(<2 x i8> %x) {\n %div = sdiv <2 x i8> %x, <i8 -42, i8 poison>\n ret <2 x i8> %div\n}\n"}, {"test_name": "udiv_zero_elt_vec_constfold", "test_body": "define <2 x i8> @udiv_zero_elt_vec_constfold(<2 x i8> %x) {\n %div = udiv <2 x i8> <i8 1, i8 2>, <i8 42, i8 0>\n ret <2 x i8> %div\n}\n"}, {"test_name": "zero_dividend_vector_poison_elt", "test_body": "define <2 x i32> @zero_dividend_vector_poison_elt(<2 x i32> %A) {\n %B = sdiv <2 x i32> <i32 0, i32 poison>, %A\n ret <2 x i32> %B\n}\n"}]}, {"file": "llvm/test/Transforms/InstSimplify/rem.ll", "commands": ["opt < %s -passes=instsimplify -S"], "tests": [{"test_name": "srem_zero_elt_vec_constfold", "test_body": "define <2 x i8> @srem_zero_elt_vec_constfold(<2 x i8> %x) {\n %rem = srem <2 x i8> <i8 1, i8 2>, <i8 0, i8 -42>\n ret <2 x i8> %rem\n}\n"}, {"test_name": "urem_zero_elt_vec", "test_body": "define <2 x i8> @urem_zero_elt_vec(<2 x i8> %x) {\n %rem = urem <2 x i8> %x, <i8 0, i8 42>\n ret <2 x i8> %rem\n}\n"}, {"test_name": "urem_zero_elt_vec_constfold", "test_body": "define <2 x i8> @urem_zero_elt_vec_constfold(<2 x i8> %x) {\n %rem = urem <2 x i8> <i8 1, i8 2>, <i8 42, i8 0>\n ret <2 x i8> %rem\n}\n"}, {"test_name": "srem_undef_elt_vec", "test_body": "define <2 x i8> @srem_undef_elt_vec(<2 x i8> %x) {\n %rem = srem <2 x i8> %x, <i8 -42, i8 undef>\n ret <2 x i8> %rem\n}\n"}, {"test_name": "urem_undef_elt_vec", "test_body": "define <2 x i8> @urem_undef_elt_vec(<2 x i8> %x) {\n %rem = urem <2 x i8> %x, <i8 undef, i8 42>\n ret <2 x i8> %rem\n}\n"}, {"test_name": "zero_dividend_vector_poison_elt", "test_body": "define <2 x i32> @zero_dividend_vector_poison_elt(<2 x i32> %A) {\n %B = urem <2 x i32> <i32 poison, i32 0>, %A\n ret <2 x i32> %B\n}\n"}, {"test_name": "srem_zero_elt_vec", "test_body": "define <2 x i8> @srem_zero_elt_vec(<2 x i8> %x) {\n %rem = srem <2 x i8> %x, <i8 -42, i8 0>\n ret <2 x i8> %rem\n}\n"}]}], "issue": {"title": "[InstCombine] miscompilation of `or` of vectors", "body": "Alive2 report: https://alive2.llvm.org/ce/z/LyM8sY\r\n\r\n```llvm\r\n----------------------------------------\r\ndefine <2 x i32> @or_sext_to_sel_constant_vec.3(<2 x i1> %y) {\r\n#0:\r\n %sext = sext <2 x i1> %y to <2 x i32>\r\n %#1 = or <2 x i32> %sext, { 0, 1 }\r\n %#2 = udiv <2 x i32> { 42, 4294967289 }, %#1\r\n ret <2 x i32> %#2\r\n}\r\n=>\r\ndefine <2 x i32> @or_sext_to_sel_constant_vec.3(<2 x i1> %y) {\r\n#0:\r\n ret <2 x i32> { 0, 0 }\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Value mismatch\r\n\r\nExample:\r\n<2 x i1> %y = < #x1 (1), #x0 (0) >\r\n\r\nSource:\r\n<2 x i32> %sext = < #xffffffff (4294967295, -1), #x00000000 (0) >\r\n<2 x i32> %#1 = < #xffffffff (4294967295, -1), #x00000001 (1) >\r\n<2 x i32> %#2 = < #x00000000 (0), #xfffffff9 (4294967289, -7) >\r\n\r\nTarget:\r\nSource value: < #x00000000 (0), #xfffffff9 (4294967289, -7) >\r\nTarget value: < #x00000000 (0), #x00000000 (0) >\r\n\r\n\r\n----------------------------------------\r\ndefine <2 x i32> @or_sext_to_sel_constant_vec.2(<2 x i1> %y) {\r\n#0:\r\n %sext = sext <2 x i1> %y to <2 x i32>\r\n %#1 = or <2 x i32> %sext, { 0, 1 }\r\n %#2 = sdiv <2 x i32> { 42, 4294967289 }, %#1\r\n %#3 = udiv exact <2 x i32> %#2, %#2\r\n %#4 = or <2 x i32> %#2, %#2\r\n ret <2 x i32> %#4\r\n}\r\n=>\r\ndefine <2 x i32> @or_sext_to_sel_constant_vec.2(<2 x i1> %y) {\r\n#0:\r\n ret <2 x i32> { 4294967254, 7 }\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Value mismatch\r\n\r\nExample:\r\n<2 x i1> %y = < #x1 (1), #x0 (0) >\r\n\r\nSource:\r\n<2 x i32> %sext = < #xffffffff (4294967295, -1), #x00000000 (0) >\r\n<2 x i32> %#1 = < #xffffffff (4294967295, -1), #x00000001 (1) >\r\n<2 x i32> %#2 = < #xffffffd6 (4294967254, -42), #xfffffff9 (4294967289, -7) >\r\n<2 x i32> %#3 = < #x00000001 (1), #x00000001 (1) >\r\n<2 x i32> %#4 = < #xffffffd6 (4294967254, -42), #xfffffff9 (4294967289, -7) >\r\n\r\nTarget:\r\nSource value: < #xffffffd6 (4294967254, -42), #xfffffff9 (4294967289, -7) >\r\nTarget value: < #xffffffd6 (4294967254, -42), #x00000007 (7) >\r\n\r\nSummary:\r\n 0 correct transformations\r\n 2 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\n```", "author": "bongjunj", "labels": ["miscompilation", "llvm:instcombine", "llvm:analysis"], "comments": [{"author": "dtcxzyw", "body": "@bongjunj Feel free to ping me if you find new InstCombine miscompilation bugs without involving undef values/NaN payloads."}, {"author": "dtcxzyw", "body": "https://github.com/llvm/llvm-project/blob/eac2c182c6f852fc187af9952250a43d6fb17b28/llvm/lib/Analysis/InstructionSimplify.cpp#L1098-L1109\r\n\r\nWe cannot do this simplification when threading udiv over selects.\r\n "}]}, "verified": true}
|
251 |
{"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 <[email protected]>\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<llvm::SCEVExpander, llvm::Value*>::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<llvm::SCEVExpander, llvm::Value*>::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::Instruction*>&, llvm::SCEVAddRecExpr const*, llvm::SCEV const*, bool, bool) LoopIdiomRecognize.cpp:0:0\r\n#21 0x00007fc24ce539b7 (anonymous namespace)::LoopIdiomRecognize::processLoopStores(llvm::SmallVectorImpl<llvm::StoreInst*>&, 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::Loop, llvm::LoopStandardAnalysisResults&>&, 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::Loop, llvm::LoopIdiomRecognizePass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x378c6c6)\r\n#25 0x00007fc24ce7544f std::optional<llvm::PreservedAnalyses> llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::runSinglePass<llvm::Loop, std::unique_ptr<llvm::detail::PassConcept<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>, std::default_delete<llvm::detail::PassConcept<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>>>>(llvm::Loop&, std::unique_ptr<llvm::detail::PassConcept<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>, std::default_delete<llvm::detail::PassConcept<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>>>&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, 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::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::runWithoutLoopNestPasses(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1f136f6)\r\n#27 0x00007fc24ce76b0d llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, 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<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1f15d62)\r\n#29 0x00007fc24e6eb0c6 llvm::detail::PassModel<llvm::Function, llvm::FunctionToLoopPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x37890c6)\r\n#30 0x00007fc24ba8a40d llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0xb2840d)\r\n#31 0x00007fc24e6e41a6 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x37821a6)\r\n#32 0x00007fc24ba88c9d llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0xb26c9d)\r\n#33 0x00007fc24e6eb026 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x3789026)\r\n#34 0x00007fc24ba86c1d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/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::PassPlugin>, 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}
|
252 |
{"bug_id": "113516", "issue_url": "https://github.com/llvm/llvm-project/issues/113516", "bug_type": "crash", "base_commit": "0aec4d2b78a08f5f3e4b0ad0340a99e486d00110", "knowledge_cutoff": "2024-10-24T03:05:37Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "d2e7ee77d33e8b3be3b1d4e9bc5bc4c60b62b554", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[16118, 16124]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["BoUpSLP::vectorizeTree"]}}, "patch": "commit d2e7ee77d33e8b3be3b1d4e9bc5bc4c60b62b554\nAuthor: Alexey Bataev <[email protected]>\nDate: Thu Oct 24 08:15:21 2024 -0700\n\n [SLP]Do not check for clustered loads only\n \n Since SLP support \"clusterization\" of the non-load instructions, the\n restriction for reduced values for loads only should be removed to avoid\n compiler crash.\n \n Fixes #113516\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex f76e913a57d5..012d85353f08 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -16118,7 +16118,7 @@ BoUpSLP::vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues,\n for (Instruction *I : RemovedInsts) {\n const TreeEntry *IE = getTreeEntry(I);\n if (IE->Idx != 0 &&\n- !(VectorizableTree.front()->isGather() && isa<LoadInst>(I) &&\n+ !(VectorizableTree.front()->isGather() &&\n !IE->UserTreeIndices.empty() &&\n any_of(IE->UserTreeIndices,\n [&](const EdgeInfo &EI) {\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/X86/non-load-reduced-as-part-of-bv.ll", "commands": ["opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s"], "tests": [{"test_name": "foo", "test_body": "define i1 @foo() {\nentry:\n %tobool.not.not509.i.1311.i.i = icmp ne i32 0, 0\n %cmp80.1319.i.i189 = icmp sgt i32 0, 0\n %tobool.not.not509.i.1.1.i.i = icmp ne i32 0, 0\n %cmp80.1.1.i.i190 = icmp sgt i32 0, 0\n %tobool.not.not509.i.2329.i.i = icmp ne i32 0, 0\n %storemerge.2333.i.i = select i1 %tobool.not.not509.i.2329.i.i, i32 0, i32 0\n %cmp80.2337.i.i192 = icmp sgt i32 0, 0\n %tobool.not.not509.i.1.2.i.i = icmp ne i32 %storemerge.2333.i.i, 0\n %cmp80.1.2.i.i193 = icmp sgt i32 0, 0\n %cmp80.1.2.i.i = select i1 %tobool.not.not509.i.1.2.i.i, i1 %cmp80.1.2.i.i193, i1 false\n %0 = select i1 %cmp80.1.2.i.i, i1 %tobool.not.not509.i.2329.i.i, i1 false\n %1 = select i1 %0, i1 %cmp80.2337.i.i192, i1 false\n %2 = select i1 %1, i1 false, i1 false\n %3 = select i1 %2, i1 %tobool.not.not509.i.1.1.i.i, i1 false\n %4 = select i1 %3, i1 %cmp80.1.1.i.i190, i1 false\n %5 = select i1 %4, i1 %tobool.not.not509.i.1311.i.i, i1 false\n %6 = select i1 %5, i1 %cmp80.1319.i.i189, i1 false\n ret i1 %6\n}\n"}]}], "issue": {"title": "[SLPVectorizer] Assertion `(I->use_empty() || all_of(I->uses(), [&](Use &U) { return isDeleted( cast<Instruction>(U.getUser())); })) && \"trying to erase instruction with users.\"' failed.", "body": "Reduced reproducer: https://godbolt.org/z/azEc6zjod\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 @foo() {\r\nentry:\r\n %tobool.not.not509.i.1311.i.i = icmp ne i32 0, 0\r\n %cmp80.1319.i.i189 = icmp sgt i32 0, 0\r\n %tobool.not.not509.i.1.1.i.i = icmp ne i32 0, 0\r\n %cmp80.1.1.i.i190 = icmp sgt i32 0, 0\r\n %tobool.not.not509.i.2329.i.i = icmp ne i32 0, 0\r\n %storemerge.2333.i.i = select i1 %tobool.not.not509.i.2329.i.i, i32 0, i32 0\r\n %cmp80.2337.i.i192 = icmp sgt i32 0, 0\r\n %tobool.not.not509.i.1.2.i.i = icmp ne i32 %storemerge.2333.i.i, 0\r\n %cmp80.1.2.i.i193 = icmp sgt i32 0, 0\r\n %cmp80.1.2.i.i = select i1 %tobool.not.not509.i.1.2.i.i, i1 %cmp80.1.2.i.i193, i1 false\r\n %0 = select i1 %cmp80.1.2.i.i, i1 %tobool.not.not509.i.2329.i.i, i1 false\r\n %1 = select i1 %0, i1 %cmp80.2337.i.i192, i1 false\r\n %2 = select i1 %1, i1 false, i1 false\r\n %3 = select i1 %2, i1 %tobool.not.not509.i.1.1.i.i, i1 false\r\n %4 = select i1 %3, i1 %cmp80.1.1.i.i190, i1 false\r\n %5 = select i1 %4, i1 %tobool.not.not509.i.1311.i.i, i1 false\r\n %6 = select i1 %5, i1 %cmp80.1319.i.i189, i1 false\r\n ret i1 %6\r\n}\r\n```\r\n```\r\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:2748: void llvm::slpvectorizer::BoUpSLP::removeInstructionsAndOperands(llvm::ArrayRef<U*>) [with T = llvm::Instruction]: Assertion `(I->use_empty() || all_of(I->uses(), [&](Use &U) { return isDeleted( cast<Instruction>(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 <source>\r\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\r\n2.\tRunning pass \"slp-vectorizer\" on function \"foo\"\r\n #0 0x00000000050d8608 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x50d8608)\r\n #1 0x00000000050d5fbc SignalHandler(int) Signals.cpp:0:0\r\n #2 0x000071afd7642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000071afd76969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x000071afd7642476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x000071afd76287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x000071afd762871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x000071afd7639e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x000000000414e3af void llvm::slpvectorizer::BoUpSLP::removeInstructionsAndOperands<llvm::Instruction>(llvm::ArrayRef<llvm::Instruction*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x414e3af)\r\n #9 0x00000000041aa335 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::SmallDenseSet<llvm::Value*, 4u, llvm::DenseMapInfo<llvm::Value*, void>> const&, llvm::Instruction*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41aa335)\r\n#10 0x00000000041bcd90 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\r\n#11 0x00000000041bfb71 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41bfb71)\r\n#12 0x00000000041c431b llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0\r\n#13 0x00000000041c8ae8 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41c8ae8)\r\n#14 0x00000000041cf231 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 0x00000000041cfedb llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41cfedb)\r\n#16 0x0000000002f64f0e llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2f64f0e)\r\n#17 0x0000000004ed9788 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4ed9788)\r\n#18 0x0000000000e2773e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe2773e)\r\n#19 0x0000000004ed81ae llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4ed81ae)\r\n#20 0x0000000000e26e8e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe26e8e)\r\n#21 0x0000000004ed7be0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4ed7be0)\r\n#22 0x000000000090a07a llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x90a07a)\r\n#23 0x00000000008fce7c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8fce7c)\r\n#24 0x000071afd7629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#25 0x000071afd7629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#26 0x00000000008f493e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f493e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```\r\nllvm version: 33363521ca24f912cc25530f6cecbca53acce8a3", "author": "dtcxzyw", "labels": ["llvm:SLPVectorizer", "crash-on-valid"], "comments": []}, "verified": true}
|
|
|
246 |
{"bug_id": "87378", "issue_url": "https://github.com/llvm/llvm-project/issues/87378", "bug_type": "crash", "base_commit": "d8db13edd60b195e6692deb04d63e633319e486a", "knowledge_cutoff": "2024-04-02T17:38:53Z", "lit_test_dir": ["llvm/test/Transforms/LoopVectorize"], "hints": {"fix_commit": "6261c53c6f9c82bfca5df2ed5917876d748ed079", "components": ["LoopVectorize"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": [[175, 181]], "llvm/lib/Transforms/Vectorize/VPlan.h": [[913, 918], [920, 928], [1016, 1021], [1221, 1226]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": ["createOr", "createSelect"], "llvm/lib/Transforms/Vectorize/VPlan.h": ["GEPFlagsTy", "VPInstruction", "VPRecipeWithIRFlags"]}}, "patch": "commit 6261c53c6f9c82bfca5df2ed5917876d748ed079\nAuthor: Florian Hahn <[email protected]>\nDate: Tue Apr 2 21:48:35 2024 +0100\n\n [VPlan] Make sure OR VPInstructions are treated as disjoint ops.\n \n Make sure that VPInstructions with OR opcodes are properly registered as\n disjoint ops.\n \n Fixes https://github.com/llvm/llvm-project/issues/87378.\n\ndiff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h\nindex 5d03b66b0ce3..ebca2d855a46 100644\n--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h\n+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h\n@@ -175,7 +175,10 @@ public:\n \n VPValue *createOr(VPValue *LHS, VPValue *RHS, DebugLoc DL = {},\n const Twine &Name = \"\") {\n- return createInstruction(Instruction::BinaryOps::Or, {LHS, RHS}, DL, Name);\n+\n+ return tryInsertInstruction(new VPInstruction(\n+ Instruction::BinaryOps::Or, {LHS, RHS},\n+ VPRecipeWithIRFlags::DisjointFlagsTy(false), DL, Name));\n }\n \n VPValue *createSelect(VPValue *Cond, VPValue *TrueVal, VPValue *FalseVal,\ndiff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h\nindex 3baca43f7276..707a826ecdc2 100644\n--- a/llvm/lib/Transforms/Vectorize/VPlan.h\n+++ b/llvm/lib/Transforms/Vectorize/VPlan.h\n@@ -913,6 +913,11 @@ public:\n WrapFlagsTy(bool HasNUW, bool HasNSW) : HasNUW(HasNUW), HasNSW(HasNSW) {}\n };\n \n+ struct DisjointFlagsTy {\n+ char IsDisjoint : 1;\n+ DisjointFlagsTy(bool IsDisjoint) : IsDisjoint(IsDisjoint) {}\n+ };\n+\n protected:\n struct GEPFlagsTy {\n char IsInBounds : 1;\n@@ -920,9 +925,6 @@ protected:\n };\n \n private:\n- struct DisjointFlagsTy {\n- char IsDisjoint : 1;\n- };\n struct ExactFlagsTy {\n char IsExact : 1;\n };\n@@ -1016,6 +1018,12 @@ public:\n : VPSingleDefRecipe(SC, Operands, DL), OpType(OperationType::FPMathOp),\n FMFs(FMFs) {}\n \n+ template <typename IterT>\n+ VPRecipeWithIRFlags(const unsigned char SC, IterT Operands,\n+ DisjointFlagsTy DisjointFlags, DebugLoc DL = {})\n+ : VPSingleDefRecipe(SC, Operands, DL), OpType(OperationType::DisjointOp),\n+ DisjointFlags(DisjointFlags) {}\n+\n protected:\n template <typename IterT>\n VPRecipeWithIRFlags(const unsigned char SC, IterT Operands,\n@@ -1221,6 +1229,14 @@ public:\n : VPRecipeWithIRFlags(VPDef::VPInstructionSC, Operands, WrapFlags, DL),\n Opcode(Opcode), Name(Name.str()) {}\n \n+ VPInstruction(unsigned Opcode, std::initializer_list<VPValue *> Operands,\n+ DisjointFlagsTy DisjointFlag, DebugLoc DL = {},\n+ const Twine &Name = \"\")\n+ : VPRecipeWithIRFlags(VPDef::VPInstructionSC, Operands, DisjointFlag, DL),\n+ Opcode(Opcode), Name(Name.str()) {\n+ assert(Opcode == Instruction::Or && \"only OR opcodes can be disjoint\");\n+ }\n+\n VPInstruction(unsigned Opcode, std::initializer_list<VPValue *> Operands,\n FastMathFlags FMFs, DebugLoc DL = {}, const Twine &Name = \"\");\n \n", "tests": [{"file": "llvm/test/Transforms/LoopVectorize/pr87378-vpinstruction-or-drop-poison-generating-flags.ll", "commands": ["opt -p loop-vectorize -mattr=\"+v\" -S %s"], "tests": [{"test_name": "<module>", "test_body": "\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\n; Test case for https://github.com/llvm/llvm-project/issues/87378.\ndefine void @pr87378_vpinstruction_or_drop_poison_generating_flags(ptr %arg, i64 %a, i64 %b, i64 %c) {\n;\nentry:\n br label %loop.header\n\nloop.header:\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %c.1 = icmp ule i64 %iv, %a\n br i1 %c.1, label %then.1, label %else.1\n\nthen.1:\n %c.2 = icmp ule i64 %iv, %b\n br i1 %c.2, label %else.1, label %merge\n\nelse.1:\n %c.3 = icmp ule i64 %iv, %c\n br i1 %c.3, label %then.2, label %loop.latch\n\nthen.2:\n br label %merge\n\nmerge:\n %idx = phi i64 [ poison, %then.1 ], [ %iv, %then.2 ]\n %getelementptr = getelementptr i16, ptr %arg, i64 %idx\n store i16 0, ptr %getelementptr, align 2\n br label %loop.latch\n\nloop.latch:\n %iv.next = add i64 %iv, 1\n %icmp = icmp eq i64 %iv, 1000\n br i1 %icmp, label %exit, label %loop.header\n\nexit:\n ret void\n}\n;.\n;."}]}], "issue": {"title": "[LoopVectorize] Assertion `OpType == OperationType::DisjointOp && \"recipe cannot have a disjoing flag\"' failed.", "body": "Reduced LLVM IR:\r\n``` llvm ir\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 i32 @main() #0 {\r\nentry:\r\n br label %for.body300.us.us.i\r\n\r\nfor.body300.us.us.i: ; preds = %if.end559.us.us.i, %entry\r\n br label %for.body326.us.us.i\r\n\r\nfor.body326.us.us.i: ; preds = %if.end559.us.us.i, %for.body300.us.us.i\r\n %indvars.iv18 = phi i64 [ 0, %for.body300.us.us.i ], [ %indvars.iv.next19, %if.end559.us.us.i ]\r\n br i1 false, label %cond.end339.us.us.i, label %cond.end354.us.us.i\r\n\r\ncond.end339.us.us.i: ; preds = %for.body326.us.us.i\r\n br i1 false, label %cond.end339.us.us.i.if.then357.us.us.i_crit_edge, label %cond.end339.us.us.i.cond.end354.us.us.i_crit_edge\r\n\r\ncond.end339.us.us.i.cond.end354.us.us.i_crit_edge: ; preds = %cond.end339.us.us.i\r\n br label %cond.end354.us.us.i\r\n\r\ncond.end339.us.us.i.if.then357.us.us.i_crit_edge: ; preds = %cond.end339.us.us.i\r\n br label %if.then357.us.us.i\r\n\r\ncond.end354.us.us.i: ; preds = %cond.end339.us.us.i.cond.end354.us.us.i_crit_edge, %for.body326.us.us.i\r\n br i1 false, label %cond.end354.us.us.i.if.then357.us.us.i_crit_edge, label %if.end559.us.us.i\r\n\r\ncond.end354.us.us.i.if.then357.us.us.i_crit_edge: ; preds = %cond.end354.us.us.i\r\n br label %if.then357.us.us.i\r\n\r\nif.then357.us.us.i: ; preds = %cond.end354.us.us.i.if.then357.us.us.i_crit_edge, %cond.end339.us.us.i.if.then357.us.us.i_crit_edge\r\n %.pre1143.i7 = phi i64 [ poison, %cond.end339.us.us.i.if.then357.us.us.i_crit_edge ], [ %indvars.iv18, %cond.end354.us.us.i.if.then357.us.us.i_crit_edge ]\r\n %arrayidx429.us.us.i = getelementptr [14 x i16], ptr null, i64 0, i64 %.pre1143.i7\r\n store i16 0, ptr %arrayidx429.us.us.i, align 2\r\n br label %if.end559.us.us.i\r\n\r\nif.end559.us.us.i: ; preds = %if.then357.us.us.i, %cond.end354.us.us.i\r\n %indvars.iv.next19 = add i64 %indvars.iv18, 1\r\n %0 = trunc i64 %indvars.iv18 to i32\r\n %cmp323.us.us.i = icmp slt i32 %0, 1\r\n br i1 %cmp323.us.us.i, label %for.body326.us.us.i, label %for.body300.us.us.i\r\n}\r\n\r\nattributes #0 = { \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl256b,+zvl32b,+zvl64b,-e,-experimental-smmpm,-experimental-smnpm,-experimental-ssnpm,-experimental-sspm,-experimental-ssqosid,-experimental-supm,-experimental-zaamo,-experimental-zabha,-experimental-zalasr,-experimental-zalrsc,-experimental-zcmop,-experimental-zfbfmin,-experimental-zicfilp,-experimental-zicfiss,-experimental-zimop,-experimental-ztso,-experimental-zvfbfmin,-experimental-zvfbfwma,-h,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smepmp,-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,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmp,-zcmt,-zdinx,-zfa,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zihintntl,-zihintpause,-zihpm,-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,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b\" }\r\n```\r\n\r\nBacktrace:\r\n```\r\nopt: /scratch/tc-testing/tc-apr-2/llvm/llvm/lib/Transforms/Vectorize/VPlan.h:1131: bool llvm::VPRecipeWithIRFlags::isDisjoint() const: Assertion `OpType == OperationType::DisjointOp && \"recipe cannot have a disjoing flag\"' 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-apr-2/build-rv64gcv/build-llvm-linux/bin/opt reduced.ll --passes=loop-vectorize\r\n #0 0x00005bd204995b60 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2d84b60)\r\n #1 0x00005bd204992f6f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2d81f6f)\r\n #2 0x00005bd2049930c5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x000076eef1a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x000076eef1a969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x000076eef1a969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x000076eef1a969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x000076eef1a42476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x000076eef1a287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x000076eef1a2871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x000076eef1a39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x00005bd203b25ea2 llvm::VPlanTransforms::dropPoisonGeneratingRecipes(llvm::VPlan&, llvm::function_ref<bool (llvm::BasicBlock*)>)::'lambda'(llvm::VPRecipeBase*)::operator()(llvm::VPRecipeBase*) const VPlanTransforms.cpp:0:0\r\n#12 0x00005bd203b2c77d llvm::VPlanTransforms::dropPoisonGeneratingRecipes(llvm::VPlan&, llvm::function_ref<bool (llvm::BasicBlock*)>) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1f1b77d)\r\n#13 0x00005bd203a05435 llvm::LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(llvm::VFRange&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1df4435)\r\n#14 0x00005bd203a05c9e llvm::LoopVectorizationPlanner::buildVPlansWithVPRecipes(llvm::ElementCount, llvm::ElementCount) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1df4c9e)\r\n#15 0x00005bd203a0c319 llvm::LoopVectorizationPlanner::plan(llvm::ElementCount, unsigned int) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1dfb319)\r\n#16 0x00005bd203a0f8a9 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1dfe8a9)\r\n#17 0x00005bd203a1273e 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*) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1e0173e)\r\n#18 0x00005bd203a1388d llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1e0288d)\r\n#19 0x00005bd20291a276 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0xd09276)\r\n#20 0x00005bd2047bc141 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2bab141)\r\n#21 0x00005bd202911bd6 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0xd00bd6)\r\n#22 0x00005bd2047bae3b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2ba9e3b)\r\n#23 0x00005bd202919dc6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0xd08dc6)\r\n#24 0x00005bd2047b8cb1 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2ba7cb1)\r\n#25 0x00005bd202193ce5 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x582ce5)\r\n#26 0x00005bd202186316 optMain (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x575316)\r\n#27 0x000076eef1a29d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#28 0x000076eef1a29e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#29 0x000076eef1a29e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#30 0x00005bd20217bf95 _start (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x56af95)\r\nzsh: IOT instruction (core dumped) /scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt reduced.l\r\n```\r\n\r\nGodbolt: https://godbolt.org/z/jj39h3z7M\r\n\r\nMinor spelling nit: `disjoing -> disjoint`\r\n\r\nFound via fuzzer.\r\n\r\nLikely caused/exposed by https://github.com/llvm/llvm-project/commit/6ef829941b38f7e8a28c4cba1ff25cd0ae9f7d3d https://github.com/llvm/llvm-project/pull/83821 @fhahn ", "author": "patrick-rivos", "labels": ["vectorizers", "crash"], "comments": []}, "verified": true}
|
247 |
{"bug_id": "121581", "issue_url": "https://github.com/llvm/llvm-project/issues/121581", "bug_type": "miscompilation", "base_commit": "95c5c5d4badf7c2128d098be325356e15c2197be", "knowledge_cutoff": "2025-01-03T16:31:11Z", "lit_test_dir": ["llvm/test/Transforms/InstCombine"], "hints": {"fix_commit": "fac46469977da9c4e9c6eeaac21103c971190577", "components": ["InstCombine"], "bug_location_lineno": {"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": [[747, 752], [764, 770], [804, 810]]}, "bug_location_funcname": {"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": ["InstCombinerImpl::foldGEPICmp"]}}, "patch": "commit fac46469977da9c4e9c6eeaac21103c971190577\nAuthor: Yingwei Zheng <[email protected]>\nDate: Sat Jan 4 17:23:57 2025 +0800\n\n [InstCombine] Check no wrap flags before folding icmp of GEPs with same indices (#121628)\n \n Alive2: https://alive2.llvm.org/ce/z/Dr3Sbe\n Closes https://github.com/llvm/llvm-project/issues/121581.\n\ndiff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp\nindex d6fdade25559..8b23583c5106 100644\n--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp\n+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp\n@@ -747,6 +747,8 @@ Instruction *InstCombinerImpl::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,\n ConstantExpr::getPointerBitCastOrAddrSpaceCast(\n cast<Constant>(RHS), Base->getType()));\n } else if (GEPOperator *GEPRHS = dyn_cast<GEPOperator>(RHS)) {\n+ GEPNoWrapFlags NW = GEPLHS->getNoWrapFlags() & GEPRHS->getNoWrapFlags();\n+\n // If the base pointers are different, but the indices are the same, just\n // compare the base pointer.\n if (PtrBase != GEPRHS->getOperand(0)) {\n@@ -764,7 +766,8 @@ Instruction *InstCombinerImpl::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,\n \n // If all indices are the same, just compare the base pointers.\n Type *BaseType = GEPLHS->getOperand(0)->getType();\n- if (IndicesTheSame && CmpInst::makeCmpResultType(BaseType) == I.getType())\n+ if (IndicesTheSame &&\n+ CmpInst::makeCmpResultType(BaseType) == I.getType() && CanFold(NW))\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n \n // If we're comparing GEPs with two base pointers that only differ in type\n@@ -804,7 +807,6 @@ Instruction *InstCombinerImpl::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,\n return transformToIndexedCompare(GEPLHS, RHS, Cond, DL, *this);\n }\n \n- GEPNoWrapFlags NW = GEPLHS->getNoWrapFlags() & GEPRHS->getNoWrapFlags();\n if (GEPLHS->getNumOperands() == GEPRHS->getNumOperands() &&\n GEPLHS->getSourceElementType() == GEPRHS->getSourceElementType()) {\n // If the GEPs only differ by one index, compare it.\n", "tests": [{"file": "llvm/test/Transforms/InstCombine/icmp-gep.ll", "commands": ["opt -passes=instcombine -S < %s"], "tests": [{"test_name": "pointer_icmp_aligned_with_offset_negative", "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 @pointer_icmp_aligned_with_offset_negative(ptr align 8 %a, ptr align 8 %a2) {\n %gep = getelementptr i8, ptr %a, i64 8\n %cmp = icmp eq ptr %gep, %a2\n ret i1 %cmp\n}\n"}, {"test_name": "gep_diff_base_same_indices_nuw_nusw", "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 @gep_diff_base_same_indices_nuw_nusw(ptr %x, ptr %y, i64 %z) {\n %gep1 = getelementptr nuw i8, ptr %x, i64 %z\n %gep2 = getelementptr nusw i8, ptr %y, i64 %z\n %cmp = icmp ult ptr %gep1, %gep2\n ret i1 %cmp\n}\n"}, {"test_name": "gep_diff_base_same_indices", "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 @gep_diff_base_same_indices(ptr %x, ptr %y, i64 %z) {\n %gep1 = getelementptr i8, ptr %x, i64 %z\n %gep2 = getelementptr i8, ptr %y, i64 %z\n %cmp = icmp ult ptr %gep1, %gep2\n ret i1 %cmp\n}\n"}, {"test_name": "gep_diff_base_same_indices_nusw", "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 @gep_diff_base_same_indices_nusw(ptr %x, ptr %y, i64 %z) {\n %gep1 = getelementptr nusw i8, ptr %x, i64 %z\n %gep2 = getelementptr nusw i8, ptr %y, i64 %z\n %cmp = icmp ult ptr %gep1, %gep2\n ret i1 %cmp\n}\n"}, {"test_name": "gep_diff_base_same_indices_nuw", "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 @gep_diff_base_same_indices_nuw(ptr %x, ptr %y, i64 %z) {\n %gep1 = getelementptr nuw i8, ptr %x, i64 %z\n %gep2 = getelementptr nuw i8, ptr %y, i64 %z\n %cmp = icmp ult ptr %gep1, %gep2\n ret i1 %cmp\n}\n"}]}], "issue": {"title": "[InstCombine] Incorrect fold of the comparison of GEPs", "body": "Alive2: https://alive2.llvm.org/ce/z/HRsqeW\n```\ndefine i1 @test(ptr %x, ptr %y) {\n %gep1 = getelementptr i8, ptr %x, i32 1\n %gep2 = getelementptr i8, ptr %y, i32 1\n %cmp = icmp ult ptr %gep1, %gep2\n ret i1 %cmp\n}\n```\n```\n\n----------------------------------------\ndefine i1 @test(ptr %x, ptr %y) {\n#0:\n %gep1 = gep ptr %x, 1 x i32 1\n %gep2 = gep ptr %y, 1 x i32 1\n %cmp = icmp ult ptr %gep1, %gep2\n ret i1 %cmp\n}\n=>\ndefine i1 @test(ptr %x, ptr %y) {\n#0:\n %cmp = icmp ult ptr %x, %y\n ret i1 %cmp\n}\nTransformation doesn't verify!\n\nERROR: Value mismatch\n\nExample:\nptr %x = pointer(non-local, block_id=0, offset=-1) / Address=#xf\nptr %y = null\n\nSource:\nptr %gep1 = null\nptr %gep2 = pointer(non-local, block_id=0, offset=1) / Address=#x1\ni1 %cmp = #x1 (1)\n\nSOURCE MEMORY STATE\n===================\nNON-LOCAL BLOCKS:\nBlock 0 >\tsize: 0\talign: 1\talloc type: 0\talive: false\taddress: 0\nBlock 1 >\tsize: 1\talign: 2\talloc type: 0\talive: true\taddress: 2\nBlock 2 >\tsize: 0\talign: 1\talloc type: 0\talive: true\taddress: 3\n\nTarget:\ni1 %cmp = #x0 (0)\nSource value: #x1 (1)\nTarget value: #x0 (0)\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}
|
248 |
{"bug_id": "117517", "issue_url": "https://github.com/llvm/llvm-project/issues/117517", "bug_type": "crash", "base_commit": "7e3187e12a2cef8b2552e08ce9423aca9c09d813", "knowledge_cutoff": "2024-11-25T05:18:47Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "57bbdbd7ae3698a274edd4dd6ef1b53d9129e552", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[1143, 1151]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["addMask"]}}, "patch": "commit 57bbdbd7ae3698a274edd4dd6ef1b53d9129e552\nAuthor: Alexey Bataev <[email protected]>\nDate: Mon Nov 25 07:56:45 2024 -0800\n\n [SLP]Relax assertion in mask combine for non-power-of-2 number of elements\n \n The nodes may contain non-power-of-2 number of elements. Need to relax\n the assertion to avoid possible compiler crash\n \n Fixes #117517\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex d033b7c2ef4a..73218f377a06 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -1143,9 +1143,7 @@ static void addMask(SmallVectorImpl<int> &Mask, ArrayRef<int> SubMask,\n assert(\n (!ExtendingManyInputs || SubMask.size() > Mask.size() ||\n // Check if input scalars were extended to match the size of other node.\n- (SubMask.size() == Mask.size() &&\n- std::all_of(std::next(Mask.begin(), Mask.size() / 2), Mask.end(),\n- [](int Idx) { return Idx == PoisonMaskElem; }))) &&\n+ (SubMask.size() == Mask.size() && Mask.back() == PoisonMaskElem)) &&\n \"SubMask with many inputs support must be larger than the mask.\");\n if (Mask.empty()) {\n Mask.append(SubMask.begin(), SubMask.end());\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/X86/non-power-2-num-elems-reused.ll", "commands": ["opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -slp-threshold=-10 < %s"], "tests": [{"test_name": "<module>", "test_body": "\ndefine i64 @test() {\n;\nentry:\n %xor148.2.i = xor i32 0, 0\n %conv193.i = zext i32 %xor148.2.i to i64\n %conv193.1.i = zext i32 %xor148.2.i to i64\n %or194.1.i = or i64 %conv193.i, %conv193.1.i\n %xor148.2.i.1 = xor i32 0, 0\n %conv193.i.1 = zext i32 %xor148.2.i.1 to i64\n %or194.i.1 = or i64 %or194.1.i, %conv193.i.1\n %conv193.1.i.1 = zext i32 %xor148.2.i.1 to i64\n %or194.1.i.1 = or i64 %or194.i.1, %conv193.1.i.1\n %xor148.2.i.2 = xor i32 0, 0\n %conv193.i.2 = zext i32 %xor148.2.i.2 to i64\n %or194.i.2 = or i64 %or194.1.i.1, %conv193.i.2\n %conv193.1.i.2 = zext i32 %xor148.2.i.2 to i64\n %or194.1.i.2 = or i64 %or194.i.2, %conv193.1.i.2\n %xor148.2.i.3 = xor i32 0, 0\n %conv193.i.3 = zext i32 %xor148.2.i.3 to i64\n %or194.i.3 = or i64 %or194.1.i.2, %conv193.i.3\n %conv193.1.i.3 = zext i32 %xor148.2.i.3 to i64\n %or194.1.i.3 = or i64 %or194.i.3, %conv193.1.i.3\n %xor148.2.i.4 = xor i32 0, 0\n %conv193.i.4 = zext i32 %xor148.2.i.4 to i64\n %or194.i.4 = or i64 %or194.1.i.3, %conv193.i.4\n %conv193.1.i.4 = zext i32 %xor148.2.i.4 to i64\n %or194.1.i.4 = or i64 %or194.i.4, %conv193.1.i.4\n %xor148.2.i.5 = xor i32 0, 0\n %conv193.i.5 = zext i32 %xor148.2.i.5 to i64\n %or194.i.5 = or i64 %or194.1.i.4, %conv193.i.5\n %conv193.1.i.5 = zext i32 %xor148.2.i.5 to i64\n %or194.1.i.5 = or i64 %or194.i.5, %conv193.1.i.5\n %xor148.2.i.6 = xor i32 0, 0\n %conv193.i.6 = zext i32 %xor148.2.i.6 to i64\n %or194.i.6 = or i64 %or194.1.i.5, %conv193.i.6\n %or54.i.i.6 = or i32 %xor148.2.i.6, 0\n %conv193.1.i.6 = zext i32 %or54.i.i.6 to i64\n %xor148.2.i.7 = xor i32 0, 0\n %conv193.i.7 = zext i32 %xor148.2.i.7 to i64\n %0 = or i64 %or194.i.6, %conv193.i.7\n %conv193.1.i.7 = zext i32 %xor148.2.i.7 to i64\n %1 = or i64 %0, %conv193.1.i.7\n %or194.1.i.7 = or i64 %1, %conv193.1.i.6\n ret i64 %or194.1.i.7\n}"}]}], "issue": {"title": "[SLPVectorizer] Assertion \"SubMask with many inputs support must be larger than the mask.\" failed.", "body": "Reproducer: https://godbolt.org/z/Mzbe1G875\r\n```\r\n; bin/opt -passes=slp-vectorizer test.ll -S\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine i64 @test() {\r\nentry:\r\n %xor148.2.i = xor i32 0, 0\r\n %conv193.i = zext i32 %xor148.2.i to i64\r\n %conv193.1.i = zext i32 %xor148.2.i to i64\r\n %or194.1.i = or i64 %conv193.i, %conv193.1.i\r\n %xor148.2.i.1 = xor i32 0, 0\r\n %conv193.i.1 = zext i32 %xor148.2.i.1 to i64\r\n %or194.i.1 = or i64 %or194.1.i, %conv193.i.1\r\n %conv193.1.i.1 = zext i32 %xor148.2.i.1 to i64\r\n %or194.1.i.1 = or i64 %or194.i.1, %conv193.1.i.1\r\n %xor148.2.i.2 = xor i32 0, 0\r\n %conv193.i.2 = zext i32 %xor148.2.i.2 to i64\r\n %or194.i.2 = or i64 %or194.1.i.1, %conv193.i.2\r\n %conv193.1.i.2 = zext i32 %xor148.2.i.2 to i64\r\n %or194.1.i.2 = or i64 %or194.i.2, %conv193.1.i.2\r\n %xor148.2.i.3 = xor i32 0, 0\r\n %conv193.i.3 = zext i32 %xor148.2.i.3 to i64\r\n %or194.i.3 = or i64 %or194.1.i.2, %conv193.i.3\r\n %conv193.1.i.3 = zext i32 %xor148.2.i.3 to i64\r\n %or194.1.i.3 = or i64 %or194.i.3, %conv193.1.i.3\r\n %xor148.2.i.4 = xor i32 0, 0\r\n %conv193.i.4 = zext i32 %xor148.2.i.4 to i64\r\n %or194.i.4 = or i64 %or194.1.i.3, %conv193.i.4\r\n %conv193.1.i.4 = zext i32 %xor148.2.i.4 to i64\r\n %or194.1.i.4 = or i64 %or194.i.4, %conv193.1.i.4\r\n %xor148.2.i.5 = xor i32 0, 0\r\n %conv193.i.5 = zext i32 %xor148.2.i.5 to i64\r\n %or194.i.5 = or i64 %or194.1.i.4, %conv193.i.5\r\n %conv193.1.i.5 = zext i32 %xor148.2.i.5 to i64\r\n %or194.1.i.5 = or i64 %or194.i.5, %conv193.1.i.5\r\n %xor148.2.i.6 = xor i32 0, 0\r\n %conv193.i.6 = zext i32 %xor148.2.i.6 to i64\r\n %or194.i.6 = or i64 %or194.1.i.5, %conv193.i.6\r\n %or54.i.i.6 = or i32 %xor148.2.i.6, 0\r\n %conv193.1.i.6 = zext i32 %or54.i.i.6 to i64\r\n %xor148.2.i.7 = xor i32 0, 0\r\n %conv193.i.7 = zext i32 %xor148.2.i.7 to i64\r\n %0 = or i64 %or194.i.6, %conv193.i.7\r\n %conv193.1.i.7 = zext i32 %xor148.2.i.7 to i64\r\n %1 = or i64 %0, %conv193.1.i.7\r\n %or194.1.i.7 = or i64 %1, %conv193.1.i.6\r\n ret i64 %or194.1.i.7\r\n}\r\n```\r\n```\r\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:1143: void addMask(llvm::SmallVectorImpl<int>&, llvm::ArrayRef<int>, bool): Assertion `(!ExtendingManyInputs || SubMask.size() > Mask.size() || (SubMask.size() == Mask.size() && std::all_of(std::next(Mask.begin(), Mask.size() / 2), Mask.end(), [](int Idx) { return Idx == PoisonMaskElem; }))) && \"SubMask with many inputs support must be larger than the mask.\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=slp-vectorizer <source>\r\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\r\n2.\tRunning pass \"slp-vectorizer\" on function \"test\"\r\n #0 0x00000000051b7378 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x51b7378)\r\n #1 0x00000000051b4d6c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x0000751221842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007512218969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x0000751221842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007512218287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x000075122182871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x0000751221839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x00000000041e91f7 llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator::finalize(llvm::ArrayRef<int>, llvm::ArrayRef<std::pair<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, unsigned int>>, llvm::ArrayRef<int>, unsigned int, llvm::function_ref<void (llvm::Value*&, llvm::SmallVectorImpl<int>&)>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41e91f7)\r\n #9 0x00000000042256f9 llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::processBuildVector<llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator, llvm::InstructionCost, llvm::TargetTransformInfo, llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP, llvm::SmallPtrSetImpl<llvm::Value*>>(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::Type*, llvm::TargetTransformInfo&, llvm::ArrayRef<llvm::Value*>&, llvm::slpvectorizer::BoUpSLP&, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x42256f9)\r\n#10 0x000000000422f707 llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x422f707)\r\n#11 0x00000000042636a1 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x42636a1)\r\n#12 0x00000000042691b0 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\r\n#13 0x000000000426c681 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x426c681)\r\n#14 0x0000000004270deb llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0\r\n#15 0x00000000042758a6 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x42758a6)\r\n#16 0x000000000427bf86 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0\r\n#17 0x000000000427ca9b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x427ca9b)\r\n#18 0x0000000002fcc5ce llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2fcc5ce)\r\n#19 0x0000000004fb6a68 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fb6a68)\r\n#20 0x0000000000e3dd4e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe3dd4e)\r\n#21 0x0000000004fb548e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fb548e)\r\n#22 0x0000000000e3d3fe llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe3d3fe)\r\n#23 0x0000000004fb4ec0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fb4ec0)\r\n#24 0x000000000090ce7a llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x90ce7a)\r\n#25 0x00000000008ff519 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ff519)\r\n#26 0x0000751221829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#27 0x0000751221829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#28 0x00000000008f6d6e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f6d6e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "dtcxzyw", "labels": ["llvm:SLPVectorizer", "crash-on-valid"], "comments": []}, "verified": true}
|
249 |
+
{"bug_id": "109528", "issue_url": "https://github.com/llvm/llvm-project/issues/109528", "bug_type": "crash", "base_commit": "586736226e3a25b1fd647d3257270c1388f907bf", "knowledge_cutoff": "2024-09-21T14:20:16Z", "lit_test_dir": ["llvm/test/Transforms/LoopVectorize"], "hints": {"fix_commit": "6d6eea92e36c301e34a7ec11b2a40e3080f79f53", "components": ["LoopVectorize"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [[8420, 8440]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": ["VPRecipeBuilder::tryToWiden"]}}, "patch": "commit 6d6eea92e36c301e34a7ec11b2a40e3080f79f53\nAuthor: Florian Hahn <[email protected]>\nDate: Wed Oct 2 13:45:48 2024 +0100\n\n [LV] Use SCEV to simplify wide binop operand to constant.\n \n The legacy cost model uses SCEV to determine if the second operand of a\n binary op is a constant. Update the VPlan construction logic to mirror\n the current legacy behavior, to fix a difference in the cost models.\n \n Fixes https://github.com/llvm/llvm-project/issues/109528.\n Fixes https://github.com/llvm/llvm-project/issues/110440.\n\ndiff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\nindex e1f9f29ac6d9..de3b981a4fe3 100644\n--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\n@@ -8420,21 +8420,28 @@ VPWidenRecipe *VPRecipeBuilder::tryToWiden(Instruction *I,\n case Instruction::Sub:\n case Instruction::Xor:\n case Instruction::Freeze:\n- if (I->getOpcode() == Instruction::Mul) {\n- // Simplify operands of multiplications using SCEV. This is needed at the\n- // moment to match the behavior of the legacy cost-model.\n- // TODO: Generalize to any opcode and move to VPlan transformation.\n- SmallVector<VPValue *> NewOps(Operands);\n+ SmallVector<VPValue *> NewOps(Operands);\n+ if (Instruction::isBinaryOp(I->getOpcode())) {\n+ // The legacy cost model uses SCEV to check if some of the operands are\n+ // constants. To match the legacy cost model's behavior, use SCEV to try\n+ // to replace operands with constants.\n ScalarEvolution &SE = *PSE.getSE();\n- for (unsigned I = 0; I < Operands.size(); ++I) {\n- Value *V = NewOps[I]->getUnderlyingValue();\n- if (!isa<Constant>(V) && SE.isSCEVable(V->getType()))\n- if (auto *C = dyn_cast<SCEVConstant>(PSE.getSE()->getSCEV(V)))\n- NewOps[I] = Plan.getOrAddLiveIn(C->getValue());\n- }\n- return new VPWidenRecipe(*I, make_range(NewOps.begin(), NewOps.end()));\n+ auto GetConstantViaSCEV = [this, &SE](VPValue *Op) {\n+ Value *V = Op->getUnderlyingValue();\n+ if (isa<Constant>(V) || !SE.isSCEVable(V->getType()))\n+ return Op;\n+ auto *C = dyn_cast<SCEVConstant>(SE.getSCEV(V));\n+ if (!C)\n+ return Op;\n+ return Plan.getOrAddLiveIn(C->getValue());\n+ };\n+ // For Mul, the legacy cost model checks both operands.\n+ if (I->getOpcode() == Instruction::Mul)\n+ NewOps[0] = GetConstantViaSCEV(NewOps[0]);\n+ // For other binops, the legacy cost model only checks the second operand.\n+ NewOps[1] = GetConstantViaSCEV(NewOps[1]);\n }\n- return new VPWidenRecipe(*I, make_range(Operands.begin(), Operands.end()));\n+ return new VPWidenRecipe(*I, make_range(NewOps.begin(), NewOps.end()));\n };\n }\n \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"}, {"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, 0\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"}]}], "issue": {"title": "[clang] Assertion failed in Vectorize", "body": "When I compiled this code with O2 flag, it crashed:\r\n\r\n```c\r\n#include <stdint.h>\r\nstatic uint64_t\r\nsafe_sub_func_uint64_t_u_u(uint64_t ui1, uint64_t ui2)\r\n{\r\n return ui1 - ui2;\r\n}\r\nlong a;\r\nstatic int8_t c;\r\nvoid b(long d, int f) {\r\n int e = 0;\r\n for (; e < 64; e++)\r\n if (e - f)\r\n a |= e >> f;\r\n else\r\n a |= d & e;\r\n}\r\nuint32_t g() {\r\n b(6, c);\r\n for (;; c = safe_sub_func_uint64_t_u_u(c, 4))\r\n ;\r\n}\r\n```\r\n\r\nThe crash is:\r\n```\r\nclang: /root/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7383: 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\n```\r\n\r\nDetails can be found here: https://godbolt.org/z/7733x1hvP", "author": "cardigan1008", "labels": ["vectorizers", "confirmed", "crash"], "comments": [{"author": "shafik", "body": "This looks like a regression in trunk: https://godbolt.org/z/eo7WG1e66"}, {"author": "hiraditya", "body": "Probably a recent change caused this? cc: @ayalz @fhahn "}]}, "verified": true}
|
250 |
{"bug_id": "114191", "issue_url": "https://github.com/llvm/llvm-project/issues/114191", "bug_type": "miscompilation", "base_commit": "e577f14b670ee2ae6bb717133310b215be4331b3", "knowledge_cutoff": "2024-10-30T07:41:28Z", "lit_test_dir": ["llvm/test/Transforms/InstCombine", "llvm/test/Transforms/InstSimplify"], "hints": {"fix_commit": "a77dedcacb4c5eb221395b69877981dd6ad98989", "components": ["IR", "InstCombine", "InstructionSimplify"], "bug_location_lineno": {"llvm/lib/Analysis/InstructionSimplify.cpp": [[1095, 1113]], "llvm/lib/IR/ConstantFold.cpp": [[902, 912]], "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": [[102, 107]], "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": [[1158, 1186], [1189, 1194], [2138, 2166]]}, "bug_location_funcname": {"llvm/lib/Analysis/InstructionSimplify.cpp": ["simplifyDivRem"], "llvm/lib/IR/ConstantFold.cpp": ["llvm::ConstantFoldBinaryInstruction"], "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": ["InstCombinerImpl::commonIDivTransforms", "InstCombinerImpl::commonIRemTransforms", "foldIDivShl"]}}, "patch": "commit a77dedcacb4c5eb221395b69877981dd6ad98989\nAuthor: Yingwei Zheng <[email protected]>\nDate: Fri Nov 1 22:56:22 2024 +0800\n\n [InstSimplify][InstCombine][ConstantFold] Move vector div/rem by zero fold to InstCombine (#114280)\n \n Previously we fold `div/rem X, C` into `poison` if any element of the\n constant divisor `C` is zero or undef. However, it is incorrect when\n threading udiv over an vector select:\n https://alive2.llvm.org/ce/z/3Ninx5\n ```\n define <2 x i32> @vec_select_udiv_poison(<2 x i1> %x) {\n %sel = select <2 x i1> %x, <2 x i32> <i32 -1, i32 -1>, <2 x i32> <i32 0, i32 1>\n %div = udiv <2 x i32> <i32 42, i32 -7>, %sel\n ret <2 x i32> %div\n }\n ```\n In this case, `threadBinOpOverSelect` folds `udiv <i32 42, i32 -7>, <i32\n -1, i32 -1>` and `udiv <i32 42, i32 -7>, <i32 0, i32 1>` into\n `zeroinitializer` and `poison`, respectively. One solution is to\n introduce a new flag indicating that we are threading over a vector\n select. But it requires to modify both `InstSimplify` and\n `ConstantFold`.\n \n However, this optimization doesn't provide benefits to real-world\n programs:\n \n https://dtcxzyw.github.io/llvm-opt-benchmark/coverage/data/zyw/opt-ci/actions-runner/_work/llvm-opt-benchmark/llvm-opt-benchmark/llvm/llvm-project/llvm/lib/IR/ConstantFold.cpp.html#L908\n \n https://dtcxzyw.github.io/llvm-opt-benchmark/coverage/data/zyw/opt-ci/actions-runner/_work/llvm-opt-benchmark/llvm-opt-benchmark/llvm/llvm-project/llvm/lib/Analysis/InstructionSimplify.cpp.html#L1107\n \n This patch moves the fold into InstCombine to avoid breaking numerous\n existing tests.\n \n Fixes #114191 and #113866 (only poison-safety issue).\n\ndiff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp\nindex d08be1e55c85..2cb2612bf611 100644\n--- a/llvm/lib/Analysis/InstructionSimplify.cpp\n+++ b/llvm/lib/Analysis/InstructionSimplify.cpp\n@@ -1095,19 +1095,6 @@ static Value *simplifyDivRem(Instruction::BinaryOps Opcode, Value *Op0,\n if (match(Op1, m_Zero()))\n return PoisonValue::get(Ty);\n \n- // If any element of a constant divisor fixed width vector is zero or undef\n- // the behavior is undefined and we can fold the whole op to poison.\n- auto *Op1C = dyn_cast<Constant>(Op1);\n- auto *VTy = dyn_cast<FixedVectorType>(Ty);\n- if (Op1C && VTy) {\n- unsigned NumElts = VTy->getNumElements();\n- for (unsigned i = 0; i != NumElts; ++i) {\n- Constant *Elt = Op1C->getAggregateElement(i);\n- if (Elt && (Elt->isNullValue() || Q.isUndefValue(Elt)))\n- return PoisonValue::get(Ty);\n- }\n- }\n-\n // poison / X -> poison\n // poison % X -> poison\n if (isa<PoisonValue>(Op0))\ndiff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp\nindex 07dfbc41e79b..c2780faee403 100644\n--- a/llvm/lib/IR/ConstantFold.cpp\n+++ b/llvm/lib/IR/ConstantFold.cpp\n@@ -902,11 +902,6 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1,\n Constant *ExtractIdx = ConstantInt::get(Ty, i);\n Constant *LHS = ConstantExpr::getExtractElement(C1, ExtractIdx);\n Constant *RHS = ConstantExpr::getExtractElement(C2, ExtractIdx);\n-\n- // If any element of a divisor vector is zero, the whole op is poison.\n- if (Instruction::isIntDivRem(Opcode) && RHS->isNullValue())\n- return PoisonValue::get(VTy);\n-\n Constant *Res = ConstantExpr::isDesirableBinOp(Opcode)\n ? ConstantExpr::get(Opcode, LHS, RHS)\n : ConstantFoldBinaryInstruction(Opcode, LHS, RHS);\ndiff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h\nindex 7a060cdab2d3..adbd9186c59c 100644\n--- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h\n+++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h\n@@ -102,6 +102,7 @@ public:\n Instruction *visitSRem(BinaryOperator &I);\n Instruction *visitFRem(BinaryOperator &I);\n bool simplifyDivRemOfSelectWithZeroOp(BinaryOperator &I);\n+ Instruction *commonIDivRemTransforms(BinaryOperator &I);\n Instruction *commonIRemTransforms(BinaryOperator &I);\n Instruction *commonIDivTransforms(BinaryOperator &I);\n Instruction *visitUDiv(BinaryOperator &I);\ndiff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp\nindex b9c165da906d..f85a3c936513 100644\n--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp\n+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp\n@@ -1158,29 +1158,39 @@ static Value *foldIDivShl(BinaryOperator &I, InstCombiner::BuilderTy &Builder) {\n return nullptr;\n }\n \n-/// This function implements the transforms common to both integer division\n-/// instructions (udiv and sdiv). It is called by the visitors to those integer\n-/// division instructions.\n-/// Common integer divide transforms\n-Instruction *InstCombinerImpl::commonIDivTransforms(BinaryOperator &I) {\n- if (Instruction *Phi = foldBinopWithPhiOperands(I))\n- return Phi;\n-\n+/// Common integer divide/remainder transforms\n+Instruction *InstCombinerImpl::commonIDivRemTransforms(BinaryOperator &I) {\n+ assert(I.isIntDivRem() && \"Unexpected instruction\");\n Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);\n- bool IsSigned = I.getOpcode() == Instruction::SDiv;\n+\n+ // If any element of a constant divisor fixed width vector is zero or undef\n+ // the behavior is undefined and we can fold the whole op to poison.\n+ auto *Op1C = dyn_cast<Constant>(Op1);\n Type *Ty = I.getType();\n+ auto *VTy = dyn_cast<FixedVectorType>(Ty);\n+ if (Op1C && VTy) {\n+ unsigned NumElts = VTy->getNumElements();\n+ for (unsigned i = 0; i != NumElts; ++i) {\n+ Constant *Elt = Op1C->getAggregateElement(i);\n+ if (Elt && (Elt->isNullValue() || isa<UndefValue>(Elt)))\n+ return replaceInstUsesWith(I, PoisonValue::get(Ty));\n+ }\n+ }\n+\n+ if (Instruction *Phi = foldBinopWithPhiOperands(I))\n+ return Phi;\n \n // The RHS is known non-zero.\n if (Value *V = simplifyValueKnownNonZero(I.getOperand(1), *this, I))\n return replaceOperand(I, 1, V);\n \n- // Handle cases involving: [su]div X, (select Cond, Y, Z)\n- // This does not apply for fdiv.\n+ // Handle cases involving: div/rem X, (select Cond, Y, Z)\n if (simplifyDivRemOfSelectWithZeroOp(I))\n return &I;\n \n // If the divisor is a select-of-constants, try to constant fold all div ops:\n- // C / (select Cond, TrueC, FalseC) --> select Cond, (C / TrueC), (C / FalseC)\n+ // C div/rem (select Cond, TrueC, FalseC) --> select Cond, (C div/rem TrueC),\n+ // (C div/rem FalseC)\n // TODO: Adapt simplifyDivRemOfSelectWithZeroOp to allow this and other folds.\n if (match(Op0, m_ImmConstant()) &&\n match(Op1, m_Select(m_Value(), m_ImmConstant(), m_ImmConstant()))) {\n@@ -1189,6 +1199,21 @@ Instruction *InstCombinerImpl::commonIDivTransforms(BinaryOperator &I) {\n return R;\n }\n \n+ return nullptr;\n+}\n+\n+/// This function implements the transforms common to both integer division\n+/// instructions (udiv and sdiv). It is called by the visitors to those integer\n+/// division instructions.\n+/// Common integer divide transforms\n+Instruction *InstCombinerImpl::commonIDivTransforms(BinaryOperator &I) {\n+ if (Instruction *Res = commonIDivRemTransforms(I))\n+ return Res;\n+\n+ Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);\n+ bool IsSigned = I.getOpcode() == Instruction::SDiv;\n+ Type *Ty = I.getType();\n+\n const APInt *C2;\n if (match(Op1, m_APInt(C2))) {\n Value *X;\n@@ -2138,29 +2163,11 @@ static Instruction *simplifyIRemMulShl(BinaryOperator &I,\n /// remainder instructions.\n /// Common integer remainder transforms\n Instruction *InstCombinerImpl::commonIRemTransforms(BinaryOperator &I) {\n- if (Instruction *Phi = foldBinopWithPhiOperands(I))\n- return Phi;\n+ if (Instruction *Res = commonIDivRemTransforms(I))\n+ return Res;\n \n Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);\n \n- // The RHS is known non-zero.\n- if (Value *V = simplifyValueKnownNonZero(I.getOperand(1), *this, I))\n- return replaceOperand(I, 1, V);\n-\n- // Handle cases involving: rem X, (select Cond, Y, Z)\n- if (simplifyDivRemOfSelectWithZeroOp(I))\n- return &I;\n-\n- // If the divisor is a select-of-constants, try to constant fold all rem ops:\n- // C % (select Cond, TrueC, FalseC) --> select Cond, (C % TrueC), (C % FalseC)\n- // TODO: Adapt simplifyDivRemOfSelectWithZeroOp to allow this and other folds.\n- if (match(Op0, m_ImmConstant()) &&\n- match(Op1, m_Select(m_Value(), m_ImmConstant(), m_ImmConstant()))) {\n- if (Instruction *R = FoldOpIntoSelect(I, cast<SelectInst>(Op1),\n- /*FoldWithMultiUse*/ true))\n- return R;\n- }\n-\n if (isa<Constant>(Op1)) {\n if (Instruction *Op0I = dyn_cast<Instruction>(Op0)) {\n if (SelectInst *SI = dyn_cast<SelectInst>(Op0I)) {\n", "tests": [{"file": "llvm/test/Transforms/InstCombine/div.ll", "commands": ["opt < %s -passes=instcombine -S"], "tests": [{"test_name": "sdiv_constant_dividend_select_of_constants_divisor_vec", "test_body": "define <2 x i8> @sdiv_constant_dividend_select_of_constants_divisor_vec(i1 %b) {\n %s = select i1 %b, <2 x i8> <i8 12, i8 -5>, <2 x i8> <i8 -4, i8 4>\n %r = sdiv <2 x i8> <i8 42, i8 -42>, %s\n ret <2 x i8> %r\n}\n"}, {"test_name": "udiv_constant_dividend_select_of_constants_divisor_vec", "test_body": "define <2 x i8> @udiv_constant_dividend_select_of_constants_divisor_vec(i1 %b) {\n %s = select i1 %b, <2 x i8> <i8 12, i8 -5>, <2 x i8> <i8 -4, i8 4>\n %r = udiv <2 x i8> <i8 42, i8 -42>, %s\n ret <2 x i8> %r\n}\n"}, {"test_name": "sdiv_constant_dividend_select_of_constants_divisor_vec_ub1", "test_body": "define <2 x i8> @sdiv_constant_dividend_select_of_constants_divisor_vec_ub1(i1 %b) {\n %s = select i1 %b, <2 x i8> <i8 0, i8 -5>, <2 x i8> <i8 -4, i8 4>\n %r = sdiv <2 x i8> <i8 42, i8 -42>, %s\n ret <2 x i8> %r\n}\n"}, {"test_name": "udiv_constant_dividend_select_of_constants_divisor_vec_ub1", "test_body": "define <2 x i8> @udiv_constant_dividend_select_of_constants_divisor_vec_ub1(i1 %b) {\n %s = select i1 %b, <2 x i8> <i8 0, i8 -5>, <2 x i8> <i8 -4, i8 4>\n %r = udiv <2 x i8> <i8 42, i8 -42>, %s\n ret <2 x i8> %r\n}\n"}]}, {"file": "llvm/test/Transforms/InstCombine/rem.ll", "commands": ["opt < %s -passes=instcombine -S"], "tests": [{"test_name": "urem_constant_dividend_select_of_constants_divisor_vec_ub1", "test_body": "define <2 x i8> @urem_constant_dividend_select_of_constants_divisor_vec_ub1(i1 %b) {\n %s = select i1 %b, <2 x i8> <i8 0, i8 -5>, <2 x i8> <i8 -4, i8 4>\n %r = urem <2 x i8> <i8 42, i8 -42>, %s\n ret <2 x i8> %r\n}\n"}, {"test_name": "urem_constant_dividend_select_of_constants_divisor_vec", "test_body": "define <2 x i8> @urem_constant_dividend_select_of_constants_divisor_vec(i1 %b) {\n %s = select i1 %b, <2 x i8> <i8 12, i8 -5>, <2 x i8> <i8 -4, i8 4>\n %r = urem <2 x i8> <i8 42, i8 -42>, %s\n ret <2 x i8> %r\n}\n"}]}, {"file": "llvm/test/Transforms/InstCombine/vector-udiv.ll", "commands": ["opt < %s -passes=instcombine -S"], "tests": [{"test_name": "vec_select_udiv_poison", "test_body": "define <2 x i32> @vec_select_udiv_poison(<2 x i1> %x) {\n %sel = select <2 x i1> %x, <2 x i32> splat (i32 -1), <2 x i32> <i32 0, i32 1>\n %div = udiv <2 x i32> <i32 42, i32 -7>, %sel\n ret <2 x i32> %div\n}\n"}, {"test_name": "test_v4i32_zext_shl_const_pow2", "test_body": "define <4 x i32> @test_v4i32_zext_shl_const_pow2(<4 x i32> %a0, <4 x i16> %a1) {\n %1 = shl <4 x i16> <i16 4, i16 8, i16 16, i16 32>, %a1\n %2 = zext <4 x i16> %1 to <4 x i32>\n %3 = udiv <4 x i32> %a0, %2\n ret <4 x i32> %3\n}\n"}]}, {"file": "llvm/test/Transforms/InstSimplify/div.ll", "commands": ["opt < %s -passes=instsimplify -S"], "tests": [{"test_name": "udiv_zero_elt_vec", "test_body": "define <2 x i8> @udiv_zero_elt_vec(<2 x i8> %x) {\n %div = udiv <2 x i8> %x, <i8 0, i8 42>\n ret <2 x i8> %div\n}\n"}, {"test_name": "sdiv_zero_elt_vec", "test_body": "define <2 x i8> @sdiv_zero_elt_vec(<2 x i8> %x) {\n %div = sdiv <2 x i8> %x, <i8 -42, i8 0>\n ret <2 x i8> %div\n}\n"}, {"test_name": "udiv_poison_elt_vec", "test_body": "define <2 x i8> @udiv_poison_elt_vec(<2 x i8> %x) {\n %div = udiv <2 x i8> %x, <i8 poison, i8 42>\n ret <2 x i8> %div\n}\n"}, {"test_name": "sdiv_zero_elt_vec_constfold", "test_body": "define <2 x i8> @sdiv_zero_elt_vec_constfold(<2 x i8> %x) {\n %div = sdiv <2 x i8> <i8 1, i8 2>, <i8 0, i8 -42>\n ret <2 x i8> %div\n}\n"}, {"test_name": "sdiv_poison_elt_vec", "test_body": "define <2 x i8> @sdiv_poison_elt_vec(<2 x i8> %x) {\n %div = sdiv <2 x i8> %x, <i8 -42, i8 poison>\n ret <2 x i8> %div\n}\n"}, {"test_name": "udiv_zero_elt_vec_constfold", "test_body": "define <2 x i8> @udiv_zero_elt_vec_constfold(<2 x i8> %x) {\n %div = udiv <2 x i8> <i8 1, i8 2>, <i8 42, i8 0>\n ret <2 x i8> %div\n}\n"}, {"test_name": "zero_dividend_vector_poison_elt", "test_body": "define <2 x i32> @zero_dividend_vector_poison_elt(<2 x i32> %A) {\n %B = sdiv <2 x i32> <i32 0, i32 poison>, %A\n ret <2 x i32> %B\n}\n"}]}, {"file": "llvm/test/Transforms/InstSimplify/rem.ll", "commands": ["opt < %s -passes=instsimplify -S"], "tests": [{"test_name": "srem_zero_elt_vec_constfold", "test_body": "define <2 x i8> @srem_zero_elt_vec_constfold(<2 x i8> %x) {\n %rem = srem <2 x i8> <i8 1, i8 2>, <i8 0, i8 -42>\n ret <2 x i8> %rem\n}\n"}, {"test_name": "urem_zero_elt_vec", "test_body": "define <2 x i8> @urem_zero_elt_vec(<2 x i8> %x) {\n %rem = urem <2 x i8> %x, <i8 0, i8 42>\n ret <2 x i8> %rem\n}\n"}, {"test_name": "urem_zero_elt_vec_constfold", "test_body": "define <2 x i8> @urem_zero_elt_vec_constfold(<2 x i8> %x) {\n %rem = urem <2 x i8> <i8 1, i8 2>, <i8 42, i8 0>\n ret <2 x i8> %rem\n}\n"}, {"test_name": "srem_undef_elt_vec", "test_body": "define <2 x i8> @srem_undef_elt_vec(<2 x i8> %x) {\n %rem = srem <2 x i8> %x, <i8 -42, i8 undef>\n ret <2 x i8> %rem\n}\n"}, {"test_name": "urem_undef_elt_vec", "test_body": "define <2 x i8> @urem_undef_elt_vec(<2 x i8> %x) {\n %rem = urem <2 x i8> %x, <i8 undef, i8 42>\n ret <2 x i8> %rem\n}\n"}, {"test_name": "zero_dividend_vector_poison_elt", "test_body": "define <2 x i32> @zero_dividend_vector_poison_elt(<2 x i32> %A) {\n %B = urem <2 x i32> <i32 poison, i32 0>, %A\n ret <2 x i32> %B\n}\n"}, {"test_name": "srem_zero_elt_vec", "test_body": "define <2 x i8> @srem_zero_elt_vec(<2 x i8> %x) {\n %rem = srem <2 x i8> %x, <i8 -42, i8 0>\n ret <2 x i8> %rem\n}\n"}]}], "issue": {"title": "[InstCombine] miscompilation of `or` of vectors", "body": "Alive2 report: https://alive2.llvm.org/ce/z/LyM8sY\r\n\r\n```llvm\r\n----------------------------------------\r\ndefine <2 x i32> @or_sext_to_sel_constant_vec.3(<2 x i1> %y) {\r\n#0:\r\n %sext = sext <2 x i1> %y to <2 x i32>\r\n %#1 = or <2 x i32> %sext, { 0, 1 }\r\n %#2 = udiv <2 x i32> { 42, 4294967289 }, %#1\r\n ret <2 x i32> %#2\r\n}\r\n=>\r\ndefine <2 x i32> @or_sext_to_sel_constant_vec.3(<2 x i1> %y) {\r\n#0:\r\n ret <2 x i32> { 0, 0 }\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Value mismatch\r\n\r\nExample:\r\n<2 x i1> %y = < #x1 (1), #x0 (0) >\r\n\r\nSource:\r\n<2 x i32> %sext = < #xffffffff (4294967295, -1), #x00000000 (0) >\r\n<2 x i32> %#1 = < #xffffffff (4294967295, -1), #x00000001 (1) >\r\n<2 x i32> %#2 = < #x00000000 (0), #xfffffff9 (4294967289, -7) >\r\n\r\nTarget:\r\nSource value: < #x00000000 (0), #xfffffff9 (4294967289, -7) >\r\nTarget value: < #x00000000 (0), #x00000000 (0) >\r\n\r\n\r\n----------------------------------------\r\ndefine <2 x i32> @or_sext_to_sel_constant_vec.2(<2 x i1> %y) {\r\n#0:\r\n %sext = sext <2 x i1> %y to <2 x i32>\r\n %#1 = or <2 x i32> %sext, { 0, 1 }\r\n %#2 = sdiv <2 x i32> { 42, 4294967289 }, %#1\r\n %#3 = udiv exact <2 x i32> %#2, %#2\r\n %#4 = or <2 x i32> %#2, %#2\r\n ret <2 x i32> %#4\r\n}\r\n=>\r\ndefine <2 x i32> @or_sext_to_sel_constant_vec.2(<2 x i1> %y) {\r\n#0:\r\n ret <2 x i32> { 4294967254, 7 }\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Value mismatch\r\n\r\nExample:\r\n<2 x i1> %y = < #x1 (1), #x0 (0) >\r\n\r\nSource:\r\n<2 x i32> %sext = < #xffffffff (4294967295, -1), #x00000000 (0) >\r\n<2 x i32> %#1 = < #xffffffff (4294967295, -1), #x00000001 (1) >\r\n<2 x i32> %#2 = < #xffffffd6 (4294967254, -42), #xfffffff9 (4294967289, -7) >\r\n<2 x i32> %#3 = < #x00000001 (1), #x00000001 (1) >\r\n<2 x i32> %#4 = < #xffffffd6 (4294967254, -42), #xfffffff9 (4294967289, -7) >\r\n\r\nTarget:\r\nSource value: < #xffffffd6 (4294967254, -42), #xfffffff9 (4294967289, -7) >\r\nTarget value: < #xffffffd6 (4294967254, -42), #x00000007 (7) >\r\n\r\nSummary:\r\n 0 correct transformations\r\n 2 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\n```", "author": "bongjunj", "labels": ["miscompilation", "llvm:instcombine", "llvm:analysis"], "comments": [{"author": "dtcxzyw", "body": "@bongjunj Feel free to ping me if you find new InstCombine miscompilation bugs without involving undef values/NaN payloads."}, {"author": "dtcxzyw", "body": "https://github.com/llvm/llvm-project/blob/eac2c182c6f852fc187af9952250a43d6fb17b28/llvm/lib/Analysis/InstructionSimplify.cpp#L1098-L1109\r\n\r\nWe cannot do this simplification when threading udiv over selects.\r\n "}]}, "verified": true}
|
251 |
{"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 <[email protected]>\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<llvm::SCEVExpander, llvm::Value*>::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<llvm::SCEVExpander, llvm::Value*>::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::Instruction*>&, llvm::SCEVAddRecExpr const*, llvm::SCEV const*, bool, bool) LoopIdiomRecognize.cpp:0:0\r\n#21 0x00007fc24ce539b7 (anonymous namespace)::LoopIdiomRecognize::processLoopStores(llvm::SmallVectorImpl<llvm::StoreInst*>&, 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::Loop, llvm::LoopStandardAnalysisResults&>&, 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::Loop, llvm::LoopIdiomRecognizePass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x378c6c6)\r\n#25 0x00007fc24ce7544f std::optional<llvm::PreservedAnalyses> llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::runSinglePass<llvm::Loop, std::unique_ptr<llvm::detail::PassConcept<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>, std::default_delete<llvm::detail::PassConcept<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>>>>(llvm::Loop&, std::unique_ptr<llvm::detail::PassConcept<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>, std::default_delete<llvm::detail::PassConcept<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>>>&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, 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::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::runWithoutLoopNestPasses(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1f136f6)\r\n#27 0x00007fc24ce76b0d llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, 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<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1f15d62)\r\n#29 0x00007fc24e6eb0c6 llvm::detail::PassModel<llvm::Function, llvm::FunctionToLoopPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x37890c6)\r\n#30 0x00007fc24ba8a40d llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0xb2840d)\r\n#31 0x00007fc24e6e41a6 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x37821a6)\r\n#32 0x00007fc24ba88c9d llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0xb26c9d)\r\n#33 0x00007fc24e6eb026 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x3789026)\r\n#34 0x00007fc24ba86c1d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/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::PassPlugin>, 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}
|
252 |
{"bug_id": "113516", "issue_url": "https://github.com/llvm/llvm-project/issues/113516", "bug_type": "crash", "base_commit": "0aec4d2b78a08f5f3e4b0ad0340a99e486d00110", "knowledge_cutoff": "2024-10-24T03:05:37Z", "lit_test_dir": ["llvm/test/Transforms/SLPVectorizer"], "hints": {"fix_commit": "d2e7ee77d33e8b3be3b1d4e9bc5bc4c60b62b554", "components": ["SLPVectorizer"], "bug_location_lineno": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [[16118, 16124]]}, "bug_location_funcname": {"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": ["BoUpSLP::vectorizeTree"]}}, "patch": "commit d2e7ee77d33e8b3be3b1d4e9bc5bc4c60b62b554\nAuthor: Alexey Bataev <[email protected]>\nDate: Thu Oct 24 08:15:21 2024 -0700\n\n [SLP]Do not check for clustered loads only\n \n Since SLP support \"clusterization\" of the non-load instructions, the\n restriction for reduced values for loads only should be removed to avoid\n compiler crash.\n \n Fixes #113516\n\ndiff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\nindex f76e913a57d5..012d85353f08 100644\n--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n@@ -16118,7 +16118,7 @@ BoUpSLP::vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues,\n for (Instruction *I : RemovedInsts) {\n const TreeEntry *IE = getTreeEntry(I);\n if (IE->Idx != 0 &&\n- !(VectorizableTree.front()->isGather() && isa<LoadInst>(I) &&\n+ !(VectorizableTree.front()->isGather() &&\n !IE->UserTreeIndices.empty() &&\n any_of(IE->UserTreeIndices,\n [&](const EdgeInfo &EI) {\n", "tests": [{"file": "llvm/test/Transforms/SLPVectorizer/X86/non-load-reduced-as-part-of-bv.ll", "commands": ["opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s"], "tests": [{"test_name": "foo", "test_body": "define i1 @foo() {\nentry:\n %tobool.not.not509.i.1311.i.i = icmp ne i32 0, 0\n %cmp80.1319.i.i189 = icmp sgt i32 0, 0\n %tobool.not.not509.i.1.1.i.i = icmp ne i32 0, 0\n %cmp80.1.1.i.i190 = icmp sgt i32 0, 0\n %tobool.not.not509.i.2329.i.i = icmp ne i32 0, 0\n %storemerge.2333.i.i = select i1 %tobool.not.not509.i.2329.i.i, i32 0, i32 0\n %cmp80.2337.i.i192 = icmp sgt i32 0, 0\n %tobool.not.not509.i.1.2.i.i = icmp ne i32 %storemerge.2333.i.i, 0\n %cmp80.1.2.i.i193 = icmp sgt i32 0, 0\n %cmp80.1.2.i.i = select i1 %tobool.not.not509.i.1.2.i.i, i1 %cmp80.1.2.i.i193, i1 false\n %0 = select i1 %cmp80.1.2.i.i, i1 %tobool.not.not509.i.2329.i.i, i1 false\n %1 = select i1 %0, i1 %cmp80.2337.i.i192, i1 false\n %2 = select i1 %1, i1 false, i1 false\n %3 = select i1 %2, i1 %tobool.not.not509.i.1.1.i.i, i1 false\n %4 = select i1 %3, i1 %cmp80.1.1.i.i190, i1 false\n %5 = select i1 %4, i1 %tobool.not.not509.i.1311.i.i, i1 false\n %6 = select i1 %5, i1 %cmp80.1319.i.i189, i1 false\n ret i1 %6\n}\n"}]}], "issue": {"title": "[SLPVectorizer] Assertion `(I->use_empty() || all_of(I->uses(), [&](Use &U) { return isDeleted( cast<Instruction>(U.getUser())); })) && \"trying to erase instruction with users.\"' failed.", "body": "Reduced reproducer: https://godbolt.org/z/azEc6zjod\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 @foo() {\r\nentry:\r\n %tobool.not.not509.i.1311.i.i = icmp ne i32 0, 0\r\n %cmp80.1319.i.i189 = icmp sgt i32 0, 0\r\n %tobool.not.not509.i.1.1.i.i = icmp ne i32 0, 0\r\n %cmp80.1.1.i.i190 = icmp sgt i32 0, 0\r\n %tobool.not.not509.i.2329.i.i = icmp ne i32 0, 0\r\n %storemerge.2333.i.i = select i1 %tobool.not.not509.i.2329.i.i, i32 0, i32 0\r\n %cmp80.2337.i.i192 = icmp sgt i32 0, 0\r\n %tobool.not.not509.i.1.2.i.i = icmp ne i32 %storemerge.2333.i.i, 0\r\n %cmp80.1.2.i.i193 = icmp sgt i32 0, 0\r\n %cmp80.1.2.i.i = select i1 %tobool.not.not509.i.1.2.i.i, i1 %cmp80.1.2.i.i193, i1 false\r\n %0 = select i1 %cmp80.1.2.i.i, i1 %tobool.not.not509.i.2329.i.i, i1 false\r\n %1 = select i1 %0, i1 %cmp80.2337.i.i192, i1 false\r\n %2 = select i1 %1, i1 false, i1 false\r\n %3 = select i1 %2, i1 %tobool.not.not509.i.1.1.i.i, i1 false\r\n %4 = select i1 %3, i1 %cmp80.1.1.i.i190, i1 false\r\n %5 = select i1 %4, i1 %tobool.not.not509.i.1311.i.i, i1 false\r\n %6 = select i1 %5, i1 %cmp80.1319.i.i189, i1 false\r\n ret i1 %6\r\n}\r\n```\r\n```\r\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:2748: void llvm::slpvectorizer::BoUpSLP::removeInstructionsAndOperands(llvm::ArrayRef<U*>) [with T = llvm::Instruction]: Assertion `(I->use_empty() || all_of(I->uses(), [&](Use &U) { return isDeleted( cast<Instruction>(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 <source>\r\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\r\n2.\tRunning pass \"slp-vectorizer\" on function \"foo\"\r\n #0 0x00000000050d8608 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x50d8608)\r\n #1 0x00000000050d5fbc SignalHandler(int) Signals.cpp:0:0\r\n #2 0x000071afd7642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000071afd76969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x000071afd7642476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x000071afd76287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x000071afd762871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x000071afd7639e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x000000000414e3af void llvm::slpvectorizer::BoUpSLP::removeInstructionsAndOperands<llvm::Instruction>(llvm::ArrayRef<llvm::Instruction*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x414e3af)\r\n #9 0x00000000041aa335 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::SmallDenseSet<llvm::Value*, 4u, llvm::DenseMapInfo<llvm::Value*, void>> const&, llvm::Instruction*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41aa335)\r\n#10 0x00000000041bcd90 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\r\n#11 0x00000000041bfb71 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41bfb71)\r\n#12 0x00000000041c431b llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0\r\n#13 0x00000000041c8ae8 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41c8ae8)\r\n#14 0x00000000041cf231 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 0x00000000041cfedb llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41cfedb)\r\n#16 0x0000000002f64f0e llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2f64f0e)\r\n#17 0x0000000004ed9788 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4ed9788)\r\n#18 0x0000000000e2773e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe2773e)\r\n#19 0x0000000004ed81ae llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4ed81ae)\r\n#20 0x0000000000e26e8e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe26e8e)\r\n#21 0x0000000004ed7be0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4ed7be0)\r\n#22 0x000000000090a07a llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x90a07a)\r\n#23 0x00000000008fce7c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8fce7c)\r\n#24 0x000071afd7629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#25 0x000071afd7629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#26 0x00000000008f493e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f493e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```\r\nllvm version: 33363521ca24f912cc25530f6cecbca53acce8a3", "author": "dtcxzyw", "labels": ["llvm:SLPVectorizer", "crash-on-valid"], "comments": []}, "verified": true}
|
dataset/109528.json
CHANGED
@@ -22,7 +22,7 @@
|
|
22 |
},
|
23 |
"bug_location_funcname": {
|
24 |
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [
|
25 |
-
"VPRecipeBuilder::
|
26 |
]
|
27 |
}
|
28 |
},
|
|
|
22 |
},
|
23 |
"bug_location_funcname": {
|
24 |
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [
|
25 |
+
"VPRecipeBuilder::tryToWiden"
|
26 |
]
|
27 |
}
|
28 |
},
|