Skip to content

Conversation

alexander-shaposhnikov
Copy link
Collaborator

@alexander-shaposhnikov alexander-shaposhnikov commented Jan 22, 2024

Add tests for llvm.abs >= 0.
This is a preparation for #79070 .

@llvmbot
Copy link
Member

llvmbot commented Jan 22, 2024

@llvm/pr-subscribers-llvm-transforms

Author: Alexander Shaposhnikov (alexander-shaposhnikov)

Changes

Add tests for llvm.abs >= 0


Full diff: https://github.com/llvm/llvm-project/pull/79068.diff

1 Files Affected:

  • (modified) llvm/test/Transforms/ConstraintElimination/abs.ll (+47)
diff --git a/llvm/test/Transforms/ConstraintElimination/abs.ll b/llvm/test/Transforms/ConstraintElimination/abs.ll
index c3162ba48c2e4af..a7b20997fa4cd34 100644
--- a/llvm/test/Transforms/ConstraintElimination/abs.ll
+++ b/llvm/test/Transforms/ConstraintElimination/abs.ll
@@ -114,5 +114,52 @@ define i1 @abs_constant_positive_arg() {
   ret i1 %cmp
 }
 
+define i1 @abs_is_nonnegative_except_for_int_min_if_int_min_is_not_poison(i32 %arg) {
+; CHECK-LABEL: define i1 @abs_is_nonnegative_except_for_int_min_if_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]], 0
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %abs = tail call i32 @llvm.abs.i32(i32 %arg, i1 false)
+  %cmp = icmp sge i32 %abs, 0
+  ret i1 %cmp
+}
+
+define i1 @abs_is_not_strictly_positive(i32 %arg) {
+; CHECK-LABEL: define i1 @abs_is_not_strictly_positive(
+; CHECK-SAME: i32 [[ARG:%.*]]) {
+; CHECK-NEXT:    [[ABS:%.*]] = tail call i32 @llvm.abs.i32(i32 [[ARG]], i1 true)
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt i32 [[ABS]], 0
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %abs = tail call i32 @llvm.abs.i32(i32 %arg, i1 true)
+  %cmp = icmp sgt i32 %abs, 0
+  ret i1 %cmp
+}
+
+define i1 @abs_is_nonnegative_int_min_is_poison(i32 %arg) {
+; CHECK-LABEL: define i1 @abs_is_nonnegative_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]], 0
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %abs = tail call i32 @llvm.abs.i32(i32 %arg, i1 true)
+  %cmp = icmp sge i32 %abs, 0
+  ret i1 %cmp
+}
+
+define i1 @abs_is_nonnegative_constant_arg() {
+; CHECK-LABEL: define i1 @abs_is_nonnegative_constant_arg() {
+; CHECK-NEXT:    [[ABS:%.*]] = tail call i32 @llvm.abs.i32(i32 -3, i1 true)
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sge i32 [[ABS]], 0
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %abs = tail call i32 @llvm.abs.i32(i32 -3, i1 true)
+  %cmp = icmp sge i32 %abs, 0
+  ret i1 %cmp
+}
+
 declare i32 @llvm.abs.i32(i32, i1 immarg)
 declare void @llvm.assume(i1)

@alexander-shaposhnikov
Copy link
Collaborator Author

@fhahn

Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@alexander-shaposhnikov alexander-shaposhnikov merged commit eb98b50 into llvm:main Jan 29, 2024
@alexander-shaposhnikov
Copy link
Collaborator Author

@fhahn - the accompanying PR is #79070 - is it OK to land it too ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants