{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/22525","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/22525/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/22525/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/22525/events","html_url":"https://github.com/rust-lang/rust/issues/22525","id":58180462,"number":22525,"title":"-C lto -O does not enable LLVM optimizations for the LTO passes","user":{"login":"rprichard","id":1572855,"avatar_url":"https://avatars.githubusercontent.com/u/1572855?v=3","gravatar_id":"","url":"https://api.github.com/users/rprichard","html_url":"https://github.com/rprichard","followers_url":"https://api.github.com/users/rprichard/followers","following_url":"https://api.github.com/users/rprichard/following{/other_user}","gists_url":"https://api.github.com/users/rprichard/gists{/gist_id}","starred_url":"https://api.github.com/users/rprichard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rprichard/subscriptions","organizations_url":"https://api.github.com/users/rprichard/orgs","repos_url":"https://api.github.com/users/rprichard/repos","events_url":"https://api.github.com/users/rprichard/events{/privacy}","received_events_url":"https://api.github.com/users/rprichard/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/A-optimization","name":"A-optimization","color":"d7e102"},{"url":"https://api.github.com/repos/rust-lang/rust/labels/I-slow","name":"I-slow","color":"e10c02"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-02-19T08:38:16Z","updated_at":"2015-02-19T09:08:04Z","closed_at":null,"body":"`-O` seems to function like an alias for `-C opt-level=2`, but `-O` does not enable certain LTO LLVM optimizations (inlining?), whereas `-C opt-level=2` does.  This seems like a mistake.\r\n\r\nThe problem is this code in `librustc_trans/back/lto.rs`:\r\n\r\n        let opt = sess.opts.cg.opt_level.unwrap_or(0) as libc::c_uint;\r\n\r\n        let builder = llvm::LLVMPassManagerBuilderCreate();\r\n        llvm::LLVMPassManagerBuilderSetOptLevel(builder, opt);\r\n        llvm::LLVMPassManagerBuilderPopulateLTOPassManager(builder, pm,\r\n            /* Internalize = */ False,\r\n            /* RunInliner = */ True);\r\n        llvm::LLVMPassManagerBuilderDispose(builder);\r\n\r\n`sess.opts.cg.opt_level` is the `-C opt-level` setting, which is `None` with `-O`.\r\n\r\ntest.rs:\r\n\r\n    pub fn test() {}\r\n\r\noutput:\r\n\r\n    $ rustc test.rs --crate-type staticlib --emit llvm-ir -C lto -O\r\n    $ ls -l test.ll\r\n    -rw-rw-r-- 1 rprichard rprichard 36920440 Feb 19 00:25 test.ll\r\n    $ rustc test.rs --crate-type staticlib --emit llvm-ir -C lto -C opt-level=2\r\n    $ ls -l test.ll \r\n    -rw-rw-r-- 1 rprichard rprichard 1312070 Feb 19 00:25 test.ll\r\n\r\nI think we should base the LLVM optimization level on `sess.opts.optimize`.  (Maybe it ought to use `write::get_llvm_opt_level`?)"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/75018342","html_url":"https://github.com/rust-lang/rust/issues/22525#issuecomment-75018342","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/22525","id":75018342,"user":{"login":"rprichard","id":1572855,"avatar_url":"https://avatars.githubusercontent.com/u/1572855?v=3","gravatar_id":"","url":"https://api.github.com/users/rprichard","html_url":"https://github.com/rprichard","followers_url":"https://api.github.com/users/rprichard/followers","following_url":"https://api.github.com/users/rprichard/following{/other_user}","gists_url":"https://api.github.com/users/rprichard/gists{/gist_id}","starred_url":"https://api.github.com/users/rprichard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rprichard/subscriptions","organizations_url":"https://api.github.com/users/rprichard/orgs","repos_url":"https://api.github.com/users/rprichard/repos","events_url":"https://api.github.com/users/rprichard/events{/privacy}","received_events_url":"https://api.github.com/users/rprichard/received_events","type":"User","site_admin":false},"created_at":"2015-02-19T09:08:04Z","updated_at":"2015-02-19T09:08:04Z","body":"I'd be happy to make a PR, though I probably won't get to it until tomorrow."}}