<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.5890" name=GENERATOR></HEAD>
<BODY
style="WORD-WRAP: break-word; webkit-nbsp-mode: space; webkit-line-break: after-white-space">
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=678214015-07112009>I agree that this is not the ideal way to do things,
and the list of operations is indeed incomplete and may be different on
different targets.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=678214015-07112009>The problem is that the type legalization is done
without taking the operations into </SPAN></FONT><FONT face=Arial color=#0000ff
size=2><SPAN class=678214015-07112009>account. A more general solution
would be to combine the type and ops legalization into one pass. A somewhat
simpler solution could be to</SPAN></FONT><FONT face=Arial color=#0000ff
size=2><SPAN class=678214015-07112009> scalarize operations first, then do the
type legalization and finally apply the non-scalarizing legalize
</SPAN></FONT><FONT face=Arial color=#0000ff size=2><SPAN
class=678214015-07112009>vector ops. I do not know if there are
</SPAN></FONT><FONT face=Arial color=#0000ff size=2><SPAN
class=678214015-07112009>any cases where legalization needs more
information about the surrounding operations to produce correct code.
</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=678214015-07112009></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=678214015-07112009>- Jan</SPAN></FONT></DIV><FONT face=Arial color=#0000ff
size=2></FONT><BR>
<BLOCKQUOTE dir=ltr
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> Mon Ping Wang [mailto:wangmp@apple.com]
<BR><B>Sent:</B> Friday, November 06, 2009 11:59 PM<BR><B>To:</B> Sjodin,
Jan<BR><B>Cc:</B> 'llvm-commits@cs.uiuc.edu'<BR><B>Subject:</B> Re:
[llvm-commits] Patch for scalarized division.<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV>Hi Jan,</DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT><FONT face=Arial
color=#0000ff size=2></FONT><FONT face=Arial color=#0000ff
size=2></FONT><BR></DIV>
<DIV>Some quick comments about the patch.</DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT><FONT face=Arial
color=#0000ff size=2></FONT><FONT face=Arial color=#0000ff
size=2></FONT><BR></DIV>
<DIV>
<DIV><FONT class=Apple-style-span face=Courier size=3><SPAN
class=Apple-style-span style="FONT-SIZE: 12px">@@ -282,6 +289,95 @@ SDValue
VectorLegalizer::UnrollVSETCC(SD</SPAN></FONT></DIV>
<DIV><FONT class=Apple-style-span face=Courier size=3><SPAN
class=Apple-style-span style="FONT-SIZE: 12px"><BR></SPAN></FONT></DIV></DIV>
<DIV>
<DIV><FONT class=Apple-style-span face=Courier size=3><SPAN
class=Apple-style-span style="FONT-SIZE: 12px">+bool
VectorLegalizer::rangeIsDefined(SDValue Op, </SPAN></FONT></DIV>
<DIV><FONT class=Apple-style-span face=Courier size=3><SPAN
class=Apple-style-span style="FONT-SIZE: 12px">+
uint64_t LoBitIndex, </SPAN></FONT></DIV>
<DIV><FONT class=Apple-style-span face=Courier size=3><SPAN
class=Apple-style-span style="FONT-SIZE: 12px">+
uint64_t HiBitIndex)</SPAN></FONT></DIV>
<DIV><FONT class=Apple-style-span face=Courier size=3><SPAN
class=Apple-style-span style="FONT-SIZE: 12px">+{</SPAN></FONT></DIV>
<DIV><FONT class=Apple-style-span face=Courier size=3><SPAN
class=Apple-style-span style="FONT-SIZE: 12px">+[Deleted
Code]</SPAN></FONT></DIV>
<DIV><FONT class=Apple-style-span face=Courier size=3><SPAN
class=Apple-style-span style="FONT-SIZE: 12px">+ case
ISD::ADD: </SPAN></FONT></DIV>
<DIV><FONT class=Apple-style-span face=Courier size=3><SPAN
class=Apple-style-span style="FONT-SIZE: 12px">+ case
ISD::SUB:</SPAN></FONT></DIV>
<DIV><FONT class=Apple-style-span face=Courier size=3><SPAN
class=Apple-style-span style="FONT-SIZE: 12px">+ case
ISD::MUL:</SPAN></FONT></DIV>
<DIV><FONT class=Apple-style-span face=Courier size=3><SPAN
class=Apple-style-span style="FONT-SIZE: 12px">+ case
ISD::SDIV:</SPAN></FONT></DIV>
<DIV><FONT class=Apple-style-span face=Courier size=3><SPAN
class=Apple-style-span style="FONT-SIZE: 12px">+ case
ISD::UDIV:</SPAN></FONT></DIV>
<DIV><FONT class=Apple-style-span face=Courier size=3><SPAN
class=Apple-style-span style="FONT-SIZE: 12px">+ case
ISD::SREM:</SPAN></FONT></DIV>
<DIV><FONT class=Apple-style-span face=Courier size=3><SPAN
class=Apple-style-span style="FONT-SIZE: 12px">+ case ISD::UREM:
{</SPAN></FONT></DIV></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT><FONT face=Arial
color=#0000ff size=2></FONT><FONT face=Arial color=#0000ff size=2></FONT><FONT
face=Arial color=#0000ff size=2></FONT><BR></DIV>
<DIV>We should expand the list will have to expand to almost all
operators. For example, an ISD::AND or ISD::XOR could cause the same
problem as well as VECTOR_SHUFFLE. </DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT><FONT face=Arial
color=#0000ff size=2></FONT><FONT face=Arial color=#0000ff size=2></FONT><FONT
face=Arial color=#0000ff size=2></FONT><FONT face=Arial color=#0000ff
size=2></FONT><FONT face=Arial color=#0000ff size=2></FONT><BR></DIV>
<DIV>
<DIV><FONT class=Apple-style-span face=Courier size=3><SPAN
class=Apple-style-span style="FONT-SIZE: 12px">@@ -326,6 +422,16
@@</SPAN></FONT></DIV>
<DIV><FONT class=Apple-style-span face=Courier size=3><SPAN
class=Apple-style-span style="FONT-SIZE: 12px">SDValue
VectorLegalizer::UnrollVectorOp(</SPAN></FONT></DIV>
<DIV><FONT class=Apple-style-span face=Courier size=3><SPAN
class=Apple-style-span style="FONT-SIZE: 12px">
Scalars.push_back(DAG.getNode(Op.getOpcode(), dl, EltVT,
Operands[0],</SPAN></FONT></DIV>
<DIV><FONT class=Apple-style-span face=Courier size=3><SPAN
class=Apple-style-span style="FONT-SIZE: 12px">
DAG.getShiftAmountOperand(Operands[1])));</SPAN></FONT></DIV>
<DIV><FONT class=Apple-style-span face=Courier size=3><SPAN
class=Apple-style-span style="FONT-SIZE: 12px">
break;</SPAN></FONT></DIV>
<DIV><FONT class=Apple-style-span face=Courier size=3><SPAN
class=Apple-style-span style="FONT-SIZE: 12px">+ // Ensure
that both operands are defined, if not, the result will</SPAN></FONT></DIV>
<DIV><FONT class=Apple-style-span face=Courier size=3><SPAN
class=Apple-style-span style="FONT-SIZE: 12px">+ // be
undefined. </SPAN></FONT></DIV>
<DIV><FONT class=Apple-style-span face=Courier size=3><SPAN
class=Apple-style-span style="FONT-SIZE: 12px">+ case
ISD::SDIV:</SPAN></FONT></DIV>
<DIV><FONT class=Apple-style-span face=Courier size=3><SPAN
class=Apple-style-span style="FONT-SIZE: 12px">+ case
ISD::UDIV:</SPAN></FONT></DIV></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT><FONT face=Arial
color=#0000ff size=2></FONT><FONT face=Arial color=#0000ff size=2></FONT><FONT
face=Arial color=#0000ff size=2></FONT><FONT face=Arial color=#0000ff
size=2></FONT><BR></DIV>
<DIV>For some machines, SREM and UREM could have the same issue.</DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT><FONT face=Arial
color=#0000ff size=2></FONT><FONT face=Arial color=#0000ff size=2></FONT><FONT
face=Arial color=#0000ff size=2></FONT><FONT face=Arial color=#0000ff
size=2></FONT><BR></DIV>
<DIV>This is a generic issue that goes beyond just SDIV/UDIV. In
the majority of these cases, I think we should try to avoid generating
operations for UNDEF. The only cases that give me pause of doing this
all the time are operations like multiplication by 0, and of 0, etc.. where
the UNDEF would be defined. The only other thing is that we recursively
walk up an expression tree. If the expression tree is deep, this could
cost some time.</DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT><FONT face=Arial
color=#0000ff size=2></FONT><FONT face=Arial color=#0000ff size=2></FONT><FONT
face=Arial color=#0000ff size=2></FONT><FONT face=Arial color=#0000ff
size=2></FONT><BR></DIV>
<DIV>The main culprit that causes these UNDEF is due to widening.
A crazy idea to avoid doing this is if a hardware knows a particular
operation should not be widened, maybe it could use a target hook to scalarize
the operation early doing LegalizeTypes. For X86, since divides will not
be vector operations, we would avoid widening them only to lower them and work
hard trying to avoid generating the extra divides.</DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT><FONT face=Arial
color=#0000ff size=2></FONT><FONT face=Arial color=#0000ff
size=2></FONT><BR></DIV>
<DIV>-- Mon Ping</DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT><FONT face=Arial
color=#0000ff size=2></FONT><FONT face=Arial color=#0000ff
size=2></FONT><BR></DIV><BR>
<DIV>
<DIV>On Nov 6, 2009, at 1:39 PM, Sjodin, Jan wrote:</DIV><BR
class=Apple-interchange-newline>
<BLOCKQUOTE type="cite">
<DIV>In LegalizeVectorOps the resulting scalar divisions must not
be<BR>generated if they have undefined vector elements as operands. This
may<BR>be unsafe because the divides can cause division by zero
exceptions,<BR>and also slows down the code. This patch attempts to fix this
issue by<BR>checking if the operands are defined or not. I would be grateful
if<BR>someone could review this patch. Thanks!<BR><BR>- Jan
Sjodin<SPAN><0015_scalarized_div.diff></SPAN>_______________________________________________<BR>llvm-commits
mailing list<BR><A
href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</A><BR><A
href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</A><BR></DIV></BLOCKQUOTE>
<DIV><FONT face=Arial color=#0000ff size=2></FONT><BR></DIV></DIV>
<DIV>
<DIV><FONT face=Arial color=#0000ff
size=2></FONT><BR></DIV></DIV></BLOCKQUOTE></BODY></HTML>