[InstCombine] Canonicalize GEP of GEP by swapping constant-indexed GEP to the back
authorWilliam Huang <williamjhuang@google.com>
Wed, 12 Oct 2022 17:49:24 +0000 (17:49 +0000)
committerWilliam Huang <williamjhuang@google.com>
Thu, 20 Oct 2022 17:41:26 +0000 (17:41 +0000)
commit6c767cef5a1d21154730f18ec01d76b7f36a3610
tree42f8d481430c90f1ebcb1e115fa4369b18cac4f3
parent93f1b48cbbeae0a04be560a98daa16350a3da069
[InstCombine] Canonicalize GEP of GEP by swapping constant-indexed GEP to the back

Canonicalize GEP of GEP by swapping GEP with some suffix constant indices to the back (and GEP with all constant indices to the back of that), this allows more constant index GEP merging to happen. Exceptions are: If swapping violates use-def relations, or anti-optimizes LICM

For constant indexed GEP of GEP, if they cannot be merged directly, they will be casted to i8* and merged.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D125845
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/gep-canonicalize-constant-indices.ll
llvm/test/Transforms/InstCombine/gep-merge-constant-indices.ll
llvm/test/Transforms/InstCombine/shift.ll
llvm/test/Transforms/LoopVectorize/AArch64/vector-reverse-mask4.ll
llvm/test/Transforms/LoopVectorize/interleaved-accesses.ll
llvm/test/Transforms/PhaseOrdering/single-iteration-loop-sroa.ll