llvm / llvm-project

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

Implement __attribute__((noipa)) to make a function a black box for interprocedural optimizations #40819

Open comex opened 5 years ago

comex commented 5 years ago
Bugzilla Link 41474
Version trunk
OS All
CC @hfinkel,@zygoloid

Extended Description

Currently, Clang will always optimize this to return 3:

static int inner(int a) { return a + 1; } int outer() { return inner(2); }

Notably, this happens even if inner is marked noinline, because of the Interprocedural Sparse Conditional Constant Propagation pass.

This is unhelpful for various use cases, including:

GCC has a function attribute noipa, whose effect is (to quote the manual):

Disable interprocedural optimizations between the function with this attribute and its callers, as if the body of the function is not available when optimizing callers and the callers are unavailable when optimizing the body.

It would be good to support this in LLVM/Clang as well.

dwblaikie commented 1 year ago

Some work/discussion around this did happen last year: https://discourse.llvm.org/t/revisiting-refining-the-definition-of-optnone-with-interprocedural-transformations/58095/11 https://reviews.llvm.org/D101011