@@ -4666,3 +4666,50 @@ define i8 @test_replace_freeze_oneuse(i1 %x, i8 %y) {
4666
4666
%sel = select i1 %x , i8 0 , i8 %shl.fr
4667
4667
ret i8 %sel
4668
4668
}
4669
+
4670
+ define i8 @select_knownbits_simplify (i8 noundef %x ) {
4671
+ ; CHECK-LABEL: @select_knownbits_simplify(
4672
+ ; CHECK-NEXT: [[X_LO:%.*]] = and i8 [[X:%.*]], 1
4673
+ ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X_LO]], 0
4674
+ ; CHECK-NEXT: [[AND:%.*]] = and i8 [[X]], -2
4675
+ ; CHECK-NEXT: [[RES:%.*]] = select i1 [[CMP]], i8 [[AND]], i8 0
4676
+ ; CHECK-NEXT: ret i8 [[RES]]
4677
+ ;
4678
+ %x.lo = and i8 %x , 1
4679
+ %cmp = icmp eq i8 %x.lo , 0
4680
+ %and = and i8 %x , -2
4681
+ %res = select i1 %cmp , i8 %and , i8 0
4682
+ ret i8 %res
4683
+ }
4684
+
4685
+ define i8 @select_knownbits_simplify_nested (i8 noundef %x ) {
4686
+ ; CHECK-LABEL: @select_knownbits_simplify_nested(
4687
+ ; CHECK-NEXT: [[X_LO:%.*]] = and i8 [[X:%.*]], 1
4688
+ ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X_LO]], 0
4689
+ ; CHECK-NEXT: [[AND:%.*]] = and i8 [[X]], -2
4690
+ ; CHECK-NEXT: [[MUL:%.*]] = mul i8 [[AND]], [[AND]]
4691
+ ; CHECK-NEXT: [[RES:%.*]] = select i1 [[CMP]], i8 [[MUL]], i8 0
4692
+ ; CHECK-NEXT: ret i8 [[RES]]
4693
+ ;
4694
+ %x.lo = and i8 %x , 1
4695
+ %cmp = icmp eq i8 %x.lo , 0
4696
+ %and = and i8 %x , -2
4697
+ %mul = mul i8 %and , %and
4698
+ %res = select i1 %cmp , i8 %mul , i8 0
4699
+ ret i8 %res
4700
+ }
4701
+
4702
+ define i8 @select_knownbits_simplify_missing_noundef (i8 %x ) {
4703
+ ; CHECK-LABEL: @select_knownbits_simplify_missing_noundef(
4704
+ ; CHECK-NEXT: [[X_LO:%.*]] = and i8 [[X:%.*]], 1
4705
+ ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X_LO]], 0
4706
+ ; CHECK-NEXT: [[AND:%.*]] = and i8 [[X]], -2
4707
+ ; CHECK-NEXT: [[RES:%.*]] = select i1 [[CMP]], i8 [[AND]], i8 0
4708
+ ; CHECK-NEXT: ret i8 [[RES]]
4709
+ ;
4710
+ %x.lo = and i8 %x , 1
4711
+ %cmp = icmp eq i8 %x.lo , 0
4712
+ %and = and i8 %x , -2
4713
+ %res = select i1 %cmp , i8 %and , i8 0
4714
+ ret i8 %res
4715
+ }
0 commit comments