This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Fix wrong type prototype of RVVSlideOneBuiltinSet
ClosedPublic

Authored by wangpc on Aug 8 2023, 11:28 PM.

Details

Summary

We need unsigned integer here.

Fixes #64534

Diff Detail

Event Timeline

wangpc created this revision.Aug 8 2023, 11:28 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 8 2023, 11:28 PM
wangpc requested review of this revision.Aug 8 2023, 11:28 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 8 2023, 11:28 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
eopXD added a comment.Aug 9 2023, 12:27 AM

I guess we need to update the test cases too, are you able to generate them by modifying the the generator under riscv-non-isa/rvv-intrinsic-doc?

wangpc added a comment.EditedAug 9 2023, 12:42 AM

I guess we need to update the test cases too, are you able to generate them by modifying the the generator under riscv-non-isa/rvv-intrinsic-doc?

For this patch, we don't need to update tests because they are using the right integer types and we didn't generate tests that pass immediates to integer arguments.
If we decide to generate/add such kind of tests, then we should post another patch I think.

eopXD added a comment.Aug 9 2023, 12:54 AM

I mean

vint8mf8_t test_vslide1up_vx_i8mf8(vint8mf8_t src, int8_t value, size_t vl) {
  return __riscv_vslide1up_vx_i8mf8(src, value, vl);
}

should change into

vint8mf8_t test_vslide1up_vx_i8mf8(vint8mf8_t src, uint8_t value, size_t vl) {
  return __riscv_vslide1up_vx_i8mf8(src, value, vl);
}
wangpc added a comment.EditedAug 9 2023, 2:01 AM

I mean

vint8mf8_t test_vslide1up_vx_i8mf8(vint8mf8_t src, int8_t value, size_t vl) {
  return __riscv_vslide1up_vx_i8mf8(src, value, vl);
}

should change into

vint8mf8_t test_vslide1up_vx_i8mf8(vint8mf8_t src, uint8_t value, size_t vl) {
  return __riscv_vslide1up_vx_i8mf8(src, value, vl);
}

Why do we need pass unsigned integers when the vector elements are signed? Am I missing something here?

Sorry, my previous comment was wrong. Please allow me to correct myself here.


I went through the v-spec again, it says that:

The vslide1up instruction places the x register argument at location 0 of the destination vector register group, provided that element 0 is active, otherwise the destination element update follows the current mask agnostic/undisturbed policy. If XLEN < SEW, the value is sign-extended to SEW bits. If XLEN > SEW, the least-significant bits are copied over and the high SEW-XLEN bits are ignored.

So I think the righteous fix here is to have the rs1 parameter as type of long, which is to use l in the TableGen.


I still think that modifying the generated test cases is needed. If you find it tedious, may I open up a revision that resolves the problem while adding you as co-author since you gave this problem the first try?

I still think that modifying the generated test cases is needed. If you find it tedious, may I open up a revision that resolves the problem while adding you as co-author since you gave this problem the first try?

@eopXD Yeah, it's OK! I will hand over the work to you, thanks! :-)

You do agree with my latest comment that long is the righteous fix, right? :)

wangpc added a comment.EditedAug 10 2023, 1:59 AM

You do agree with my latest comment that long is the righteous fix, right? :)

Oh sorry, somehow I missed it.
I still think that using the element type is the right way. Because user will know the range of effective inserted value.
For example:

vint16m1_t __riscv_vslide1up_vx_i16m1 (vint16m1_t src, int16_t value, size_t vl);
vint16m1_t __riscv_vslide1up_vx_i16m1 (vint16m1_t src, long value, size_t vl);

We can know the range is [-32768, 32767] for the first intrinsic. When the user pass an argument larger than that(e.g. __riscv_vslide1up_vx_i16m1(src, 0xFFFFFFFF, vl)), the compiler can warn the user and may avoid unexpected behaviors.
For the second intrinsic, we can pass a long value. But for SEW<XLEN, the inserted value will be truncated. For example, __riscv_vslide1up_vx_i16m1(src, 0xFFFFFFFF, vl) won't report any warning, but the inserted value is just 0xFFFF, which may be unexpected/confused.
That's just my thought. Issue or proposal can be raised in Github repo if we can't come up with an agreement here. :-)

eopXD accepted this revision.Aug 10 2023, 2:31 AM

I have been misunderstanding the problem the whole time. I see the clear solution you have right now. No changes in the spec / test cases are needed.

This revision is now accepted and ready to land.Aug 10 2023, 2:31 AM
This revision was automatically updated to reflect the committed changes.