[llvm-commits] [llvm] r122265 - /llvm/trunk/lib/Transforms/Utils/SimplifyInstructions.cpp

Frits van Bommel fvbommel at gmail.com
Mon Dec 20 14:19:13 PST 2010


On Mon, Dec 20, 2010 at 10:07 PM, Duncan Sands <baldrick at free.fr> wrote:
> +    bool runOnFunction(Function &F) {
> +      bool Changed = false;
> +      const TargetData *TD = getAnalysisIfAvailable<TargetData>();
> +      const DominatorTree *DT = getAnalysisIfAvailable<DominatorTree>();
> +      for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
> +        for (BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI != BE;) {
> +          Instruction *I = BI++;
> +          if (Value *V = SimplifyInstruction(I, TD, DT)) {
> +            I->replaceAllUsesWith(V);
> +            I->eraseFromParent();
> +            Changed = true;
> +            ++NumSimplified;
> +          }
> +        }
> +      return Changed;
> +    }

I know this is intended primarily for testing, but maybe this should
iterate until no changes were made just to be thorough? Or use a
worklist so users of replaced values are re-examined later?
Currently this pass depends on basic blocks order; IIRC
SimplifyInstruction assumes the operands have already been simplified,
which currently isn't necessarily the case if blocks don't happen to
be topologically sorted (with respect to domination).




More information about the llvm-commits mailing list