Running DCE after my pass


I wrote an IR pass and it adds some instructions that are not used.

For example:

%1 = call i64 @foo()

When %1 is not used at all.

I thought that running DCE (-dce) or DIE (-die) after my pass will remove such instructions, but it didn’t.

Why? And is there a way to do that?



Hi Tehila,

LLVM should not unconditionally remove such a function call because @foo may have side effects. IIRC, if you mark @foo as “readonly” (, then DCE should be able to remove the call.

I understand. Thanks a lot!