<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 - instcombine transform ruins simplifycfg if-then to select optimization"
   href="https://bugs.llvm.org/show_bug.cgi?id=50425">50425</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>instcombine transform ruins simplifycfg if-then to select optimization
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </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>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>valery.n.dmitriev@intel.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I recently encountered a case where instcombine transform
icmp (A-B), (C-B) -> icmp A, C
affects simplifycfg ability to fold if-then into a select.

Here is test case:
; begin
target triple = "x86_64-unknown-linux-gnu"

define dso_local void @foo(i32* %p1, i32* %p2, i32 %g, i32 %gh) {
entry:
  %i2 = load i32, i32* %p1, align 4
  %sub17 = sub nsw i32 %i2, %gh
  store i32 %sub17, i32* %p1, align 4
  %i3 = load i32, i32* %p2, align 4
  %i20 = add nsw i32 %i3, %g
  %sub21 = sub nsw i32 %i20, %gh
  %cmp24 = icmp slt i32 %sub17, %sub21
  br i1 %cmp24, label %if.then25, label %if.end28

if.then25:
  store i32 %sub21, i32* %p1, align 4
  br label %if.end28

if.end28:
  br label %end

end:
  ret void
}
; end

To reproduce compare
opt -S -instcombine -simplifycfg  test.ll
versus
opt -S -simplifycfg  test.ll

At first glance it may appear as if instcombine sinking creates an issue for
simplifycfg
but even with -instcombine-code-sinking=false option simplifycfg does not fold
if-then:

<a href="https://alive2.llvm.org/ce/z/sYXoZO">https://alive2.llvm.org/ce/z/sYXoZO</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>