[llvm-commits] [llvm] r164933 - /llvm/trunk/lib/Transforms/Scalar/SROA.cpp

Duncan Sands baldrick at free.fr
Mon Oct 1 05:22:31 PDT 2012


Hi Chandler,

> Factor the PHI and select speculation into a separate rewriter. This
> could probably be factored still further to hoist this logic into
> a generic helper, but currently I don't have particularly clean ideas
> about how to handle that.

> --- llvm/trunk/lib/Transforms/Scalar/SROA.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/SROA.cpp Mon Oct  1 05:54:05 2012
> @@ -1770,6 +1765,278 @@
>   }
>
>   namespace {
> +/// \brief Visitor to speculate PHIs and Selects where possible.
> +class PHIOrSelectSpeculator : public InstVisitor<PHIOrSelectSpeculator> {
> +  // Befriend the base class so it can delegate to private visit methods.
> +  friend class llvm::InstVisitor<PHIOrSelectSpeculator>;
> +
> +  const TargetData &TD;
> +  AllocaPartitioning &P;
> +  SROA &Pass;
> +
> +public:
> +  PHIOrSelectSpeculator(const TargetData &TD, AllocaPartitioning &P, SROA &Pass)
> +    : TD(TD), P(P), Pass(Pass) {}
> +
> +  /// \brief Visit the users of the alloca partition and rewrite them.
> +  void visitUsers(AllocaPartitioning::const_use_iterator I,
> +                  AllocaPartitioning::const_use_iterator E) {
> +    for (; I != E; ++I)
> +      visit(cast<Instruction>(I->U->getUser()));
> +  }
> +
> +private:
> +  // By default, skip this instruction.
> +  void visitInstruction(Instruction &I) {}
> +
> +  /// PHI instructions that use an alloca and are subsequently loaded can be
> +  /// rewritten to load both input pointers in the pred blocks and then PHI the
> +  /// results, allowing the load of the alloca to be promoted.
> +  /// From this:
> +  ///   %P2 = phi [i32* %Alloca, i32* %Other]
> +  ///   %V = load i32* %P2
> +  /// to:
> +  ///   %V1 = load i32* %Alloca      -> will be mem2reg'd
> +  ///   ...
> +  ///   %V2 = load i32* %Other
> +  ///   ...
> +  ///   %V = phi [i32 %V1, i32 %V2]
> +  ///
> +  /// We can do this to a select if its only uses are loads and if the operand

the operand -> the operands

> +  /// to the select can be loaded unconditionally.

Ciao, Duncan.



More information about the llvm-commits mailing list