Dominique Torette via llvm-dev
2018-Jul-10 08:57 UTC
[llvm-dev] [isel] OPC_EmitMergeInputChains failure on intrinsic lowering.
Hi, I'm still missing something on the operations used by the DAG Pattern ISel state machine, in particular operations like 'OPC_EmitMergeInputChains'. I've define an architecture specific intrinsic mapping to the target NOP operation, like this: def : Pat<(int_clp_nop), (NOP)>; In many 'contexts', it works perfectly. But prior to 'TokenFactor' it fails as in following example: Total amount of phi nodes to update: 2 Node 0 : (0x31d8508, 2147483651) Node 1 : (0x31d8568, 2147483652) Initial selection DAG: BB#1 '_start:while.body' SelectionDAG has 24 nodes: t0: ch = EntryToken t4: i32,ch = CopyFromReg t0, Register:i32 %vreg1 t12: i32,ch = CopyFromReg t0, Register:i32 %vreg0 t13: i32 = add t12, t4 t15: ch = CopyToReg t0, Register:i32 %vreg2, t13 t5: ch = llvm.clp.writeapb.i32 t0, TargetConstant:i16<398>, Constant:i32<24574>, t4 t7: ch = llvm.clp.nop t5, TargetConstant:i16<390> t8: ch = llvm.clp.nop t7, TargetConstant:i16<390> t9: ch = llvm.clp.nop t8, TargetConstant:i16<390> t10: ch = llvm.clp.nop t9, TargetConstant:i16<390> t20: ch = TokenFactor t15, t10 t18: i1 = setcc t13, Constant:i32<100>, setlt:ch t21: ch = brcond t20, t18, BasicBlock:ch<while.body 0x31d8458> t23: ch = br t21, BasicBlock:ch<while.end 0x31d85c8> Selecting: t20: ch = TokenFactor t15, t10 Selecting: t10: ch = llvm.clp.nop t9, TargetConstant:i16<390> ISEL: Starting pattern match on root node: t10: ch = llvm.clp.nop t9, TargetConstant:i16<390> Initial Opcode index to 5 Skipped scope entry (due to false predicate) at index 8, continuing at 44 Skipped scope entry (due to false predicate) at index 45, continuing at 68 Skipped scope entry (due to false predicate) at index 69, continuing at 92 Skipped scope entry (due to false predicate) at index 93, continuing at 116 Match failed at index 120 Continuing at 127 Match failed at index 128 ... LLVM ERROR: Cannot select: intrinsic %llvm.clp.nop ------ I was expecting a match and a morphing to CLP::NOP at line 121. While investigating the cause in the SelectCode MatcherTable[], it fails on 'OPC_emitMergInputsChains'. While viewing the dag-combine1-dags graph, the TokenFactor has two chains (blue dashed lines). Is it the cause of the failure? Why such TokenFactor are introduced? Where/how are they removed? Do I have to define something else in my Pattern<> or in the NOP Instruction<>? ------ /*116*/ /*Scope*/ 10, /*->127*/ /*117*/ OPC_CheckChild1Integer, 6|128,3/*390*/, /*120*/ OPC_EmitMergeInputChains1_0, /*121*/ OPC_MorphNodeTo, TARGET_VAL(CLP::NOP), 0|OPFL_Chain, 0/*#VTs*/, 0/*#Ops*/, // Src: (intrinsic_void 390:iPTR) - Complexity = 8 // Dst: (NOP) TIA, Dominique T. Dominique Torette System Architect Rue des Chasseurs Ardennais - Liège Science Park - B-4031 Angleur Tel: +32 (0) 4 361 81 11 - Fax: +32 (0) 4 361 81 20 www.spacebel.be ------------------------------------------------------------------------------ E-MAIL DISCLAIMER The present message may contain confidential and/or legally privileged information. If you are not the intended addressee and in case of a transmission error, please notify the sender immediately and destroy this E-mail. Disclosure, reproduction or distribution of this document and its possible attachments is strictly forbidden. SPACEBEL denies all liability for incomplete, improper, inaccurate, intercepted, (partly) destroyed, lost and/or belated transmission of the current information given that unencrypted electronic transmission cannot currently be guaranteed to be secure or error free. Upon request or in conformity with formal, contractual agreements, an originally signed hard copy will be sent to you to confirm the information contained in this E-mail. SPACEBEL denies all liability where E-mail is used for private use. SPACEBEL cannot be held responsible for possible viruses that might corrupt this message and/or your computer system. ------------------------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180710/3e27c6b0/attachment.html>
Krzysztof Parzyszek via llvm-dev
2018-Jul-10 13:52 UTC
[llvm-dev] [isel] OPC_EmitMergeInputChains failure on intrinsic lowering.
Hi Dominique, TokenFactors are merge points for multiple chains. A chain is an artificial dependency that is used to maintain (linear) ordering between operations. A TokenFactor takes several input chains, and ensures that the output chain is preceded by each of the inputs (so it allows non-linear ordering). The most common cause of failure during instruction selection in MergeInputChains is that the chains form a loop. The DAG after instruction selection is still a DAG (except that all nodes are now machine nodes), and it will still have chains in it. When instructions are selected, old chains can be replaced with new chains, and somewhere in that process a mistake can cause a loop to be formed. It is also a fairly tedious issue to debug. You can try to dump the DAG right before the OPC_EmitMergeInputChains is executed (in SelectCodeCommon, in SelectionDAGISel.cpp) to see if the problem is evident. Then you can work backwards to see where the problem first shows up. -Krzysztof On 7/10/2018 3:57 AM, Dominique Torette via llvm-dev wrote:> Hi, > > I’m still missing something on the operations used by the DAG Pattern > ISel state machine, in particular operations like > ‘OPC_EmitMergeInputChains’. > > I’ve define an architecture specific intrinsic mapping to the target NOP > operation, like this: > > def : Pat<(int_clp_nop), (NOP)>; > > In many ‘contexts’, it works perfectly. But prior to ‘TokenFactor’ it > fails as in following example: > > Total amount of phi nodes to update: 2 > > Node 0 : (0x31d8508, 2147483651) > > Node 1 : (0x31d8568, 2147483652) > > Initial selection DAG: BB#1 '_start:while.body' > > SelectionDAG has 24 nodes: > > t0: ch = EntryToken > > t4: i32,ch = CopyFromReg t0, Register:i32 %vreg1 > > t12: i32,ch = CopyFromReg t0, Register:i32 %vreg0 > > t13: i32 = add t12, t4 > > t15: ch = CopyToReg t0, Register:i32 %vreg2, t13 > > t5: ch = llvm.clp.writeapb.i32 t0, > TargetConstant:i16<398>, Constant:i32<24574>, t4 > > t7: ch = llvm.clp.nop t5, TargetConstant:i16<390> > > t8: ch = llvm.clp.nop t7, TargetConstant:i16<390> > > t9: ch = llvm.clp.nop t8, TargetConstant:i16<390> > > t10: ch = llvm.clp.nop t9, TargetConstant:i16<390> > > t20: ch = TokenFactor t15, t10 > > t18: i1 = setcc t13, Constant:i32<100>, setlt:ch > > t21: ch = brcond t20, t18, BasicBlock:ch<while.body 0x31d8458> > > t23: ch = br t21, BasicBlock:ch<while.end 0x31d85c8> > > Selecting: t20: ch = TokenFactor t15, t10 > > Selecting: t10: ch = llvm.clp.nop t9, TargetConstant:i16<390> > > ISEL: Starting pattern match on root node: t10: ch = llvm.clp.nop t9, > TargetConstant:i16<390> > > Initial Opcode index to 5 > > Skipped scope entry (due to false predicate) at index 8, continuing at 44 > > Skipped scope entry (due to false predicate) at index 45, continuing > at 68 > > Skipped scope entry (due to false predicate) at index 69, continuing > at 92 > > Skipped scope entry (due to false predicate) at index 93, continuing > at 116 > > Match failed at index 120 > > Continuing at 127 > > Match failed at index 128 > > … > > LLVM ERROR: Cannot select: intrinsic %llvm.clp.nop > > ------ > > I was expecting a match and a morphing to CLP::NOP at line 121. > > While investigating the cause in the SelectCode MatcherTable[], it fails > on ‘OPC_emitMergInputsChains’. > > While viewing the dag-combine1-dags graph, the TokenFactor has two > chains (blue dashed lines). > > Is it the cause of the failure? Why such TokenFactor are introduced? > Where/how are they removed? > > Do I have to define something else in my Pattern<> or in the NOP > Instruction<>? > > ------ > > /*116*//*Scope*/10, /*->127*/ > > /*117*/_OPC_CheckChild1Integer_, 6|128,3/*390*/, > > /*120*/_OPC_EmitMergeInputChains1_0_, > > /*121*/_OPC_MorphNodeTo_, TARGET_VAL(_CLP::NOP_), 0|_OPFL_Chain_, > > 0/*#VTs*/, 0/*#_Ops_*/, > > // _Src_: (intrinsic_void 390:iPTR) - Complexity = 8 > > // _Dst_: (NOP) > > TIA, Dominique T. > > Dominique Torette > > System Architect > > Rue des Chasseurs Ardennais - Liège Science Park - B-4031 Angleur > > Tel: +32 (0) 4 361 81 11 - Fax: +32 (0) 4 361 81 20 > > www.spacebel.be > > > ------------------------------------------------------------------------------ > > E-MAIL DISCLAIMER > > The present message may contain confidential and/or legally privileged > information. If you are not the intended addressee and in case of a > transmission error, please notify the sender immediately and destroy > this E-mail. Disclosure, reproduction or distribution of this document > and its possible attachments is strictly forbidden. > > SPACEBEL denies all liability for incomplete, improper, inaccurate, > intercepted, (partly) destroyed, lost and/or belated transmission of the > current information given that unencrypted electronic transmission > cannot currently be guaranteed to be secure or error free. > Upon request or in conformity with formal, contractual agreements, an > originally signed hard copy will be sent to you to confirm the > information contained in this E-mail. > > SPACEBEL denies all liability where E-mail is used for private use. > > SPACEBEL cannot be held responsible for possible viruses that might > corrupt this message and/or your computer system. > ------------------------------------------------------------------------------- > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation