Skip to content

Commit

Permalink
[InstCombine] Pre-commit tests (NFC)
Browse files Browse the repository at this point in the history
  • Loading branch information
AreaZR committed Jun 24, 2024
1 parent 905c58f commit ec19249
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
43 changes: 43 additions & 0 deletions llvm/test/Transforms/InstCombine/ashr-lshr.ll
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,17 @@ define i32 @lshr_mul_times_3_div_2_exact(i32 %x) {
ret i32 %lshr
}

define i32 @reduce_shift(i32 %x) {
; CHECK-LABEL: @reduce_shift(
; CHECK-NEXT: [[MUL:%.*]] = mul nsw i32 [[X:%.*]], 12
; CHECK-NEXT: [[SHR:%.*]] = ashr i32 [[MUL]], 4
; CHECK-NEXT: ret i32 [[SHR]]
;
%mul = mul nsw i32 %x, 12
%shr = ashr i32 %mul, 4
ret i32 %shr
}

; Negative test

define i32 @lshr_mul_times_3_div_2_no_flags(i32 %0) {
Expand All @@ -640,6 +651,17 @@ define i32 @lshr_mul_times_3_div_2_no_flags(i32 %0) {
ret i32 %lshr
}

define i32 @reduce_shift_no_nsw(i32 %x) {
; CHECK-LABEL: @reduce_shift_no_nsw(
; CHECK-NEXT: [[MUL:%.*]] = mul nuw i32 [[X:%.*]], 12
; CHECK-NEXT: [[SHR:%.*]] = ashr i32 [[MUL]], 4
; CHECK-NEXT: ret i32 [[SHR]]
;
%mul = mul nuw i32 %x, 12
%shr = ashr i32 %mul, 4
ret i32 %shr
}

; Negative test

define i32 @mul_times_3_div_2_multiuse_lshr(i32 %x) {
Expand Down Expand Up @@ -863,3 +885,24 @@ define i32 @ashr_mul_times_5_div_4_exact_2(i32 %x) {
}

declare void @use(i32)
define i32 @reduce_shift_wrong_mul(i32 %x) {
; CHECK-LABEL: @reduce_shift_wrong_mul(
; CHECK-NEXT: [[MUL:%.*]] = mul nsw i32 [[X:%.*]], 11
; CHECK-NEXT: [[SHR:%.*]] = ashr i32 [[MUL]], 4
; CHECK-NEXT: ret i32 [[SHR]]
;
%mul = mul nsw i32 %x, 11
%shr = ashr i32 %mul, 4
ret i32 %shr
}

define i32 @reduce_shift_exact(i32 %x) {
; CHECK-LABEL: @reduce_shift_exact(
; CHECK-NEXT: [[MUL:%.*]] = mul nsw i32 [[X:%.*]], 12
; CHECK-NEXT: [[SHR:%.*]] = ashr exact i32 [[MUL]], 4
; CHECK-NEXT: ret i32 [[SHR]]
;
%mul = mul nsw i32 %x, 12
%shr = ashr exact i32 %mul, 4
ret i32 %shr
}
48 changes: 48 additions & 0 deletions llvm/test/Transforms/InstCombine/lshr.ll
Original file line number Diff line number Diff line change
Expand Up @@ -1523,3 +1523,51 @@ define <2 x i8> @bool_add_lshr_vec_wrong_shift_amt(<2 x i1> %a, <2 x i1> %b) {
%lshr = lshr <2 x i8> %add, <i8 1, i8 2>
ret <2 x i8> %lshr
}

define i32 @reduce_shift(i32 %x) {
; CHECK-LABEL: @reduce_shift(
; CHECK-NEXT: [[MUL:%.*]] = mul nuw i32 [[X:%.*]], 12
; CHECK-NEXT: [[SHR:%.*]] = lshr i32 [[MUL]], 4
; CHECK-NEXT: ret i32 [[SHR]]
;
%mul = mul nuw i32 %x, 12
%shr = lshr i32 %mul, 4
ret i32 %shr
}

; Negative test

define i32 @reduce_shift_no_nuw(i32 %x) {
; CHECK-LABEL: @reduce_shift_no_nuw(
; CHECK-NEXT: [[MUL:%.*]] = mul nsw i32 [[X:%.*]], 12
; CHECK-NEXT: [[SHR:%.*]] = lshr i32 [[MUL]], 4
; CHECK-NEXT: ret i32 [[SHR]]
;
%mul = mul nsw i32 %x, 12
%shr = lshr i32 %mul, 4
ret i32 %shr
}

; Negative test

define i32 @reduce_shift_wrong_mul(i32 %x) {
; CHECK-LABEL: @reduce_shift_wrong_mul(
; CHECK-NEXT: [[MUL:%.*]] = mul nuw i32 [[X:%.*]], 11
; CHECK-NEXT: [[SHR:%.*]] = lshr i32 [[MUL]], 4
; CHECK-NEXT: ret i32 [[SHR]]
;
%mul = mul nuw i32 %x, 11
%shr = lshr i32 %mul, 4
ret i32 %shr
}

define i32 @reduce_shift_exact(i32 %x) {
; CHECK-LABEL: @reduce_shift_exact(
; CHECK-NEXT: [[MUL:%.*]] = mul nuw i32 [[X:%.*]], 12
; CHECK-NEXT: [[SHR:%.*]] = lshr exact i32 [[MUL]], 4
; CHECK-NEXT: ret i32 [[SHR]]
;
%mul = mul nuw i32 %x, 12
%shr = lshr exact i32 %mul, 4
ret i32 %shr
}

0 comments on commit ec19249

Please sign in to comment.