-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir][arith] Add comparison integration tests #96974
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d7602db
adding comparison unit tests
pingshiyu 4909f9e
reindented
pingshiyu ca0e890
comparison adopting format of previous other tests
pingshiyu f48f880
updated based on comments
pingshiyu 45ccc02
Update mlir/test/Integration/Dialect/Arith/CPU/comparison.mlir
pingshiyu 13ae182
updates to latest comments #1
pingshiyu 9c6af68
comparison updated with new case
pingshiyu 1d9d292
Merge branch 'arith-regression-comparison' of github.com:pingshiyu/ll…
pingshiyu 9d509b3
more tests added, comments updated
pingshiyu d68f34b
Update mlir/test/Integration/Dialect/Arith/CPU/comparison.mlir
pingshiyu 5c77e4d
adding equality tests
pingshiyu 3cb8377
Merge branch 'arith-regression-comparison' of github.com:pingshiyu/ll…
pingshiyu e8f8a53
fixup, comments addressed
pingshiyu 5591bc9
addressed comment,s added more tests
pingshiyu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
174 changes: 174 additions & 0 deletions
174
mlir/test/Integration/Dialect/Arith/CPU/comparison.mlir
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
// RUN: mlir-opt %s --convert-scf-to-cf --convert-cf-to-llvm --convert-vector-to-llvm \ | ||
// RUN: --convert-func-to-llvm --convert-arith-to-llvm | \ | ||
// RUN: mlir-cpu-runner -e entry -entry-point-result=void \ | ||
// RUN: --shared-libs=%mlir_c_runner_utils | \ | ||
// RUN: FileCheck %s --match-full-lines | ||
|
||
func.func @cmpi_eq_i1(%v1 : i1, %v2 : i1) { | ||
vector.print str "@cmpi_eq_i1\n" | ||
%res = arith.cmpi eq, %v1, %v2 : i1 | ||
vector.print %res : i1 | ||
return | ||
} | ||
|
||
func.func @cmpi_slt_i1(%v1 : i1, %v2 : i1) { | ||
vector.print str "@cmpi_slt_i1\n" | ||
%res = arith.cmpi slt, %v1, %v2 : i1 | ||
vector.print %res : i1 | ||
return | ||
} | ||
|
||
func.func @cmpi_sle_i1(%v1 : i1, %v2 : i1) { | ||
vector.print str "@cmpi_sle_i1\n" | ||
%res = arith.cmpi sle, %v1, %v2 : i1 | ||
vector.print %res : i1 | ||
return | ||
} | ||
|
||
func.func @cmpi_sgt_i1(%v1 : i1, %v2 : i1) { | ||
vector.print str "@cmpi_sgt_i1\n" | ||
%res = arith.cmpi sgt, %v1, %v2 : i1 | ||
vector.print %res : i1 | ||
return | ||
} | ||
|
||
func.func @cmpi_sge_i1(%v1 : i1, %v2 : i1) { | ||
vector.print str "@cmpi_sge_i1\n" | ||
%res = arith.cmpi sge, %v1, %v2 : i1 | ||
vector.print %res : i1 | ||
return | ||
} | ||
|
||
func.func @cmpi_eq() { | ||
// ------------------------------------------------ | ||
// Test i1 | ||
// ------------------------------------------------ | ||
%false_i1 = arith.constant 0 : i1 | ||
%true_i1 = arith.constant 1 : i1 | ||
%true_i1_n1 = arith.constant -1 : i1 | ||
|
||
// int values 1 and -1 are represented with the same bitvector (`0b1`) | ||
// CHECK-LABEL: @cmpi_eq_i1 | ||
// CHECK-NEXT: 1 | ||
func.call @cmpi_eq_i1(%true_i1, %true_i1_n1) : (i1, i1) -> () | ||
|
||
// CHECK-LABEL: @cmpi_eq_i1 | ||
// CHECK-NEXT: 0 | ||
func.call @cmpi_eq_i1(%false_i1, %true_i1) : (i1, i1) -> () | ||
|
||
// CHECK-LABEL: @cmpi_eq_i1 | ||
// CHECK-NEXT: 0 | ||
func.call @cmpi_eq_i1(%true_i1, %false_i1) : (i1, i1) -> () | ||
|
||
// CHECK-LABEL: @cmpi_eq_i1 | ||
// CHECK-NEXT: 1 | ||
func.call @cmpi_eq_i1(%true_i1, %true_i1) : (i1, i1) -> () | ||
|
||
// CHECK-LABEL: @cmpi_eq_i1 | ||
// CHECK-NEXT: 1 | ||
func.call @cmpi_eq_i1(%false_i1, %false_i1) : (i1, i1) -> () | ||
|
||
%false = arith.constant false | ||
%true = arith.constant true | ||
|
||
// CHECK-LABEL: @cmpi_eq_i1 | ||
// CHECK-NEXT: 1 | ||
func.call @cmpi_eq_i1(%true, %true_i1) : (i1, i1) -> () | ||
|
||
// CHECK-LABEL: @cmpi_eq_i1 | ||
// CHECK-NEXT: 1 | ||
func.call @cmpi_eq_i1(%false, %false_i1) : (i1, i1) -> () | ||
|
||
// CHECK-LABEL: @cmpi_eq_i1 | ||
// CHECK-NEXT: 1 | ||
func.call @cmpi_eq_i1(%true, %true_i1_n1) : (i1, i1) -> () | ||
|
||
// ------------------------------------------------ | ||
// TODO: Test i8, i16 etc.. | ||
// ------------------------------------------------ | ||
return | ||
} | ||
|
||
func.func @cmpi_signed() { | ||
// ------------------------------------------------ | ||
// Test i1 | ||
// ------------------------------------------------ | ||
%false_i1 = arith.constant 0 : i1 | ||
%true_i1 = arith.constant 1 : i1 | ||
%true_i1_n1 = arith.constant -1 : i1 | ||
pingshiyu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// int values 1 and -1 are represented with the same bitvector (`0b1`) | ||
// But, bitvector `1` is interpreted as int value -1 in signed comparison | ||
|
||
// CHECK-LABEL: @cmpi_sge_i1 | ||
// CHECK-NEXT: 1 | ||
func.call @cmpi_sge_i1(%false_i1, %true_i1_n1) : (i1, i1) -> () | ||
|
||
// CHECK-LABEL: @cmpi_sge_i1 | ||
// CHECK-NEXT: 1 | ||
func.call @cmpi_sge_i1(%false_i1, %true_i1) : (i1, i1) -> () | ||
pingshiyu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// CHECK-LABEL: @cmpi_sge_i1 | ||
// CHECK-NEXT: 0 | ||
func.call @cmpi_sge_i1(%true_i1, %false_i1) : (i1, i1) -> () | ||
|
||
%false = arith.constant false | ||
%true = arith.constant true | ||
pingshiyu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// CHECK-LABEL: @cmpi_slt_i1 | ||
// CHECK-NEXT: 0 | ||
func.call @cmpi_slt_i1(%false, %true) : (i1, i1) -> () | ||
|
||
// CHECK-LABEL: @cmpi_sle_i1 | ||
// CHECK-NEXT: 0 | ||
func.call @cmpi_sle_i1(%false, %true) : (i1, i1) -> () | ||
|
||
// CHECK-LABEL: @cmpi_sgt_i1 | ||
// CHECK-NEXT: 1 | ||
func.call @cmpi_sgt_i1(%false, %true) : (i1, i1) -> () | ||
|
||
// CHECK-LABEL: @cmpi_sge_i1 | ||
// CHECK-NEXT: 1 | ||
func.call @cmpi_sge_i1(%false, %true) : (i1, i1) -> () | ||
|
||
// CHECK-LABEL: @cmpi_sge_i1 | ||
// CHECK-NEXT: 0 | ||
func.call @cmpi_sge_i1(%true, %false) : (i1, i1) -> () | ||
|
||
// ------------------------------------------------ | ||
// TODO: Test i8, i16 etc.. | ||
// ------------------------------------------------ | ||
return | ||
} | ||
|
||
func.func @cmpi_ult_index(%v1 : index, %v2 : index) { | ||
vector.print str "@cmpi_ult_index\n" | ||
%res = arith.cmpi ult, %v1, %v2 : index | ||
vector.print %res : i1 | ||
return | ||
} | ||
|
||
func.func @cmpi_unsigned() { | ||
// ------------------------------------------------ | ||
// Test index | ||
// ------------------------------------------------ | ||
// 0 `ult` -2^63 = true | ||
%zero = arith.constant 0 : index | ||
%index_min = arith.constant -9223372036854775808 : index | ||
|
||
// CHECK-LABEL: @cmpi_ult_index | ||
// CHECK-NEXT: 1 | ||
func.call @cmpi_ult_index(%zero, %index_min) : (index, index) -> () | ||
|
||
// ------------------------------------------------ | ||
// TODO: i1, i8, i16, uge, ule etc.. | ||
// ------------------------------------------------ | ||
return | ||
} | ||
|
||
func.func @entry() { | ||
func.call @cmpi_eq() : () -> () | ||
func.call @cmpi_signed() : () -> () | ||
func.call @cmpi_unsigned() : () -> () | ||
return | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.