[llvm] Adding change to IndVarSimplify pass to optimize IVs stuck in trivial vector operations (PR #122248)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 9 03:49:59 PST 2025
anilavakundu007 wrote:
> Can you share an IR sample before and after the pass, so it's easier to understand what it does?
Before IndVarSimplify Pass (in the -O2 pipeline):
```
%vecinit = insertelement <2 x i32> poison, i32 %u_xlati59.06, i64 0
%vecinit1 = shufflevector <2 x i32> %vecinit, <2 x i32> poison, <2 x i32> zeroinitializer
%add = add <2 x i32> %vecinit1, <i32 -1, i32 1>
%0 = extractelement <2 x i32> %add, i64 0
%add3 = add nsw i32 %add345, %0
%1 = extractelement <2 x i32> %add, i64 1
%cmp = icmp sgt i32 %1, 2
```
After my patch in IndVarSimplify Pass:
```
%vecinit = insertelement <2 x i32> poison, i32 %u_xlati59.06, i64 0
%vecinit1 = shufflevector <2 x i32> %vecinit, <2 x i32> poison, <2 x i32> zeroinitializer
%add = add <2 x i32> %vecinit1, <i32 -1, i32 1>
%0 = extractelement <2 x i32> %add, i64 0
%add3 = add nsw i32 %add345, %0
%1 = add nsw i32 %u_xlati59.06, 1
%cmp = icmp sgt i32 %1, 2
```
Here the:
```
%1 = extractelement <2 x i32> %add, i64 1
%add = add <2 x i32> %vecinit1, <i32 -1, i32 1>
```
is broken to have a scalar bin op instruction:
```
%1 = add nsw i32 %u_xlati59.06, 1
```
https://github.com/llvm/llvm-project/pull/122248
More information about the llvm-commits
mailing list