Skip to content

Commit 44c89c3

Browse files
[GlobalISel] Allow per-lane truncating/extending G_STORE/G_LOAD semantics
The semantics of vector G_STORE is currently not well defined. The docs have diverged with the implementation on whether vector G_STORE/G_LOAD instructions have per-lane truncating/extending behavior. The docs say G_LOAD/G_STORE is not per-lane truncating/extending. This diverges from the SelectionDAG semantics and also does not match our current implementation in some cases. One case I am aware of is llvm#121169. We do require some implementation of these semantics for handling cases like in the above PR, e.g. storing a <8 x s8> register into a <8 x s1> bitfield. I would like to discuss which route we want to take. 1. Allow per-lane truncating/extending G_STORE/G_LOAD semantics like SelectionDAG. If we do not have a good reason to diverge from SelectionDAG here, this probably is the default option, as it would make it more straightforward to port patterns and lowering code from SDAG. However, I think we would need to tighten down the MemDesc legality rules, because they currently only check the size of the memory type. I have drafted the documentation changes for this route in this PR, but I am not familiar with scalable vectors in GISel, so I would appreciate some input on how they are supposed to behave with extending/truncating stores. 2. Add new opcodes. 3. Other ideas?
1 parent 16d1054 commit 44c89c3

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

llvm/docs/GlobalISel/GenericOpcode.rst

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -861,9 +861,16 @@ Generic load. Expects a MachineMemOperand in addition to explicit
861861
operands. If the result size is larger than the memory size, the
862862
high bits are undefined, sign-extended, or zero-extended respectively.
863863

864-
Only G_LOAD is valid if the result is a vector type. If the result is larger
865-
than the memory size, the high elements are undefined (i.e. this is not a
866-
per-element, vector anyextload)
864+
If both the result value type (<ValElems x ValElemTy>) and the memory type
865+
(<MemElems x MemElemTy>) are vectors:
866+
* and ValElemTy is larger than ValElemTy: the high bits of each vector element
867+
are extended according to the opcode (i.e. this acts as a per-lane
868+
anyext/zext/sext load).
869+
* and ValElemTy is larger than MemElems: the high elements are undefined.
870+
871+
Note that if either the result value type or memory type is scalar (e.g.
872+
loading <4 x s8> from s28), extension applies to the high bits of the entire
873+
value instead of per-lane.
867874

868875
Unlike in SelectionDAG, atomic loads are expressed with the same
869876
opcodes as regular loads. G_LOAD, G_SEXTLOAD and G_ZEXTLOAD may all
@@ -889,11 +896,19 @@ Same as G_INDEXED_LOAD except that the load performed is zero-extending, as with
889896
G_STORE
890897
^^^^^^^
891898

892-
Generic store. Expects a MachineMemOperand in addition to explicit
893-
operands. If the stored value size is greater than the memory size,
894-
the high bits are implicitly truncated. If this is a vector store, the
895-
high elements are discarded (i.e. this does not function as a per-lane
896-
vector, truncating store)
899+
Generic store. Expects a MachineMemOperand in addition to explicit operands.
900+
If the stored value size is greater than the memory size, the high bits are
901+
implicitly truncated.
902+
903+
If both the stored value type (<ValElems x ValElemTy>) and the memory type
904+
(<MemElems x MemElemTy>) are vectors:
905+
* and MemElemTy is smaller than ValElemTy: the high bits of each vector element
906+
are truncated (i.e. this acts as a per-lane truncating store).
907+
* and MemElms is smaller than MemElems: the high elements are discarded.
908+
909+
Note that if either the stored value type or memory type is scalar (e.g.
910+
storing <4 x s8> as s28), truncation applies to the high bits of the entire
911+
value instead of per-lane.
897912

898913
G_INDEXED_STORE
899914
^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)