Dmitri Gribenko | b137c9e | 2012-12-30 01:28:40 +0000 | [diff] [blame] | 1 | ; RUN: opt -S -loop-rotate < %s | FileCheck %s |
Daniel Jasper | aec2fa3 | 2016-12-19 08:22:17 +0000 | [diff] [blame] | 2 | ; RUN: opt -S -passes='require<targetir>,require<assumptions>,loop(rotate)' < %s | FileCheck %s |
Justin Bogner | d0d2341 | 2016-05-03 22:02:31 +0000 | [diff] [blame] | 3 | |
Chris Lattner | b01c24a | 2010-09-06 01:10:22 +0000 | [diff] [blame] | 4 | target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" |
| 5 | target triple = "x86_64-apple-darwin10.0.0" |
| 6 | |
| 7 | ; PR5319 - The "arrayidx" gep should be hoisted, not duplicated. We should |
| 8 | ; end up with one phi node. |
| 9 | define void @test1() nounwind ssp { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 10 | ; CHECK-LABEL: @test1( |
Chris Lattner | b01c24a | 2010-09-06 01:10:22 +0000 | [diff] [blame] | 11 | entry: |
| 12 | %array = alloca [20 x i32], align 16 |
| 13 | br label %for.cond |
| 14 | |
| 15 | for.cond: ; preds = %for.body, %entry |
| 16 | %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ] |
| 17 | %cmp = icmp slt i32 %i.0, 100 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 18 | %arrayidx = getelementptr inbounds [20 x i32], [20 x i32]* %array, i64 0, i64 0 |
Chris Lattner | b01c24a | 2010-09-06 01:10:22 +0000 | [diff] [blame] | 19 | br i1 %cmp, label %for.body, label %for.end |
| 20 | |
| 21 | ; CHECK: for.body: |
| 22 | ; CHECK-NEXT: phi i32 [ 0 |
| 23 | ; CHECK-NEXT: store i32 0 |
| 24 | |
| 25 | for.body: ; preds = %for.cond |
| 26 | store i32 0, i32* %arrayidx, align 16 |
| 27 | %inc = add nsw i32 %i.0, 1 |
| 28 | br label %for.cond |
| 29 | |
| 30 | for.end: ; preds = %for.cond |
| 31 | %arrayidx.lcssa = phi i32* [ %arrayidx, %for.cond ] |
| 32 | call void @g(i32* %arrayidx.lcssa) nounwind |
| 33 | ret void |
| 34 | } |
| 35 | |
| 36 | declare void @g(i32*) |
| 37 | |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 38 | ; CHECK-LABEL: @test2( |
James Molloy | 4f6fb95 | 2012-12-20 16:04:27 +0000 | [diff] [blame] | 39 | define void @test2() nounwind ssp { |
| 40 | entry: |
| 41 | %array = alloca [20 x i32], align 16 |
| 42 | br label %for.cond |
| 43 | |
| 44 | for.cond: ; preds = %for.body, %entry |
| 45 | %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ] |
| 46 | %cmp = icmp slt i32 %i.0, 100 |
| 47 | ; CHECK: call void @f |
| 48 | ; CHECK-NOT: call void @f |
| 49 | call void @f() noduplicate |
| 50 | br i1 %cmp, label %for.body, label %for.end |
| 51 | |
| 52 | for.body: ; preds = %for.cond |
| 53 | %inc = add nsw i32 %i.0, 1 |
| 54 | call void @h() |
| 55 | br label %for.cond |
| 56 | |
| 57 | for.end: ; preds = %for.cond |
| 58 | ret void |
| 59 | ; CHECK: } |
| 60 | } |
| 61 | |
| 62 | declare void @f() noduplicate |
| 63 | declare void @h() |