Adarsh Konchady
2012-Feb-11 08:47 UTC
[LLVMdev] 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120211/deeedb88/attachment.html>
Duncan Sands
2012-Feb-11 09:43 UTC
[LLVMdev] Remove an instruction through Dead Code Elimination pass of llvm
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.
Devang Patel
2012-Feb-13 17:45 UTC
[LLVMdev] Remove an instruction through Dead Code Elimination pass of llvm
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. - Devang On Feb 11, 2012, at 1:43 AM, Duncan Sands <baldrick at free.fr> wrote:> 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. > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev