[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:19 PST 2020


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
  }


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75782/new/

https://reviews.llvm.org/D75782





More information about the llvm-commits mailing list