[InstCombine] add tests for low-mask of ashr; NFC

This commit is contained in:
Sanjay Patel 2022-04-11 10:48:47 -04:00
parent 1ddc719680
commit 141892d481
1 changed files with 72 additions and 8 deletions

View File

@ -390,17 +390,81 @@ define i8 @test27(i8 %A) {
ret i8 %E
}
;; This is just a zero-extending shr.
define i32 @test28(i32 %X) {
; CHECK-LABEL: @test28(
;; No demand for extra sign bits.
define i32 @ashr_lowmask(i32 %x) {
; CHECK-LABEL: @ashr_lowmask(
; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 24
; CHECK-NEXT: ret i32 [[TMP1]]
;
;; Sign extend
%Y = ashr i32 %X, 24
;; Mask out sign bits
%Z = and i32 %Y, 255
ret i32 %Z
%a = ashr i32 %x, 24
%r = and i32 %a, 255
ret i32 %r
}
define i32 @ashr_lowmask_use(i32 %x) {
; CHECK-LABEL: @ashr_lowmask_use(
; CHECK-NEXT: [[A:%.*]] = ashr i32 [[X:%.*]], 1
; CHECK-NEXT: call void @use32(i32 [[A]])
; CHECK-NEXT: [[R:%.*]] = and i32 [[A]], 2147483647
; CHECK-NEXT: ret i32 [[R]]
;
%a = ashr i32 %x, 1
call void @use32(i32 %a)
%r = and i32 %a, 2147483647
ret i32 %r
}
define <2 x i8> @ashr_lowmask_use_splat(<2 x i8> %x, <2 x i8>* %p) {
; CHECK-LABEL: @ashr_lowmask_use_splat(
; CHECK-NEXT: [[A:%.*]] = ashr <2 x i8> [[X:%.*]], <i8 7, i8 7>
; CHECK-NEXT: store <2 x i8> [[A]], <2 x i8>* [[P:%.*]], align 2
; CHECK-NEXT: [[R:%.*]] = and <2 x i8> [[A]], <i8 1, i8 1>
; CHECK-NEXT: ret <2 x i8> [[R]]
;
%a = ashr <2 x i8> %x, <i8 7, i8 7>
store <2 x i8> %a, <2 x i8>* %p
%r = and <2 x i8> %a, <i8 1, i8 1>
ret <2 x i8> %r
}
define i32 @ashr_not_lowmask1_use(i32 %x) {
; CHECK-LABEL: @ashr_not_lowmask1_use(
; CHECK-NEXT: [[A:%.*]] = ashr i32 [[X:%.*]], 24
; CHECK-NEXT: call void @use32(i32 [[A]])
; CHECK-NEXT: [[R:%.*]] = and i32 [[A]], 254
; CHECK-NEXT: ret i32 [[R]]
;
%a = ashr i32 %x, 24
call void @use32(i32 %a)
%r = and i32 %a, 254
ret i32 %r
}
define i32 @ashr_not_lowmask2_use(i32 %x) {
; CHECK-LABEL: @ashr_not_lowmask2_use(
; CHECK-NEXT: [[A:%.*]] = ashr i32 [[X:%.*]], 24
; CHECK-NEXT: call void @use32(i32 [[A]])
; CHECK-NEXT: [[R:%.*]] = and i32 [[A]], 127
; CHECK-NEXT: ret i32 [[R]]
;
%a = ashr i32 %x, 24
call void @use32(i32 %a)
%r = and i32 %a, 127
ret i32 %r
}
define i32 @ashr_not_lowmask3_use(i32 %x) {
; CHECK-LABEL: @ashr_not_lowmask3_use(
; CHECK-NEXT: [[A:%.*]] = ashr i32 [[X:%.*]], 24
; CHECK-NEXT: call void @use32(i32 [[A]])
; CHECK-NEXT: [[R:%.*]] = and i32 [[A]], 511
; CHECK-NEXT: ret i32 [[R]]
;
%a = ashr i32 %x, 24
call void @use32(i32 %a)
%r = and i32 %a, 511
ret i32 %r
}
define i32 @test29(i8 %X) {