@@ -2068,3 +2068,52 @@ define i8 @mul_sub_common_factor_use(i8 %x, i8 %y) {
2068
2068
%a = sub i8 %m , %x
2069
2069
ret i8 %a
2070
2070
}
2071
+
2072
+ define i5 @demand_low_bits_uses (i8 %x , i8 %y ) {
2073
+ ; CHECK-LABEL: @demand_low_bits_uses(
2074
+ ; CHECK-NEXT: [[M:%.*]] = and i8 [[X:%.*]], 96
2075
+ ; CHECK-NEXT: [[A:%.*]] = sub i8 [[Y:%.*]], [[M]]
2076
+ ; CHECK-NEXT: call void @use8(i8 [[A]])
2077
+ ; CHECK-NEXT: [[R:%.*]] = trunc i8 [[A]] to i5
2078
+ ; CHECK-NEXT: ret i5 [[R]]
2079
+ ;
2080
+ %m = and i8 %x , 96 ; 0x60
2081
+ %a = sub i8 %y , %m
2082
+ call void @use8 (i8 %a )
2083
+ %r = trunc i8 %a to i5
2084
+ ret i5 %r
2085
+ }
2086
+
2087
+ ; negative test - demands one more bit
2088
+
2089
+ define i6 @demand_low_bits_uses_extra_bit (i8 %x , i8 %y ) {
2090
+ ; CHECK-LABEL: @demand_low_bits_uses_extra_bit(
2091
+ ; CHECK-NEXT: [[M:%.*]] = and i8 [[X:%.*]], 96
2092
+ ; CHECK-NEXT: [[A:%.*]] = sub i8 [[Y:%.*]], [[M]]
2093
+ ; CHECK-NEXT: call void @use8(i8 [[A]])
2094
+ ; CHECK-NEXT: [[R:%.*]] = trunc i8 [[A]] to i6
2095
+ ; CHECK-NEXT: ret i6 [[R]]
2096
+ ;
2097
+ %m = and i8 %x , 96 ; 0x60
2098
+ %a = sub i8 %y , %m
2099
+ call void @use8 (i8 %a )
2100
+ %r = trunc i8 %a to i6
2101
+ ret i6 %r
2102
+ }
2103
+
2104
+ define i8 @demand_low_bits_uses_commute (i8 %x , i8 %y , i8 %z ) {
2105
+ ; CHECK-LABEL: @demand_low_bits_uses_commute(
2106
+ ; CHECK-NEXT: [[M:%.*]] = and i8 [[X:%.*]], -64
2107
+ ; CHECK-NEXT: [[A:%.*]] = sub i8 [[M]], [[Y:%.*]]
2108
+ ; CHECK-NEXT: call void @use8(i8 [[A]])
2109
+ ; CHECK-NEXT: [[S:%.*]] = sub i8 [[A]], [[Z:%.*]]
2110
+ ; CHECK-NEXT: [[R:%.*]] = shl i8 [[S]], 2
2111
+ ; CHECK-NEXT: ret i8 [[R]]
2112
+ ;
2113
+ %m = and i8 %x , -64 ; 0xC0
2114
+ %a = sub i8 %m , %y
2115
+ call void @use8 (i8 %a )
2116
+ %s = sub i8 %a , %z
2117
+ %r = shl i8 %s , 2
2118
+ ret i8 %r
2119
+ }
0 commit comments