[llvm] d64d577 - Add InstSimplify tests for comparisons between known constants

Matt Devereau via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 15 01:57:05 PST 2023


Author: Matt Devereau
Date: 2023-02-15T09:56:02Z
New Revision: d64d5772b1ea85b6b382ca777b7e2f75ac8e50ac

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

LOG: Add InstSimplify tests for comparisons between known constants

Added: 
    

Modified: 
    llvm/test/Transforms/InstSimplify/compare.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstSimplify/compare.ll b/llvm/test/Transforms/InstSimplify/compare.ll
index 7432804f747c..c0e51f15d18e 100644
--- a/llvm/test/Transforms/InstSimplify/compare.ll
+++ b/llvm/test/Transforms/InstSimplify/compare.ll
@@ -2812,6 +2812,170 @@ define i1 @neg_global_alias() {
   ret i1 %res
 }
 
+
+define i1 @icmp_lshr_known_non_zero_ult_true(i8 %x) {
+; CHECK-LABEL: @icmp_lshr_known_non_zero_ult_true(
+; CHECK-NEXT:    [[OR:%.*]] = or i8 [[X:%.*]], 1
+; CHECK-NEXT:    [[X1:%.*]] = shl nuw i8 [[OR]], 1
+; CHECK-NEXT:    [[X2:%.*]] = shl nuw i8 [[OR]], 2
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ult i8 [[X1]], [[X2]]
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %or = or i8 %x, 1
+  %x1 = shl nuw i8 %or, 1
+  %x2 = shl nuw i8 %or, 2
+  %cmp = icmp ult i8 %x1, %x2
+  ret i1 %cmp
+}
+
+define i1 @icmp_lshr_known_non_zero_ult_false(i8 %x) {
+; CHECK-LABEL: @icmp_lshr_known_non_zero_ult_false(
+; CHECK-NEXT:    [[OR:%.*]] = or i8 [[X:%.*]], 1
+; CHECK-NEXT:    [[X1:%.*]] = shl nuw i8 [[OR]], 1
+; CHECK-NEXT:    [[X2:%.*]] = shl nuw i8 [[OR]], 2
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt i8 [[X1]], [[X2]]
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %or = or i8 %x, 1
+  %x1 = shl nuw i8 %or, 1
+  %x2 = shl nuw i8 %or, 2
+  %cmp = icmp ugt i8 %x1, %x2
+  ret i1 %cmp
+}
+
+define i1 @icmp_lshr_known_non_zero_slt_true(i8 %x) {
+; CHECK-LABEL: @icmp_lshr_known_non_zero_slt_true(
+; CHECK-NEXT:    [[OR:%.*]] = or i8 [[X:%.*]], 1
+; CHECK-NEXT:    [[X1:%.*]] = shl nuw nsw i8 [[OR]], 1
+; CHECK-NEXT:    [[X2:%.*]] = shl nuw nsw i8 [[OR]], 2
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i8 [[X1]], [[X2]]
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %or = or i8 %x, 1
+  %x1 = shl nuw nsw i8 %or, 1
+  %x2 = shl nuw nsw i8 %or, 2
+  %cmp = icmp slt i8 %x1, %x2
+  ret i1 %cmp
+}
+
+define i1 @icmp_lshr_known_non_zero_slt_false(i8 %x) {
+; CHECK-LABEL: @icmp_lshr_known_non_zero_slt_false(
+; CHECK-NEXT:    [[OR:%.*]] = or i8 [[X:%.*]], 1
+; CHECK-NEXT:    [[X1:%.*]] = shl nuw nsw i8 [[OR]], 2
+; CHECK-NEXT:    [[X2:%.*]] = shl nuw nsw i8 [[OR]], 1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i8 [[X1]], [[X2]]
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %or = or i8 %x, 1
+  %x1 = shl nuw nsw i8 %or, 2
+  %x2 = shl nuw nsw i8 %or, 1
+  %cmp = icmp slt i8 %x1, %x2
+  ret i1 %cmp
+}
+
+define i1 @neg_icmp_lshr_known_non_zero_slt_no_nsw(i8 %x) {
+; CHECK-LABEL: @neg_icmp_lshr_known_non_zero_slt_no_nsw(
+; CHECK-NEXT:    [[OR:%.*]] = or i8 [[X:%.*]], 1
+; CHECK-NEXT:    [[X1:%.*]] = shl nuw i8 [[OR]], 1
+; CHECK-NEXT:    [[X2:%.*]] = shl nuw i8 [[OR]], 2
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i8 [[X1]], [[X2]]
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %or = or i8 %x, 1
+  %x1 = shl nuw i8 %or, 1
+  %x2 = shl nuw i8 %or, 2
+  %cmp = icmp slt i8 %x1, %x2
+  ret i1 %cmp
+}
+
+define i1 @neg_icmp_lshr_known_non_zero_slt_no_nuw(i8 %x) {
+; CHECK-LABEL: @neg_icmp_lshr_known_non_zero_slt_no_nuw(
+; CHECK-NEXT:    [[OR:%.*]] = or i8 [[X:%.*]], 1
+; CHECK-NEXT:    [[X1:%.*]] = shl nsw i8 [[OR]], 1
+; CHECK-NEXT:    [[X2:%.*]] = shl nsw i8 [[OR]], 2
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i8 [[X1]], [[X2]]
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %or = or i8 %x, 1
+  %x1 = shl nsw i8 %or, 1
+  %x2 = shl nsw i8 %or, 2
+  %cmp = icmp slt i8 %x1, %x2
+  ret i1 %cmp
+}
+
+define i1 @neg_icmp_lshr_unknown_value(i8 %x) {
+; CHECK-LABEL: @neg_icmp_lshr_unknown_value(
+; CHECK-NEXT:    [[X1:%.*]] = shl nuw i8 [[X:%.*]], 2
+; CHECK-NEXT:    [[X2:%.*]] = shl nuw i8 [[X]], 1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt i8 [[X1]], [[X2]]
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %x1 = shl nuw i8 %x, 2
+  %x2 = shl nuw i8 %x, 1
+  %cmp = icmp ugt i8 %x1, %x2
+  ret i1 %cmp
+}
+
+define i1 @neg_icmp_lshr_unknown_shift(i8 %x, i8 %C1) {
+; CHECK-LABEL: @neg_icmp_lshr_unknown_shift(
+; CHECK-NEXT:    [[OR:%.*]] = or i8 [[X:%.*]], 1
+; CHECK-NEXT:    [[X1:%.*]] = shl nuw i8 [[OR]], 2
+; CHECK-NEXT:    [[X2:%.*]] = shl nuw i8 [[OR]], [[C1:%.*]]
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt i8 [[X1]], [[X2]]
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %or = or i8 %x, 1
+  %x1 = shl nuw i8 %or, 2
+  %x2 = shl nuw i8 %or, %C1
+  %cmp = icmp ugt i8 %x1, %x2
+  ret i1 %cmp
+}
+
+define i1 @neg_icmp_lshr_
diff erent_shift_values(i8 %x, i8 %y) {
+; CHECK-LABEL: @neg_icmp_lshr_
diff erent_shift_values(
+; CHECK-NEXT:    [[X1:%.*]] = shl nuw nsw i8 [[X:%.*]], 1
+; CHECK-NEXT:    [[X2:%.*]] = shl nuw nsw i8 [[Y:%.*]], 2
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ult i8 [[X1]], [[X2]]
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %x1 = shl nuw nsw i8 %x, 1
+  %x2 = shl nuw nsw i8 %y, 2
+  %cmp = icmp ult i8 %x1, %x2
+  ret i1 %cmp
+}
+
+define i1 @icmp_ult_vscale_true(i8 %x, i8 %y) {
+; CHECK-LABEL: @icmp_ult_vscale_true(
+; CHECK-NEXT:    [[VSCALE:%.*]] = call i64 @llvm.vscale.i64()
+; CHECK-NEXT:    [[X1:%.*]] = shl nuw nsw i64 [[VSCALE]], 1
+; CHECK-NEXT:    [[X2:%.*]] = shl nuw nsw i64 [[VSCALE]], 2
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ult i64 [[X1]], [[X2]]
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %vscale = call i64 @llvm.vscale.i64()
+  %x1 = shl nuw nsw i64 %vscale, 1
+  %x2 = shl nuw nsw i64 %vscale, 2
+  %cmp = icmp ult i64 %x1, %x2
+  ret i1 %cmp
+}
+
+define i1 @icmp_ult_vscale_false(i8 %x, i8 %y) {
+; CHECK-LABEL: @icmp_ult_vscale_false(
+; CHECK-NEXT:    [[VSCALE:%.*]] = call i64 @llvm.vscale.i64()
+; CHECK-NEXT:    [[X1:%.*]] = shl nuw nsw i64 [[VSCALE]], 1
+; CHECK-NEXT:    [[X2:%.*]] = shl nuw nsw i64 [[VSCALE]], 2
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt i64 [[X1]], [[X2]]
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %vscale = call i64 @llvm.vscale.i64()
+  %x1 = shl nuw nsw i64 %vscale, 1
+  %x2 = shl nuw nsw i64 %vscale, 2
+  %cmp = icmp ugt i64 %x1, %x2
+  ret i1 %cmp
+}
+
+declare i64 @llvm.vscale.i64()
+
 ; TODO: Add coverage for global aliases, link once, etc..
 
 


        


More information about the llvm-commits mailing list