[PATCH] D15146: [InstCombine] Look through PHIs, GEPs, IntToPtrs and PtrToInts to expose more constants when comparing GEPs

silviu.baranga@arm.com via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 2 03:38:13 PST 2015


sbaranga created this revision.
sbaranga added a reviewer: majnemer.
sbaranga added subscribers: llvm-commits, aadg, jmolloy.

When comparing two GEP instructions which have the same base pointer
and one of them has a constant index, it is possible to only compare
indices, transforming it to a compare with a constant. This removes
one use for the GEP instruction with the constant index, can reduce
register pressure and can sometimes lead to removing the comparisson
entirely.

InstCombine was already doing this when comparing two GEPs if the
base pointers were the same. However, in the case where we have
complex pointer arithmetic (GEPs applied to GEPs, PHIs of GEPs,
conversions to or from integers, etc) the value of the original
base pointer will be hidden to the optimizer and this transformation
will be disabled.

This change detects when the two sides of the comparison can be
expressed as GEPs with the same base pointer, even if they don't
appear as such in the IR. The transformation will convert all the
pointer arithmetic to arithmetic done on indices and all the
relevant uses of GEPs to GEPs with a common base pointer. The
GEP comparison will be converted to a comparison done on indices.

http://reviews.llvm.org/D15146

Files:
  lib/Transforms/InstCombine/InstCombineCompares.cpp
  test/Transforms/InstCombine/indexed-gep-compares.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15146.41607.patch
Type: text/x-patch
Size: 16770 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151202/9d3ccc1a/attachment.bin>


More information about the llvm-commits mailing list