1; RUN: opt < %s -instcombine -S | FileCheck %s
2
3
4define i32 @test1(i32 %X, i8 %A) {
5        %shift.upgrd.1 = zext i8 %A to i32              ; <i32> [#uses=1]
6        ; can be logical shift.
7        %Y = ashr i32 %X, %shift.upgrd.1                ; <i32> [#uses=1]
8        %Z = and i32 %Y, 1              ; <i32> [#uses=1]
9        ret i32 %Z
10; CHECK-LABEL: @test1(
11; CHECK: lshr i32 %X, %shift.upgrd.1
12}
13
14define i32 @test2(i8 %tmp) {
15        %tmp3 = zext i8 %tmp to i32             ; <i32> [#uses=1]
16        %tmp4 = add i32 %tmp3, 7                ; <i32> [#uses=1]
17        %tmp5 = ashr i32 %tmp4, 3               ; <i32> [#uses=1]
18        ret i32 %tmp5
19; CHECK-LABEL: @test2(
20; CHECK: lshr i32 %tmp4, 3
21}
22
23define i64 @test3(i1 %X, i64 %Y, i1 %Cond) {
24  br i1 %Cond, label %T, label %F
25T:
26  %X2 = sext i1 %X to i64
27  br label %C
28F:
29  %Y2 = ashr i64 %Y, 63
30  br label %C
31C:
32  %P = phi i64 [%X2, %T], [%Y2, %F]
33  %S = ashr i64 %P, 12
34  ret i64 %S
35
36; CHECK-LABEL: @test3(
37; CHECK: %P = phi i64
38; CHECK-NEXT: ret i64 %P
39}
40
41define i64 @test4(i1 %X, i64 %Y, i1 %Cond) {
42  br i1 %Cond, label %T, label %F
43T:
44  %X2 = sext i1 %X to i64
45  br label %C
46F:
47  %Y2 = ashr i64 %Y, 63
48  br label %C
49C:
50  %P = phi i64 [%X2, %T], [%Y2, %F]
51  %R = shl i64 %P, 12
52  %S = ashr i64 %R, 12
53  ret i64 %S
54
55; CHECK-LABEL: @test4(
56; CHECK: %P = phi i64
57; CHECK-NEXT: ret i64 %P
58}
59
60; rdar://7732987
61define i32 @test5(i32 %Y) {
62  br i1 undef, label %A, label %C
63A:
64  br i1 undef, label %B, label %D
65B:
66  br label %D
67C:
68  br i1 undef, label %D, label %E
69D:
70  %P = phi i32 [0, %A], [0, %B], [%Y, %C]
71  %S = ashr i32 %P, 16
72  ret i32 %S
73; CHECK-LABEL: @test5(
74; CHECK: %P = phi i32
75; CHECK-NEXT: ashr i32 %P, 16
76E:
77  ret i32 0
78}
79