[llvm] 5bf4ab0 - [InstCombine] add tests for inc/dec with min/max; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 11 09:48:17 PDT 2021


Author: Sanjay Patel
Date: 2021-08-11T12:48:10-04:00
New Revision: 5bf4ab0e79e1a8552019918a662bdf7af8b3825a

URL: https://github.com/llvm/llvm-project/commit/5bf4ab0e79e1a8552019918a662bdf7af8b3825a
DIFF: https://github.com/llvm/llvm-project/commit/5bf4ab0e79e1a8552019918a662bdf7af8b3825a.diff

LOG: [InstCombine] add tests for inc/dec with min/max; NFC

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/icmp-add.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/icmp-add.ll b/llvm/test/Transforms/InstCombine/icmp-add.ll
index c6dfb9d0e5d86..187e0ad1a31bf 100644
--- a/llvm/test/Transforms/InstCombine/icmp-add.ll
+++ b/llvm/test/Transforms/InstCombine/icmp-add.ll
@@ -971,3 +971,61 @@ define i1 @slt_offset_nsw(i8 %a, i8 %c) {
   %ov = icmp slt i8 %t, 42
   ret i1 %ov
 }
+
+; FIXME:
+; In the following 4 tests, we could push the inc/dec
+; through the min/max, but we should not break up the
+; min/max idiom by using 
diff erent icmp and select
+; operands.
+
+define i32 @increment_max(i32 %x) {
+; CHECK-LABEL: @increment_max(
+; CHECK-NEXT:    [[A:%.*]] = add nsw i32 [[X:%.*]], 1
+; CHECK-NEXT:    [[C_INV:%.*]] = icmp slt i32 [[X]], 0
+; CHECK-NEXT:    [[S:%.*]] = select i1 [[C_INV]], i32 0, i32 [[A]]
+; CHECK-NEXT:    ret i32 [[S]]
+;
+  %a = add nsw i32 %x, 1
+  %c = icmp sgt i32 %a, 0
+  %s = select i1 %c, i32 %a, i32 0
+  ret i32 %s
+}
+
+define i32 @decrement_max(i32 %x) {
+; CHECK-LABEL: @decrement_max(
+; CHECK-NEXT:    [[TMP1:%.*]] = icmp sgt i32 [[X:%.*]], 1
+; CHECK-NEXT:    [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 1
+; CHECK-NEXT:    [[S:%.*]] = add nsw i32 [[TMP2]], -1
+; CHECK-NEXT:    ret i32 [[S]]
+;
+  %a = add nsw i32 %x, -1
+  %c = icmp sgt i32 %a, 0
+  %s = select i1 %c, i32 %a, i32 0
+  ret i32 %s
+}
+
+define i32 @increment_min(i32 %x) {
+; CHECK-LABEL: @increment_min(
+; CHECK-NEXT:    [[TMP1:%.*]] = icmp slt i32 [[X:%.*]], -1
+; CHECK-NEXT:    [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 -1
+; CHECK-NEXT:    [[S:%.*]] = add nsw i32 [[TMP2]], 1
+; CHECK-NEXT:    ret i32 [[S]]
+;
+  %a = add nsw i32 %x, 1
+  %c = icmp slt i32 %a, 0
+  %s = select i1 %c, i32 %a, i32 0
+  ret i32 %s
+}
+
+define i32 @decrement_min(i32 %x) {
+; CHECK-LABEL: @decrement_min(
+; CHECK-NEXT:    [[A:%.*]] = add nsw i32 [[X:%.*]], -1
+; CHECK-NEXT:    [[C_INV:%.*]] = icmp sgt i32 [[X]], 0
+; CHECK-NEXT:    [[S:%.*]] = select i1 [[C_INV]], i32 0, i32 [[A]]
+; CHECK-NEXT:    ret i32 [[S]]
+;
+  %a = add nsw i32 %x, -1
+  %c = icmp slt i32 %a, 0
+  %s = select i1 %c, i32 %a, i32 0
+  ret i32 %s
+}


        


More information about the llvm-commits mailing list