https://bugs.llvm.org/show_bug.cgi?id=41137

            Bug ID: 41137
           Summary: missed opt: target-feature propagation
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedb...@nondot.org
          Reporter: gonzalob...@gmail.com
                CC: llvm-bugs@lists.llvm.org

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 (https://rust.godbolt.org/z/fzcraS):

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 (https://rust.godbolt.org/z/XgMyCJ). 

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to