1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=aggressive-instcombine -S | FileCheck %s
4 define i16 @trunc_phi(i8 %x) {
5 ; CHECK-LABEL: @trunc_phi(
6 ; CHECK-NEXT: LoopHeader:
7 ; CHECK-NEXT: [[ZEXT:%.*]] = zext i8 [[X:%.*]] to i16
8 ; CHECK-NEXT: br label [[LOOP:%.*]]
10 ; CHECK-NEXT: [[ZEXT2:%.*]] = phi i16 [ [[ZEXT]], [[LOOPHEADER:%.*]] ], [ [[SHL:%.*]], [[LOOP]] ]
11 ; CHECK-NEXT: [[J:%.*]] = phi i32 [ 0, [[LOOPHEADER]] ], [ [[I:%.*]], [[LOOP]] ]
12 ; CHECK-NEXT: [[SHL]] = shl i16 [[ZEXT2]], 1
13 ; CHECK-NEXT: [[I]] = add i32 [[J]], 1
14 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I]], 10
15 ; CHECK-NEXT: br i1 [[CMP]], label [[LOOPEND:%.*]], label [[LOOP]]
17 ; CHECK-NEXT: ret i16 [[SHL]]
20 %zext = zext i8 %x to i32
24 %zext2 = phi i32 [%zext, %LoopHeader], [%shl, %Loop]
25 %j = phi i32 [0, %LoopHeader], [%i, %Loop]
26 %shl = shl i32 %zext2, 1
27 %trunc = trunc i32 %shl to i16
29 %cmp = icmp eq i32 %i, 10
30 br i1 %cmp, label %LoopEnd, label %Loop
36 define i16 @trunc_phi2(i8 %x, i32 %sw) {
37 ; CHECK-LABEL: @trunc_phi2(
38 ; CHECK-NEXT: LoopHeader:
39 ; CHECK-NEXT: [[ZEXT:%.*]] = zext i8 [[X:%.*]] to i16
40 ; CHECK-NEXT: switch i32 [[SW:%.*]], label [[LOOPEND:%.*]] [
41 ; CHECK-NEXT: i32 0, label [[LOOP:%.*]]
42 ; CHECK-NEXT: i32 1, label [[LOOP]]
45 ; CHECK-NEXT: [[ZEXT2:%.*]] = phi i16 [ [[ZEXT]], [[LOOPHEADER:%.*]] ], [ [[ZEXT]], [[LOOPHEADER]] ], [ [[SHL:%.*]], [[LOOP]] ]
46 ; CHECK-NEXT: [[J:%.*]] = phi i32 [ 0, [[LOOPHEADER]] ], [ 0, [[LOOPHEADER]] ], [ [[I:%.*]], [[LOOP]] ]
47 ; CHECK-NEXT: [[SHL]] = shl i16 [[ZEXT2]], 1
48 ; CHECK-NEXT: [[I]] = add i32 [[J]], 1
49 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I]], 10
50 ; CHECK-NEXT: br i1 [[CMP]], label [[LOOPEND]], label [[LOOP]]
52 ; CHECK-NEXT: [[ZEXT3:%.*]] = phi i16 [ [[ZEXT]], [[LOOPHEADER]] ], [ [[ZEXT2]], [[LOOP]] ]
53 ; CHECK-NEXT: ret i16 [[ZEXT3]]
56 %zext = zext i8 %x to i32
57 switch i32 %sw, label %LoopEnd [ i32 0, label %Loop
61 %zext2 = phi i32 [%zext, %LoopHeader], [%zext, %LoopHeader], [%shl, %Loop]
62 %j = phi i32 [0, %LoopHeader], [0, %LoopHeader], [%i, %Loop]
63 %shl = shl i32 %zext2, 1
65 %cmp = icmp eq i32 %i, 10
66 br i1 %cmp, label %LoopEnd, label %Loop
69 %zext3 = phi i32 [%zext, %LoopHeader], [%zext2, %Loop]
70 %trunc = trunc i32 %zext3 to i16