[llvm] [ConstraintElim] Add tests for llvm.abs (PR #76374)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 25 14:13:38 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Alexander Shaposhnikov (alexander-shaposhnikov)
<details>
<summary>Changes</summary>
This is a preparation for https://github.com/llvm/llvm-project/pull/73189
Test plan: ninja check-all
---
Full diff: https://github.com/llvm/llvm-project/pull/76374.diff
1 Files Affected:
- (added) llvm/test/Transforms/ConstraintElimination/abs.ll (+64)
``````````diff
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)
``````````
</details>
https://github.com/llvm/llvm-project/pull/76374
More information about the llvm-commits
mailing list