<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 drops range information when combining inttoptr with load"
   href="https://bugs.llvm.org/show_bug.cgi?id=47243">47243</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Instcombine drops range information when combining inttoptr with load
          </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>All
          </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>quentin.colombet@gmail.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=23865" name="attach_23865" title="Reproducer">attachment 23865</a> <a href="attachment.cgi?id=23865&action=edit" title="Reproducer">[details]</a></span>
Reproducer

When instcombine replaces inttoptr(load intTy) to (load ptrTy) it drops the
range information attached to the load.
More precisely, it replaces the range information with an inferior metadata.

The problem may lay into what the range information can represent, but we
should fix that one way or another as this may result in suboptimal code.

* Example *

Consider the following snippet:
```
define float* @test5_range(i64* %ptr) {
entry:
  %val = load i64, i64* %ptr, !range !{i64 64, i64 65536}
  %valptr = inttoptr i64 %val to float*
  ret float* %valptr
}
```

The returned pointer is known to be between address 64 and address 65536.

After instcombine however, this information is lost and instead we have a less
rich information that the pointer is non-null:
```
define float* @test5_range(i64* %ptr) {
entry:
  %0 = bitcast i64* %ptr to float**
  %val1 = load float*, float** %0, align 4, !nonnull !0
  ret float* %val1
}
```

* To Reproduce *

opt -S  -instcombine ~/Downloads/instcombine_range.ll  -o -</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>