Are function calls removed if their result is unused?

If the optimizer can see into the code you're calling and guarantee there are no effects, it definitely does remove function calls and other code. The benchmarks used for Swift's development use calls to non-inlinable functions in another module to prevent that optimization. See the functions at the end of this file, which gets compiled into a TestUtils module: swift/TestsUtils.swift at 4694310e51330aadf079cf15497c789ce686e1a1 · apple/swift · GitHub

8 Likes