[llvm-commits] [llvm] r131979 - /llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp

Bob Wilson bob.wilson at apple.com
Tue May 24 15:28:05 PDT 2011


Nice!  Good catch.

On May 24, 2011, at 11:52 AM, Eli Friedman wrote:

> Author: efriedma
> Date: Tue May 24 13:52:07 2011
> New Revision: 131979
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=131979&view=rev
> Log:
> Make instcombine O(N) instead of O(N^2) in code where the same simplifiable constant is used many times.
> Part of rdar://9471075.
> 
> 
> Modified:
>    llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
> 
> Modified: llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp?rev=131979&r1=131978&r2=131979&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp (original)
> +++ llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp Tue May 24 13:52:07 2011
> @@ -1385,8 +1385,8 @@
>   Worklist.push_back(BB);
> 
>   SmallVector<Instruction*, 128> InstrsForInstCombineWorklist;
> -  SmallPtrSet<ConstantExpr*, 64> FoldedConstants;
> -  
> +  DenseMap<ConstantExpr*, Constant*> FoldedConstants;
> +
>   do {
>     BB = Worklist.pop_back_val();
> 
> @@ -1421,14 +1421,15 @@
>              i != e; ++i) {
>           ConstantExpr *CE = dyn_cast<ConstantExpr>(i);
>           if (CE == 0) continue;
> -          
> -          // If we already folded this constant, don't try again.
> -          if (!FoldedConstants.insert(CE))
> -            continue;
> -          
> -          Constant *NewC = ConstantFoldConstantExpression(CE, TD);
> -          if (NewC && NewC != CE) {
> -            *i = NewC;
> +
> +          Constant*& FoldRes = FoldedConstants[CE];
> +          if (!FoldRes)
> +            FoldRes = ConstantFoldConstantExpression(CE, TD);
> +          if (!FoldRes)
> +            FoldRes = CE;
> +
> +          if (FoldRes != CE) {
> +            *i = FoldRes;
>             MadeIRChange = 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