<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Nov 1, 2014, at 2:19 AM, Boris Boesler <<a href="mailto:baembel@gmx.de">baembel@gmx.de</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Hi Quentin,<br><br>Am 01.11.2014 um 00:39 schrieb Quentin Colombet <<a href="mailto:qcolombet@apple.com">qcolombet@apple.com</a>>:<br><br><blockquote type="cite"><br>On Oct 31, 2014, at 11:00 AM, Boris Boesler <<a href="mailto:baembel@gmx.de">baembel@gmx.de</a>> wrote:<br><br><blockquote type="cite">Hi Quentin,<br><br>I added some debug output (N->dump()) in ::Select(SDNode*N) and compared it to the dot/Graphviz output (-view-legalize-types-dags; the last one with correct code). I found out, that some SDNodes are not passed to the ::Select(SDNode*N), approximately 11 nodes are missing. The first add-node (v1+v2) is missing.<br><br>Is it normal that not all nodes are passes to ::Select()?<br><br></blockquote><br>Does not sound right!<br><br>They should be selected, unless they are dead (i.e., no uses).<br><br>Have you looked to the others dag (view-isel-dags in particular).<br></blockquote><br>Yes, the dags in view-isel-dags and view-legalize-types-dags are correct (the add operations are here and are their results are used) and the dags are the same.<br></div></blockquote><div><br></div><div>And what about view-sched-dags?</div><div>This one should give you what has been selected. So if this is not correct, you have indeed a problem in the selection problem.</div><div>If that is the case, you can use -debug-only=isel to help you figuring out what is the problem.</div><div><br></div><div>-Quentin</div><br><blockquote type="cite"><div style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br>Boris<br><br><blockquote type="cite"><br>-Quentin<br><br><blockquote type="cite">Thanks,<br>Boris<br><br><br>Am 30.10.2014 um 19:23 schrieb Quentin Colombet <<a href="mailto:qcolombet@apple.com">qcolombet@apple.com</a>>:<br><br><blockquote type="cite">Hi Boris,<br><br>On Oct 29, 2014, at 10:35 AM, Boris Boesler <<a href="mailto:baembel@gmx.de">baembel@gmx.de</a>> wrote:<br><br><blockquote type="cite">Hi Quentin,<br><br>yes, this happens quite late. With the Option --debug-pass=Structure it's in or after "Assembly Printer".<br>I do have a very simple DAGToDAGISel::Select() method:<br><br>SDNode *MyTargetDAGToDAGISel::Select(SDNode *N)<br>{<br>SDLoc dl(N);<br>// default implementation<br>if (N -> isMachineOpcode()) {<br>N -> setNodeId(-1);<br>return NULL; // Already selected.<br>}<br>SDNode *res = SelectCode(N);<br>return res;<br>}<br><br>Is that too simple? There are no further passes that eliminate anything.<br><br>Anyway, I have another test program, that could point to my bug:<br><br>int formal_args_3(int p1, int p2, int p3)<br>{<br>int v1 = p1;<br>int v2 = p2;<br>int v3 = p3;<br>int res = v1 + v2;<br>return(res);<br>}<br><br>I can compile this test and I get correct code. With option -view-sched-dags I can verify that all arguments are stored in the stack-frame, the local variables are initialized (several store operations in stack-frame) and the return value is evaluated.<br><br>But if I use the statement "int res = v1 + v2 + v3;" something strange happens: all arguments are stored in the stack-frame and the local variables are initialized. Now, the variables v1 and v2 are loaded, but they are not used (no ADD instructions) and a MOVE instruction register to register is generated that uses itself as an operand. This register should be stored and should be used as function result.<br><br>Well, the LOAD instruction uses another register class for the destination register than the ADD instruction uses for its operands, but both classes share some registers. That should not be a problem.<br></blockquote><br>Like you said, that shouldn’t be a problem.<br><br><blockquote type="cite"><br>Any hints where I can search for my bug?<br></blockquote><br>Try using -print-machineinstrs and check where the Machine IR diverge from what you were expected.<br>Then, you can use -debug-only <the offending pass> to have more details.<br><br>Cheers,<br>-Quentin<br><br><blockquote type="cite"><br>Thanks,<br>Boris<br><br><br>Am 24.10.2014 um 19:27 schrieb Quentin Colombet <<a href="mailto:qcolombet@apple.com">qcolombet@apple.com</a>>:<br><br><blockquote type="cite">Hi Boris,<br><br>I don’t see any phis in your machine code whereas the IR had some. This means you are already pretty late in the pipeline of the backend (i.e., after SSA form has been deconstructed).<br>Do you have any custom pass between instruction selection and the PHIElimination pass?<br><br>If so, I would look into them.<br><br>Cheers,<br>-Quentin<br><br><blockquote type="cite">On Oct 24, 2014, at 7:53 AM, Boris Boesler <<a href="mailto:baembel@gmx.de">baembel@gmx.de</a>> wrote:<br><br>Hi!<br><br>During my backend development I get the error message for some tests:<br>*** Bad machine code: Virtual register def doesn't dominate all uses. ***<br><br>(C source-code, byte-code disassembly and printed machine code at the end of the email)<br><br>The first USE of vreg4 in BB#1 has no previous DEF in BB#0 or #1. But why? I can't see how the LLVM byte-code is transformed to the lower machine code.<br><br>One possible reason could be that I haven't implemented all operations, eg I didn't implement MUL at this stage. Their "state" is LEGAL and not CUSTOM or EXPAND. But it fails with implemented operations as well.<br><br>What did I do wrong? Missing implementation for some operations? What did I miss to implement?<br><br>Thanks in advance,<br>Boris<br><br>----8<----<br><br>C source-code:<br>int simple_loop(int end_loop_index)<br>{<br>int sum = 0;<br>for(int i = 0; i < end_loop_index; i++) {<br>sum += i;<br>}<br>return(sum);<br>}<br><br><br>LLVm byte-code disassembly:<br>; Function Attrs: nounwind readnone<br>define i32 @simple_loop(i32 %end_loop_index) #1 {<br>entry:<br>%cmp4 = icmp sgt i32 %end_loop_index, 0<br>br i1 %cmp4, label %for.cond.for.end_crit_edge, label %for.end<br><br>for.cond.for.end_crit_edge: ; preds = %entry<br>%0 = add i32 %end_loop_index, -2<br>%1 = add i32 %end_loop_index, -1<br>%2 = zext i32 %0 to i33<br>%3 = zext i32 %1 to i33<br>%4 = mul i33 %3, %2<br>%5 = lshr i33 %4, 1<br>%6 = trunc i33 %5 to i32<br>%7 = add i32 %6, %end_loop_index<br>%8 = add i32 %7, -1<br>br label %for.end<br><br>for.end: ; preds = %for.cond.for.end_crit_edge, %entry<br>%sum.0.lcssa = phi i32 [ %8, %for.cond.for.end_crit_edge ], [ 0, %entry ]<br>ret i32 %sum.0.lcssa<br>}<br><br><br>The emitted blocks are:<br>Function Live Ins: %R0 in %vreg2<br><br>BB#0: derived from LLVM BB %entry<br>Live Ins: %R0<br><span class="Apple-tab-span" style="white-space: pre;"> </span>%vreg2<def> = COPY %R0; IntRegs:%vreg2<br><span class="Apple-tab-span" style="white-space: pre;"> </span>%vreg3<def> = MV 0; SRegs:%vreg3<br><span class="Apple-tab-span" style="white-space: pre;"> </span>CMP %vreg2, 1, %FLAG<imp-def>; IntRegs:%vreg2<br><span class="Apple-tab-span" style="white-space: pre;"> </span>%vreg6<def> = COPY %vreg3; SRegs:%vreg6,%vreg3<br><span class="Apple-tab-span" style="white-space: pre;"> </span>BR_cc <BB#2>, 20, %FLAG<imp-use,kill><br><span class="Apple-tab-span" style="white-space: pre;"> </span>BR <BB#1><br>Successors according to CFG: BB#1(20) BB#2(12)<br><br>BB#1: derived from LLVM BB %for.cond.for.end_crit_edge<br>Predecessors according to CFG: BB#0<br><span class="Apple-tab-span" style="white-space: pre;"> </span>%vreg4<def> = MV %vreg4; IntRegs:%vreg4<br><span class="Apple-tab-span" style="white-space: pre;"> </span>%vreg5<def> = ADD %vreg4<kill>, -1; IntRegs:%vreg5,%vreg4<br><span class="Apple-tab-span" style="white-space: pre;"> </span>%vreg0<def> = COPY %vreg5<kill>; SRegs:%vreg0 IntRegs:%vreg5<br><span class="Apple-tab-span" style="white-space: pre;"> </span>%vreg6<def> = COPY %vreg0; SRegs:%vreg6,%vreg0<br>Successors according to CFG: BB#2<br><br>BB#2: derived from LLVM BB %for.end<br>Predecessors according to CFG: BB#0 BB#1<br><span class="Apple-tab-span" style="white-space: pre;"> </span>%vreg1<def> = COPY %vreg6<kill>; SRegs:%vreg1,%vreg6<br><span class="Apple-tab-span" style="white-space: pre;"> </span>%R0<def> = COPY %vreg1; SRegs:%vreg1<br><span class="Apple-tab-span" style="white-space: pre;"> </span>RETURN %R0<imp-use><br><br># End machine code for function simple_loop.<br><br>*** Bad machine code: Virtual register def doesn't dominate all uses. ***<br>- function: simple_loop<br>- basic block: BB#1 for.cond.for.end_crit_edge (0x7fd7cb025250)<br>- instruction: %vreg4<def> = MV %vreg4; IntRegs:%vreg4<br>LLVM ERROR: Found 1 machine code errors.<br><br><br>_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote></div></blockquote></div><br></body></html>