Skip to content

Commit 5ea5e3c

Browse files
rotaterighttstellar
authored andcommitted
[InstCombine] add tests for low-mask of ashr; NFC
(cherry picked from commit 141892d)
1 parent fe8a27a commit 5ea5e3c

File tree

1 file changed

+72
-8
lines changed
  • llvm/test/Transforms/InstCombine

1 file changed

+72
-8
lines changed

llvm/test/Transforms/InstCombine/and.ll

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -390,17 +390,81 @@ define i8 @test27(i8 %A) {
390390
ret i8 %E
391391
}
392392

393-
;; This is just a zero-extending shr.
394-
define i32 @test28(i32 %X) {
395-
; CHECK-LABEL: @test28(
393+
;; No demand for extra sign bits.
394+
395+
define i32 @ashr_lowmask(i32 %x) {
396+
; CHECK-LABEL: @ashr_lowmask(
396397
; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 24
397398
; CHECK-NEXT: ret i32 [[TMP1]]
398399
;
399-
;; Sign extend
400-
%Y = ashr i32 %X, 24
401-
;; Mask out sign bits
402-
%Z = and i32 %Y, 255
403-
ret i32 %Z
400+
%a = ashr i32 %x, 24
401+
%r = and i32 %a, 255
402+
ret i32 %r
403+
}
404+
405+
define i32 @ashr_lowmask_use(i32 %x) {
406+
; CHECK-LABEL: @ashr_lowmask_use(
407+
; CHECK-NEXT: [[A:%.*]] = ashr i32 [[X:%.*]], 1
408+
; CHECK-NEXT: call void @use32(i32 [[A]])
409+
; CHECK-NEXT: [[R:%.*]] = and i32 [[A]], 2147483647
410+
; CHECK-NEXT: ret i32 [[R]]
411+
;
412+
%a = ashr i32 %x, 1
413+
call void @use32(i32 %a)
414+
%r = and i32 %a, 2147483647
415+
ret i32 %r
416+
}
417+
418+
define <2 x i8> @ashr_lowmask_use_splat(<2 x i8> %x, <2 x i8>* %p) {
419+
; CHECK-LABEL: @ashr_lowmask_use_splat(
420+
; CHECK-NEXT: [[A:%.*]] = ashr <2 x i8> [[X:%.*]], <i8 7, i8 7>
421+
; CHECK-NEXT: store <2 x i8> [[A]], <2 x i8>* [[P:%.*]], align 2
422+
; CHECK-NEXT: [[R:%.*]] = and <2 x i8> [[A]], <i8 1, i8 1>
423+
; CHECK-NEXT: ret <2 x i8> [[R]]
424+
;
425+
%a = ashr <2 x i8> %x, <i8 7, i8 7>
426+
store <2 x i8> %a, <2 x i8>* %p
427+
%r = and <2 x i8> %a, <i8 1, i8 1>
428+
ret <2 x i8> %r
429+
}
430+
431+
define i32 @ashr_not_lowmask1_use(i32 %x) {
432+
; CHECK-LABEL: @ashr_not_lowmask1_use(
433+
; CHECK-NEXT: [[A:%.*]] = ashr i32 [[X:%.*]], 24
434+
; CHECK-NEXT: call void @use32(i32 [[A]])
435+
; CHECK-NEXT: [[R:%.*]] = and i32 [[A]], 254
436+
; CHECK-NEXT: ret i32 [[R]]
437+
;
438+
%a = ashr i32 %x, 24
439+
call void @use32(i32 %a)
440+
%r = and i32 %a, 254
441+
ret i32 %r
442+
}
443+
444+
define i32 @ashr_not_lowmask2_use(i32 %x) {
445+
; CHECK-LABEL: @ashr_not_lowmask2_use(
446+
; CHECK-NEXT: [[A:%.*]] = ashr i32 [[X:%.*]], 24
447+
; CHECK-NEXT: call void @use32(i32 [[A]])
448+
; CHECK-NEXT: [[R:%.*]] = and i32 [[A]], 127
449+
; CHECK-NEXT: ret i32 [[R]]
450+
;
451+
%a = ashr i32 %x, 24
452+
call void @use32(i32 %a)
453+
%r = and i32 %a, 127
454+
ret i32 %r
455+
}
456+
457+
define i32 @ashr_not_lowmask3_use(i32 %x) {
458+
; CHECK-LABEL: @ashr_not_lowmask3_use(
459+
; CHECK-NEXT: [[A:%.*]] = ashr i32 [[X:%.*]], 24
460+
; CHECK-NEXT: call void @use32(i32 [[A]])
461+
; CHECK-NEXT: [[R:%.*]] = and i32 [[A]], 511
462+
; CHECK-NEXT: ret i32 [[R]]
463+
;
464+
%a = ashr i32 %x, 24
465+
call void @use32(i32 %a)
466+
%r = and i32 %a, 511
467+
ret i32 %r
404468
}
405469

406470
define i32 @test29(i8 %X) {

0 commit comments

Comments
 (0)