<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div></div><div><br></div><div><br></div><div><br><div><div>On Nov 7, 2009, at 7:55 AM, Sjodin, Jan wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">
<div 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> <a href="mailto:'llvm-commits@cs.uiuc.edu">'llvm-commits@cs.uiuc.edu</a>'<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></div>
</blockquote></div><br></div></body></html>