Hey folks,
I have a function with an unused parameter of pointer type, which LLVM marks as readnone
and nocapture
. I also have a caller that allocates the argument with alloca
and writes some data to it before passing it to the function.
LLVM optimizes the caller’s code by removing the writes to the argument since it’s never read from, passing the alloca
ted memory uninitialized.
But it seems like it could go further. If the argument was e.g. replaced with undef
, the alloca
could be removed altogether. This seems like a missed optimization opportunity to me.
So the question is whether this would be a sound optimization for LLVM to do in general, and if so, are the readnone
and nocapture
attributes enough to determine that the argument can be undef
, or do we need an additional attribute like unused
?
Olle