[CodeGenPrepare] Move away sign extensions that get in the way of addressing
authorQuentin Colombet <qcolombet@apple.com>
Thu, 6 Feb 2014 21:44:56 +0000 (21:44 +0000)
committerQuentin Colombet <qcolombet@apple.com>
Thu, 6 Feb 2014 21:44:56 +0000 (21:44 +0000)
commit30c0f722370210d746c3bf4c3104952b78e5e498
tree1e16d6e8ff598e64189290a3887f1aba723f4133
parent2be0fae98c54ff6b0e7a53ee1d01b5a402eaa51e
[CodeGenPrepare] Move away sign extensions that get in the way of addressing
mode.

Basically the idea is to transform code like this:
%idx = add nsw i32 %a, 1
%sextidx = sext i32 %idx to i64
%gep = gep i8* %myArray, i64 %sextidx
load i8* %gep

Into:
%sexta = sext i32 %a to i64
%idx = add nsw i64 %sexta, 1
%gep = gep i8* %myArray, i64 %idx
load i8* %gep

That way the computation can be folded into the addressing mode.

This transformation is done as part of the addressing mode matcher.
If the matching fails (not profitable, addressing mode not legal, etc.), the
matcher will revert the related promotions.

<rdar://problem/15519855>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200947 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Scalar/CodeGenPrepare.cpp
test/CodeGen/X86/codegen-prepare-addrmode-sext.ll [new file with mode: 0644]