Michael Zolotukhin | 8e7e767 | 2016-06-08 23:13:21 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -lcssa -loop-simplify -indvars -S | FileCheck %s |
| 2 | target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" |
| 3 | target triple = "x86_64-unknown-unknown" |
| 4 | |
| 5 | @a = external global i32, align 4 |
| 6 | |
| 7 | ; Check that loop-simplify merges two loop exits, but preserves LCSSA form. |
| 8 | ; CHECK-LABEL: @foo |
| 9 | ; CHECK: for: |
| 10 | ; CHECK: %or.cond = and i1 %cmp1, %cmp2 |
| 11 | ; CHECK-NOT: for.cond: |
| 12 | ; CHECK: for.end: |
| 13 | ; CHECK: %a.lcssa = phi i32 [ %a, %for ] |
| 14 | define i32 @foo(i32 %x) { |
| 15 | entry: |
| 16 | br label %for |
| 17 | |
| 18 | for: |
| 19 | %iv = phi i32 [ 0, %entry ], [ %iv.next, %for.cond ] |
| 20 | %cmp1 = icmp eq i32 %x, 0 |
| 21 | %iv.next = add nuw nsw i32 %iv, 1 |
| 22 | %a = load i32, i32* @a |
| 23 | br i1 %cmp1, label %for.cond, label %for.end |
| 24 | |
| 25 | for.cond: |
| 26 | %cmp2 = icmp slt i32 %iv.next, 4 |
| 27 | br i1 %cmp2, label %for, label %for.end |
| 28 | |
| 29 | for.end: |
| 30 | %a.lcssa = phi i32 [ %a, %for ], [ %a, %for.cond ] |
| 31 | ret i32 %a.lcssa |
| 32 | } |