[llvm-dev] Intrinsics InstrReadMem memory properties

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Thu Jul 25 02:58:04 PDT 2019


On Thu, 25 Jul 2019 at 09:53, Son Tuan VU via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> - IntrWriteMem: memset() optimized away by DSE but the intrinsic isn't. I would expect both to be removed, since the intrinsic is now also a dead store.

IntrWriteMem means the intrinsic could write to memory *anywhere*, not
just based on its argument.

> - IntrReadMem: memset() and the intrinsic are both optimized away *unexpectedly* (CSE removes the intrinsic, then InstCombine removes memset). The latter is understandable, but why the intrinsic gets optimized in the first place?

I haven't checked the code, but an intrinsic that only reads memory
(no other side effects) and returns void can't actually accomplish
anything observable.

> Am I missing something here or there are indeed bugs here?

It all looks as expected to me.

> Btw, can you tell me how and why 'tail' changes the optimizer behavior?

>From the LangRef about tail (and musttail): "Both markers imply that
the callee does not access allocas from the caller". That seems
directly applicable to your example.

The reason, of course, is that if a call is actually implemented as a
tail call then the current stack frame is reused for the new callee.
So the lifetime of objects on it has ended and accessing them is just
not possible in a well-defined program.

Cheers.

Tim.


More information about the llvm-dev mailing list