This is an archive of the discontinued LLVM Phabricator instance.

[InstSimplify][SVE] Fix SimplifyInsert/ExtractElementInst for scalable vector.
ClosedPublic

Authored by huihuiz on Mar 6 2020, 4:04 PM.

Details

Summary

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.

Diff Detail

Event Timeline

huihuiz created this revision.Mar 6 2020, 4:04 PM

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
}
This revision is now accepted and ready to land.Mar 11 2020, 1:04 PM
This revision was automatically updated to reflect the committed changes.