llc -mtriple=powerpc64-pc-linux will crash on ----------------------------------- %struct.test = type { i64, [8 x i8] } @gt = common global %struct.test zeroinitializer, align 16 define hidden signext i32 @test1(i32 signext, %struct.test* byval align 16, i32 signext) { ret i32 0 } define void @caller1(i32 signext %z) { entry: %call = tail call signext i32 @test1(i32 signext 0, %struct.test* byval align 16 @gt, i32 signext %z) ret void } --------------------------------------- The backtrace is llc: /home/espindola/llvm/llvm/include/llvm/CodeGen/SelectionDAGNodes.h:662: const llvm::SDValue &llvm::SDNode::getOperand(unsigned int) const: Assertion `Num < NumOperands && "Invalid child # of SDNode!"' failed. #0 0x0000000002465b2c llvm::sys::PrintStackTrace(llvm::raw_ostream&) /home/espindola/llvm/llvm/lib/Support/Unix/Signals.inc:402:11 #1 0x0000000002466019 PrintStackTraceSignalHandler(void*) /home/espindola/llvm/llvm/lib/Support/Unix/Signals.inc:470:1 #2 0x00000000024646f3 llvm::sys::RunSignalHandlers() /home/espindola/llvm/llvm/lib/Support/Signals.cpp:45:5 #3 0x0000000002466364 SignalHandler(int) /home/espindola/llvm/llvm/lib/Support/Unix/Signals.inc:256:1 #4 0x00007f9d9ca53a00 __restore_rt (/lib64/libpthread.so.0+0x10a00) #5 0x00007f9d9b5cfa28 __GI_raise (/lib64/libc.so.6+0x34a28) #6 0x00007f9d9b5d162a __GI_abort (/lib64/libc.so.6+0x3662a) #7 0x00007f9d9b5c8227 __assert_fail_base (/lib64/libc.so.6+0x2d227) #8 0x00007f9d9b5c82d2 (/lib64/libc.so.6+0x2d2d2) #9 0x000000000093020a llvm::SDNode::getOperand(unsigned int) const /home/espindola/llvm/llvm/include/llvm/CodeGen/SelectionDAGNodes.h:663:12 #10 0x000000000132d3bf llvm::PPCTargetLowering::createMemcpyOutsideCallSeq(llvm::SDValue, llvm::SDValue, llvm::SDValue, llvm::ISD::ArgFlagsTy, llvm::SelectionDAG&, llvm::SDLoc const&) const /home/espindola/llvm/llvm/lib/Target/PowerPC/PPCISelLowering.cpp:4896:25 #11 0x0000000001322c31 llvm::PPCTargetLowering::LowerCall_64SVR4(llvm::SDValue, llvm::SDValue, unsigned int, bool, bool, bool, llvm::SmallVectorImpl<llvm::ISD::OutputArg> const&, llvm::SmallVectorImpl<llvm::SDValue> const&, llvm::SmallVectorImpl<llvm::ISD::InputArg> const&, llvm::SDLoc const&, llvm::SelectionDAG&, llvm::SmallVectorImpl<llvm::SDValue>&, llvm::ImmutableCallSite*) const /home/espindola/llvm/llvm/lib/Target/PowerPC/PPCISelLowering.cpp:5189:32 #12 0x0000000001320f60 llvm::PPCTargetLowering::LowerCall(llvm::TargetLowering::CallLoweringInfo&, llvm::SmallVectorImpl<llvm::SDValue>&) const /home/espindola/llvm/llvm/lib/Target/PowerPC/PPCISelLowering.cpp:4653:14 #13 0x000000000222d1e9 llvm::TargetLowering::LowerCallTo(llvm::TargetLowering::CallLoweringInfo&) const /home/espindola/llvm/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:7676:15 #14 0x000000000224a870 llvm::SelectionDAGBuilder::lowerInvokable(llvm::TargetLowering::CallLoweringInfo&, llvm::BasicBlock const*) /home/espindola/llvm/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:5713:3 #15 0x000000000223531d llvm::SelectionDAGBuilder::LowerCallTo(llvm::ImmutableCallSite, llvm::SDValue, bool, llvm::BasicBlock const*) /home/espindola/llvm/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:5806:40 #16 0x000000000221fe18 llvm::SelectionDAGBuilder::visitCall(llvm::CallInst const&) /home/espindola/llvm/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:6373:1 #17 0x00000000022154e7 llvm::SelectionDAGBuilder::visit(unsigned int, llvm::User const&) /home/espindola/llvm/llvm/include/llvm/IR/Instruction.def:186:1 #18 0x00000000022142e9 llvm::SelectionDAGBuilder::visit(llvm::Instruction const&) /home/espindola/llvm/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:980:3 #19 0x00000000022c8024 llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator<llvm::Instruction const>, llvm::ilist_iterator<llvm::Instruction const>, bool&) /home/espindola/llvm/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:672:10 #20 0x00000000022c7ee6 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) /home/espindola/llvm/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1486:5 #21 0x00000000022c5d55 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) /home/espindola/llvm/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:506:36 #22 0x00000000012d6f28 (anonymous namespace)::PPCDAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) /home/espindola/llvm/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp:83:12 #23 0x0000000001b63e86 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /home/espindola/llvm/llvm/lib/CodeGen/MachineFunctionPass.cpp:60:8 #24 0x0000000001ed4eaf llvm::FPPassManager::runOnFunction(llvm::Function&) /home/espindola/llvm/llvm/lib/IR/LegacyPassManager.cpp:1526:27 #25 0x0000000001ed51c5 llvm::FPPassManager::runOnModule(llvm::Module&) /home/espindola/llvm/llvm/lib/IR/LegacyPassManager.cpp:1547:16 #26 0x0000000001ed595a (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /home/espindola/llvm/llvm/lib/IR/LegacyPassManager.cpp:1603:27 #27 0x0000000001ed5486 llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/espindola/llvm/llvm/lib/IR/LegacyPassManager.cpp:1706:16 #28 0x0000000001ed5e71 llvm::legacy::PassManager::run(llvm::Module&) /home/espindola/llvm/llvm/lib/IR/LegacyPassManager.cpp:1737:3 #29 0x000000000086247e compileModule(char**, llvm::LLVMContext&) /home/espindola/llvm/llvm/tools/llc/llc.cpp:483:42 #30 0x00000000008609cd main /home/espindola/llvm/llvm/tools/llc/llc.cpp:260:13 #31 0x00007f9d9b5bb580 __libc_start_main (/lib64/libc.so.6+0x20580) #32 0x0000000000860589 _start (./bin/llc+0x860589)
Seems like a regression from 3.8?
Bisection points to r267527: Author: Chuang-Yu Cheng <cycheng@multicorewareinc.com> Date: Tue Apr 26 07:38:24 2016 +0000 [ppc64] Reenable sibling call optimization on ppc64 since fixed tsan library tail-call issue print-stack-trace.cc test failure of compiler-rt has been fixed by r266869 (http://reviews.llvm.org/D19148), so reenable sibling call optimization on ppc64 Reviewers: nemanjai kbarton cycheng: Can you please investigate?
Ok, I'll look at the issue. Simplify the test pattern: %struct.test = type { i64, [8 x i8] } @gt = common global %struct.test zeroinitializer define hidden i32 @test1(%struct.test* byval) { ret i32 0 } define void @caller1(i32 %z) { entry: %call = tail call i32 @test1(%struct.test* byval @gt) ret void }
The simplest solution is: PPCISelLowering.cpp bool PPCTargetLowering::IsEligibleForTailCallOptimization_64SVR4( SDValue Callee, CallingConv::ID CalleeCC, ImmutableCallSite *CS, bool isVarArg, const SmallVectorImpl<ISD::OutputArg> &Outs, const SmallVectorImpl<ISD::InputArg> &Ins, SelectionDAG& DAG) const { if (std::any_of(Ins.begin(), Ins.end(), [](const ISD::InputArg& IA) { return IA.Flags.isByVal(); })) return false; added following code: // If callee has byval arg, don't do tail-call-opt. if (std::any_of(Outs.begin(), Outs.end(), [](const ISD::OutputArg& OA) { return OA.Flags.isByVal(); })) return false; But I'm thinking if this is a right solution.
I submitted a patch for this bug: https://reviews.llvm.org/D23441 I'm sorry and thanks for reporting this bug!
Committed: r278900