This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen][AMDGPU] EXTRACT_VECTOR_ELT: input vector element type can differ from output type
ClosedPublic

Authored by jmmartinez on Dec 13 2022, 8:38 AM.

Details

Summary

In function SITargetLowering::performExtractVectorElt,
the output type was not considered which could lead to type mismatches
later.

Diff Detail

Event Timeline

jmmartinez created this revision.Dec 13 2022, 8:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 13 2022, 8:38 AM
jmmartinez added inline comments.Dec 13 2022, 8:52 AM
llvm/lib/Target/AMDGPU/SIISelLowering.cpp
10816

This condition has to be stengtened. This is valid for smin, smax, umin and umax if the types have the same size or if they are truncated.

Implicit element conversion strikes again. LGTM but needs tests

llvm/lib/Target/AMDGPU/SIISelLowering.cpp
10816

Not sure what you mean, those are handled below?

Corrected binop case

Still missing tests for all of this

Implicit element conversion strikes again. LGTM but needs tests

Sure sorry! I didn't know phabricatior sent notifications when the patch is marked as draft. I submitted it in draft mode and I hoped to submit it after adding the tests.

  • Added test (I found the test a bit awkward but I haven't managed to trigger it otherwise)
jmmartinez published this revision for review.Dec 20 2022, 3:14 AM
jmmartinez added a reviewer: arsenm.
jmmartinez added inline comments.
llvm/lib/Target/AMDGPU/SIISelLowering.cpp
10816

I meant that when ResVT != VecEltVT the transformation could not be valid.

For example, if ResVT == i8 but VecEltVT == i16 for the min/max operations.

I wasn't able to trigger this path, so I haven't added the code to do the transformation. Still, I added a check in the if anyways.

llvm/test/CodeGen/AMDGPU/dagcomb-extract-vec-elt-different-sizes.ll
2

@arsenm If you have some advice about how to reduce even more this test case I'll be glad.

I tried triggering this case by hand but I didn't succeed. In the end I used llvm-reduce and applied some optimizations to get up to this.

Herald added a project: Restricted Project. · View Herald TranscriptDec 20 2022, 3:14 AM
arsenm added inline comments.Jan 3 2023, 8:56 AM
llvm/test/CodeGen/AMDGPU/dagcomb-extract-vec-elt-different-sizes.ll
3

Should drop the -verify-machineinstrs, I've been thinking we should drop most of these in tests

6–8

Don't need this stuff

10

Should use opaque pointers

94

I'm sure you don't need the addrspacecasts here, should just change the address spaces of the arguments (We should have an optimization and have llvm-reduce start doing this too)

111

Does it only happen with 1 x vectors, and do you need so many elements?

120

Can you hit this with a few more vector types?

jmmartinez updated this revision to Diff 486220.Jan 4 2023, 2:54 AM
jmmartinez marked 5 inline comments as done.
  • Remove -verify-machineinstrs
  • Remove source_filename, datalayout and triple
  • Make test pointers opaque
  • Remove addresspace cast and move addrspace to the declaration
llvm/test/CodeGen/AMDGPU/dagcomb-extract-vec-elt-different-sizes.ll
111

It seems that <1 x i8> is the only case where the bug gets triggered: I tried using directly i8; using <8 x i1>; changing the int type to i16, i32 or float; or changing the number of elements in the vector. I also tried removing some of the store instructions or replacing some of its arguments by another.

jmmartinez marked an inline comment as done.Jan 5 2023, 5:52 AM
arsenm accepted this revision.Jan 5 2023, 12:08 PM
This revision is now accepted and ready to land.Jan 5 2023, 12:08 PM
This revision was landed with ongoing or failed builds.Jan 6 2023, 12:56 AM
This revision was automatically updated to reflect the committed changes.