[llvm-commits] [PATCH] Promote all possible memory to registers

Kenneth Uildriks kennethuil at gmail.com
Sun Oct 17 12:44:41 PDT 2010

This is a new pass, activated by the "-allmem2reg" switch for opt.  It
is a generalization of the SSA algorithm, attempting to promote all
non-volatile loads within a function, not just those from alloca's
which haven't had their address taken.

While the Memory Dependence analysis scans backwards from loads to
find the corresponding stores, allmem2reg works forward through the
entire function.  This makes it easier to properly support invariant
regions (Memory Dependence currently stops at any clobbering
instruction, without checking whether it's preceded by an
llvm.invariant.begin; continuing the scan would of course require
scanning more instructions) and removes loads from the IR so that they
don't have to be traced back to stores repeatedly (Memory Dependence
will cache its results, but its cache sometimes gets invalidated by
later passes).  It uses AliasSets containing only variables that
MustAlias each other; each such AliasSet is a "variable" in the SSA
algorithm.  Variables are invalidated by stores to any variable that
MayAlias it and by calls that might Clobber it.  A load of an invalid
variable is left in place as a load; the result of the load is
assigned back to the variable at that point so it can be used in a
later instruction if it's not invalidated again.  A load of a valid
variable is simply replaced by the variable's value.

Whereas Memory Dependence currently requires an llvm.invariant.end to
precede a load instruction in order to detect the invariant region
(and thus requires the invariant region to *not* contain the load),
this pass by scanning forward through the whole function is able to
find all invariant regions and tie them to variables, then skipping
attempts to invalidate them through stores to MayAliases and clobbers.

Currently, the pass doesn't attempt to remove any stores, since it is
intended to handle memory references that might escape the function.

This patch includes unit tests copied from the mem2reg unit tests,
plus a few tests to check invariant support and proper handling of
escaping pointers.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: allmem2reg.patch
Type: text/x-patch
Size: 89723 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20101017/27d53775/attachment.bin>

More information about the llvm-commits mailing list