<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 - opt -simplifycfg generates different code when dbg intrinsics are present"
   href="https://bugs.llvm.org/show_bug.cgi?id=49982">49982</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>opt -simplifycfg generates different code when dbg intrinsics are present
          </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>NEW
          </td>
        </tr>

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

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

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>mikael.holmen@ericsson.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=24760" name="attach_24760" title="scfg.ll reproducer">attachment 24760</a> <a href="attachment.cgi?id=24760&action=edit" title="scfg.ll reproducer">[details]</a></span>
scfg.ll reproducer

Reproduce with:
opt -simplifycfg -S -o - scfg.ll | opt -strip-debug -S -o res1.ll
and
opt -strip-debug -o - -S scfg.ll | opt -simplifycfg -S -o - | opt -strip-debug
-S -o res2.ll
diff res1.ll res2.ll

Result

11c11
< for.cond:                                         ; preds = %cond.end,
%lor.lhs.false, %land.lhs.true, %entry
---
<span class="quote">> for.cond:                                         ; preds = %land.lhs.true21, %cond.end, %lor.lhs.false, %entry</span >
14,19c14
<   br i1 %cmp, label %land.lhs.true, label %lor.lhs.false

< land.lhs.true:                                    ; preds = %for.cond
<   %tobool.not = icmp ugt i32 %i5, 2
<   store i16 0, i16* getelementptr inbounds ([1 x i16], [1 x i16]* @f, i16 0,
i16 0), align 1
<   br label %for.cond
---
<span class="quote">>   br i1 %cmp, label %land.lhs.true21, label %lor.lhs.false</span >
25a21,24
<span class="quote">>   store i16 0, i16* getelementptr inbounds ([1 x i16], [1 x i16]* @f, i16 0, i16 0), align 1
>   br label %for.cond

> land.lhs.true21:                                  ; preds = %for.cond</span >

This starts happening with 467b1f1cd2f277:
    [SimplifyCFG] Allow hoisting terminators only with HoistCommonInsts=false.

    As a side-effect of the change to default HoistCommonInsts to false
    early in the pipeline, we fail to convert conditional branch & phis to
    selects early on, which prevents vectorization for loops that contain
    conditional branches that effectively are selects (or if the loop gets
    vectorized, it will get vectorized very inefficiently).

    This patch updates SimplifyCFG to perform hoisting if the only
    instruction in both BBs is an equal branch. In this case, the only
    additional instructions are selects for phis, which should be cheap.

    Even though we perform hoisting, the benefits of this kind of hoisting
    should by far outweigh the negatives.

    For example, the loop in the code below will not get vectorized on
    AArch64 with the current default, but will with the patch. This is a
    fundamental pattern we should definitely vectorize. Besides that, I
    think the select variants should be easier to use for reasoning across
    other passes as well.

    <a href="https://clang.godbolt.org/z/sbjd8Wshx">https://clang.godbolt.org/z/sbjd8Wshx</a>

    ```
    double clamp(double v) {
      if (v < 0.0)
        return 0.0;
      if (v > 6.0)
        return 6.0;
      return v;
    }

    void loop(double* X, double *Y) {
      for (unsigned i = 0; i < 20000; i++) {
        X[i] = clamp(Y[i]);
      }
    }
    ```

    Reviewed By: lebedev.ri

    Differential Revision: <a href="https://reviews.llvm.org/D100329">https://reviews.llvm.org/D100329</a></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>