Skip to content

Commit 02b49d1

Browse files
committed
[ValueTracking] Add tests for computing known bits from (icmp eq (and/or x,y), C); NFC
1 parent 220cdf9 commit 02b49d1

File tree

1 file changed

+105
-5
lines changed

1 file changed

+105
-5
lines changed

llvm/test/Transforms/InstCombine/known-bits.ll

Lines changed: 105 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ exit:
124124
ret i8 %or2
125125
}
126126

127-
128127
define i8 @test_cond_and_bothways(i8 %x) {
129128
; CHECK-LABEL: @test_cond_and_bothways(
130129
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], 91
@@ -181,8 +180,6 @@ exit:
181180
ret i8 %or2
182181
}
183182

184-
185-
186183
define i8 @test_cond_and_commuted(i8 %x, i1 %c1, i1 %c2) {
187184
; CHECK-LABEL: @test_cond_and_commuted(
188185
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], 3
@@ -343,7 +340,7 @@ exit:
343340
ret i8 %or2
344341
}
345342

346-
define i32 @test_icmp_trunc1(i32 %x){
343+
define i32 @test_icmp_trunc1(i32 %x) {
347344
; CHECK-LABEL: @test_icmp_trunc1(
348345
; CHECK-NEXT: entry:
349346
; CHECK-NEXT: [[Y:%.*]] = trunc i32 [[X:%.*]] to i16
@@ -365,7 +362,7 @@ else:
365362
ret i32 0
366363
}
367364

368-
define i32 @test_icmp_trunc_assume(i32 %x){
365+
define i32 @test_icmp_trunc_assume(i32 %x) {
369366
; CHECK-LABEL: @test_icmp_trunc_assume(
370367
; CHECK-NEXT: entry:
371368
; CHECK-NEXT: [[Y:%.*]] = trunc i32 [[X:%.*]] to i16
@@ -532,7 +529,110 @@ if.else:
532529
ret i1 %other
533530
}
534531

532+
define i8 @and_eq_bits_must_be_set(i8 %x, i8 %y) {
533+
; CHECK-LABEL: @and_eq_bits_must_be_set(
534+
; CHECK-NEXT: [[XY:%.*]] = and i8 [[X:%.*]], [[Y:%.*]]
535+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[XY]], 123
536+
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
537+
; CHECK-NEXT: [[R:%.*]] = and i8 [[X]], 1
538+
; CHECK-NEXT: ret i8 [[R]]
539+
;
540+
%xy = and i8 %x, %y
541+
%cmp = icmp eq i8 %xy, 123
542+
call void @llvm.assume(i1 %cmp)
543+
%r = and i8 %x, 1
544+
ret i8 %r
545+
}
546+
547+
define i8 @and_eq_bits_must_be_set2(i8 %x, i8 %y) {
548+
; CHECK-LABEL: @and_eq_bits_must_be_set2(
549+
; CHECK-NEXT: [[XY:%.*]] = and i8 [[X:%.*]], [[Y:%.*]]
550+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[XY]], 123
551+
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
552+
; CHECK-NEXT: [[R:%.*]] = and i8 [[Y]], 11
553+
; CHECK-NEXT: ret i8 [[R]]
554+
;
555+
%xy = and i8 %x, %y
556+
%cmp = icmp eq i8 %xy, 123
557+
call void @llvm.assume(i1 %cmp)
558+
%r = and i8 %y, 11
559+
ret i8 %r
560+
}
561+
562+
define i8 @and_eq_bits_must_be_set2_partial_fail(i8 %x, i8 %y) {
563+
; CHECK-LABEL: @and_eq_bits_must_be_set2_partial_fail(
564+
; CHECK-NEXT: [[XY:%.*]] = and i8 [[X:%.*]], [[Y:%.*]]
565+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[XY]], 123
566+
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
567+
; CHECK-NEXT: [[R:%.*]] = and i8 [[Y]], 111
568+
; CHECK-NEXT: ret i8 [[R]]
569+
;
570+
%xy = and i8 %x, %y
571+
%cmp = icmp eq i8 %xy, 123
572+
call void @llvm.assume(i1 %cmp)
573+
%r = and i8 %y, 111
574+
ret i8 %r
575+
}
576+
577+
define i8 @or_eq_bits_must_be_unset(i8 %x, i8 %y) {
578+
; CHECK-LABEL: @or_eq_bits_must_be_unset(
579+
; CHECK-NEXT: [[XY:%.*]] = or i8 [[X:%.*]], [[Y:%.*]]
580+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[XY]], 124
581+
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
582+
; CHECK-NEXT: [[R:%.*]] = and i8 [[X]], 3
583+
; CHECK-NEXT: ret i8 [[R]]
584+
;
585+
%xy = or i8 %x, %y
586+
%cmp = icmp eq i8 %xy, 124
587+
call void @llvm.assume(i1 %cmp)
588+
%r = and i8 %x, 3
589+
ret i8 %r
590+
}
591+
592+
define i8 @or_eq_bits_must_be_unset2(i8 %x, i8 %y) {
593+
; CHECK-LABEL: @or_eq_bits_must_be_unset2(
594+
; CHECK-NEXT: [[XY:%.*]] = or i8 [[X:%.*]], [[Y:%.*]]
595+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[XY]], 124
596+
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
597+
; CHECK-NEXT: [[R:%.*]] = and i8 [[Y]], 1
598+
; CHECK-NEXT: ret i8 [[R]]
599+
;
600+
%xy = or i8 %x, %y
601+
%cmp = icmp eq i8 %xy, 124
602+
call void @llvm.assume(i1 %cmp)
603+
%r = and i8 %y, 1
604+
ret i8 %r
605+
}
535606

607+
define i8 @or_eq_bits_must_be_unset2_partial_fail(i8 %x, i8 %y) {
608+
; CHECK-LABEL: @or_eq_bits_must_be_unset2_partial_fail(
609+
; CHECK-NEXT: [[XY:%.*]] = or i8 [[X:%.*]], [[Y:%.*]]
610+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[XY]], 124
611+
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
612+
; CHECK-NEXT: [[R:%.*]] = and i8 [[Y]], 7
613+
; CHECK-NEXT: ret i8 [[R]]
614+
;
615+
%xy = or i8 %x, %y
616+
%cmp = icmp eq i8 %xy, 124
617+
call void @llvm.assume(i1 %cmp)
618+
%r = and i8 %y, 7
619+
ret i8 %r
620+
}
621+
622+
define i8 @or_ne_bits_must_be_unset2_fail(i8 %x, i8 %y) {
623+
; CHECK-LABEL: @or_ne_bits_must_be_unset2_fail(
624+
; CHECK-NEXT: [[XY:%.*]] = or i8 [[X:%.*]], [[Y:%.*]]
625+
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[XY]], 124
626+
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
627+
; CHECK-NEXT: [[R:%.*]] = and i8 [[X]], 3
628+
; CHECK-NEXT: ret i8 [[R]]
629+
;
630+
%xy = or i8 %x, %y
631+
%cmp = icmp ne i8 %xy, 124
632+
call void @llvm.assume(i1 %cmp)
633+
%r = and i8 %x, 3
634+
ret i8 %r
635+
}
536636

537637
declare void @use(i1)
538638
declare void @sink(i8)

0 commit comments

Comments
 (0)