[ConstantFold] Improve the bitcast folding logic for constant vectors.
authorAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>
Tue, 13 Sep 2016 14:50:47 +0000 (14:50 +0000)
committerAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>
Tue, 13 Sep 2016 14:50:47 +0000 (14:50 +0000)
commit7277afeec1ca638fea3f987696df504138937d24
treeee312a44cae17c22d336ec268cf8a292850f8934
parent161c7f866114aea9901b9c9665f0af4786a62efa
[ConstantFold] Improve the bitcast folding logic for constant vectors.

The constant folder didn't know how to always fold bitcasts of constant integer
vectors. In particular, it was unable to handle the case where a constant vector
had some undef elements, and the resulting (i.e. bitcasted) vector type had more
elements than the original vector type.

Example:
  %cast = bitcast <2 x i64><i64 undef, i64 2> to <4 x i32>

On a little endian target, %cast could have been folded to:
  <4 x i32><i32 undef, i32 undef, i32 2, i32 0>

This patch improves the folding logic by teaching how to correctly propagate
undef elements in the folded vector.

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

llvm-svn: 281343
llvm/lib/Analysis/ConstantFolding.cpp
llvm/test/Transforms/InstCombine/x86-sse4a.ll
llvm/test/Transforms/InstSimplify/bitcast-vector-fold.ll