[LICM] Reassociate GEPs to allow hoisting
authorNikita Popov <npopov@redhat.com>
Fri, 24 Mar 2023 14:10:53 +0000 (15:10 +0100)
committerNikita Popov <npopov@redhat.com>
Tue, 11 Apr 2023 08:34:04 +0000 (10:34 +0200)
commitb8917ac62ad49a0ce6de026c086599fc5fa35566
tree293c28f52c5f15fad8d31414356c45ab65d21a0e
parentcd91992de838af1ec1d8d6983402e2b2a6474d7b
[LICM] Reassociate GEPs to allow hoisting

Reassociate gep (gep ptr, idx1), idx2 to gep (gep ptr, idx2), idx1
if this would make the inner GEP loop invariant and thus hoistable.

This is intended to replace an InstCombine fold that does this (in
https://github.com/llvm/llvm-project/blob/04f61fb73dc6a994ab267d431f2fdaedc67430ff/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp#L2006).
The problem with the InstCombine fold is that LoopInfo is an optional
dependency, so it is not performed reliably.

Differential Revision: https://reviews.llvm.org/D146813
llvm/lib/Transforms/Scalar/LICM.cpp
llvm/test/CodeGen/PowerPC/no-ctr-loop-if-exit-in-nested-loop.ll
llvm/test/Transforms/LICM/gep-reassociate.ll