[PATCH] D75782: [InstSimplify][SVE] Fix SimplifyInsert/ExtractElementInst for scalable vector.

Huihui Zhang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 6 16:34:16 PST 2020


huihuiz created this revision.
huihuiz added reviewers: sdesmalen, efriedma, spatel, apazos.
huihuiz added a project: LLVM.
Herald added subscribers: psnobl, rkruppe, hiraditya, tschuett.
huihuiz added a comment.

Current upstream is doing wrong fold for scalable vectors.

for test case: insertelement_idx_maybe_out_of_bound

  define <vscale x 4 x i32> @insertelement_idx_maybe_out_of_bound(<vscale x 4 x i32> %a) {
    %r = insertelement <vscale x 4 x i32> %a, i32 5, i64 4
    ret <vscale x 4 x i32> %r
  }

run: opt -instsimplify -S t.ll -o -

we end up with

  define <vscale x 4 x i32> @insertelement_idx_maybe_out_of_bound(<vscale x 4 x i32> %a) {
    ret <vscale x 4 x i32> undef
  }

Index 4 could be out-of-bound for scalable vector, however we don't know this at compile-time.

Also take test case insert_extract_element_same_vec_idx_2

  define i32 @insert_extract_element_same_vec_idx_2(<vscale x 4 x i32> %a) {
    %v = insertelement <vscale x 4 x i32> undef, i32 1, i64 4
    %r = extractelement <vscale x 4 x i32> %v, i64 4
    ret i32 %r
  }

run: opt -instsimplify -S t.ll -o -

we got

  define i32 @insert_extract_element_same_vec_idx_2(<vscale x 4 x i32> %a) {
    ret i32 undef
  }

That's the wrong fold in findScalarElement

we should be getting

  define i32 @insert_extract_element_same_vec_idx_2(<vscale x 4 x i32> %a) {
    ret i32 1
  }


For scalable vector, index out-of-bound can not be determined at compile-time.
The same apply for VectorUtil findScalarElement().

Add test cases to check the functionality of SimplifyInsert/ExtractElementInst for scalable vector.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75782

Files:
  llvm/lib/Analysis/InstructionSimplify.cpp
  llvm/lib/Analysis/VectorUtils.cpp
  llvm/test/Transforms/InstSimplify/vscale.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75782.248854.patch
Type: text/x-patch
Size: 5896 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200307/c3c63411/attachment.bin>


More information about the llvm-commits mailing list