[PATCH] D39906: [InstCombine] Allowing GEP Instructions with loop Invariant operands to combine

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 8 15:17:36 PST 2018


efriedma added a comment.

> I also don't see where "duplicating code" comes from.

You're inserting an "add" instruction without removing any other instructions; in general, this hurts codesize/performance.  This is why the combine is restricted in the first place.  You might get lucky sometimes and simplify away the extra instruction, but you can't rely on that.

The "reassociation" way to optimize this is to consider the following two instructions:

  %add.ptr = getelementptr inbounds i8, i8* %win, i64 %idx.ext
  %add.ptr2 = getelementptr inbounds i8, i8* %add.ptr, i64 %idx.ext1

These can be reassociated into the following:

  %tmp = getelementptr inbounds i8, i8* %win, i64 %idx.ext1
  %add.ptr2 = getelementptr inbounds i8, i8* %tmp, i64 %idx.ext

The first GEP then gets hoisted out of the loop.


https://reviews.llvm.org/D39906





More information about the llvm-commits mailing list