Hi
The router must know in advance which label corresponds to packets of which L3 type
(this info should be contained in mpls.0 table and derived from signaling protocol).
Check out RFC 3032 (http://www.ietf.org/rfc/rfc3032.txt):
"When the last label is popped from a packet's label stack (resulting
in the stack being emptied), further processing of the packet is
based on the packet's network layer header. The LSR which pops the
last label off the stack must therefore be able to identify the
packet's network layer protocol. However, the label stack does not
contain any field which explicitly identifies the network layer
protocol. This means that the identity of the network layer protocol
must be inferable from the value of the label which is popped from
the bottom of the stack, possibly along with the contents of the
network layer header itself.
Therefore, when the first label is pushed onto a network layer
packet, either the label must be one which is used ONLY for packets
of a particular network layer, or the label must be one which is used
ONLY for a specified set of network layer protocols, where packets of
the specified network layers can be distinguished by inspection of
the network layer header. Furthermore, whenever that label is
replaced by another label value during a packet's transit, the new
value must also be one which meets the same criteria. If these
conditions are not met, the LSR which pops the last label off a
packet will not be able to identify the packet's network layer
protocol."
One example is Explicit NULL Label which is dofferent for IPv4 (label = 0)
and IPv6 (label = 2).
I hope this helps.