[llvm] db34a94 - [ConstraintElim] Add tests for shl nsw decomposition (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 4 06:13:21 PST 2024


Author: Nikita Popov
Date: 2024-01-04T15:13:10+01:00
New Revision: db34a94710bc93970b5a873b1eef5c7ae2a3e046

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

LOG: [ConstraintElim] Add tests for shl nsw decomposition (NFC)

Added: 
    

Modified: 
    llvm/test/Transforms/ConstraintElimination/shl.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/ConstraintElimination/shl.ll b/llvm/test/Transforms/ConstraintElimination/shl.ll
index 9fe8c147017b09..8a00eb9b2830ba 100644
--- a/llvm/test/Transforms/ConstraintElimination/shl.ll
+++ b/llvm/test/Transforms/ConstraintElimination/shl.ll
@@ -1274,3 +1274,90 @@ entry:
   %shl.cmp = icmp uge i256 %shl.ub, 1
   ret i1 %shl.cmp
 }
+
+define i1 @shl_nsw_x8_slt_x7(i8 %start, i8 %high) {
+; CHECK-LABEL: @shl_nsw_x8_slt_x7(
+; CHECK-NEXT:    [[C_0:%.*]] = icmp sge i8 [[HIGH:%.*]], 0
+; CHECK-NEXT:    call void @llvm.assume(i1 [[C_0]])
+; CHECK-NEXT:    [[START_SHL_3:%.*]] = shl nsw i8 [[START:%.*]], 3
+; CHECK-NEXT:    [[C_1:%.*]] = icmp slt i8 [[START_SHL_3]], [[HIGH]]
+; CHECK-NEXT:    call void @llvm.assume(i1 [[C_1]])
+; CHECK-NEXT:    [[START_MUL_7:%.*]] = mul nsw i8 [[START]], 7
+; CHECK-NEXT:    [[T_1:%.*]] = icmp slt i8 [[START_MUL_7]], [[HIGH]]
+; CHECK-NEXT:    ret i1 [[T_1]]
+;
+  %c.0 = icmp sge i8 %high, 0
+  call void @llvm.assume(i1 %c.0)
+
+  %start.shl.3 = shl nsw i8 %start, 3
+  %c.1 = icmp slt i8 %start.shl.3, %high
+  call void @llvm.assume(i1 %c.1)
+
+  %start.mul.7 = mul nsw i8 %start, 7
+  %t.1 = icmp slt i8 %start.mul.7, %high
+  ret i1 %t.1
+}
+
+define i1 @shl_nsw_x8_not_slt_x9(i8 %start, i8 %high) {
+; CHECK-LABEL: @shl_nsw_x8_not_slt_x9(
+; CHECK-NEXT:    [[C_0:%.*]] = icmp sge i8 [[HIGH:%.*]], 0
+; CHECK-NEXT:    call void @llvm.assume(i1 [[C_0]])
+; CHECK-NEXT:    [[START_SHL_3:%.*]] = shl nsw i8 [[START:%.*]], 3
+; CHECK-NEXT:    [[C_1:%.*]] = icmp slt i8 [[START_SHL_3]], [[HIGH]]
+; CHECK-NEXT:    call void @llvm.assume(i1 [[C_1]])
+; CHECK-NEXT:    [[START_MUL_9:%.*]] = mul nsw i8 [[START]], 9
+; CHECK-NEXT:    [[T_1:%.*]] = icmp slt i8 [[START_MUL_9]], [[HIGH]]
+; CHECK-NEXT:    ret i1 [[T_1]]
+;
+  %c.0 = icmp sge i8 %high, 0
+  call void @llvm.assume(i1 %c.0)
+
+  %start.shl.3 = shl nsw i8 %start, 3
+  %c.1 = icmp slt i8 %start.shl.3, %high
+  call void @llvm.assume(i1 %c.1)
+
+  %start.mul.9 = mul nsw i8 %start, 9
+  %t.1 = icmp slt i8 %start.mul.9, %high
+  ret i1 %t.1
+}
+
+define i1 @shl_nsw_sign_implication(i8 %x) {
+; CHECK-LABEL: @shl_nsw_sign_implication(
+; CHECK-NEXT:    [[SHL:%.*]] = shl nsw i8 [[X:%.*]], 2
+; CHECK-NEXT:    [[CMP1:%.*]] = icmp slt i8 [[X]], 0
+; CHECK-NEXT:    br i1 [[CMP1]], label [[IF:%.*]], label [[ELSE:%.*]]
+; CHECK:       if:
+; CHECK-NEXT:    [[CMP2:%.*]] = icmp slt i8 [[SHL]], 0
+; CHECK-NEXT:    ret i1 [[CMP2]]
+; CHECK:       else:
+; CHECK-NEXT:    [[CMP3:%.*]] = icmp sge i8 [[SHL]], 0
+; CHECK-NEXT:    ret i1 [[CMP3]]
+;
+  %shl = shl nsw i8 %x, 2
+  %cmp1 = icmp slt i8 %x, 0
+  br i1 %cmp1, label %if, label %else
+
+if:
+  %cmp2 = icmp slt i8 %shl, 0
+  ret i1 %cmp2
+
+else:
+  %cmp3 = icmp sge i8 %shl, 0
+  ret i1 %cmp3
+}
+
+define i1 @shl_nsw_by_bw_minus_1(i64 %x) {
+; CHECK-LABEL: @shl_nsw_by_bw_minus_1(
+; CHECK-NEXT:    [[X_SHL:%.*]] = shl nsw i64 [[X:%.*]], 63
+; CHECK-NEXT:    [[C_1:%.*]] = icmp slt i64 [[X_SHL]], 0
+; CHECK-NEXT:    call void @llvm.assume(i1 [[C_1]])
+; CHECK-NEXT:    [[T_1:%.*]] = icmp slt i64 [[X]], 0
+; CHECK-NEXT:    ret i1 [[T_1]]
+;
+  %x.shl = shl nsw i64 %x, 63
+  %c.1 = icmp slt i64 %x.shl, 0
+  call void @llvm.assume(i1 %c.1)
+
+  %t.1 = icmp slt i64 %x, 0
+  ret i1 %t.1
+}


        


More information about the llvm-commits mailing list