Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebAssembly backend doesn't inline normal functions into SIMD functions #74320

Closed
alexcrichton opened this issue Jul 14, 2020 · 1 comment
Closed
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. O-wasm Target: WASM (WebAssembly), http://webassembly.org/

Comments

@alexcrichton
Copy link
Member

alexcrichton commented Jul 14, 2020

Upstream LLVM bug

Given a program such as:

#![feature(wasm_target_feature)]

#[target_feature(enable = "simd128")]
#[no_mangle]
pub unsafe extern "C" fn bar() {
    inline_me();
}

fn inline_me() {
    unsafe { foo() } // or anything else that's "side effectful"
}

extern "C" {
    fn foo();
}

LLVM generates this IR:

$ rustc +nightly foo.rs --target wasm32-unknown-unknown --crate-type cdylib --emit llvm-ir -O
$ cat foo.ll
; ModuleID = 'foo.3a1fbbbh-cgu.0'
source_filename = "foo.3a1fbbbh-cgu.0"
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32-unknown-unknown"

; Function Attrs: nounwind
define void @bar() unnamed_addr #0 {
start:
; call foo::inline_me
  tail call fastcc void @_ZN3foo9inline_me17h0a001429f3373a4bE()
  ret void
}

; foo::inline_me
; Function Attrs: nounwind
define internal fastcc void @_ZN3foo9inline_me17h0a001429f3373a4bE() unnamed_addr #1 {
start:
  tail call void @foo()
  ret void
}

; Function Attrs: nounwind
declare void @foo() unnamed_addr #1

attributes #0 = { nounwind "target-cpu"="generic" "target-features"="+simd128" }
attributes #1 = { nounwind "target-cpu"="generic" }

Here the inline_me function is not inlined in to bar, even though it should be a candidate for doing so. This is a bug in LLVM rather than rustc, but I wanted to file an issue here since I'm about to write documentation referencing this issue. I also figured it's good for us to track this at least!

@alexcrichton alexcrichton added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. O-wasm Target: WASM (WebAssembly), http://webassembly.org/ labels Jul 14, 2020
@alexcrichton
Copy link
Member Author

Looks like this has since been fixed in upstream LLVM, so closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. O-wasm Target: WASM (WebAssembly), http://webassembly.org/
Projects
None yet
Development

No branches or pull requests

1 participant