llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.6k stars 11.34k forks source link

'pure' attribute is not considered across multiple expressions #98461

Open Sainan opened 1 month ago

Sainan commented 1 month ago

https://godbolt.org/z/WK1qbrcdh

Notice how in this case my_func is called multiple times, even tho it would be possible to avoid the second call. This behaviour would be preferable because the call could be very expensive, even if inlined.

The 'pure' attribute is already respected within the same expression: https://godbolt.org/z/Ezj5v7rTE

llvmbot commented 1 month ago

@llvm/issue-subscribers-clang-codegen

Author: None (Sainan)

https://godbolt.org/z/WK1qbrcdh Notice how in this case `my_func` is called multiple times, even tho it would be possible to avoid the second call. This behaviour would be preferable because the call could be very expensive, even if inlined. The 'pure' attribute is already respected within the same expression: https://godbolt.org/z/Ezj5v7rTE