This patch adds support for address space #258 to refer to the stack
segment (SS). It is analogous to address spaces #256 and #257, which
refer to the GS and FS segments, respectively. This can be used to
direct data accesses to the stack segment, which may be necessary when
a multi-segment memory model is in use.
For example, if the stack segment has a different base address than
the data segment, then it is necessary to output a segment override
prefix to direct a stack access to the stack segment if the memory
operand uses a base address register other than ESP or EBP.
Otherwise, the memory access would be directed to the data segment by
default, which would result in the wrong linear memory address being
accessed.
An example of a system configuration that would result in using
different base addresses for stack and data segments is one in which
the stack and data segments are separated to prevent accesses to the
data segment from corrupting a safe stack that is setup and maintained
by the SafeStack instrumentation pass in Clang. See the SafeStack
runtime library source comments for more details.
Note that although this patch provides the basic support for the stack
segment address space, it does not perform any address space casts
into this address space.
There's also similar code in X86DAGToDAGISel::matchLoadInAddress().
Did you leave that unchanged on purpose?
If yes, perhaps it's worth adding a comment there for why. If not, perhaps factor it out into a separate function instead of having it duplicated 3 times?