-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[mlir] [arith] Fix ceildivsi lowering in arith-expand #133774
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 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f829156
[mlir] Fix ceildivsi lowering in arith-expand
math-fehr b9e8280
Add integration test for ceildivsi lowering
math-fehr c392bda
Apply suggestions from code review
math-fehr 1a771e4
Add missing newline
math-fehr 71ffae5
Fix correct newline
math-fehr 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
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
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
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
106 changes: 106 additions & 0 deletions
106
mlir/test/Integration/Dialect/Arith/CPU/test-arith-expand-ceildivsi.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,106 @@ | ||
// Check that the ceildivsi lowering is correct. | ||
// We do not check any poison or UB values, as it is not possible to catch them. | ||
|
||
// RUN: mlir-opt %s --convert-vector-to-llvm \ | ||
// RUN: --convert-func-to-llvm --convert-arith-to-llvm | \ | ||
// RUN: mlir-runner -e entry -entry-point-result=void \ | ||
// RUN: --shared-libs=%mlir_c_runner_utils | \ | ||
// RUN: FileCheck %s --match-full-lines | ||
|
||
func.func @check_ceildivsi(%lhs : i32, %rhs : i32) -> () { | ||
%res = arith.ceildivsi %lhs, %rhs : i32 | ||
vector.print %res : i32 | ||
return | ||
} | ||
|
||
func.func @entry() { | ||
%int_min = arith.constant -2147483648 : i32 | ||
%int_max = arith.constant 2147483647 : i32 | ||
%minus_three = arith.constant -3 : i32 | ||
%minus_two = arith.constant -2 : i32 | ||
%minus_one = arith.constant -1 : i32 | ||
%zero = arith.constant 0 : i32 | ||
%one = arith.constant 1 : i32 | ||
%two = arith.constant 2 : i32 | ||
%three = arith.constant 3 : i32 | ||
|
||
// INT_MAX divided by values | ||
math-fehr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// CHECK: 1 | ||
func.call @check_ceildivsi(%int_max, %int_max) : (i32, i32) -> () | ||
// CHECK-NEXT: 0 | ||
func.call @check_ceildivsi(%int_max, %int_min) : (i32, i32) -> () | ||
// CHECK-NEXT: -2147483647 | ||
func.call @check_ceildivsi(%int_max, %minus_one) : (i32, i32) -> () | ||
// CHECK-NEXT: -1073741823 | ||
func.call @check_ceildivsi(%int_max, %minus_two) : (i32, i32) -> () | ||
// CHECK-NEXT: 2147483647 | ||
func.call @check_ceildivsi(%int_max, %one) : (i32, i32) -> () | ||
// CHECK-NEXT: 1073741824 | ||
func.call @check_ceildivsi(%int_max, %two) : (i32, i32) -> () | ||
|
||
// INT_MIN divided by values | ||
math-fehr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// We do not check the result of INT_MIN divided by -1, as it is UB. | ||
// CHECK-NEXT: 1 | ||
func.call @check_ceildivsi(%int_min, %int_min) : (i32, i32) -> () | ||
// CHECK-NEXT: -1 | ||
func.call @check_ceildivsi(%int_min, %int_max) : (i32, i32) -> () | ||
// CHECK-NEXT: 1073741824 | ||
func.call @check_ceildivsi(%int_min, %minus_two) : (i32, i32) -> () | ||
// CHECK-NEXT: -2147483648 | ||
func.call @check_ceildivsi(%int_min, %one) : (i32, i32) -> () | ||
// CHECK-NEXT: -1073741824 | ||
func.call @check_ceildivsi(%int_min, %two) : (i32, i32) -> () | ||
|
||
// Divide values by INT_MIN | ||
math-fehr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// CHECK-NEXT: 0 | ||
func.call @check_ceildivsi(%one, %int_min) : (i32, i32) -> () | ||
// CHECK-NEXT: 0 | ||
func.call @check_ceildivsi(%two, %int_min) : (i32, i32) -> () | ||
// CHECK-NEXT: 1 | ||
func.call @check_ceildivsi(%minus_one, %int_min) : (i32, i32) -> () | ||
// CHECK-NEXT: 1 | ||
func.call @check_ceildivsi(%minus_two, %int_min) : (i32, i32) -> () | ||
|
||
// Divide values by INT_MAX | ||
math-fehr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// CHECK-NEXT: 1 | ||
func.call @check_ceildivsi(%one, %int_max) : (i32, i32) -> () | ||
// CHECK-NEXT: 1 | ||
func.call @check_ceildivsi(%two, %int_max) : (i32, i32) -> () | ||
// CHECK-NEXT: 0 | ||
func.call @check_ceildivsi(%minus_one, %int_max) : (i32, i32) -> () | ||
// CHECK-NEXT: 0 | ||
func.call @check_ceildivsi(%minus_two, %int_max) : (i32, i32) -> () | ||
|
||
// Check divisions by 2 | ||
math-fehr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// CHECK-NEXT: -1 | ||
func.call @check_ceildivsi(%minus_three, %two) : (i32, i32) -> () | ||
// CHECK-NEXT: -1 | ||
func.call @check_ceildivsi(%minus_two, %two) : (i32, i32) -> () | ||
// CHECK-NEXT: 0 | ||
func.call @check_ceildivsi(%minus_one, %two) : (i32, i32) -> () | ||
// CHECK-NEXT: 0 | ||
func.call @check_ceildivsi(%zero, %two) : (i32, i32) -> () | ||
// CHECK-NEXT: 1 | ||
func.call @check_ceildivsi(%one, %two) : (i32, i32) -> () | ||
// CHECK-NEXT: 1 | ||
func.call @check_ceildivsi(%two, %two) : (i32, i32) -> () | ||
// CHECK-NEXT: 2 | ||
func.call @check_ceildivsi(%three, %two) : (i32, i32) -> () | ||
|
||
// Check divisions by -2 | ||
math-fehr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// CHECK-NEXT: 2 | ||
func.call @check_ceildivsi(%minus_three, %minus_two) : (i32, i32) -> () | ||
// CHECK-NEXT: 1 | ||
func.call @check_ceildivsi(%minus_two, %minus_two) : (i32, i32) -> () | ||
// CHECK-NEXT: 1 | ||
func.call @check_ceildivsi(%minus_one, %minus_two) : (i32, i32) -> () | ||
// CHECK-NEXT: 0 | ||
func.call @check_ceildivsi(%zero, %minus_two) : (i32, i32) -> () | ||
// CHECK-NEXT: 0 | ||
func.call @check_ceildivsi(%one, %minus_two) : (i32, i32) -> () | ||
// CHECK-NEXT: -1 | ||
func.call @check_ceildivsi(%two, %minus_two) : (i32, i32) -> () | ||
// CHECK-NEXT: -1 | ||
func.call @check_ceildivsi(%three, %minus_two) : (i32, i32) -> () | ||
return | ||
} | ||
math-fehr marked this conversation as resolved.
Show resolved
Hide resolved
|
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.