<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_ASSIGNED "
   title="ASSIGNED --- - [Reassociation w/fast-math] Assert when calling getNeg() on undef of type float"
   href="http://llvm.org/bugs/show_bug.cgi?id=21205">21205</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[Reassociation w/fast-math] Assert  when calling getNeg() on undef of type float
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>ASSIGNED
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Transformation Utilities
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>mcrosier@codeaurora.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>mcrosier@codeaurora.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>chandlerc@gmail.com, llvmbugs@cs.uiuc.edu, resistor@mac.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>An assertion is hit in the Reassociation pass on x86 at -O2 -ffast-math with
the following code:

a, b;
fn1() {
  switch (0)
  case 0: {
    float c;
    b = a - c - 1;
  }
}


The SROA introduces the following instruction:
  %sub = fsub fast float %conv, undef

Complete function:
define i32 @fn1() {
entry:
  %0 = load i32* @a, align 4, !tbaa !1
  %conv = sitofp i32 %0 to float
  %sub = fsub fast float %conv, undef
  %sub1 = fsub fast float %sub, 1.000000e+00
  %conv2 = fptosi float %sub1 to i32
  store i32 %conv2, i32* @b, align 4, !tbaa !1
  ret i32 undef
}

The reassociation pass is trying to canonicalize X-Y into X+(0-Y) to expose
more opportunities for reassociation.  In this case, Y is undef with type
float, but getNeg() is being called, as opposed to getFNeg().

The logic in the pass looks like this:

static Value *NegateValue(Value *V, Instruction *BI) {
  if (ConstantFP *C = dyn_cast<ConstantFP>(V))
    return ConstantExpr::getFNeg(C);
  if (Constant *C = dyn_cast<Constant>(V))
    return ConstantExpr::getNeg(C);
...

I guess an undef of type float isn't a ConstantFP...  ..continuing to
investigate a solution.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>