aboutsummaryrefslogtreecommitdiff
path: root/llvm
diff options
context:
space:
mode:
authorNoah Goldstein <goldstein.w.n@gmail.com>2024-03-28 14:23:58 -0500
committerNoah Goldstein <goldstein.w.n@gmail.com>2024-04-04 12:42:58 -0500
commit02b49d14a50cbfad0196cdddba6771f0593fdc3b (patch)
tree563f72c72d75c1daff0e429bb3a23f9f6db7ead6 /llvm
parent220cdf940e953002df1521bbd061d8e0b4ffed5c (diff)
downloadllvm-02b49d14a50cbfad0196cdddba6771f0593fdc3b.zip
llvm-02b49d14a50cbfad0196cdddba6771f0593fdc3b.tar.gz
llvm-02b49d14a50cbfad0196cdddba6771f0593fdc3b.tar.bz2
[ValueTracking] Add tests for computing known bits from `(icmp eq (and/or x,y), C)`; NFC
Diffstat (limited to 'llvm')
-rw-r--r--llvm/test/Transforms/InstCombine/known-bits.ll110
1 files changed, 105 insertions, 5 deletions
diff --git a/llvm/test/Transforms/InstCombine/known-bits.ll b/llvm/test/Transforms/InstCombine/known-bits.ll
index 5305c78..af3db82 100644
--- a/llvm/test/Transforms/InstCombine/known-bits.ll
+++ b/llvm/test/Transforms/InstCombine/known-bits.ll
@@ -124,7 +124,6 @@ exit:
ret i8 %or2
}
-
define i8 @test_cond_and_bothways(i8 %x) {
; CHECK-LABEL: @test_cond_and_bothways(
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], 91
@@ -181,8 +180,6 @@ exit:
ret i8 %or2
}
-
-
define i8 @test_cond_and_commuted(i8 %x, i1 %c1, i1 %c2) {
; CHECK-LABEL: @test_cond_and_commuted(
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], 3
@@ -343,7 +340,7 @@ exit:
ret i8 %or2
}
-define i32 @test_icmp_trunc1(i32 %x){
+define i32 @test_icmp_trunc1(i32 %x) {
; CHECK-LABEL: @test_icmp_trunc1(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[Y:%.*]] = trunc i32 [[X:%.*]] to i16
@@ -365,7 +362,7 @@ else:
ret i32 0
}
-define i32 @test_icmp_trunc_assume(i32 %x){
+define i32 @test_icmp_trunc_assume(i32 %x) {
; CHECK-LABEL: @test_icmp_trunc_assume(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[Y:%.*]] = trunc i32 [[X:%.*]] to i16
@@ -532,7 +529,110 @@ if.else:
ret i1 %other
}
+define i8 @and_eq_bits_must_be_set(i8 %x, i8 %y) {
+; CHECK-LABEL: @and_eq_bits_must_be_set(
+; CHECK-NEXT: [[XY:%.*]] = and i8 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[XY]], 123
+; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
+; CHECK-NEXT: [[R:%.*]] = and i8 [[X]], 1
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %xy = and i8 %x, %y
+ %cmp = icmp eq i8 %xy, 123
+ call void @llvm.assume(i1 %cmp)
+ %r = and i8 %x, 1
+ ret i8 %r
+}
+
+define i8 @and_eq_bits_must_be_set2(i8 %x, i8 %y) {
+; CHECK-LABEL: @and_eq_bits_must_be_set2(
+; CHECK-NEXT: [[XY:%.*]] = and i8 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[XY]], 123
+; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
+; CHECK-NEXT: [[R:%.*]] = and i8 [[Y]], 11
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %xy = and i8 %x, %y
+ %cmp = icmp eq i8 %xy, 123
+ call void @llvm.assume(i1 %cmp)
+ %r = and i8 %y, 11
+ ret i8 %r
+}
+
+define i8 @and_eq_bits_must_be_set2_partial_fail(i8 %x, i8 %y) {
+; CHECK-LABEL: @and_eq_bits_must_be_set2_partial_fail(
+; CHECK-NEXT: [[XY:%.*]] = and i8 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[XY]], 123
+; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
+; CHECK-NEXT: [[R:%.*]] = and i8 [[Y]], 111
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %xy = and i8 %x, %y
+ %cmp = icmp eq i8 %xy, 123
+ call void @llvm.assume(i1 %cmp)
+ %r = and i8 %y, 111
+ ret i8 %r
+}
+
+define i8 @or_eq_bits_must_be_unset(i8 %x, i8 %y) {
+; CHECK-LABEL: @or_eq_bits_must_be_unset(
+; CHECK-NEXT: [[XY:%.*]] = or i8 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[XY]], 124
+; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
+; CHECK-NEXT: [[R:%.*]] = and i8 [[X]], 3
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %xy = or i8 %x, %y
+ %cmp = icmp eq i8 %xy, 124
+ call void @llvm.assume(i1 %cmp)
+ %r = and i8 %x, 3
+ ret i8 %r
+}
+
+define i8 @or_eq_bits_must_be_unset2(i8 %x, i8 %y) {
+; CHECK-LABEL: @or_eq_bits_must_be_unset2(
+; CHECK-NEXT: [[XY:%.*]] = or i8 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[XY]], 124
+; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
+; CHECK-NEXT: [[R:%.*]] = and i8 [[Y]], 1
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %xy = or i8 %x, %y
+ %cmp = icmp eq i8 %xy, 124
+ call void @llvm.assume(i1 %cmp)
+ %r = and i8 %y, 1
+ ret i8 %r
+}
+define i8 @or_eq_bits_must_be_unset2_partial_fail(i8 %x, i8 %y) {
+; CHECK-LABEL: @or_eq_bits_must_be_unset2_partial_fail(
+; CHECK-NEXT: [[XY:%.*]] = or i8 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[XY]], 124
+; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
+; CHECK-NEXT: [[R:%.*]] = and i8 [[Y]], 7
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %xy = or i8 %x, %y
+ %cmp = icmp eq i8 %xy, 124
+ call void @llvm.assume(i1 %cmp)
+ %r = and i8 %y, 7
+ ret i8 %r
+}
+
+define i8 @or_ne_bits_must_be_unset2_fail(i8 %x, i8 %y) {
+; CHECK-LABEL: @or_ne_bits_must_be_unset2_fail(
+; CHECK-NEXT: [[XY:%.*]] = or i8 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[XY]], 124
+; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
+; CHECK-NEXT: [[R:%.*]] = and i8 [[X]], 3
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %xy = or i8 %x, %y
+ %cmp = icmp ne i8 %xy, 124
+ call void @llvm.assume(i1 %cmp)
+ %r = and i8 %x, 3
+ ret i8 %r
+}
declare void @use(i1)
declare void @sink(i8)