[llvm-dev] Instcombine and bitcast of vector. Wrong CHECKs in cast.ll, miscompile in instcombine?

Björn Pettersson A via llvm-dev llvm-dev at lists.llvm.org
Thu Nov 28 08:20:37 PST 2019

Thanks Sanjay for confirming that this seem to be broken.
I’ll check with Mikael to make sure we write a new PR (probably have to wait until tomorrow).

PS. This kind of confirms that DAGTypeLegalizer::PromoteIntRes_BITCAST is doing the wrong thing for big-endian as well, see  https://bugs.llvm.org/show_bug.cgi?id=44135 , so maybe we can set that PR to “confirmed” (and then move forward with making a proper patch based on the workaround presented in that PR).


From: llvm-dev <llvm-dev-bounces at lists.llvm.org> On Behalf Of Sanjay Patel via llvm-dev
Sent: den 28 november 2019 16:55
To: Mikael Holmén <mikael.holmen at ericsson.com>; Chris Lattner <clattner at nondot.org>
Cc: llvm-dev at lists.llvm.org
Subject: Re: [llvm-dev] Instcombine and bitcast of vector. Wrong CHECKs in cast.ll, miscompile in instcombine?

Looks broken to me - we need to consider big/little-endian datalayout when bitcasting to/from vectors.
We should have some documentation for this in the LangRef, but I don't see anything currently.

The transform in question was added here:

You can find other vector bitcast transforms that (hopefully correctly...) account for the datalayout difference for vector elements.


So we need something like this:

On Thu, Nov 28, 2019 at 9:12 AM Mikael Holmén via llvm-dev <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>> wrote:

there is a test like this:

target datalayout = "E-p:64:64:64-p1:32:32:32-p2:64:64:64-p3:64:64:64-


define <3 x i32> @test60(<4 x i32> %call4) {
; CHECK-LABEL: @test60(
; CHECK-NEXT:    [[P10:%.*]] = shufflevector <4 x i32> [[CALL4:%.*]],
<4 x i32> undef, <3 x i32> <i32 0, i32 1, i32 2>
; CHECK-NEXT:    ret <3 x i32> [[P10]]
  %p11 = bitcast <4 x i32> %call4 to i128
  %p9 = trunc i128 %p11 to i96
  %p10 = bitcast i96 %p9 to <3 x i32>
  ret <3 x i32> %p10


If we assume the input vector is e.g. <1, 2, 3, 4> then I assume %p11
would be the (hex) value 1234, %p9 would be the 234 and %p10 would then
be the vector <2, 3, 4>.

Am I right, or am I missing something here? Note that the datalayout
says we're using big endian.

But the CHECK-NEXT checks that the result is made up of the elements at
index 0, 1 and 2 from the input vector, which would be <1, 2, 3>.

So, broken testcase or am I missing something?


LLVM Developers mailing list
llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191128/cfd6e305/attachment.html>

More information about the llvm-dev mailing list