[LLVMdev] mem2reg Question

David Greene dag at cray.com
Fri Sep 19 11:08:09 PDT 2008


I have a question about PromoteMem2Reg::RewriteSingleStoreAlloca.
Specifically, this bit of code:

    // If the store dominates the block and if we haven't processed it yet,
    // do so now.  We can't handle the case where the store doesn't dominate a
    // block because there may be a path between the store and the use, but we
    // may need to insert phi nodes to handle dominance properly.
    if (!StoringGlobalVal && !dominates(OnlyStore->getParent(), UseBlock))
      continue;

This prevents mem2reg from forwarding the single store to uses that
it does not dominate.  Why is this only prevented when NOT storing
to global values?  I would think it would be exactly the opposite.  A global
value may have some value coming into the Function so I don't see how
mem2reg can forward store values that don't dominate uses.  On the
other hand, local values that have a use not dominated by the store means
there's a potential use-before-def, the program is invalid, and the compiler
is free to do whatever it wants (assuming this is what the language semantics
say).

The condition above looks exactly opposite of what we want.

Thoughts?

                                                -Dave



More information about the llvm-dev mailing list