<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><BR><DIV><DIV>On Jul 29, 2007, at 9:37 PM, Christopher Lamb wrote:</DIV><BR class="Apple-interchange-newline"><BLOCKQUOTE type="cite"><BR><DIV><DIV>On Jul 29, 2007, at 6:20 PM, Evan Cheng wrote:</DIV><BR class="Apple-interchange-newline"><BLOCKQUOTE type="cite"><DIV>Sent from my iPhone</DIV><DIV><BR>On Jul 28, 2007, at 4:36 PM, Christopher Lamb <<A href="mailto:christopher.lamb@gmail.com">christopher.lamb@gmail.com</A>> wrote:<BR><BR></DIV><DIV></DIV><BLOCKQUOTE type="cite"><DIV><BR><DIV><DIV>On Jul 28, 2007, at 2:26 PM, Evan Cheng wrote:</DIV><BR class="Apple-interchange-newline"><BLOCKQUOTE type="cite"><DIV>On Jul 28, 2007, at 11:52 AM, Christopher Lamb <<A href="mailto:christopher.lamb@gmail.com"></A><A href="mailto:christopher.lamb@gmail.com">christopher.lamb@gmail.com</A>> wrote:<BR></DIV><DIV><BR></DIV><DIV></DIV><BLOCKQUOTE type="cite"><DIV><BR><DIV><DIV>On Jul 28, 2007, at 1:48 AM, Evan Cheng wrote:</DIV><BR class="Apple-interchange-newline"><BLOCKQUOTE type="cite"><DIV>Very cool! I need to read it more carefully. <BR></DIV></BLOCKQUOTE><BR><BLOCKQUOTE type="cite"><DIV>But I see you are lowering zext to a single insert_subreg. Is that right? It won't zero out the top part, no?</DIV></BLOCKQUOTE><DIV><BR class="khtml-block-placeholder"></DIV><DIV>It's only lowering (zext i32 to i64) to an insert_subreg on x86-64 where all writes to 32-bit registers implicitly zero-extend into the upper 32-bits.</DIV><DIV><BR></DIV></DIV></DIV></BLOCKQUOTE><DIV><BR class="webkit-block-placeholder"></DIV>I know. But thy mismatch semantically. A insert_subreg to the lower part should not change the upper half. I think this is only legal for anyext.</BLOCKQUOTE><DIV><BR class="khtml-block-placeholder"></DIV><DIV>On x86-64 the semantics of a 2 operand i32 insert_subreg is that the input super-value is implicitly zero. So in this sense the insert isn't changing the upper half, it's just that the upper half is being set to zero implicitly rather than explicitly. If you'll notice the insert_subreg is a two operand (implicit super value) not a three operand version. If the insert were the three operand version, and the super value as coming from an implicit def I'd agree with you, but it's not.</DIV></DIV></DIV></BLOCKQUOTE><DIV><BR class="webkit-block-placeholder"></DIV>Ok, let's step back for a second. There are a couple of issues that should be addressed. Plz help me understand. :)<DIV><BR class="webkit-block-placeholder"></DIV><DIV>1: Semantics of insert_subreg should be the same across all targets, right?</DIV></BLOCKQUOTE><DIV><BR class="khtml-block-placeholder"></DIV><DIV>I'm not certain that this should be so. x86-64 clearly has a target specific semantics of a 32-bit into 64-bit insert.</DIV></DIV></BLOCKQUOTE><DIV><BR class="khtml-block-placeholder"></DIV>No, that won't do. insert_subreg and extract_subreg are by definition target independent. They must have the same semantics. You are forcing x86-64 32-bit zero-extending move to fit insert_subreg when they are really not the same thing.</DIV><DIV><BR><BLOCKQUOTE type="cite"><DIV><BLOCKQUOTE type="cite"><DIV>2: two operant variant of insert_subreg should mean the superreg is undef. If you insert a value into a low part, the rest of the superreg is still undef.</DIV></BLOCKQUOTE><DIV><BR class="khtml-block-placeholder"></DIV><DIV>I think the meaning of insert_subreg instruction (both 2 and 3 operand versions) must have semantics specific to the target. For example, on x86-64 there is no valid 3 operand insert_subreg for a 32-bit value into 64-bits, because the 32-bit result is always going to be zero extended and overwrite the upper 32-bits.</DIV></DIV></BLOCKQUOTE><DIV><BR class="khtml-block-placeholder"></DIV><DIV>It just means there is no way to implement a insert_subreg with a single instruction under x86-64. But that is perfectly ok. Apart from anyext, x86-64 just isn't going to benefit from it. It's also impossible to read or modify the higher 32-bits.</DIV><BR><BLOCKQUOTE type="cite"><DIV><BLOCKQUOTE type="cite"><DIV>3: why is there a two operant variant in the first place? Why not use undef for the superreg operant?</DIV></BLOCKQUOTE><DIV><BR class="khtml-block-placeholder"></DIV><DIV>To note, the two operand variant is of the MachineInstr. The DAG form would be to represent the superregister as coming from an undef node, but this gets isel'd to the two operand MachineInstr of insert_subreg.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>The reason is that undef is typically selected to an implicit def of a register. This causes an unnecessary move to be generated later on. This move can be optimized away later with more difficulty during subreg lowering by checking whether the input register is defined by an implicit def pseudo instruction, but instead I decided to perform the optimization during ISel on the DAG form during instruction selection.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>With what you're suggesting</DIV><DIV>reg1024 = ...</DIV><DIV>reg1026 = insert_subreg undef, reg1024, 1</DIV><DIV>reg1027 = insert_subreg reg1026, reg1025, 1</DIV><DIV>use reg1027</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>would be isel'd to then subreg lowered to:</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>R6 = ...</DIV><DIV>implicit def R01 <= this implicit def is unecessary</DIV></DIV></BLOCKQUOTE><DIV><BR class="khtml-block-placeholder"></DIV>That's a pseudo instruction, it doesn't cost anything.</DIV><DIV><BR><BLOCKQUOTE type="cite"><DIV><DIV>R23 = R01 <= this copy is unnecessary </DIV></DIV></BLOCKQUOTE><DIV><BR class="khtml-block-placeholder"></DIV>It can be coalesced to:</DIV><DIV>R23 = undef</DIV><DIV><BR><BLOCKQUOTE type="cite"><DIV><DIV>R2 = R6</DIV><DIV>R45 = R23</DIV><DIV>R5 = R6</DIV><DIV>use R45</DIV></DIV></BLOCKQUOTE><DIV><BR class="khtml-block-placeholder"></DIV>Using undef explicit is the right way to go. There is a good reason it's there. Having the two operand version of insert_subreg that implicitly use an undef value doesn't fit into the overall llvm philosophy.<BR><DIV><BR class="khtml-block-placeholder"></DIV><BR><BLOCKQUOTE type="cite"><DIV><BLOCKQUOTE type="cite"><DIV>4: what's the benefit of isel a zext to insert_subreg and then xform it to a 32-bit move? <BR></DIV></BLOCKQUOTE><DIV><BR class="khtml-block-placeholder"></DIV><DIV>The xform to a 32-bit move is only the conservative behavior. The zext can be implicit if regalloc can coalesce subreg_inserts.</DIV><BR><BLOCKQUOTE type="cite"><DIV>Why not just isel the zext to the move? It's not legal to coalesce it away anyway.</DIV></BLOCKQUOTE><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Actually it is legal to coalesce it. On x86-64 any write to a 32-bit register zero extends the value to 64-bits. For the insert_subreg under discussion the inserted value is a 32-bit result, that has in-fact already be zero extended implicitly.</DIV></DIV></BLOCKQUOTE><DIV><BR class="khtml-block-placeholder"></DIV>It's not legal to coalesce away the 32-bit zero extending move.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Suppose RAX contains some value with top 32-bits non-zero.</DIV><DIV>mov EAX, EAX (zero extend top bits)</DIV><DIV>use RAX (expecting top bits to be zero)</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Coalesced away the move is a miscompilation.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Evan</DIV><DIV><DIV><BR class="khtml-block-placeholder"></DIV><BR><BLOCKQUOTE type="cite"><DIV><BLOCKQUOTE type="cite"><DIV><BLOCKQUOTE type="cite"><DIV><DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Also the current behavior is to use a 32-bit mov instruction for both zeroext and for anyext, I don't see how this is any different.</DIV><BR><BLOCKQUOTE type="cite"><DIV><BLOCKQUOTE type="cite"><DIV><DIV><DIV>--</DIV><DIV>Chris</DIV><DIV><BR class="khtml-block-placeholder"></DIV><BLOCKQUOTE type="cite"><DIV>Sent from my iPhone</DIV><DIV><BR>On Jul 28, 2007, at 12:17 AM, Christopher Lamb <<A href="mailto:christopher.lamb@gmail.com"></A><A href="mailto:christopher.lamb@gmail.com"></A><A href="mailto:christopher.lamb@gmail.com">christopher.lamb@gmail.com</A>> wrote:<BR><BR></DIV><DIV></DIV><BLOCKQUOTE type="cite"><DIV>This patch changes the X86 back end to use the new subreg operations for appropriate truncate and extend operations. This should allow regression testing of the subreg feature going forward, as it's now used in a public target.<DIV><BR class="khtml-block-placeholder"></DIV><DIV>The patch passed DejaGnu and all of SingleSource on my x86 machine, but there are changes for x86-64 as well which I haven't been able to test. Output assembly for x86-64 appears sane, but I'd appreciate someone giving the patch a try on their x86-64 system. Other 32-bit x86 testing is also appreciated.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Thanks<BR><DIV> <SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><DIV>--</DIV><DIV>Christopher Lamb</DIV><DIV><BR class="khtml-block-placeholder"></DIV></SPAN></SPAN></DIV></DIV></DIV></BLOCKQUOTE><BLOCKQUOTE type="cite"><DIV><x86_subregs.patch></DIV></BLOCKQUOTE><BLOCKQUOTE type="cite"><DIV><DIV><DIV><SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><BR class="Apple-interchange-newline"></SPAN></SPAN> </DIV><BR></DIV></DIV></BLOCKQUOTE><BLOCKQUOTE type="cite"><DIV><SPAN>_______________________________________________</SPAN><BR><SPAN>llvm-commits mailing list</SPAN><BR><SPAN><A href="mailto:llvm-commits@cs.uiuc.edu"></A><A href="mailto:llvm-commits@cs.uiuc.edu"></A><A href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</A></SPAN><BR><SPAN><A href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits"></A><A href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits"></A><A href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</A></SPAN><BR></DIV></BLOCKQUOTE><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">_______________________________________________</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">llvm-commits mailing list</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A href="mailto:llvm-commits@cs.uiuc.edu"></A><A href="mailto:llvm-commits@cs.uiuc.edu"></A><A href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</A></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits"></A><A href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits"></A><A href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</A></DIV> </BLOCKQUOTE></DIV><BR><DIV> <SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><DIV>--</DIV><DIV>Christopher Lamb</DIV><DIV><BR class="khtml-block-placeholder"></DIV><BR class="Apple-interchange-newline"></SPAN></SPAN> </DIV><BR></DIV></BLOCKQUOTE><BLOCKQUOTE type="cite"><DIV><SPAN>_______________________________________________</SPAN><BR><SPAN>llvm-commits mailing list</SPAN><BR><SPAN><A href="mailto:llvm-commits@cs.uiuc.edu"></A><A href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</A></SPAN><BR><SPAN><A href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits"></A><A href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</A></SPAN><BR></DIV></BLOCKQUOTE></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">_______________________________________________</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">llvm-commits mailing list</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A href="mailto:llvm-commits@cs.uiuc.edu"></A><A href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</A></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits"></A><A href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</A></DIV> </BLOCKQUOTE></DIV><BR><DIV> <SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><DIV>--</DIV><DIV>Christopher Lamb</DIV><DIV><BR class="khtml-block-placeholder"></DIV><BR class="Apple-interchange-newline"></SPAN></SPAN> </DIV><BR></DIV></BLOCKQUOTE><BLOCKQUOTE type="cite"><DIV><SPAN>_______________________________________________</SPAN><BR><SPAN>llvm-commits mailing list</SPAN><BR><SPAN><A href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</A></SPAN><BR><SPAN><A href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</A></SPAN><BR></DIV></BLOCKQUOTE></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">_______________________________________________</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">llvm-commits mailing list</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</A></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</A></DIV> </BLOCKQUOTE></DIV><BR><DIV> <SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><DIV>--</DIV><DIV>Christopher Lamb</DIV><DIV><BR class="khtml-block-placeholder"></DIV><BR class="Apple-interchange-newline"></SPAN></SPAN> </DIV><BR><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">_______________________________________________</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">llvm-commits mailing list</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</A></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</A></DIV> </BLOCKQUOTE></DIV><BR></BODY></HTML>