Eric Christopher | cee313d | 2019-04-17 04:52:47 +0000 | [diff] [blame] | 1 | ; RUN: opt -S -indvars < %s | FileCheck %s |
| 2 | |
| 3 | ; Do not rewrite the user outside the loop because we must keep the instruction |
| 4 | ; inside the loop due to store. Rewrite doesn't give us any profit. |
| 5 | define void @f(i32 %length.i.88, i32 %length.i, i8* %tmp12, i32 %tmp10, i8* %tmp8) { |
| 6 | ; CHECK-LABEL: @f( |
| 7 | not_zero11.preheader: |
| 8 | %tmp13 = icmp ugt i32 %length.i, %length.i.88 |
| 9 | %tmp14 = select i1 %tmp13, i32 %length.i.88, i32 %length.i |
| 10 | %tmp15 = icmp sgt i32 %tmp14, 0 |
| 11 | br i1 %tmp15, label %not_zero11, label %not_zero11.postloop |
| 12 | |
| 13 | not_zero11: |
| 14 | %v_1 = phi i32 [ %tmp22, %not_zero11 ], [ 0, %not_zero11.preheader ] |
| 15 | %tmp16 = zext i32 %v_1 to i64 |
| 16 | %tmp17 = getelementptr inbounds i8, i8* %tmp8, i64 %tmp16 |
| 17 | %tmp18 = load i8, i8* %tmp17, align 1 |
| 18 | %tmp19 = zext i8 %tmp18 to i32 |
| 19 | %tmp20 = or i32 %tmp19, %tmp10 |
| 20 | %tmp21 = trunc i32 %tmp20 to i8 |
| 21 | %addr22 = getelementptr inbounds i8, i8* %tmp12, i64 %tmp16 |
| 22 | store i8 %tmp21, i8* %addr22, align 1 |
| 23 | %tmp22 = add nuw nsw i32 %v_1, 1 |
| 24 | %tmp23 = icmp slt i32 %tmp22, %tmp14 |
| 25 | br i1 %tmp23, label %not_zero11, label %main.exit.selector |
| 26 | |
| 27 | main.exit.selector: |
| 28 | ; CHECK-LABEL: main.exit.selector: |
| 29 | ; CHECK: %tmp22.lcssa = phi i32 [ %tmp22, %not_zero11 ] |
| 30 | ; CHECK: %tmp24 = icmp slt i32 %tmp22.lcssa, %length. |
| 31 | %tmp24 = icmp slt i32 %tmp22, %length.i |
| 32 | br i1 %tmp24, label %not_zero11.postloop, label %leave |
| 33 | |
| 34 | leave: |
| 35 | ret void |
| 36 | |
| 37 | not_zero11.postloop: |
| 38 | ret void |
| 39 | } |
| 40 | |
| 41 | ; Rewrite the user outside the loop because there is no hard users inside the loop. |
| 42 | define void @f1(i32 %length.i.88, i32 %length.i, i8* %tmp12, i32 %tmp10, i8* %tmp8) { |
| 43 | ; CHECK-LABEL: @f1( |
| 44 | not_zero11.preheader: |
| 45 | %tmp13 = icmp ugt i32 %length.i, %length.i.88 |
| 46 | %tmp14 = select i1 %tmp13, i32 %length.i.88, i32 %length.i |
| 47 | %tmp15 = icmp sgt i32 %tmp14, 0 |
| 48 | br i1 %tmp15, label %not_zero11, label %not_zero11.postloop |
| 49 | |
| 50 | not_zero11: |
| 51 | %v_1 = phi i32 [ %tmp22, %not_zero11 ], [ 0, %not_zero11.preheader ] |
| 52 | %tmp16 = zext i32 %v_1 to i64 |
| 53 | %tmp17 = getelementptr inbounds i8, i8* %tmp8, i64 %tmp16 |
| 54 | %tmp18 = load i8, i8* %tmp17, align 1 |
| 55 | %tmp19 = zext i8 %tmp18 to i32 |
| 56 | %tmp20 = or i32 %tmp19, %tmp10 |
| 57 | %tmp21 = trunc i32 %tmp20 to i8 |
| 58 | %addr22 = getelementptr inbounds i8, i8* %tmp12, i64 %tmp16 |
| 59 | %tmp22 = add nuw nsw i32 %v_1, 1 |
| 60 | %tmp23 = icmp slt i32 %tmp22, %tmp14 |
| 61 | br i1 %tmp23, label %not_zero11, label %main.exit.selector |
| 62 | |
| 63 | main.exit.selector: |
| 64 | ; CHECK-LABEL: main.exit.selector: |
| 65 | ; CHECK: %tmp24 = icmp slt i32 %tmp14, %length.i |
| 66 | %tmp24 = icmp slt i32 %tmp22, %length.i |
| 67 | br i1 %tmp24, label %not_zero11.postloop, label %leave |
| 68 | |
| 69 | leave: |
| 70 | ret void |
| 71 | |
| 72 | not_zero11.postloop: |
| 73 | ret void |
| 74 | } |