[LLVMdev] Removing dead code

Chris Lattner sabre at nondot.org
Thu Jun 29 22:02:15 PDT 2006


On Thu, 29 Jun 2006, Fernando Magno Quintao Pereira wrote:
>    I am working in a register allocator for LLVM, and I realized that,
> after I perform register allocation, there is many move instructions that
> are dead code, and can safely be removed. It is easy for the RA algorithm
> to remove these instructions. It seems to me that the only instructions
> with dead definitions that I should not remove are the calls. Is it true?
> I would like to know if a code like this below is safe, that is, besides
> call instructions, is there other instructions that must stay in the code
> even if their definitions are dead?
>
> MachineInstr * mi = iter;
> opCode = // get the opcode of mi
> if(!mi.isCall(opCode)) {
>    mbb.remove(iter);
> }

You can't do that unless you can prove the instructions don't have side 
effects, which you can't.  Higher-level passes will remove dead code.  Are 
you seeing a case where dead code is making it down to the codegen level?

-Chris

-- 
http://nondot.org/sabre/
http://llvm.org/



More information about the llvm-dev mailing list