Remove an instruction through Dead Code Elimination pass of llvm

My pass in LLVM generates an IR like this
%5 = icmp eq i32 %4, 0
%7 = or i1 %5, %5
;. . .
Since the ‘or’ instruction is actually not needed(dead code), I replaced all occurences of %7 with %5.
Now, the ‘or’ instruction should get deleted. How can I call Dead Code Elimination pass of LLVM from my pass or is there any method to remove that ‘or’ instruction?

Thank you.
Adarsh Konchady

Hi Adarsh,


Usually the pass should handle such simple and clear clean ups itself. If you grep for Inst->eraseFromParent() in source based then you'll see that many transformations are doing it immediately after they know that they have replaced all occurrences of %7.