[InstCombine] When canonicalizing gep indices, prefer zext when possible
authorPhilip Reames <listmail@philipreames.com>
Sat, 14 Feb 2015 00:05:36 +0000 (00:05 +0000)
committerPhilip Reames <listmail@philipreames.com>
Sat, 14 Feb 2015 00:05:36 +0000 (00:05 +0000)
commitd777c2c0c09f20bf2decf763bb2946291f28960f
treedfc7897352618d8ceca1ffc8e6313de8af433415
parentc4300b9c0147889e77d2a51ded9fa025545d27e2
[InstCombine] When canonicalizing gep indices, prefer zext when possible

If we know that the sign bit of a value being sign extended is zero, we can use a zero extension instead.  This is motivated by the fact that zero extensions are generally cheaper on x86 (and most other architectures?).  We already apply a similar transform in DAGCombine, this just extends that to the IR level.

This comes up when we eagerly canonicalize gep indices to the width of a machine register (i64 on x86_64). To do so, we insert sign extensions (sext) to promote smaller types.

Differential Revision: http://reviews.llvm.org/D7255

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229189 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombineCasts.cpp
test/Transforms/InstCombine/gep-sext.ll [new file with mode: 0644]