1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -loop-idiom -mtriple=x86_64 -mcpu=corei7 < %s -S | FileCheck %s
4 declare void @escape_inner(i8, i8, i8, i1, i8)
5 declare void @escape_outer(i8, i8, i8, i1, i8)
7 ; On corei7, lzcount is not cheap, so we don't transform.
8 define i8 @n(i8 %val, i8 %start, i8 %extraoffset) {
11 ; CHECK-NEXT: br label [[LOOP:%.*]]
13 ; CHECK-NEXT: [[IV:%.*]] = phi i8 [ [[START:%.*]], [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
14 ; CHECK-NEXT: [[NBITS:%.*]] = add nsw i8 [[IV]], [[EXTRAOFFSET:%.*]]
15 ; CHECK-NEXT: [[VAL_SHIFTED:%.*]] = lshr i8 [[VAL:%.*]], [[NBITS]]
16 ; CHECK-NEXT: [[VAL_SHIFTED_ISZERO:%.*]] = icmp eq i8 [[VAL_SHIFTED]], 0
17 ; CHECK-NEXT: [[IV_NEXT]] = add i8 [[IV]], 1
18 ; CHECK-NEXT: call void @escape_inner(i8 [[IV]], i8 [[NBITS]], i8 [[VAL_SHIFTED]], i1 [[VAL_SHIFTED_ISZERO]], i8 [[IV_NEXT]])
19 ; CHECK-NEXT: br i1 [[VAL_SHIFTED_ISZERO]], label [[END:%.*]], label [[LOOP]]
21 ; CHECK-NEXT: [[IV_RES:%.*]] = phi i8 [ [[IV]], [[LOOP]] ]
22 ; CHECK-NEXT: [[NBITS_RES:%.*]] = phi i8 [ [[NBITS]], [[LOOP]] ]
23 ; CHECK-NEXT: [[VAL_SHIFTED_RES:%.*]] = phi i8 [ [[VAL_SHIFTED]], [[LOOP]] ]
24 ; CHECK-NEXT: [[VAL_SHIFTED_ISZERO_RES:%.*]] = phi i1 [ [[VAL_SHIFTED_ISZERO]], [[LOOP]] ]
25 ; CHECK-NEXT: [[IV_NEXT_RES:%.*]] = phi i8 [ [[IV_NEXT]], [[LOOP]] ]
26 ; CHECK-NEXT: call void @escape_outer(i8 [[IV_RES]], i8 [[NBITS_RES]], i8 [[VAL_SHIFTED_RES]], i1 [[VAL_SHIFTED_ISZERO_RES]], i8 [[IV_NEXT_RES]])
27 ; CHECK-NEXT: ret i8 [[IV_RES]]
33 %iv = phi i8 [ %start, %entry ], [ %iv.next, %loop ]
34 %nbits = add nsw i8 %iv, %extraoffset
35 %val.shifted = lshr i8 %val, %nbits
36 %val.shifted.iszero = icmp eq i8 %val.shifted, 0
37 %iv.next = add i8 %iv, 1
39 call void @escape_inner(i8 %iv, i8 %nbits, i8 %val.shifted, i1 %val.shifted.iszero, i8 %iv.next)
41 br i1 %val.shifted.iszero, label %end, label %loop
44 %iv.res = phi i8 [ %iv, %loop ]
45 %nbits.res = phi i8 [ %nbits, %loop ]
46 %val.shifted.res = phi i8 [ %val.shifted, %loop ]
47 %val.shifted.iszero.res = phi i1 [ %val.shifted.iszero, %loop ]
48 %iv.next.res = phi i8 [ %iv.next, %loop ]
50 call void @escape_outer(i8 %iv.res, i8 %nbits.res, i8 %val.shifted.res, i1 %val.shifted.iszero.res, i8 %iv.next.res)