<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [DAGCombine] Missed A + -2.0*B*C -> A - (B+B)*C"
   href="https://bugs.llvm.org/show_bug.cgi?id=32939">32939</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[DAGCombine] Missed A + -2.0*B*C -> A - (B+B)*C
          </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>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Common Code Generator Code
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

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

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Given the following C code

double test1(double a, double b, double c) {
  return a + 2.0*b*c;
}

Clang removes a multiply by transforming '2.0*b' to 'b+b' during DAGCombine. 
For example, we generate the following when targeting AArch64:

test1:                                  // @test1
        fadd    d1, d1, d1
        fmul    d1, d1, d2
        fadd    d0, d1, d0
        ret

Given the below code

double test2(double a, double b, double c) {
  return a + -2.0*b*c;
}

we should be able to perform a similar transform if we can remove the negative
constant by converting the addition into subtraction.

Currently we generate the below when targeting AArch64:
test2:                                  // @test2
        fmov    d3, #-2.00000000
        fmul    d1, d1, d3
        fmul    d1, d1, d2
        fadd    d0, d1, d0
        ret

but I'd expect

test2:                                  // @test2
        fadd    d1, d1, d1
        fmul    d1, d1, d2
        fsub    d0, d1, d0
        ret

AFAIK, this doesn't require fast-math.</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>