[LLVMdev] Remove an instruction through Dead Code Elimination pass of llvm

Duncan Sands baldrick at free.fr
Sat Feb 11 01:43:28 PST 2012


Hi Adarsh,

On 11/02/12 09:47, Adarsh Konchady wrote:
> 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?

in LLVM passes don't schedule other passes.  Whoever schedules your pass to run
can just schedule a dead code elimination pass after yours (or instcombine, or
some other pass that will zap this kind of thing).  Alternatively, your pass
can use a utility function to do it, for example SimplifyInstructionsInBlock,
defined in llvm/Transforms/Utils/Local.h

Ciao, Duncan.



More information about the llvm-dev mailing list