Skip to content

Commit eecaa86

Browse files
committed
[InstCombine] add tests for multi-use sub demanded bits: NFC
1 parent 782b987 commit eecaa86

File tree

1 file changed

+49
-0
lines changed
  • llvm/test/Transforms/InstCombine

1 file changed

+49
-0
lines changed

llvm/test/Transforms/InstCombine/sub.ll

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,3 +2068,52 @@ define i8 @mul_sub_common_factor_use(i8 %x, i8 %y) {
20682068
%a = sub i8 %m, %x
20692069
ret i8 %a
20702070
}
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

Comments
 (0)