Page MenuHomePhabricator

[clang codegen] Clean up handling of vectors with trivial-auto-var-init.

Authored by efriedma on Mar 20 2020, 2:31 PM.



The code was pretending to be doing something useful with vectors, but really it was doing nothing: the element type of a vector is always a scalar type, so constWithPadding would always just return the input constant.

Split off from D75661 so it can be reviewed separately.

While I'm here, also add testcase to show missing vector handling.

Diff Detail

Event Timeline

efriedma created this revision.Mar 20 2020, 2:31 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 20 2020, 2:31 PM
Herald added a subscriber: dexonsmith. · View Herald Transcript
jfb added a comment.Mar 20 2020, 4:50 PM

Oh good catch.

Were there no vector tests which tripped this?
Vectors can hold scalar types with padding (i.e. long double)?
Tail padding in vectors do seem important to initialize as well.

Not sure what sort of test would catch this; it's not crashing, and the types with the tail padding issue are not naturally exposed by target intrinsic headers (so it would only show up for code using ext_vector_type, or maybe OpenCL code). I only tripped over the issue by inspection.

The way LLVM currently works, vectors never have internal padding, only tail padding. (This could possibly change in the future, I guess, but there aren't any specific plans.)

For the types clang can generate, tail padding can show up a few different ways:

  1. A vector can have an element count that's not a power of two: <5 x double>
  2. A vector can partially cover a byte: <4 x i1>
  3. A vector can have an element type that naturally has padding, like x86 long double

I can write testcases for the above, if you would find it helpful. (Actually figuring out how to pad a vector correctly is more work than I really want to invest into this right now. In the tricky cases, it might make sense to convert the constant to an integer, and pad that.)

jfb added a comment.Mar 23 2020, 3:23 PM

The test files I added checked initialization had stores to each padding location, I think that's what would be needed here as well.

efriedma updated this revision to Diff 252169.Mar 23 2020, 4:11 PM
efriedma edited the summary of this revision. (Show Details)

Add testcase to show missing vector handling.

Actually looking again, I'm not sure there's any way to make clang generate a bool vector at the moment. Added tests for the rest.

jfb accepted this revision.Mar 23 2020, 6:34 PM


This revision is now accepted and ready to land.Mar 23 2020, 6:34 PM
This revision was automatically updated to reflect the committed changes.