Skip to content

Commit

Permalink
[InstCombine] add tests for shift-shift patterns; NFC
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293487 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
rotateright committed Jan 30, 2017
1 parent 0f1ef54 commit c8ac276
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions test/Transforms/InstCombine/shift.ll
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,8 @@ define <2 x i32> @test49_splat_vec(<2 x i32> %x) {
ret <2 x i32> %B
}

; (X <<nsw C1) >>s C2 --> X >>s (C2-C1)

define i32 @test50(i32 %x) {
; CHECK-LABEL: @test50(
; CHECK-NEXT: [[B:%.*]] = ashr i32 %x, 2
Expand All @@ -892,6 +894,21 @@ define i32 @test50(i32 %x) {
ret i32 %B
}

; (X <<nsw C1) >>s C2 --> X >>s (C2-C1)

define <2 x i32> @test50_splat_vec(<2 x i32> %x) {
; CHECK-LABEL: @test50_splat_vec(
; CHECK-NEXT: [[A:%.*]] = shl nsw <2 x i32> %x, <i32 1, i32 1>
; CHECK-NEXT: [[B:%.*]] = ashr <2 x i32> [[A]], <i32 3, i32 3>
; CHECK-NEXT: ret <2 x i32> [[B]]
;
%A = shl nsw <2 x i32> %x, <i32 1, i32 1>
%B = ashr <2 x i32> %A, <i32 3, i32 3>
ret <2 x i32> %B
}

; (X <<nuw C1) >>u C2 --> X >>u (C2-C1)

define i32 @test51(i32 %x) {
; CHECK-LABEL: @test51(
; CHECK-NEXT: [[B:%.*]] = lshr i32 %x, 2
Expand All @@ -902,6 +919,46 @@ define i32 @test51(i32 %x) {
ret i32 %B
}

; (X <<nuw C1) >>u C2 --> X >>u (C2-C1) with splats
; Also, check that exact is propagated.

define <2 x i32> @test51_splat_vec(<2 x i32> %x) {
; CHECK-LABEL: @test51_splat_vec(
; CHECK-NEXT: [[A:%.*]] = shl nuw <2 x i32> %x, <i32 1, i32 1>
; CHECK-NEXT: [[B:%.*]] = lshr exact <2 x i32> [[A]], <i32 3, i32 3>
; CHECK-NEXT: ret <2 x i32> [[B]]
;
%A = shl nuw <2 x i32> %x, <i32 1, i32 1>
%B = lshr exact <2 x i32> %A, <i32 3, i32 3>
ret <2 x i32> %B
}

; (X << C1) >>u C2 --> X >>u (C2-C1) & (-1 >> C2)

define i32 @test51_no_nuw(i32 %x) {
; CHECK-LABEL: @test51_no_nuw(
; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 %x, 2
; CHECK-NEXT: [[B:%.*]] = and i32 [[TMP1]], 536870911
; CHECK-NEXT: ret i32 [[B]]
;
%A = shl i32 %x, 1
%B = lshr i32 %A, 3
ret i32 %B
}

; (X << C1) >>u C2 --> X >>u (C2-C1) & (-1 >> C2)

define <2 x i32> @test51_no_nuw_splat_vec(<2 x i32> %x) {
; CHECK-LABEL: @test51_no_nuw_splat_vec(
; CHECK-NEXT: [[A:%.*]] = shl <2 x i32> %x, <i32 1, i32 1>
; CHECK-NEXT: [[B:%.*]] = lshr <2 x i32> [[A]], <i32 3, i32 3>
; CHECK-NEXT: ret <2 x i32> [[B]]
;
%A = shl <2 x i32> %x, <i32 1, i32 1>
%B = lshr <2 x i32> %A, <i32 3, i32 3>
ret <2 x i32> %B
}

define i32 @test52(i32 %x) {
; CHECK-LABEL: @test52(
; CHECK-NEXT: [[B:%.*]] = shl nsw i32 %x, 2
Expand Down

0 comments on commit c8ac276

Please sign in to comment.