[llvm-commits] [llvm] r147751 - /llvm/trunk/lib/CodeGen/MachineCopyPropagation.cpp

Devang Patel dpatel at apple.com
Mon Jan 9 09:59:27 PST 2012


On Jan 8, 2012, at 11:52 AM, Evan Cheng wrote:

> Author: evancheng
> Date: Sun Jan  8 13:52:28 2012
> New Revision: 147751
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=147751&view=rev
> Log:
> Avoid eraseing copies from a reserved register unless the definition can be
> safely proven not to have been clobbered. No small test case possible.
> 
> Modified:
>    llvm/trunk/lib/CodeGen/MachineCopyPropagation.cpp
> 
> Modified: llvm/trunk/lib/CodeGen/MachineCopyPropagation.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineCopyPropagation.cpp?rev=147751&r1=147750&r2=147751&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/MachineCopyPropagation.cpp (original)
> +++ llvm/trunk/lib/CodeGen/MachineCopyPropagation.cpp Sun Jan  8 13:52:28 2012
> @@ -83,6 +83,25 @@
>   }
> }
> 
> +static bool NoInterveningSideEffect(const MachineInstr *CopyMI,
> +                                    const MachineInstr *MI) {

Please add comment before the function. It'd be good idea to follow coding standard for new pass and start function names with lower case letter.

-
Devang

> +  const MachineBasicBlock *MBB = CopyMI->getParent();
> +  if (MI->getParent() != MBB)
> +    return false;
> +  MachineBasicBlock::const_iterator I = CopyMI;
> +  MachineBasicBlock::const_iterator E = MBB->end();
> +  MachineBasicBlock::const_iterator E2 = MI;
> +
> +  ++I;
> +  while (I != E && I != E2) {
> +    if (I->hasUnmodeledSideEffects() || I->isCall() ||
> +        I->isTerminator())
> +      return false;
> +    ++I;
> +  }
> +  return true;
> +}
> +
> bool MachineCopyPropagation::CopyPropagateBlock(MachineBasicBlock &MBB) {
>   SmallSetVector<MachineInstr*, 8> MaybeDeadCopies; // Candidates for deletion
>   DenseMap<unsigned, MachineInstr*> AvailCopyMap;   // Def -> available copies map
> @@ -108,6 +127,7 @@
>         MachineInstr *CopyMI = CI->second;
>         unsigned SrcSrc = CopyMI->getOperand(1).getReg();
>         if (!ReservedRegs.test(Def) &&
> +            (!ReservedRegs.test(Src) || NoInterveningSideEffect(CopyMI, MI)) &&
>             (SrcSrc == Def || TRI->isSubRegister(SrcSrc, Def))) {
>           // The two copies cancel out and the source of the first copy
>           // hasn't been overridden, eliminate the second one. e.g.
> @@ -116,6 +136,12 @@
>           //  %EAX<def> = COPY %ECX
>           // =>
>           //  %ECX<def> = COPY %EAX
> +          //
> +          // Also avoid eliminating a copy from reserved registers unless the
> +          // definition is proven not clobbered. e.g.
> +          // %RSP<def> = COPY %RAX
> +          // CALL
> +          // %RAX<def> = COPY %RSP
>           CopyMI->getOperand(1).setIsKill(false);
>           MI->eraseFromParent();
>           Changed = true;
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list