-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[SCCP] Simplify [us]cmp(X, Y) into X - Y #144717
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
Changes from 2 commits
d6d8d35
79e351d
0caf7dd
0fbd2e9
784023e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: opt -passes=sccp -S < %s | FileCheck %s | ||
|
||
define i32 @scmp_to_sub(i32 range(i32 -1, 2) %a) { | ||
; CHECK-LABEL: define i32 @scmp_to_sub( | ||
; CHECK-SAME: i32 range(i32 -1, 2) [[A:%.*]]) { | ||
; CHECK-NEXT: [[SCMP:%.*]] = sub nsw i32 [[A]], 0 | ||
; CHECK-NEXT: ret i32 [[SCMP]] | ||
; | ||
%scmp = call i32 @llvm.scmp(i32 %a, i32 0) | ||
ret i32 %scmp | ||
} | ||
|
||
define i32 @scmp_zext_to_sub(i1 %a, i1 %b) { | ||
; CHECK-LABEL: define i32 @scmp_zext_to_sub( | ||
; CHECK-SAME: i1 [[A:%.*]], i1 [[B:%.*]]) { | ||
; CHECK-NEXT: [[ZEXT_A:%.*]] = zext i1 [[A]] to i32 | ||
; CHECK-NEXT: [[ZEXT_B:%.*]] = zext i1 [[B]] to i32 | ||
; CHECK-NEXT: [[SCMP:%.*]] = sub nsw i32 [[ZEXT_A]], [[ZEXT_B]] | ||
; CHECK-NEXT: ret i32 [[SCMP]] | ||
; | ||
%zext_a = zext i1 %a to i32 | ||
%zext_b = zext i1 %b to i32 | ||
%scmp = call i32 @llvm.scmp(i32 %zext_a, i32 %zext_b) | ||
ret i32 %scmp | ||
} | ||
|
||
define i8 @scmp_to_sub_trunc(i32 range(i32 -1, 2) %a) { | ||
; CHECK-LABEL: define i8 @scmp_to_sub_trunc( | ||
; CHECK-SAME: i32 range(i32 -1, 2) [[A:%.*]]) { | ||
; CHECK-NEXT: [[SCMP1:%.*]] = sub nsw i32 [[A]], 0 | ||
; CHECK-NEXT: [[SCMP:%.*]] = trunc i32 [[SCMP1]] to i8 | ||
; CHECK-NEXT: ret i8 [[SCMP]] | ||
; | ||
%scmp = call i8 @llvm.scmp(i32 %a, i32 0) | ||
ret i8 %scmp | ||
} | ||
|
||
define i64 @scmp_to_sub_sext(i32 range(i32 -1, 2) %a) { | ||
; CHECK-LABEL: define i64 @scmp_to_sub_sext( | ||
; CHECK-SAME: i32 range(i32 -1, 2) [[A:%.*]]) { | ||
; CHECK-NEXT: [[SCMP1:%.*]] = sub nsw i32 [[A]], 0 | ||
; CHECK-NEXT: [[SCMP:%.*]] = sext i32 [[SCMP1]] to i64 | ||
; CHECK-NEXT: ret i64 [[SCMP]] | ||
; | ||
%scmp = call i64 @llvm.scmp(i32 %a, i32 0) | ||
ret i64 %scmp | ||
} | ||
|
||
define i32 @scmp_to_sub_small_range(i32 range(i32 -1, 1) %a) { | ||
; CHECK-LABEL: define i32 @scmp_to_sub_small_range( | ||
; CHECK-SAME: i32 range(i32 -1, 1) [[A:%.*]]) { | ||
; CHECK-NEXT: [[SCMP:%.*]] = sub nsw i32 [[A]], 0 | ||
; CHECK-NEXT: ret i32 [[SCMP]] | ||
; | ||
%scmp = call i32 @llvm.scmp(i32 %a, i32 0) | ||
ret i32 %scmp | ||
} | ||
|
||
define i32 @ucmp_to_sub(i32 range(i32 0, 3) %a) { | ||
; CHECK-LABEL: define i32 @ucmp_to_sub( | ||
; CHECK-SAME: i32 range(i32 0, 3) [[A:%.*]]) { | ||
; CHECK-NEXT: [[SCMP:%.*]] = sub nsw i32 [[A]], 1 | ||
; CHECK-NEXT: ret i32 [[SCMP]] | ||
; | ||
%scmp = call i32 @llvm.scmp(i32 %a, i32 1) | ||
dtcxzyw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ret i32 %scmp | ||
} | ||
|
||
define i32 @scmp_to_sub_large_range(i32 range(i32 -1, 3) %a) { | ||
; CHECK-LABEL: define i32 @scmp_to_sub_large_range( | ||
; CHECK-SAME: i32 range(i32 -1, 3) [[A:%.*]]) { | ||
; CHECK-NEXT: [[SCMP:%.*]] = call i32 @llvm.scmp.i32.i32(i32 [[A]], i32 0) | ||
; CHECK-NEXT: ret i32 [[SCMP]] | ||
; | ||
%scmp = call i32 @llvm.scmp(i32 %a, i32 0) | ||
ret i32 %scmp | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing tests for ucmp? I'd also like a negative test for the case where abs diff <= 1 but the transform is invalid because it wraps. (That's why the precondition is expressed in such a roundabout way, right?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah. I don't have a better idea to weaken the precondition (see the test |
Uh oh!
There was an error while loading. Please reload this page.