[PATCH] D104468: [Verifier] Fail on overrunning and invalid indices for {insert,extract} vector intrinsics

Joe Ellis via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 17 08:57:15 PDT 2021


joechrisellis created this revision.
joechrisellis added reviewers: paulwalker-arm, bsmith, david-arm.
Herald added subscribers: frasercrmck, dexonsmith, luismarques, apazos, sameer.abuasal, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya.
joechrisellis requested review of this revision.
Herald added subscribers: llvm-commits, MaskRay.
Herald added a project: LLVM.

With regards to overrunning, the langref (llvm/docs/LangRef.rst)
specifies:

  (llvm.experimental.vector.insert)
  Elements ``idx`` through (``idx`` + num_elements(``subvec``) - 1)
  must be valid ``vec`` indices. If this condition cannot be determined
  statically but is false at runtime, then the result vector is
  undefined.
  
  (llvm.experimental.vector.extract)
  Elements ``idx`` through (``idx`` + num_elements(result_type) - 1)
  must be valid vector indices. If this condition cannot be determined
  statically but is false at runtime, then the result vector is
  undefined.

For the non-mixed cases (e.g. inserting/extracting a scalable into/from
another scalable, or inserting/extracting a fixed into/from another
fixed), it is possible to statically check whether or not the above
conditions are met. This was previously missing from the verifier, and
if the conditions were found to be false, the result of the
insertion/extraction would be replaced with an undef.

With regards to invalid indices, the langref (llvm/docs/LangRef.rst)
specifies:

  (llvm.experimental.vector.insert)
  ``idx`` represents the starting element number at which ``subvec``
  will be inserted. ``idx`` must be a constant multiple of
  ``subvec``'s known minimum vector length.
  
  (llvm.experimental.vector.extract)
  The ``idx`` specifies the starting element number within ``vec``
  from which a subvector is extracted. ``idx`` must be a constant
  multiple of the known-minimum vector length of the result type.

Similarly, these conditions were not previously enforced in the
verifier. In some circumstances, invalid indices were permitted
silently, and in other circumstances, an undef was spawned where a
verifier error would have been preferred.

This commit adds verifier checks to enforce the constraints above.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104468

Files:
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
  llvm/test/CodeGen/AArch64/sve-extract-vector.ll
  llvm/test/CodeGen/AArch64/sve-insert-vector.ll
  llvm/test/CodeGen/RISCV/rvv/fixed-vectors-extract-subvector.ll
  llvm/test/CodeGen/RISCV/rvv/fixed-vectors-insert-subvector.ll
  llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-opts-cmpne.ll
  llvm/test/Transforms/InstCombine/canonicalize-vector-extract.ll
  llvm/test/Transforms/InstCombine/canonicalize-vector-insert.ll
  llvm/test/Verifier/insert-extract-intrinsics-invalid.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104468.352746.patch
Type: text/x-patch
Size: 26801 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210617/32486770/attachment.bin>


More information about the llvm-commits mailing list