<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 - Range does not handle `add` and `ugt` comparison well"
   href="https://bugs.llvm.org/show_bug.cgi?id=35069">35069</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Range does not handle `add` and `ugt` comparison well
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>5.0
          </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>yyc1992@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Reproduced with following IR.

```
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define void @f(i64*) {
  %2 = load i64, i64* %0, align 8, !range !0
  %3 = add i64 %2, -1
  %4 = icmp ugt i64 %3, 1000
  br i1 %4, label %L1, label %L2

L1:
  tail call void @g()
  unreachable

L2:
  ret void
}

declare void @g()

!0 = !{i64 2, i64 100}
```

I believe that the function should be optmized to `ret void` since the `icmp`
should always be `false` for the specified range. However, `opt` with
`-instcombine`, `-instsimplify` or just `-O3` does nothing to the `icmp` or the
branch.

Removing the `add` (and make `icmp` take the load value directly) works as
expected as well as replacing the `ugt` with `sgt` even though it shouldn't
make a difference in the value range....</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>