Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LoopVectorize] Vectorize select-cmp reduction pattern for increasing integer induction variable #67812

Merged
merged 29 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6bdc81f
[LoopVectorize] Vectorize select-cmp reduction pattern for increasing
Mel-Chen Sep 25, 2023
bcab2a6
Refactor the identification method for FindLastIV pattern.
Mel-Chen Sep 25, 2023
dfa355b
Replace SelectInst with auto
Mel-Chen Oct 4, 2023
734da15
Drop parentheses
Mel-Chen Oct 4, 2023
2c896c4
Modified lambda to capture all external variables by reference
Mel-Chen Oct 4, 2023
1946c8c
Fix format
Mel-Chen Oct 4, 2023
e8d5b1d
Clean up comments
Mel-Chen Oct 4, 2023
d2bfe2f
Refine the expression of valid range
Mel-Chen Oct 6, 2023
4a88b44
Fix the warning caused by unused parameter
Mel-Chen Nov 27, 2023
d21b127
Fix typo
Mel-Chen Nov 27, 2023
2fe0a94
Clean comment in test case
Mel-Chen Nov 27, 2023
7ebc7d8
Fix SE pass
Mel-Chen Apr 24, 2024
3e2e9f1
Add TODO comment for the decreasing induction
Mel-Chen Apr 24, 2024
11900cd
Refine comments
Mel-Chen May 6, 2024
2924bf9
Refine debug dump
Mel-Chen May 6, 2024
dd21cd3
Refine comments
Mel-Chen May 10, 2024
76e91cc
Revert "Refine the expression of valid range"
Mel-Chen May 10, 2024
4f743ab
Refine the expression of valid range
Mel-Chen May 10, 2024
556743a
Capture LHS and RHS of select instruction by match.
Mel-Chen May 10, 2024
a852eb6
Rebase, and update test cases
Mel-Chen Oct 17, 2024
4947e0f
Restrict FindLastIV idiom to single-use reduction phi.
Mel-Chen Oct 17, 2024
6e739d8
Remove unused variable
Mel-Chen Oct 17, 2024
7d2a8ec
Refine pattern matcher
Mel-Chen Oct 31, 2024
e530a3a
Refine lit test checker format
Mel-Chen Oct 31, 2024
e50439e
Remove unused CHECK
Mel-Chen Nov 28, 2024
ab0b4d3
Refine the comment for getSentinelValue
Mel-Chen Dec 2, 2024
97e0433
Replace if-condition with assert
Mel-Chen Dec 3, 2024
69cd172
Add comment for wrap check
Mel-Chen Dec 3, 2024
5ebec5d
Add check for ensure the loop of SCEVAddRec is the same as the loop o…
Mel-Chen Dec 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove unused CHECK
  • Loading branch information
Mel-Chen committed Dec 12, 2024
commit e50439ee09d5cb0f36abb17f9f24b2583adef4b5
8 changes: 3 additions & 5 deletions llvm/test/Transforms/LoopVectorize/iv-select-cmp-trunc.ll
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt -passes=loop-vectorize -force-vector-interleave=1 -force-vector-width=4 -S < %s | FileCheck %s --check-prefixes=CHECK,CHECK-VF4IC1
; RUN: opt -passes=loop-vectorize -force-vector-interleave=4 -force-vector-width=4 -S < %s | FileCheck %s --check-prefixes=CHECK,CHECK-VF4IC4
; RUN: opt -passes=loop-vectorize -force-vector-interleave=4 -force-vector-width=1 -S < %s | FileCheck %s --check-prefixes=CHECK,CHECK-VF1IC4
; RUN: opt -passes=loop-vectorize -force-vector-interleave=1 -force-vector-width=4 -S < %s | FileCheck %s --check-prefix=CHECK-VF4IC1
; RUN: opt -passes=loop-vectorize -force-vector-interleave=4 -force-vector-width=4 -S < %s | FileCheck %s --check-prefix=CHECK-VF4IC4
; RUN: opt -passes=loop-vectorize -force-vector-interleave=4 -force-vector-width=1 -S < %s | FileCheck %s --check-prefix=CHECK-VF1IC4

; About the truncated test cases, the range analysis of induction variable is
; used to ensure the induction variable is always greater than the sentinal
Expand Down Expand Up @@ -1250,5 +1250,3 @@ exit: ; preds = %for.body, %entry
; CHECK-VF1IC4: [[LOOP6]] = distinct !{[[LOOP6]], [[META1]], [[META2]]}
; CHECK-VF1IC4: [[LOOP7]] = distinct !{[[LOOP7]], [[META1]]}
;.
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
; CHECK: {{.*}}
8 changes: 3 additions & 5 deletions llvm/test/Transforms/LoopVectorize/iv-select-cmp.ll
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt -passes=loop-vectorize -force-vector-interleave=1 -force-vector-width=4 -S < %s | FileCheck %s --check-prefixes=CHECK,CHECK-VF4IC1
; RUN: opt -passes=loop-vectorize -force-vector-interleave=4 -force-vector-width=4 -S < %s | FileCheck %s --check-prefixes=CHECK,CHECK-VF4IC4
; RUN: opt -passes=loop-vectorize -force-vector-interleave=4 -force-vector-width=1 -S < %s | FileCheck %s --check-prefixes=CHECK,CHECK-VF1IC4
; RUN: opt -passes=loop-vectorize -force-vector-interleave=1 -force-vector-width=4 -S < %s | FileCheck %s --check-prefix=CHECK-VF4IC1
; RUN: opt -passes=loop-vectorize -force-vector-interleave=4 -force-vector-width=4 -S < %s | FileCheck %s --check-prefix=CHECK-VF4IC4
; RUN: opt -passes=loop-vectorize -force-vector-interleave=4 -force-vector-width=1 -S < %s | FileCheck %s --check-prefix=CHECK-VF1IC4

define i64 @select_icmp_const_1(ptr %a, i64 %n) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both @select_icmp_const_1 and @select_icmp_const_2 look similar to test select_icmp_nuw_nsw in Transforms/LoopVectorize/iv-select-cmp-no-wrap.ll.

Also, I see the only difference between @select_icmp_const_1 and @select_icmp_const_2 is the operands to the select are swapped. I'm not sure having both versions really adds much value. Perhaps you can remove both of them and leave the one in iv-select-cmp-no-wrap.ll

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are indeed quite similar. iv-select-cmp.ll is for testing IR generation, including the case of UF > 1. iv-select-cmp-no-wrap.ll is for testing whether vectorization is legal.
My suggestion is to remove select_icmp_nuw_nsw from iv-select-cmp-no-wrap.ll, and retain @select_icmp_const_1 and @select_icmp_const_2.
What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@david-arm Ping.
Regarding my test file proposal, what do you think?

; CHECK-VF4IC1-LABEL: define i64 @select_icmp_const_1(
Expand Down Expand Up @@ -2239,5 +2239,3 @@ exit: ; preds = %for.body
; CHECK-VF1IC4: [[LOOP16]] = distinct !{[[LOOP16]], [[META1]], [[META2]]}
; CHECK-VF1IC4: [[LOOP17]] = distinct !{[[LOOP17]], [[META1]]}
;.
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
; CHECK: {{.*}}
8 changes: 3 additions & 5 deletions llvm/test/Transforms/LoopVectorize/select-min-index.ll
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just delete this file, since it looks practically the same as llvm/test/Transforms/LoopVectorize/iv-select-cmp-no-wrap.ll and doesn't seem to offer any extra value?

Copy link
Contributor Author

@Mel-Chen Mel-Chen May 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we must retain llvm/test/Transforms/LoopVectorize/select-min-index.ll. select-min-index.ll demonstrates another semantics: minmax with index. This semantics is similar to FindLastIV but different.
BTW, this patch is separated from the minmax with index patch.

int min = start_min;
int idx = start_idx;
for (int i = 0; i < n; i++)
  if (min > a[i]) {
    min = a[i];
    idx = i;
  }

// live-out: idx

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S %s | FileCheck %s --check-prefix=CHECK-VF4IC1 --check-prefix=CHECK
; RUN: opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=2 -S %s | FileCheck %s --check-prefix=CHECK-VF4IC2 --check-prefix=CHECK
; RUN: opt -passes=loop-vectorize -force-vector-width=1 -force-vector-interleave=2 -S %s | FileCheck %s --check-prefix=CHECK-VF1IC2 --check-prefix=CHECK
; RUN: opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S %s | FileCheck %s --check-prefix=CHECK-VF4IC1
; RUN: opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=2 -S %s | FileCheck %s --check-prefix=CHECK-VF4IC2
; RUN: opt -passes=loop-vectorize -force-vector-width=1 -force-vector-interleave=2 -S %s | FileCheck %s --check-prefix=CHECK-VF1IC2

; Test cases for selecting the index with the minimum value.

Expand Down Expand Up @@ -1085,5 +1085,3 @@ declare i16 @llvm.umin.i16(i16, i16)
; CHECK-VF1IC2: [[META2]] = !{!"llvm.loop.unroll.runtime.disable"}
; CHECK-VF1IC2: [[LOOP3]] = distinct !{[[LOOP3]], [[META1]]}
;.
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
; CHECK: {{.*}}