[InstCombine] add tests for mul with low-bit mask operand; NFC

This commit is contained in:
Sanjay Patel 2022-06-02 14:02:11 -04:00
parent 8689463bfb
commit 1882c25f12
1 changed files with 52 additions and 0 deletions

View File

@ -462,6 +462,58 @@ define <2 x i32> @signbit_mul_vec_commute(<2 x i32> %a, <2 x i32> %b) {
ret <2 x i32> %e
}
; (A & 1) * B --> (lowbit A) ? B : 0
define i32 @lowbit_mul(i32 %a, i32 %b) {
; CHECK-LABEL: @lowbit_mul(
; CHECK-NEXT: [[D:%.*]] = and i32 [[A:%.*]], 1
; CHECK-NEXT: [[E:%.*]] = mul nuw i32 [[D]], [[B:%.*]]
; CHECK-NEXT: ret i32 [[E]]
;
%d = and i32 %a, 1
%e = mul i32 %d, %b
ret i32 %e
}
; (A & 1) * B --> (lowbit A) ? B : 0
define <2 x i17> @lowbit_mul_commute(<2 x i17> %a, <2 x i17> %p) {
; CHECK-LABEL: @lowbit_mul_commute(
; CHECK-NEXT: [[B:%.*]] = xor <2 x i17> [[P:%.*]], <i17 42, i17 43>
; CHECK-NEXT: [[D:%.*]] = and <2 x i17> [[A:%.*]], <i17 1, i17 1>
; CHECK-NEXT: [[E:%.*]] = mul nuw <2 x i17> [[B]], [[D]]
; CHECK-NEXT: ret <2 x i17> [[E]]
;
%b = xor <2 x i17> %p, <i17 42, i17 43> ; thwart complexity-based canonicalization
%d = and <2 x i17> %a, <i17 1, i17 1>
%e = mul <2 x i17> %b, %d
ret <2 x i17> %e
}
define i32 @lowbit_mul_use(i32 %a, i32 %b) {
; CHECK-LABEL: @lowbit_mul_use(
; CHECK-NEXT: [[D:%.*]] = and i32 [[A:%.*]], 1
; CHECK-NEXT: call void @use32(i32 [[D]])
; CHECK-NEXT: [[E:%.*]] = mul nuw i32 [[D]], [[B:%.*]]
; CHECK-NEXT: ret i32 [[E]]
;
%d = and i32 %a, 1
call void @use32(i32 %d)
%e = mul i32 %d, %b
ret i32 %e
}
define i32 @not_lowbit_mul(i32 %a, i32 %b) {
; CHECK-LABEL: @not_lowbit_mul(
; CHECK-NEXT: [[D:%.*]] = and i32 [[A:%.*]], 2
; CHECK-NEXT: [[E:%.*]] = mul i32 [[D]], [[B:%.*]]
; CHECK-NEXT: ret i32 [[E]]
;
%d = and i32 %a, 2
%e = mul i32 %d, %b
ret i32 %e
}
define i32 @signsplat_mul(i32 %x) {
; CHECK-LABEL: @signsplat_mul(
; CHECK-NEXT: [[ISNEG:%.*]] = icmp slt i32 [[X:%.*]], 0