<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 - missed opt: target-feature propagation"
   href="https://bugs.llvm.org/show_bug.cgi?id=41137">41137</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>missed opt: target-feature propagation
          </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>gonzalobg88@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Minimal working example - this Rust code:

extern "C" {
   #[target_feature(enable = "avx2")]
   pub fn foo();
}

pub unsafe fn bar() { foo() }

generated the following LLVM-IR (<a href="https://rust.godbolt.org/z/fzcraS">https://rust.godbolt.org/z/fzcraS</a>):

define void @bar() unnamed_addr #0 {
  tail call void @foo()
  ret void
}

declare void @foo() unnamed_addr #1

attributes #0 = { nounwind nonlazybind uwtable
"probe-stack"="__rust_probestack" "target-cpu"="x86-64" }
attributes #1 = { nounwind nonlazybind uwtable
"probe-stack"="__rust_probestack" "target-cpu"="x86-64"
"target-features"="+avx2" }

which `opt` does not optimize further (<a href="https://rust.godbolt.org/z/XgMyCJ">https://rust.godbolt.org/z/XgMyCJ</a>). 

Note that `foo` does get the "target-features"="+avx2" attribute added, which
in general can significantly impact code generation. 

This optimization is sound, because if `foo` is called on a platform without
`avx2` support, the behavior is undefined. That is, LLVM can always assume that
`foo` will only be called on platforms where `avx2` is enabled.</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>