[llvm] 01a2ba5 - [InstCombine] add tests for abs with dominating condition; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 22 07:37:17 PDT 2022
Author: chenglin.bi
Date: 2022-03-22T10:37:12-04:00
New Revision: 01a2ba5dfbeea4d41b94df131a5f1ab5d8448f79
URL: https://github.com/llvm/llvm-project/commit/01a2ba5dfbeea4d41b94df131a5f1ab5d8448f79
DIFF: https://github.com/llvm/llvm-project/commit/01a2ba5dfbeea4d41b94df131a5f1ab5d8448f79.diff
LOG: [InstCombine] add tests for abs with dominating condition; NFC
Baseline tests for D122013 (issue #54132).
Added:
Modified:
llvm/test/Transforms/InstCombine/abs-intrinsic.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/abs-intrinsic.ll b/llvm/test/Transforms/InstCombine/abs-intrinsic.ll
index 2c28a1954d765..ed987b0a80b3b 100644
--- a/llvm/test/Transforms/InstCombine/abs-intrinsic.ll
+++ b/llvm/test/Transforms/InstCombine/abs-intrinsic.ll
@@ -424,3 +424,112 @@ define i32 @srem_by_3(i32 %x) {
%r = call i32 @llvm.abs.i32(i32 %s, i1 true)
ret i32 %r
}
+
+; Test from https://github.com/llvm/llvm-project/issues/54132.
+define i32 @sub_abs_gt(i32 %x, i32 %y) {
+; CHECK-LABEL: @sub_abs_gt(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_END:%.*]]
+; CHECK: cond.true:
+; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 [[X]], [[Y]]
+; CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.abs.i32(i32 [[SUB]], i1 true)
+; CHECK-NEXT: br label [[COND_END]]
+; CHECK: cond.end:
+; CHECK-NEXT: [[R:%.*]] = phi i32 [ [[TMP0]], [[COND_TRUE]] ], [ 0, [[ENTRY:%.*]] ]
+; CHECK-NEXT: ret i32 [[R]]
+;
+entry:
+ %cmp = icmp sgt i32 %x, %y
+ br i1 %cmp, label %cond.true, label %cond.end
+
+cond.true:
+ %sub = sub nsw i32 %x, %y
+ %0 = call i32 @llvm.abs.i32(i32 %sub, i1 true)
+ br label %cond.end
+
+cond.end:
+ %r = phi i32 [ %0, %cond.true ], [ 0, %entry ]
+ ret i32 %r
+}
+
+define i32 @sub_abs_lt(i32 %x, i32 %y) {
+; CHECK-LABEL: @sub_abs_lt(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_END:%.*]]
+; CHECK: cond.true:
+; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 [[X]], [[Y]]
+; CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.abs.i32(i32 [[SUB]], i1 true)
+; CHECK-NEXT: br label [[COND_END]]
+; CHECK: cond.end:
+; CHECK-NEXT: [[R:%.*]] = phi i32 [ [[TMP0]], [[COND_TRUE]] ], [ 0, [[ENTRY:%.*]] ]
+; CHECK-NEXT: ret i32 [[R]]
+;
+entry:
+ %cmp = icmp slt i32 %x, %y
+ br i1 %cmp, label %cond.true, label %cond.end
+
+cond.true:
+ %sub = sub nsw i32 %x, %y
+ %0 = call i32 @llvm.abs.i32(i32 %sub, i1 true)
+ br label %cond.end
+
+cond.end:
+ %r = phi i32 [ %0, %cond.true ], [ 0, %entry ]
+ ret i32 %r
+}
+
+define i32 @sub_abs_wrong_pred(i32 %x, i32 %y) {
+; CHECK-LABEL: @sub_abs_wrong_pred(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_END:%.*]]
+; CHECK: cond.true:
+; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 [[X]], [[Y]]
+; CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.abs.i32(i32 [[SUB]], i1 true)
+; CHECK-NEXT: br label [[COND_END]]
+; CHECK: cond.end:
+; CHECK-NEXT: [[R:%.*]] = phi i32 [ [[TMP0]], [[COND_TRUE]] ], [ 0, [[ENTRY:%.*]] ]
+; CHECK-NEXT: ret i32 [[R]]
+;
+entry:
+ %cmp = icmp ugt i32 %x, %y
+ br i1 %cmp, label %cond.true, label %cond.end
+
+cond.true:
+ %sub = sub nsw i32 %x, %y
+ %0 = call i32 @llvm.abs.i32(i32 %sub, i1 true)
+ br label %cond.end
+
+cond.end:
+ %r = phi i32 [ %0, %cond.true ], [ 0, %entry ]
+ ret i32 %r
+}
+
+define i32 @sub_abs_no_nsw(i32 %x, i32 %y) {
+; CHECK-LABEL: @sub_abs_no_nsw(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_END:%.*]]
+; CHECK: cond.true:
+; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[X]], [[Y]]
+; CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.abs.i32(i32 [[SUB]], i1 true)
+; CHECK-NEXT: br label [[COND_END]]
+; CHECK: cond.end:
+; CHECK-NEXT: [[R:%.*]] = phi i32 [ [[TMP0]], [[COND_TRUE]] ], [ 0, [[ENTRY:%.*]] ]
+; CHECK-NEXT: ret i32 [[R]]
+;
+entry:
+ %cmp = icmp sgt i32 %x, %y
+ br i1 %cmp, label %cond.true, label %cond.end
+
+cond.true:
+ %sub = sub i32 %x, %y
+ %0 = call i32 @llvm.abs.i32(i32 %sub, i1 true)
+ br label %cond.end
+
+cond.end:
+ %r = phi i32 [ %0, %cond.true ], [ 0, %entry ]
+ ret i32 %r
+}
More information about the llvm-commits
mailing list