RFR: 8341834: C2 compilation fails with "bad AD file" due to Replicate
Vladimir Kozlov
kvn at openjdk.org
Thu Oct 24 16:36:05 UTC 2024
On Thu, 24 Oct 2024 06:02:22 GMT, Emanuel Peter <epeter at openjdk.org> wrote:
>> src/hotspot/share/opto/superwordVTransformBuilder.cpp line 231:
>>
>>> 229: } else {
>>> 230: // Replicate the scalar same_input to every vector element.
>>> 231: BasicType element_type = p0->is_Convert() ? p0->in(1)->bottom_type()->basic_type() : _vloop_analyzer.types().velt_basic_type(p0);
>>
>> What vectors are generated (or not) with this change? The array in the test ins `int[]` but the element_type will be Long now. Will it bailout vectorization?
>
> @vnkozlov You can very easily see how it goes with my `Test4` above, I split the things onto different lines so we can see what is from where easily.
>
> The pack that `p0` belongs to is a `ConvL2I` pack. In my case, I have an `short[]`, just to make things even more interesting. Since the type is propagated from use -> def, the output of the `ConvL2I` is interpreted as a `short`, it is essentially a truncated `int`. `velt_basic_type(p0) == T_SHORT`. The vector node should be a `VectorCastL2X === _ 873 [[ ]] #vectors<S,2>`, i.e. casting from long-vector to short-vector.
>
> But now we see that the input to the pack of `p0` is all the same, and so we want to introduce a `Replicate`. We should of course replicate for `long`. But `velt_basic_type(p0) == T_SHORT` - so you get a `Replicate === _ 717 [[ ]] #vectorx<S,2>`, and then eventually a `VectorCastS2X === _ 890 [[ ]] #vectors<S,2>`... but of course the AD file has no matching node for a VectorCast from short to short -> `bad AD file`.
>
> The issue is really that `velt_basic_type(p0)` gives us the output-type, but we actually would need the input-type. In almost all cases input-type == output-type. But of course that does not hold with Convert.
>
> With Roland's fix, we now ask for the output-type of the `ConvL2I`'s input. That is the same as asking for the `ConvL2I`'s input-type. That way, we know what type to Replicate for - the `element_type`.
>
> @rwestrel given that @vnkozlov also did not right away understand what is going on, I think you need to properly explain what happens in the comments ;)
Thank you for explanation. Yes, to have comment would be nice.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/21660#discussion_r1815359076
More information about the hotspot-compiler-dev
mailing list