[PATCH] D129734: [InstCombine] Canonicalize GEP of GEP by swapping constant-indexed GEP to the front
David Li via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 13 18:15:36 PDT 2022
davidxl added a comment.
In D129734#3853403 <https://reviews.llvm.org/D129734#3853403>, @huangjd wrote:
> follow up @davidxl
> For the original issue where a chain of 3 or more gep with the first and last being constant indexed cannot be simplified, this patch can handle such case while D125845 <https://reviews.llvm.org/D125845> can't
> Consider the following code
>
> 01 b = gep a, const_index
> 02 use(b)
> 03 c = gep b, var_index
> 04 d = gep c, const_index
> 05 ret d
>
> In this patch line 4 is swapped with line 3, and then it is constant-index folded with line 1 (line 1 is unchanged, and the old line 4 is replaced with `gep a` with new constant indices, breaking the dependency of `b`, and result in better codegen.
>
> But if D125845 <https://reviews.llvm.org/D125845> is used, then line 1 is supposed to be swapped with line 3, but since `b` has more than 1 use, the swap is inhibited, and nothing can be optimized.
In theory, 01 should be propagated into 03 and then 04 after which 03 is deleted.
To compare two patches, I think it is worth collecting some benchmark numbers.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D129734/new/
https://reviews.llvm.org/D129734
More information about the llvm-commits
mailing list