-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[ConstraintElim] Add tests for llvm.abs #76374
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
[ConstraintElim] Add tests for llvm.abs #76374
Conversation
@llvm/pr-subscribers-llvm-transforms Author: Alexander Shaposhnikov (alexander-shaposhnikov) ChangesThis is a preparation for #73189 Test plan: ninja check-all Full diff: https://github.com/llvm/llvm-project/pull/76374.diff 1 Files Affected:
diff --git a/llvm/test/Transforms/ConstraintElimination/abs.ll b/llvm/test/Transforms/ConstraintElimination/abs.ll
new file mode 100644
index 00000000000000..5d788996767c4c
--- /dev/null
+++ b/llvm/test/Transforms/ConstraintElimination/abs.ll
@@ -0,0 +1,64 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
+; RUN: opt -passes=constraint-elimination -S %s | FileCheck %s
+
+define i1 @abs_int_min_is_not_poison(i32 %arg) {
+; CHECK-LABEL: define i1 @abs_int_min_is_not_poison(
+; CHECK-SAME: i32 [[ARG:%.*]]) {
+; CHECK-NEXT: [[ABS:%.*]] = tail call i32 @llvm.abs.i32(i32 [[ARG]], i1 false)
+; CHECK-NEXT: [[CMP:%.*]] = icmp sge i32 [[ABS]], [[ARG]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %abs = tail call i32 @llvm.abs.i32(i32 %arg, i1 false)
+ %cmp = icmp sge i32 %abs, %arg
+ ret i1 %cmp
+}
+
+define i1 @abs_int_min_is_poison(i32 %arg) {
+; CHECK-LABEL: define i1 @abs_int_min_is_poison(
+; CHECK-SAME: i32 [[ARG:%.*]]) {
+; CHECK-NEXT: [[ABS:%.*]] = tail call i32 @llvm.abs.i32(i32 [[ARG]], i1 true)
+; CHECK-NEXT: [[CMP:%.*]] = icmp sge i32 [[ABS]], [[ARG]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %abs = tail call i32 @llvm.abs.i32(i32 %arg, i1 true)
+ %cmp = icmp sge i32 %abs, %arg
+ ret i1 %cmp
+}
+
+define i1 @abs_plus_one(i32 %arg) {
+; CHECK-LABEL: define i1 @abs_plus_one(
+; CHECK-SAME: i32 [[ARG:%.*]]) {
+; CHECK-NEXT: [[ABS:%.*]] = tail call i32 @llvm.abs.i32(i32 [[ARG]], i1 true)
+; CHECK-NEXT: [[ABS_PLUS_ONE:%.*]] = add nsw i32 [[ABS]], 1
+; CHECK-NEXT: [[CMP:%.*]] = icmp sge i32 [[ABS_PLUS_ONE]], [[ARG]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %abs = tail call i32 @llvm.abs.i32(i32 %arg, i1 true)
+ %abs_plus_one = add nsw i32 %abs, 1
+ %cmp = icmp sge i32 %abs_plus_one, %arg
+ ret i1 %cmp
+}
+
+define i1 @abs_constant_negative_arg() {
+; CHECK-LABEL: define i1 @abs_constant_negative_arg() {
+; CHECK-NEXT: [[ABS:%.*]] = tail call i32 @llvm.abs.i32(i32 -3, i1 false)
+; CHECK-NEXT: [[CMP:%.*]] = icmp sge i32 [[ABS]], 3
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %abs = tail call i32 @llvm.abs.i32(i32 -3, i1 false)
+ %cmp = icmp sge i32 %abs, 3
+ ret i1 %cmp
+}
+
+define i1 @abs_constant_positive_arg() {
+; CHECK-LABEL: define i1 @abs_constant_positive_arg() {
+; CHECK-NEXT: [[ABS:%.*]] = tail call i32 @llvm.abs.i32(i32 3, i1 false)
+; CHECK-NEXT: [[CMP:%.*]] = icmp sge i32 [[ABS]], 3
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %abs = tail call i32 @llvm.abs.i32(i32 3, i1 false)
+ %cmp = icmp sge i32 %abs, 3
+ ret i1 %cmp
+}
+
+declare i32 @llvm.abs.i32(i32, i1 immarg)
|
Thanks for putting up the tests as separate PR! Could you also add tests with predicates other than |
573e4ab
to
8f19aa1
Compare
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update! I think the last case missing is one where a compare gets simplified to false.
ret i1 %cmp | ||
} | ||
|
||
define i1 @abs_plus_one_unsigned_greater_or_eual_cannot_be_simplified(i32 %arg) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: eual -> equal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
8f19aa1
to
0c688cc
Compare
Address comments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
This is a preparation for #73189
Test plan: ninja check-all