Remove an instruction through Dead Code Elimination pass of llvm

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Remove an instruction through Dead Code Elimination pass of llvm

Adarsh123
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

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Remove an instruction through Dead Code Elimination pass of llvm

Duncan Sands
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
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Remove an instruction through Dead Code Elimination pass of llvm

Devang Patel
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 <[hidden email]> 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
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev