Skip to content

Commit

Permalink
[InstCombine] Add more tests for shl+lshr transforms; NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
bcl5980 committed Jun 6, 2022
1 parent 52818fd commit 0cbd5d3
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions llvm/test/Transforms/InstCombine/and.ll
Expand Up @@ -1622,8 +1622,8 @@ define i8 @not_lshr_bitwidth_mask(i8 %x, i8 %y) {
ret i8 %r
}

define i16 @shl_lshr_pow2_const(i16 %x) {
; CHECK-LABEL: @shl_lshr_pow2_const(
define i16 @shl_lshr_pow2_const_case1(i16 %x) {
; CHECK-LABEL: @shl_lshr_pow2_const_case1(
; CHECK-NEXT: [[SHL:%.*]] = shl i16 4, [[X:%.*]]
; CHECK-NEXT: [[LSHR:%.*]] = lshr i16 [[SHL]], 6
; CHECK-NEXT: [[R:%.*]] = and i16 [[LSHR]], 8
Expand All @@ -1635,6 +1635,32 @@ define i16 @shl_lshr_pow2_const(i16 %x) {
ret i16 %r
}

define i16 @shl_lshr_pow2_const_case2(i16 %x) {
; CHECK-LABEL: @shl_lshr_pow2_const_case2(
; CHECK-NEXT: [[SHL:%.*]] = shl i16 4, [[X:%.*]]
; CHECK-NEXT: [[LSHR:%.*]] = lshr i16 [[SHL]], 6
; CHECK-NEXT: [[R:%.*]] = or i16 [[LSHR]], -9
; CHECK-NEXT: ret i16 [[R]]
;
%shl = shl i16 4, %x
%lshr = lshr i16 %shl, 6
%r = or i16 %lshr, 65527 ; ~8
ret i16 %r
}

define i13 @shl_lshr_pow2_const_case3(i16 %x) {
; CHECK-LABEL: @shl_lshr_pow2_const_case3(
; CHECK-NEXT: [[SHL:%.*]] = shl i16 4, [[X:%.*]]
; CHECK-NEXT: [[LSHR:%.*]] = lshr i16 [[SHL]], 6
; CHECK-NEXT: [[R:%.*]] = trunc i16 [[LSHR]] to i13
; CHECK-NEXT: ret i13 [[R]]
;
%shl = shl i16 4, %x
%lshr = lshr i16 %shl, 6
%r = trunc i16 %lshr to i13
ret i13 %r
}

define i16 @shl_lshr_pow2_const_negative_oneuse(i16 %x) {
; CHECK-LABEL: @shl_lshr_pow2_const_negative_oneuse(
; CHECK-NEXT: [[SHL:%.*]] = shl i16 4, [[X:%.*]]
Expand Down

0 comments on commit 0cbd5d3

Please sign in to comment.