[PATCH] [InstCombine] Fix big-endian miscompile of (bitcast (zext/trunc (bitcast)))
authorBjorn Pettersson <bjorn.a.pettersson@ericsson.com>
Thu, 28 Nov 2019 22:18:28 +0000 (23:18 +0100)
committerSylvestre Ledru <sylvestre@debian.org>
Sat, 31 Oct 2020 13:09:15 +0000 (13:09 +0000)
commit0d58642e8bce0f0d05ba1b4db45aa026f66c350e
treeb767a3b398189b86f18fe1f7d2e96813d3bf2ea0
parent19b7c8d07f82f91723e440058d6d8cc88fd73303
[PATCH] [InstCombine] Fix big-endian miscompile of (bitcast (zext/trunc (bitcast)))

Summary:
optimizeVectorResize is rewriting patterns like:
  %1 = bitcast vector %src to integer
  %2 = trunc/zext %1
  %dst = bitcast %2 to vector

Since bitcasting between integer an vector types gives
different integer values depending on endianness, we need
to take endianness into account. As it happens the old
implementation only produced the correct result for little
endian targets.

Fixes: https://bugs.llvm.org/show_bug.cgi?id=44178
Reviewers: spatel, lattner, lebedev.ri

Reviewed By: spatel, lebedev.ri

Subscribers: lebedev.ri, hiraditya, uabelho, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D70844

(cherry picked from commit a9d6b0e5444741d08ff1df7cf71d1559e7fefc1f)

Gbp-Pq: Name f8e146f3430de3a6cd904f3f3f7aa1bfaefee14c.patch
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
llvm/test/Transforms/InstCombine/cast.ll