[llvm] [ConstantFolding] Add flag to disable call folding (PR #140270)
Artem Belevich via llvm-commits
llvm-commits at lists.llvm.org
Fri May 16 11:33:06 PDT 2025
Artem-B wrote:
While I can see potential usefulness to be able to generate specific target code instead of getting a reference result computed by LLVM, I am not convinced that this patch is the way to go.
It does give us a bit more control and will get some computations done on the GPU instead of LLVM-computed result, but it's neither here nor there and leaves us quite far from "let GPU do all FP calculations". The fact that LLVM will still be able to optimize regular FP operations renders it all almost moot. E.g. If LLVM happens to inline some trigonometric function with constant argument, it may be able to fold it all completely bypassing this option.
Things get further complicated by the fact that NVPTX often passes reduced precision FP types as opaque integers, and we presumably want to avoid folding those, too.
That said, as a debug flag for disabling folding of some functions in general it may be useful. Working around function folding in tests is somewhat common.
If we do want to apply the no-folding to a subset of functions, we may need to find a more precise way to determine that set. Manually curating the list will be a pain. For the functions we don't want to fold during compilation we may need to have a way to mark them explicitly, perhaps via an attribute on the function itself, or on the caller function.
Another possibility is to allow specifying a list of functions or patterns to match, and apply the flag only to the matching functions. This way it will be up to the user to specify which function calls they want to preserve.
https://github.com/llvm/llvm-project/pull/140270
More information about the llvm-commits
mailing list